Fix vLLM crash when max_gen_toks exceeds model context window#153
Open
Ali-Elganzory wants to merge 3 commits intomlfoundations:mainfrom
Open
Fix vLLM crash when max_gen_toks exceeds model context window#153Ali-Elganzory wants to merge 3 commits intomlfoundations:mainfrom
Ali-Elganzory wants to merge 3 commits intomlfoundations:mainfrom
Conversation
Author
|
Hi @neginraoof, could you please review this PR when you have a chance? |
neginraoof
reviewed
Jan 4, 2026
eval/task.py
Outdated
| 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] |
Collaborator
There was a problem hiding this comment.
thanks, can you wrap lines 57 to 64 in a try catch?
Also maybe check if prompt_length is extremely long (> max_model_len)
Author
There was a problem hiding this comment.
Good point, will wrap it in a try catch.
If prompt_length > max_model_len, we could log a warning.
capped_max_new_tokens will be set to 1, and the prompt will be truncated to fit into the context window. We are fine with that logic, right?
eval/task.py
Outdated
| 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 |
Collaborator
There was a problem hiding this comment.
can you create a constant and name it instead of using 16 here
Collaborator
|
Thanks for creating the PR! |
…eeding context window - HuggingFace's transformers does NOT fail when the `context_length < prompt_length + max_new_tokens`; the behavior is rather undefined or degraded. - Cap the max number of generated tokens for both HF and vLLM.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #152 by dynamically capping
max_gen_toksto fit within the model's context window when using vLLM backend.Problem Solved
ValueError: please provide at least one promptwhenmax_gen_toksexceedsmax_model_len - prompt_lengthChanges
File Modified:
eval/task.pyKey Improvements
max_gen_toksinstead of crashingCode Changes
Testing
Impact