Skip to content

moss_ttsd: take #674's f16 decoder and KV cache, keep the encoder at f32 - #687

Merged
0xShug0 merged 1 commit into
0xShug0:mainfrom
christopherthompson81:moss-ttsd-f16-codec
Sep 24, 2026
Merged

0xShug0 merged 1 commit into
0xShug0:mainfrom
christopherthompson81:moss-ttsd-f16-codec

Conversation

@christopherthompson81

Copy link
Copy Markdown
Contributor

Follow-up to #674. MOSS-TTSD shares v1.5's codec and backbone, but it didn't opt in to the f16 path, so bf16 cloning on a 24 GiB card still fails:

alloc_tensor_range: failed to allocate CUDA0 buffer of size 3546439680
failed to allocate moss.audio_tokenizer.encoder backend weight buffer

This applies the same opt-in on CUDA, Vulkan and Metal, with one difference: the codec encoder stays at f32.

Why not the encoder

My first version copied #674 exactly. Peaks and SNR looked fine, but transcribing the output found the problem. At seed 7, the q8_0 and bf16 clones came out near-silent, 11 s long, with empty transcripts. main spoke the script.

The encoder itself is fine. I dumped the reference codes at f32 and f16: codebook 0 is identical on every clip, and the finer codebooks agree 86–100%. But MOSS-TTSD continues from those codes, and it is sensitive to them. Over 26 seeds of the same two-speaker clone:

encoder full script failures
f32 21/26 dropped the [S2] line (4), one misheard word
f16 21/26 silence (2), re-spoke the reference prompt (1), dropped or truncated a line (2)

The success rate is the same, but only f16 produced the severe failures. 3 of 26 against 0 isn't conclusive, so I kept the encoder at f32 rather than argue about it. v1.5 is unaffected: its clones transcribe exactly at every quantization with the f16 encoder.

That needed one small framework change. MossAudioTokenizerCodecRuntimeOptions gains an optional encoder_transformer_weight_storage_type, which falls back to the shared type when unset. It's appended last, so the six existing positional-brace callers compile unchanged and behave the same.

Verification

The decoder only renders finished codes, and the f16 KV cache is bit-identical on output (checked separately: base vs +KV, SNR ∞). So with the encoder at f32, the generated codes match main exactly. This is shown directly below rather than argued statistically.

RTX 3090, peak VRAM of the process, clone at seed 7, transcribed with parakeet_tdt:

package plain TTS clone clone on main
q4_k 8,448 MiB, full script 11,960 MiB, 4.00 s, full script 13,798 MiB, 4.00 s, full script
q8_0 11,130 MiB, full script 14,642 MiB, 10.40 s, full script 16,524 MiB, 10.40 s, full script
bf16 17,942 MiB, full script 21,468 MiB, 6.00 s, full script OOM
  • The seeds that failed with an f16 encoder (7, 11, 25) now match main's length and transcript exactly. Waveform SNR is 15.6–41.2 dB. The low end is seed 7, which is mostly near-silence, where decoder rounding weighs more.
  • q8_0 plain TTS against main: 44.5 dB, identical transcript, no NaN. The backbone's f16 weight problem noted in parse_weight_type concerns activations, and the KV cache stays within range. The output is bit-identical.
  • CPU is unchanged: use_f16 is false there, and the encoder was already f32.

Caveats

  • bf16 cloning fits, but only just: 21,468 MiB for the process, plus about 1.8 GiB for my desktop, out of 24,090 MiB. A card with more desktop load could still miss it.
  • The seed sweep covers one two-speaker configuration with short references (2.1 s and 3.5 s). That's enough to show the f16 encoder isn't safe for this model, but not enough to put a rate on it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KR9AUMpJhbrWijVoDacUDx

…der at f32

moss_tts_v15 loads its codec at f16 and its KV cache at f16 on GPU backends,
which is what lets bf16 clone on a 24 GiB card. moss_ttsd shares the codec
and backbone, but didn't opt in, so bf16 cloning still failed allocating
moss.audio_tokenizer.encoder.

The decoder and KV cache come across unchanged. The KV cache is
bit-identical on output, and the decoder is 44.5 dB with identical
transcripts. The encoder does not come across. This model continues
directly from the reference's codes, and an f16 encoder changes 5-14% of
the finer codebooks. Over 26 seeds that produced silence or a re-spoken
prompt 3 times, against none at f32. Add an optional encoder-only storage
type to the codec options for that. It's appended last, so the other
callers are untouched.

With the encoder at f32, the generated codes match main exactly. Cloning
peaks drop by 1.8 GiB and bf16 clones at 21.0 GiB where it failed before.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01KR9AUMpJhbrWijVoDacUDx
@0xShug0
0xShug0 merged commit 857de23 into 0xShug0:main Sep 24, 2026
6 checks passed
@0xShug0

0xShug0 commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

@christopherthompson81 I find one interesting way to reduce peak VRAM

  1. Keep encoder projection weights resident in FP16, matching their packaged precision.
  2. Insert ggml_cast(..., GGML_TYPE_F32) before those weights are consumed.
  3. Keep the existing encoder operations unchanged, consuming FP32 weights.
  4. Let the graph allocator reuse temporary FP32 buffer space after each tensor’s last use, instead of retaining all expanded weights permanently.

So basically:
PR: FP16 file → permanent FP32 weights (stored in VRAM) → encoder
Experiment: FP16 file → permanent FP16 weights (stored in VRAM) → temporary FP32 weights → encoder

CUDA configuration Peak VRAM Warm clone RTF
Q8 main 17,408 MiB 0.1339
Q8 PR 15,434 MiB 0.1287
Q8 experiment 13,766 MiB 0.1273
BF16 PR 22,266 MiB 0.2009
BF16 experiment 20,592 MiB 0.2015

This may be a useful pattern for future models.

@christopherthompson81

Copy link
Copy Markdown
Contributor Author

@0xShug0 Nice, thanks. That's a better fit for TTSD than what I did, so I put it in #690.

Since the packages store the codec at f16, the widening is exact, and the encoder's output is bit-identical to #687's f32 path on every package, including the seeds that collapsed with an f16 encoder. That's the property #687 kept f32 for, now for about 1.65 GiB less. bf16 cloning goes from 21.0 to 19.4 GiB, which takes care of the tight headroom I flagged. It also made a one-shot clone 1.3 s faster, because the lazy encoder prepare uploads half the bytes.

One thing to watch when reusing the pattern: it's only lossless when the stored type matches the source. From f32 safetensors, holding the weights at f16 is a real rounding step. So #690 loads the encoder Native rather than f16: an f16 GGUF stays f16, and an f32 source stays f32 and skips the cast.

0xShug0 pushed a commit that referenced this pull request Sep 25, 2026
…e graph (#690)

#687 kept the codec encoder at f32 because this model is sensitive to the
reference's codes. Those f32 weights are the packages' f16 values widened,
so the same numbers can be produced in the graph instead: hold each
projection at its stored type and ggml_cast it to f32 where it is consumed.
The graph allocator then reuses the widened buffers rather than keeping
every expanded weight resident. This is 0xShug0's pattern from the #687
thread.

The widening is exact, so the output is bit-identical to #687 for every
package, including the seeds that failed with an f16 encoder. The encoder
is loaded Native rather than as f16, so an f32 source is never rounded and
simply skips the cast.

Cloning peaks drop by about 1.65 GiB. A one-shot clone is 1.3 s faster,
because the lazily prepared encoder uploads half the bytes.
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.

2 participants