Skip to content

moss codec: the Nano decoder attended over twice its intended window (fixes #663) - #664

Merged
0xShug0 merged 2 commits into
0xShug0:mainfrom
christopherthompson81:moss-codec-decoder-drift
Sep 23, 2026
Merged

0xShug0 merged 2 commits into
0xShug0:mainfrom
christopherthompson81:moss-codec-decoder-drift

Conversation

@christopherthompson81

Copy link
Copy Markdown
Contributor

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:

 50 Hz × 10 s →  500      ours 1000
100 Hz ×  8 s →  800      ours 1600
200 Hz ×  6 s → 1200      ours 2400
400 Hz ×  4 s → 1600      ours 3200

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:

frames audio before after
43 3.4 s 111.3 dB 111.3 dB
94 7.5 s 23.9 dB 108.4 dB
171 13.7 s 12.2 dB 102.1 dB
500 40.0 s 2.4 dB 91.5 dB

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's own config and compares it against what is hardcoded:

codec encoder decoder families
v1 OK OK moss_tts_v15, moss_voicegen
v2 OK OK moss_tts_local
nano OK OK (this PR) moss_tts_nano, vieneu_v3_turbo

So 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.json files 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_sweep is 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_parity uses 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-cpu PASSED.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TMmMgd5xNGnjsQgybuUiK3

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
@0xShug0
0xShug0 merged commit 68b8068 into 0xShug0:main Sep 23, 2026
6 checks passed
@0xShug0

0xShug0 commented Sep 23, 2026

Copy link
Copy Markdown
Owner

@christopherthompson81 Thanks for fixing the issue! PR merged.

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.

MOSS codec decoder drifts from the reference as the input grows (63 dB at 43 frames, 13 dB at 171)

2 participants