Repository navigation
fix(vllm): respect left-padded attention masks - #1804
Conversation
| ) | ||
| prompts_ids = [ids[: int(row.sum())] for ids, row in zip(prompts_ids, mask)] | ||
| prompts_ids = [ | ||
| self._trim_masked_prompt(ids, row) for ids, row in zip(prompts_ids, mask) |
There was a problem hiding this comment.
The assembly below still lays every row out from position 0, so a left-padded batch comes back right-padded: logits[:, -1] is -inf for the shorter rows and the bridge's loss path goes NaN against the caller's mask. Can the returned logits and captures go back where the mask had them?
There was a problem hiding this comment.
Fixed in 33276b7. After vLLM processes each trimmed prompt, the driver restores reconstructed or fallback logits and captures to the caller's original mask coordinates. Pad logits remain -inf and pad captures zero. Added batched regressions for left/right/two-sided padding and a finite masked-loss check; the vLLM driver unit file passes (93 passed, 18 skipped). Real vLLM/GPU validation is still outstanding.
| mask = torch.as_tensor(attention_mask) | ||
| if mask.ndim == 2 and mask.shape[0] == 1: | ||
| mask = mask[0] | ||
| ids_list = self._trim_masked_prompt(ids_list, mask) |
There was a problem hiding this comment.
A left-padded trim shifts pos and the returned captures by the leading padding, so a pos in the caller's coordinates is rejected or lands on a different token. Is there a way to keep the caller's coordinates on this path as well?
There was a problem hiding this comment.
Fixed in 33276b7. The single-prompt path now translates caller pos coordinates to the trimmed prompt before dispatch, restores captured tensors and logits to the caller's positions, and rejects positions that point into padding. Added tests for valid and padded positions plus restored single-prompt outputs. The vLLM driver unit file passes (93 passed, 18 skipped).
|
Looks good! Thanks @emerardd |
Description
VLLMDriver.forward()previously treatedattention_mask.sum()as a prefix length. A left-padded input such as IDs[0, 0, 7, 8]with mask[0, 0, 1, 1]therefore sent[0, 0]to vLLM instead of[7, 8]. The eager batched path had the same behavior, changing the prompt and any resulting logits or captures without an error.Both paths now retain the contiguous span of real tokens, allowing left, right, and two-sided padding. The driver rejects length mismatches, non-binary masks, all-masked prompts, and interior gaps rather than silently changing the prompt's meaning. Mask validation happens before the optional vLLM import on the batched path.
Type of change
Validation
tests/unit/model_bridge/test_vllm_driver.py: 86 passed, 18 skipped. The skipped existing tests require a local vLLM installation.pycln --check --all,isort --check-only, andblack --checkpass for both changed files.mypy .: no issues in 383 source files.git diff --checkpasses.Checklist
No documentation or unrelated tests were changed.