Repository navigation
fix(audio): size RoPE table to the reachable position range - #136
Merged
sergioburdisso merged 2 commits intoOct 27, 2026
Merged
Conversation
jordiluque
force-pushed
the
fix/rope-position-capacity
branch
from
October 27, 2026 09:47
7db5495 to
27ae937
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #136 +/- ##
==========================================
+ Coverage 44.92% 50.14% +5.22%
==========================================
Files 84 84
Lines 10213 10232 +19
==========================================
+ Hits 4588 5131 +543
+ Misses 5625 5101 -524
🚀 New features to boost your workflow:
|
Member
|
@all-contributors please, add @jordiluque as a contributor for code 👍 |
Contributor
|
I've put up a pull request to add @jordiluque! 🎉 |
Member
|
Thanks @jordiluque for your fix, a new version 0.5.4 has been just released with your patch :) |
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.
Problem
With voice-clone prefixes, long turns crash with a CUDA device-side assert
(
IndexKernel.cu:94 index out of bounds), which also poisons the CUDA context soevery later generation in the same process fails.
The rotary table is sized with
max_seq_len = config.runtime.max_context_steps(
core/layers.py), but the generation loop runs absolute positions:build_initial_stateallocates the KV cache asmax_context_steps + prefix_len + 1and
warmup_with_prefixreturnsstart_step = prefix_len - 1, sotreachesprefix_len + max_context_steps - 2.RotaryEmbedding.forwardgatherscos_cached[position_ids], so anyt >= max_context_stepsindexes past the table.The 0.5.2/0.5.3 guard (
if t >= max_context: break) prevents the crash butsilently truncates generation whenever a window reaches absolute position
max_context_steps. With the defaultreference_seconds=8.0the reachable range isalready
100 ... 1598, i.e. past 1500 — the guard is only unreachable in practicebecause
max_window_words=170caps a window at ~790 generated frames, well short ofthe ~1400 needed to hit it. Raising
reference_secondsormax_window_words, orpassing a long
(array, sr)reference, makes the guard fire and the tail of theutterance is dropped with no warning.
Fix
Size the rotary table to the range that is actually reachable, at the one place
where it is known — right next to the existing
total_stepscomputation:RotaryEmbedding.ensure_capacity()extendsmax_seq_lenand rebuilds the cache.Row i depends only on i (
cos(i * inv_freq), built fromarange(max_seq_len)),so extending the range leaves every existing row bit-identical — generations that
already fit are byte-for-byte unchanged. The loop guard becomes
t >= runtime.model.position_capacity, a defensive bound that never fires in normaluse.
Files changed (3 source + 1 test, +121/-1):
src/sdialog/audio/tts/dia2/_dia2/core/layers.py—RotaryEmbedding.ensure_capacity()src/sdialog/audio/tts/dia2/_dia2/core/model.py—Dia2Model.ensure_position_capacity()+position_capacitysrc/sdialog/audio/tts/dia2/_dia2/runtime/generator.py— call it inbuild_initial_state; guard uses the real capacitytests/test_audio_rope_capacity.py— CPU-only regression tests (no weights, no GPU)Tested in H100, torch 2.6.0+cu124, sdialog 0.5.3
Memory overhead is negligible: one extra
cos/sinpair of(Δlen, head_dim)fp32per attention layer (~22 MB for 1500 → 2266).
Notes
grow (e.g. 1500 -> 1601 at the default
reference_seconds=8.0), but because row idepends only on i, the added rows are never read by a generation that previously
fit — so its audio is byte-identical. Verified numerically:
max |cos_1500[i] − cos_1601[i]| = 0.0for alli < 1500. The patch only affects generations thatwould otherwise have been truncated.