-
Notifications
You must be signed in to change notification settings - Fork 79
Fix vLLM crash when max_gen_toks exceeds model context window #153
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
Open
Ali-Elganzory
wants to merge
3
commits into
mlfoundations:main
Choose a base branch
from
Ali-Elganzory:fix/vllm-context-window-crash
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+42
−2
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
a9a4fa0
fix: cap max_gen_toks to prevent vLLM crash when exceeding context wi…
Ali-Elganzory 977d755
Address PR feedback: add try-catch, prompt_length check, and constant
Ali-Elganzory e93d565
fix: cap max_new_tokens to avoid degraded/undefined behavior when exc…
Ali-Elganzory File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,26 @@ def _normalize_model_args(self, model: LM, instances: List[Instance]) -> List[In | |
| if "4o" in model.model: | ||
| instance.args[1]["max_tokens"] = min(max_new_tokens, 16384) | ||
| elif isinstance(model, lm_eval_models.vllm_causallms.VLLM): | ||
| instance.args[1]["max_gen_toks"] = max_new_tokens | ||
| # Get prompt from instance.args[0] (the templated string) | ||
| prompt = instance.args[0] | ||
| prompt_length = len(model.tokenizer.encode(prompt)) | ||
|
|
||
| # Get max model length from vLLM engine | ||
| max_model_len = model.model.llm_engine.model_config.max_model_len | ||
|
|
||
| # Calculate max allowed generation tokens (16 token safety buffer) | ||
| max_allowed = max_model_len - prompt_length - 16 | ||
|
||
|
|
||
| # Cap to available space | ||
| capped_max_new_tokens = min(max_new_tokens, max(1, max_allowed)) | ||
|
|
||
| if capped_max_new_tokens < max_new_tokens: | ||
| self.logger.warning( | ||
| f"max_new_tokens ({max_new_tokens}) capped to {capped_max_new_tokens} " | ||
| f"(prompt: {prompt_length} tokens, model max: {max_model_len})" | ||
| ) | ||
|
|
||
| instance.args[1]["max_gen_toks"] = capped_max_new_tokens | ||
| else: # Huggingface | ||
| instance.args[1]["max_new_tokens"] = max_new_tokens | ||
| return instances | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
thanks, can you wrap lines 57 to 64 in a try catch?
Also maybe check if prompt_length is extremely long (> max_model_len)
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.
Good point, will wrap it in a try catch.
If
prompt_length > max_model_len, we could log a warning.capped_max_new_tokenswill be set to 1, and the prompt will be truncated to fit into the context window. We are fine with that logic, right?