Skip to content

vLLM generate output loses completions for shorter padded prompts when sliced at the input width #3921

Closed

Description

@Qubitium

Reproduction (main at 8ecc295)

The vLLM adapter removes per-row padding before inference, then returns a tensor reconstructed from each result's unpadded prompt_token_ids. A standard Hugging Face caller slices generated tokens using the width of the original input_ids:

input_ids = torch.tensor([[0, 0, 11, 12], [21, 22, 23, 24]])
attention_mask = torch.tensor([[0, 0, 1, 1], [1, 1, 1, 1]])
# Fake vLLM result: each prompt generates [101, 102].
output = vllm_generate(engine, input_ids=input_ids, attention_mask=attention_mask)
print(output.tolist())
# [[11, 12, 101, 102, 0, 0], [21, 22, 23, 24, 101, 102]]
print(output[:, input_ids.shape[1]:].tolist())
# [[0, 0], [101, 102]]

The first row's completion is entirely lost to the caller; with other lengths it can include prompt IDs or only part of the completion. I reproduced this with a fake vLLM engine on 8ecc295. The same behavior applies to left/right padded batches of unequal effective lengths.

Cause

_normalize_vllm_inputs strips padding for vLLM. vllm_generate concatenates result.prompt_token_ids + output.token_ids and right-pads the resulting rows; it never restores the original input width before the completion. The returned tensor therefore breaks the generate output alignment used by callers that slice at input_ids.shape[1], including the repository's server generation path (gptqmodel/utils/openai_server.py).

Expected

For tensor input_ids, preserve each row's original prefix width in the returned tensor, so output[:, input_ids.shape[1]:] begins with that row's generated token IDs. Keep the unpadded prompt sent to vLLM. Add a batched left/right-padding regression test for the returned output, not only input normalization.

This is separate from #3884, which covers attention-mask validation before generation.

Activity

  1. added a commit that references this issue on Nov 18, 2026
    656291a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions