Skip to content

[Bug]: Length Mismatch Between mrope_position_ids and position_ids & Incorrect Accumulation of image_pad Across Messages #11170

Closed as not planned

Description

@Lihui-Gu

System Info

General bug

Who can help?

No response

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

Issue 1: Length Mismatch Between mrope_position_ids and position_ids

There is a potential out-of-bounds risk caused by inconsistent length assumptions between position_ids and mrope_position_ids.

In the following code:

self.mrope_position_ids_cuda[:, :, :total_num_tokens].copy_(
    mrope_position_ids[:, :, :total_num_tokens],
    non_blocking=True
)

total_num_tokens is derived from position_ids. However, there is no guarantee that
mrope_position_ids.shape[-1] >= total_num_tokens.

If mrope_position_ids.shape[-1] < total_num_tokens, the slicing operation on
mrope_position_ids[:, :, :total_num_tokens] will result in an out-of-bounds access (or an invalid copy), leading to undefined behavior or runtime errors.

In short, total_num_tokens is implicitly assumed to be valid for both tensors, but this assumption does not always hold.


Issue 2: Incorrect Accumulation of image_pad Across Messages

When a single request contains multiple messages, and only a subset of those messages include multimodal (image) data, the current logic incorrectly propagates image_pad tokens to subsequent messages that do not contain images.
https://github.com/NVIDIA/TensorRT-LLM/blob/main/tensorrt_llm/serve/chat_utils.py#L268

Example:

  • A request contains 3 messages
  • Only 2 messages actually include image data

Due to cumulative handling of multimodal placeholders, an image_pad token is still inserted for the third message, even though it has no associated image.

As a result:

  • The number of image_pad tokens becomes inconsistent with the actual number of multimodal inputs.
  • Multimodal metadata and placeholder tokens are no longer aligned.

This cumulative behavior causes a mismatch between the multimodal data count and the image_pad markers in the serialized input.

I have proposed a solution for the issues described above and validated it using my own datasets. The fix resolves the observed inconsistencies and works correctly in all tested cases.
Lihui-Gu@a405252

However, I am not fully confident that the changes are universally correct or aligned with the intended design, so I would appreciate feedback on whether this approach is reasonable and safe under all expected scenarios.

Expected behavior

See Reproduction

actual behavior

See Reproduction

additional notes

NULL

Before submitting a new issue...

  • Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.

Activity

  1. added
    bug
    on Feb 1, 2026
  2. added
    Customized kernels
    Multimodal
    on Feb 1, 2026
  3. changed the title [-][Bug]:[/-] [+][Bug]: Length Mismatch Between mrope_position_ids and position_ids & Incorrect Accumulation of image_pad Across Messages[/+] on Feb 1, 2026
  4. zheyuf commented on Feb 1, 2026

    @zheyuf
    Collaborator

    Hi @Lihui-Gu, thanks for raising this issue! I see you already have a proposed fix. Could you open a Pull Request so we can have an engineer review the changes and run the CI?

    No worries about being unsure of the "universal" correctness — our CI testing and review process will help confirm that the logic is safe and fits the architecture.

  5. chang-l commented on Feb 2, 2026

    @chang-l
    Collaborator
  6. yechank-nvidia commented on Feb 2, 2026

    @yechank-nvidia
    Collaborator

    Thanks for raising this issue.

    For both issues, yes, I think we are lacking in considering mixture of text + mm requests when first implemented. I saw your #11179 and seems first fix is correct. But need to think more about the second case's fix.

    Will continue to add more comment on that PR. Thanks!

  7. Nekofish-L commented on Feb 3, 2026

    @Nekofish-L
    Contributor

    Issue 2 is the same as #7929.

  8. added 2 commits that reference this issue on Feb 12, 2026
  9. 2ez4bz commented on Feb 12, 2026

    @2ez4bz
    Collaborator

    @Lihui-Gu could you share details on how to repro issue 1? I would like to understand the exact scenarios under which it manifests itself. 🙏

  10. added a commit that references this issue on Feb 14, 2026
  11. added a commit that references this issue on Feb 19, 2026
  12. github-actions commented on Apr 14, 2026

    @github-actions

    Issue has not received an update in over 14 days. Adding stale label.

  13. github-actions commented on Apr 28, 2026

    @github-actions

    This issue was closed because it has been 14 days without activity since it has been marked as stale.

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

    Customized kernelsInvestigatingMultimodalbugstalewaiting for feedback

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions