Repository navigation
moss codec: the Nano decoder attended over twice its intended window (fixes #663) - #664
Merged
0xShug0 merged 2 commits intoSep 23, 2026
Merged
Conversation
0xShug0#663 reports that the MOSS codec decoder drifts from the reference as the input grows, and asks for "a way to decode a fixed set of codes through the C++ decoder alone" -- because changing weight_type in a full run also changes the codes being generated, so the comparison stops being like-for-like. Every existing codec parity harness decodes a fixed short matrix -- moss_voicegen_codec_parity uses 40 frames, 3.2 s -- so none of them can see a defect whose whole character is that it grows with length. This one takes the codes as data and the lengths as an argument, so the same matrix can be decoded as its own prefix at 43, 94, 171 frames and the reference can decode exactly the same prefixes. Two details that turned out to matter while using it: It writes float32 rather than the default PCM16. The defect being measured is a noise floor around -56 dBFS in passages the model generated as silence, and dither and hard-clip shaping are exactly the kind of post-processing that muddies a measurement of the decoder alone. It writes every channel. Nano is the 48 kHz stereo codec, and an earlier version of this comparing our channel 0 against the reference's L+R mix reported 70.6 dB where the truth was 111.4 -- a measurement error that would have sent the search in the wrong direction. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01TMmMgd5xNGnjsQgybuUiK3
Fixes 0xShug0#663. The MOSS codec decoder drifts from the reference as the input grows -- exact on short clips, 13 dB at 171 frames -- and the cause is four numbers. audio.cpp hardcodes each stage's attention context as a step count. The checkpoint states it as a DURATION per stage, which the reference turns into steps with int(round(current_frame_rate * context_duration)), the rate being the one BEFORE that transformer rather than after its patch. Nano's decoder durations are not uniform -- 10, 8, 6 and 4 seconds down the stack, where v1's are a flat 10. Derived from the checkpoint: 50 Hz x 10 s -> 500 ours 1000 100 Hz x 8 s -> 800 ours 1600 200 Hz x 6 s -> 1200 ours 2400 400 Hz x 4 s -> 1600 ours 3200 Every one exactly twice what it should be, so the decoder attended over twice the intended window. That matched the reference while sequences were shorter than the real context and diverged as soon as they outgrew it, which is the whole shape of the report: exact at 43 frames, collapsing after. Measured with tests/moss_tts_delay/codec_decode_length_sweep, decoding identical code prefixes against the reference: frames before after 43 111.3 111.3 94 23.9 108.4 171 12.2 102.1 500 2.4 91.5 Nano now tracks v1's own curve. v1's output is bit-identical before and after -- it is a separate config function and was never wrong. Blast radius checked rather than reasoned. tools/check_moss_codec_contexts.py derives every context from each checkpoint and compares against what is hardcoded: v1 encoder OK decoder OK moss_tts_v15, moss_voicegen, moss_ttsd v2 encoder OK decoder OK moss_tts_local nano encoder OK decoder OK moss_tts_nano, vieneu_v3_turbo Nano's encoder was already right, which is why only decoding was affected and probably why this went unnoticed: it reads as a slip in one list rather than a misunderstanding of the rule. The tool needs the checkpoints' config.json files so it cannot run in CI, but it makes the rule checkable for the next codec. Not shown here: the report's audible symptom is a rasp in trailing silence. My source is continuous speech, so its quietest window only moves from 0.000002 to 0.000001 against the reference's 0.000001. The drift is fixed and the floor now matches exactly; I have not reproduced the rasp itself. ci/run-local.sh linux-cpu PASSED. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01TMmMgd5xNGnjsQgybuUiK3
Owner
|
@christopherthompson81 Thanks for fixing the issue! PR merged. |
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.
Fixes #663, reported by @pnnbao97 with a reproducer good enough to find the cause from.
The cause: four numbers
audio.cpp hardcodes each codec stage's attention context as a step count. The checkpoint states it as a duration per stage, which the reference turns into steps with
int(round(current_frame_rate * context_duration))— where the rate is the one before that transformer, not after its patch.Nano's decoder durations are not uniform — 10, 8, 6 and 4 seconds down the stack — where v1's are a flat 10. Derived from the checkpoint:
Every one exactly twice what it should be. So the decoder attended over twice the intended window. That matches the reference while a sequence is shorter than the real context and diverges as soon as it outgrows it — which is the whole shape of the report: exact on short clips, collapsing after.
What it recovers
Decoding identical code prefixes against the reference decoder:
Nano now tracks v1's own curve. v1's output is bit-identical before and after — it is a separate config function and was never wrong.
Blast radius, checked rather than reasoned
tools/check_moss_codec_contexts.pyderives every context from each checkpoint's own config and compares it against what is hardcoded:moss_tts_v15,moss_voicegenmoss_tts_localmoss_tts_nano,vieneu_v3_turboSo the defect was the Nano decoder alone, and the issue title's generalisation to the shared decoder does not hold — the decode path is fine, the table feeding it was not.
Nano's encoder contexts were already right, which is why only decoding was affected and probably why this went unnoticed: it reads as a slip in one list rather than a misunderstanding of the rule. The tool needs the checkpoints'
config.jsonfiles so it cannot run in CI, but it makes the rule checkable for the next codec added.The harness
tests/moss_tts_delay/codec_decode_length_sweepis the decode-only entry point @pnnbao97 asked for: it takes a code matrix as data and a list of lengths, and decodes the same matrix as its own prefix at each, so the reference can decode exactly the same prefixes and nothing upstream differs.Every existing codec parity harness decodes a fixed short matrix —
moss_voicegen_codec_parityuses 40 frames, 3.2 s — so none of them could see a defect whose whole character is that it grows with length. That is worth fixing separately; this one at least makes the class visible.Two details in it that turned out to matter: it writes float32 rather than PCM16, because the symptom is a noise floor around −56 dBFS and dither and clip shaping muddy that; and it writes every channel, because Nano is the 48 kHz stereo codec and an early version of mine comparing our channel 0 against the reference's L+R mix reported 70.6 dB where the truth was 111.4.
Not shown here
The report's audible symptom is a rasp in trailing silence. My source is continuous speech with no long silent tail, so its quietest window only moves from 0.000002 to 0.000001 against the reference's 0.000001. The drift is fixed and the floor now matches the reference exactly, but I have not reproduced the rasp itself — @pnnbao97's reproducer, with generated audio that ends in silence, is the one that would confirm it end to end.
ci/run-local.sh linux-cpuPASSED.🤖 Generated with Claude Code
https://claude.ai/code/session_01TMmMgd5xNGnjsQgybuUiK3