-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bugfix / Core] Prefix Caching Guards (merged with main) #4846
Conversation
@@ -251,6 +263,18 @@ def get_sliding_window(self) -> Optional[int]: | |||
return None | |||
return getattr(self.hf_text_config, "sliding_window", None) | |||
|
|||
def get_sliding_window(self) -> Optional[int]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does it work for the model that already has sliding window like mistral?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not sure what you mean?
If the user does not specify --disable-sliding-window
then we use sliding window if the model supports it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh maybe it is a dumb question, but my question is for models that has slinding window by default https://huggingface.co/mistralai/Mistral-7B-v0.1/blob/26bca36bde8333b5d7f72e9ed20ccda6a618af24/config.json#L18, if we use --disable-sliding-window, does it work properly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, specifically what this does is handle a case like Mistral.
--disable-sliding-window
means we turn off sliding window and set max_model_len=sliding_window
So in the case of Mistral, we then would treat the model as a 4096 ctx-len model with no sliding window.
The reason for this feature is that if we want to use features that are incompatible with sliding window (e.g. APC or chunked prefill), then there is a pathway to disable sliding window
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. that makes sense! Thanks for the explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Minor comments. Didn't review _get_and_verify_max_len and _get_and_verify_dtype assuming it is just code refactored (lmk if it is wrong)
vllm/config.py
Outdated
if self.disable_sliding_window: | ||
logger.info("Sliding window is disabled per configuration. " | ||
"Model max length will be capped at sliding window " | ||
"length.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"length.") | |
"length, %d tokens", self.get_hf_config_sliding_window()) |
vllm/engine/arg_utils.py
Outdated
parser.add_argument('--disable-sliding-window', | ||
action='store_true', | ||
help='Disables sliding window if the model ' | ||
'supports sliding window') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you mention the model length is capped by the slinding window size?
because sliding window is propogated to attention, this is going to require me to edit most model files. Will get back to this tomorrow after I get mistral over the line |
…t non-uniform caching
@@ -173,18 +168,14 @@ def __init__( | |||
# Requires transformers > 4.32.0 | |||
rope_theta = getattr(config, "rope_theta", 1000000) | |||
rope_scaling = getattr(config, "rope_scaling", None) | |||
use_sliding_window = (config.use_sliding_window |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
"architectures": [
"Qwen2ForCausalLM"
],
"attention_dropout": 0.0,
"bos_token_id": 151643,
"eos_token_id": 151645,
"hidden_act": "silu",
"hidden_size": 4096,
"initializer_range": 0.02,
"intermediate_size": 11008,
"max_position_embeddings": 32768,
"max_window_layers": 28, << qwen2 uses sliding window for some layers
"model_type": "qwen2",
"num_attention_heads": 32,
"num_hidden_layers": 32,
"num_key_value_heads": 32,
"rms_norm_eps": 1e-06,
"rope_theta": 1000000.0,
"sliding_window": 32768,
"tie_word_embeddings": false,
"torch_dtype": "bfloat16",
"transformers_version": "4.37.0",
"use_cache": true,
"use_sliding_window": false, << qwen2 does not use sliding window by default
"vocab_size": 151936
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we had a bug in Qwen2 - this path will not be followed very often b/c qwen2 does not use sliding window by default
Currently, if use_sliding_window=True
, only some layers will use sliding window. But we have global KV cache management that would treat KVs the same. So I do not see how it is possible that this could be working correctly.
This is not a very common user path because they would have to opt into sliding window on Qwen.
So I disabled this by default.
Disabling sliding window ended up being more work than I expected because we broke some abstractions where the models are accessing the hf_config to determine whether sliding window is used when passing arguments to attention. As a result, the user's specification is ignored. So, I updated Additionally, I noticed in this that Qwen2 attempts to support having only some layers with sliding window. We do not support this in our KV cache management, so I removed this bug by Failing if the system is configured this way. (note: this is not a popular codepath b/c Qwen2 does not use sliding window by default. |
…t#4846) Co-authored-by: rsnm2 <[email protected]> Co-authored-by: Robert Shaw <[email protected]>
…t#4846) Co-authored-by: rsnm2 <[email protected]> Co-authored-by: Robert Shaw <[email protected]>
…t#4846) Co-authored-by: rsnm2 <[email protected]> Co-authored-by: Robert Shaw <[email protected]>
…t#4846) Co-authored-by: rsnm2 <[email protected]> Co-authored-by: Robert Shaw <[email protected]>
…t#4846) Co-authored-by: rsnm2 <[email protected]> Co-authored-by: Robert Shaw <[email protected]>
…t#4846) Co-authored-by: rsnm2 <[email protected]> Co-authored-by: Robert Shaw <[email protected]>
Updated version of #3903
PR Checklist (Click to Expand)
Thank you for your contribution to vLLM! Before submitting the pull request, please ensure the PR meets the following criteria. This helps vLLM maintain the code quality and improve the efficiency of the review process.
PR Title and Classification
Only specific types of PRs will be reviewed. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:
[Bugfix]
for bug fixes.[CI/Build]
for build or continuous integration improvements.[Doc]
for documentation fixes and improvements.[Model]
for adding a new model or improving an existing model. Model name should appear in the title.[Frontend]
For changes on the vLLM frontend (e.g., OpenAI API server,LLM
class, etc.)[Kernel]
for changes affecting CUDA kernels or other compute kernels.[Core]
for changes in the core vLLM logic (e.g.,LLMEngine
,AsyncLLMEngine
,Scheduler
, etc.)[Hardware][Vendor]
for hardware-specific changes. Vendor name should appear in the prefix (e.g.,[Hardware][AMD]
).[Misc]
for PRs that do not fit the above categories. Please use this sparingly.Note: If the PR spans more than one category, please include all relevant prefixes.
Code Quality
The PR need to meet the following code quality standards:
format.sh
to format your code.docs/source/
if the PR modifies the user-facing behaviors of vLLM. It helps vLLM user understand and utilize the new features or changes.Notes for Large Changes
Please keep the changes as concise as possible. For major architectural changes (>500 LOC excluding kernel/data/config/test), we would expect a GitHub issue (RFC) discussing the technical design and justification. Otherwise, we will tag it with
rfc-required
and might not go through the PR.What to Expect for the Reviews
The goal of the vLLM team is to be a transparent reviewing machine. We would like to make the review process transparent and efficient and make sure no contributor feel confused or frustrated. However, the vLLM team is small, so we need to prioritize some PRs over others. Here is what you can expect from the review process:
action-required
label on the PR if there are changes required. The contributor should address the comments and ping the reviewer to re-review the PR.Thank You
Finally, thank you for taking the time to read these guidelines and for your interest in contributing to vLLM. Your contributions make vLLM a great tool for everyone!