Repository navigation
fix(vllm): reject attention masks a token prompt cannot represent (#3884) - #3900
Merged
Merged
Conversation
_apply_attention_mask filtered every masked-out token, so an interior hole deleted a token from the middle of the prompt and renumbered the rest. A vLLM token prompt is a bare ID sequence and cannot express a hole, so the translation silently changed prompt IDs, length, and positions. Non-binary mask values were also accepted via bool(), and a mask passed with a text prompt was ignored entirely. Mirror the SGLang adapter contract: accept only boolean/0-1 masks, require the kept positions to be contiguous (left or right padding removal only), and reject a mask supplied with a text prompt. Valid padding removal keeps the same token sequence as before. Fixes #3884
Record which masks a vLLM/SGLang token prompt can represent, the rejected cases, and the before/after behavior for the vLLM adapter.
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.
Fixes #3884
Root cause
_normalize_vllm_inputs/_apply_attention_mask(gptqmodel/utils/vllm.py) filtered out every masked position:A vLLM token prompt is a bare ID sequence, so an interior zero deleted a token from the middle of the prompt and renumbered every later position. The adapter also coerced any truthy value with
bool()and ignored a mask supplied with a text prompt. The SGLang adapter already rejected both.Reproduced on
daa5dae:Fix
Mirror the SGLang contract in the vLLM adapter:
0/1integer mask values are accepted (TypeErrorotherwise);ValueErroron an interior hole);ValueError).Valid padding removal returns exactly the same token sequence as before.
Flow
flowchart TD A["_normalize_vllm_inputs(prompts, input_ids, attention_mask)"] --> B{"text prompt?"} B -- Yes --> C{"mask supplied?"} C -- Yes --> R1["ValueError: mask needs input_ids"] C -- No --> OK1["Pass text through"] B -- No --> D["_apply_attention_mask"] D --> E{"values boolean or 0/1?"} E -- No --> R2["TypeError"] E -- Yes --> F{"kept positions contiguous?"} F -- No --> R3["ValueError: interior hole"] F -- Yes --> G{"any token kept?"} G -- No --> R4["ValueError: removed every token"] G -- Yes --> H["Trim left and right padding only"] style R1 fill:#fee,stroke:#c00 style R2 fill:#fee,stroke:#c00 style R3 fill:#fee,stroke:#c00 style R4 fill:#fee,stroke:#c00[10, 20, 30], mask[1, 0, 1][[10, 30]]ValueError(interior hole)[10, 20], mask[1, 2][[10, 20]]TypeError"hello", mask[1, 0]ValueError[0, 0, 10, 20], mask[0, 0, 1, 1][[10, 20]][[10, 20]]Reference page:
docs/runtime-prompt-input-normalization.md(linked fromREADME.md).Validation
pytest tests/test_vllm_input_normalization.py -qpytest tests/test_vllm.py -qLocalized adapter-contract fix; no GPU required.