Skip to content

Optimize rope_deltas propagation logic in Qwen2.5-VL#41176

Closed
Xqle wants to merge 4 commits intohuggingface:mainfrom
Xqle:fix-propagate-rope-deltas-qwen2.5-vl
Closed

Optimize rope_deltas propagation logic in Qwen2.5-VL#41176
Xqle wants to merge 4 commits intohuggingface:mainfrom
Xqle:fix-propagate-rope-deltas-qwen2.5-vl

Conversation

@Xqle
Copy link
Copy Markdown
Contributor

@Xqle Xqle commented Sep 26, 2025

What does this PR do?

This PR fixes the propagation of rope_deltas in the Qwen2.5-VL model during generation.

Currently, the forward() method of Qwen2_5_VLForConditionalGeneration accepts rope_deltas as an argument, but the value is never passed to the underlying Qwen2_5_VLModel. As a result, users providing rope_deltas directly to forward() would see no effect.

Modifications

  1. Qwen2_5_VLForConditionalGeneration.forward() now passes rope_deltas to Qwen2_5_VLModel.forward().
  2. Qwen2_5_VLModel.forward() now accepts rope_deltas and updates its internal state accordingly.
  3. Updates prepare_inputs_for_generation() to store calculated rope_deltas
    in model_inputs, aligning its handling with position_ids.

Impact

  • Users can now explicitly provide rope_deltas during generation and have them correctly applied.
  • Ensures consistency between prefill and decoding phases in multi-modal generation.
  • Aligns the API behavior with documentation.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

- Forward rope_deltas from Qwen2_5_VLForConditionalGeneration to Qwen2_5_VLModel
- Update Qwen2_5_VLModel to accept rope_deltas and store internally
- Refactor prepare_inputs_for_generation to unify rope_deltas handling
- Ensure that passing rope_deltas in forward() now correctly affects position_ids calculation
This fixes an issue where passing rope_deltas directly to the model's forward() had no effect,
which could lead to inconsistencies between pre-fill generation and manual forward calls.
@Xqle Xqle changed the title Optimize rope_deltas propagation logic in Qwen2.5-VL ✅ Optimize rope_deltas propagation logic in Qwen2.5-VL Sep 26, 2025
@Rocketknight1
Copy link
Copy Markdown
Member

cc @zucchini-nlp for VLMs, @ArthurZucker for rope

@github-actions
Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: qwen2_5_vl

or (past_key_values is None or past_key_values.get_seq_length() == 0)
)
if (prefill_compiled_stage or prefill_noncompiled_stage) or self.rope_deltas is None:
if (prefill_compiled_stage or prefill_noncompiled_stage) or rope_deltas is None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it enough to move above the line self.rope_deltas = rope_deltas?

Copy link
Copy Markdown
Contributor

@molbap molbap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed rope_deltas is not propagated from forward, but I think we can catch it earlier and not touch the rest

@molbap
Copy link
Copy Markdown
Contributor

molbap commented Sep 29, 2025

Btw could this influence #41180 ? If the rope_deltas state is never modified in the forward

Copy link
Copy Markdown
Member

@zucchini-nlp zucchini-nlp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Xqle , thanks for the PR! Indeed they are not being propagated to forward. Though we can also see that the forward does not use rope_deltas so the current changes will not be enough to make it work

We had a PR in the past which was very close to how it should look like for Qwen-VL series in #39756. It got stale so we could not merge it. I'd suggest to make changes accordingly so that the deltas are actually used by the forward (pls take a look at comments under #39756) and add a small test

@zucchini-nlp
Copy link
Copy Markdown
Member

LMK if you have bandwidth to apply the changes, otherwise I will add it to my TODO so we don't forget adding it in the future :)

@Xqle Xqle closed this Oct 23, 2025
@Xqle Xqle deleted the fix-propagate-rope-deltas-qwen2.5-vl branch October 23, 2025 11:56
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.

4 participants