Skip to content

Fix Qwen2.5-Omni get_chunked_index chunking functionality #37631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 22, 2025

Conversation

imkero
Copy link
Contributor

@imkero imkero commented Apr 19, 2025

What does this PR do?

This PR fixes the incorrect mrope position chunking function get_chunked_index in modular_qwen2_5_omni.

The shape of token_indices for modular_qwen2_5_omni.get_chunked_index is (3, seq_len) in main branch

It takes a constant value 3 (comes from len(token_indices)) in the loop condition to iterate the token_indices input (instead of the correct value token_indices.shape[1]). This will make it always produce only a single chunk. (Line 1160 vs Line 1166)

def _iter():
i, start_idx = 0, 0 # skip bos token
current_chunk = 1
while i < len(token_indices): # skip eos token
if token_indices[0][i] - remove_index >= current_chunk * tokens_per_chunk:
yield (start_idx, i)
start_idx = i
current_chunk += 1
i += 1
yield (start_idx, token_indices.shape[1])
return list(_iter())

Another similar but correct impl lies in processing_qwen2_5_omni and we can take it as a reference. (Line 303 vs Line 309)

def _iter():
i, start_idx = 0, 0 # skip bos token
current_chunk = 1
while i < len(token_indices): # skip eos token
if token_indices[i] >= current_chunk * tokens_per_chunk:
yield (start_idx, i)
start_idx = i
current_chunk += 1
i += 1
yield (start_idx, len(token_indices))
return list(_iter())

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.

@BakerBunker can you take a look about this bugfix please?

@github-actions github-actions bot marked this pull request as draft April 19, 2025 15:36
Copy link
Contributor

Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the Ready for review button (at the bottom of the PR page). This will assign reviewers and trigger CI.

@imkero imkero changed the title Bugfix/qwen2 5 omni mrope chunk Fix Qwen2.5-Omni get_chunked_index impl Apr 19, 2025
@imkero imkero marked this pull request as ready for review April 19, 2025 15:38
@imkero imkero changed the title Fix Qwen2.5-Omni get_chunked_index impl Fix Qwen2.5-Omni get_chunked_index chunking functionality Apr 19, 2025
@BakerBunker
Copy link
Contributor

Thank you, I will look at this tomorrow.

@BakerBunker
Copy link
Contributor

LGTM, can be merged after the test cases are passed.

cc @zucchini-nlp

@imkero
Copy link
Contributor Author

imkero commented Apr 21, 2025

I think my change on the spatial_merge_size config broke some unit tests, will fix them soon.

@imkero imkero force-pushed the bugfix/qwen2-5-omni-mrope-chunk branch from f9aeef6 to ad926cc Compare April 21, 2025 08:55
@imkero
Copy link
Contributor Author

imkero commented Apr 21, 2025

I think my change on the spatial_merge_size config broke some unit tests, will fix them soon.

The failed tests have been fixed and pass now.

@BakerBunker
Copy link
Contributor

@zucchini-nlp Ready to merge.

Copy link
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.

Thanks, LGTM

@zucchini-nlp zucchini-nlp merged commit 5f79128 into huggingface:main Apr 22, 2025
12 checks passed
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request May 14, 2025
…e#37631)

* fix: qwen2.5 omni modular get_rope_index

* test: add test for qwen2.5 omni rope index (video with audio input)

* style

* expected_position_ids readability

* fix: use spatial_merge_size = 1 in unit test
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.

3 participants