Skip to content

fix(vllm): reject attention masks a token prompt cannot represent (#3884) - #3900

Merged
Qubitium merged 2 commits into
mainfrom
fix/issue-3884
Nov 14, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/issue-3884

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #3884

Root cause

_normalize_vllm_inputs / _apply_attention_mask (gptqmodel/utils/vllm.py) filtered out every masked position:

filtered = [token_id for token_id, keep in zip(token_ids, mask) if bool(keep)]

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:

_normalize_vllm_inputs(None, [10, 20, 30], [1, 0, 1]) -> (None, [[10, 30]])
_normalize_vllm_inputs("hello", None, [1, 0])        -> ("hello", None)

Fix

Mirror the SGLang contract in the vLLM adapter:

  • only boolean or 0/1 integer mask values are accepted (TypeError otherwise);
  • the kept positions must be contiguous, so only left/right padding can be removed (ValueError on an interior hole);
  • a mask supplied with a text prompt is rejected (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
Loading
Input Before After
[10, 20, 30], mask [1, 0, 1] [[10, 30]] ValueError (interior hole)
[10, 20], mask [1, 2] [[10, 20]] TypeError
"hello", mask [1, 0] mask ignored ValueError
[0, 0, 10, 20], mask [0, 0, 1, 1] [[10, 20]] [[10, 20]]

Reference page: docs/runtime-prompt-input-normalization.md (linked from README.md).

Validation

Command Result
pytest tests/test_vllm_input_normalization.py -q 8 passed
same file before the fix (source stashed) 4 failed, 4 passed
pytest tests/test_vllm.py -q 3 skipped (vLLM is not installed in this venv)

Localized adapter-contract fix; no GPU required.

_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.
@Qubitium
Qubitium merged commit 40fe9fd into main Nov 14, 2026
4 of 6 checks passed
@Qubitium
Qubitium deleted the fix/issue-3884 branch November 14, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vLLM input normalization silently changes prompts for interior or ignored attention masks

1 participant