Fix Qwen2.5-Omni Token2Wav DiT rotary embedding layout (interleaved cos/sin)#47403
Open
HenryVarro666 wants to merge 1 commit into
Open
Fix Qwen2.5-Omni Token2Wav DiT rotary embedding layout (interleaved cos/sin)#47403HenryVarro666 wants to merge 1 commit into
HenryVarro666 wants to merge 1 commit into
Conversation
The Token2Wav DiT applies an interleaved rotate (`rotate_half_codec`, pairing channels (2i, 2i+1)), but since huggingface#39847 the DiT rotary embedding built cos/sin with the half-split `torch.cat((freqs, freqs))` layout inherited from `LlamaRotaryEmbedding`. A half-split cos/sin combined with an interleaved rotate is not a valid rotation: RoPE's translation invariance is destroyed on head 0 of every DiT attention layer, degrading the predicted mel-spectrogram (and thus the synthesized audio). Override `Qwen2_5OmniDiTRotaryEmbedding.forward` to emit the interleaved `repeat_interleave(freqs, 2)` layout, restoring the pre-huggingface#39847 behavior that matches `rotate_half_codec` and the released weights (originally integration-tested in huggingface#36752). Add CPU regression tests asserting the interleaved layout and RoPE translation invariance.
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: qwen2_5_omni |
Contributor
CI recapDashboard: View test results in Grafana |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #47328.
The Token2Wav DiT applies an interleaved rotate —
rotate_half_codec, which pairs adjacent channels(2i, 2i+1)— but since #39847 (🚨 [v5] Refactor RoPE for layer types)Qwen2_5OmniDiTRotaryEmbeddinginheritedLlamaRotaryEmbedding.forward, which buildscos/sinwith the half-split layouttorch.cat((freqs, freqs)). A half-splitcos/sincombined with an interleaved rotate is not a valid rotation: RoPE's defining property —⟨R_m·q, R_n·k⟩depending only on the relative offsetm − n— is destroyed. It is applied to head 0 of every DiT attention layer (query[:, :1], key[:, :1] = apply_rotary_pos_emb(...)), silently degrading the predicted mel-spectrogram and thus the synthesized audio forreturn_audio=True.This is a regression, not the checkpoint design. Before #39847 (e.g.
v4.57.0),Qwen2_5OmniDiTRotaryEmbedding.forwardbuilt the rotary embedding asi.e. the interleaved layout that matches
rotate_half_codec. #39847 made the class inheritLlamaRotaryEmbeddingand silently replaced this with the half-splittorch.cat((freqs, freqs)), while leavingrotate_half_codecinterleaved. The original add PR #36752 was integration-tested againstQwen/Qwen2.5-Omni-7Bwith the interleaved layout, so the released weights expect it. The code also carries the note# Modified from Llama with a different rotate function, will fixed in next releaseonapply_rotary_pos_emb, confirming the rotate is intentionally non-standard (interleaved).This PR restores the original interleaved layout via
repeat_interleave(freqs, 2). Why this direction, rather than switching the rotate to Llama's half-split? Both would be valid rotations in isolation, butrotate_half_codecis exactly the(2i, 2i+1)pairing the released weights were trained with, so it is left untouched — which makes interleavedcos/sinthe only checkpoint-preserving choice. Rewriting the rotate to half-split would be a different rotation convention the checkpoint was never trained for. The text model's mrope (Qwen2_5OmniRotaryEmbedding) legitimately keepscatwith the half-splitrotate_halfand is untouched;qwen3_omni_moehas its own rotary and is unaffected.Reproduction / verification (CPU, no weights)
Driving the real
Qwen2_5OmniDiTRotaryEmbedding.forward+apply_rotary_pos_emb, and measuring the max drift of⟨R_m·q, R_{m+Δ}·k⟩across absolute positionm(≈ 0 ⟺ valid RoPE):maincat)repeat_interleave)Tests
Adds
Qwen2_5OmniDiTRotaryEmbeddingTest(CPU, weight-free): it asserts the interleavedcos/sinlayout and RoPE translation invariance (checked across several offsets) for the DiT rotary. Both tests fail onmainand pass with this fix.Before submitting
Who can review?
@eustlb @ebezzam
Thanks to @pepepeboom for independently reproducing the root cause and confirming the regression on
main.