Skip to content

moss_ttsd: hold the encoder at its stored type and widen to f32 in the graph - #690

Merged
0xShug0 merged 1 commit into
0xShug0:mainfrom
christopherthompson81:moss-ttsd-encoder-cast
Sep 25, 2026
Merged

0xShug0 merged 1 commit into
0xShug0:mainfrom
christopherthompson81:moss-ttsd-encoder-cast

Conversation

@christopherthompson81

Copy link
Copy Markdown
Contributor

Applies @0xShug0's experiment from the #687 thread to MOSS-TTSD. The encoder's projection weights stay resident at their stored type and are ggml_cast to f32 where the graph consumes them. The graph allocator can then reuse the widened buffers instead of keeping every expanded weight in VRAM.

Why the output doesn't change at all

#687 kept the encoder at f32 because this model continues directly from the reference's codes and is sensitive to them. But the published packages store the codec at f16, so those f32 weights are just f16 values widened, and f16→f32 is exact. Widening inside the graph gives the matmuls the same operands, so the result is bit-identical, not just close.

One deliberate difference from the experiment as described: the encoder is loaded Native rather than as f16. A fixed f16 would round an f32 safetensors source, which is exactly the change to the codes that #687 avoided. With Native, an f16 GGUF stays f16 in VRAM, and an f32 source stays f32 and skips the cast (projection_weight returns F32 weights unchanged).

Changes

  • MossAudioTokenizerCodecRuntimeOptions::widen_encoder_transformer_weights_to_f32, appended last, default false. The other callers are unchanged.
  • projection_weight() applies the cast at the six projections (input_proj, output_proj, in_proj, out_proj, fc1, fc2). The decoder never sets the flag, so its graph is unchanged.
  • moss_ttsd on CUDA/Vulkan/Metal: encoder Native + widen. On CPU: F32, no widening, as before.

Verification

RTX 3090, compared with a build of main at #687:

case peak VRAM output
q4_k clone 11,960 → 10,316 MiB bit-identical
q8_0 clone 14,690 → 12,998 MiB bit-identical
bf16 clone 21,464 → 19,824 MiB bit-identical
q8_0 clone, seeds 11 and 25 (the seeds that failed with an f16 encoder) — bit-identical
q8_0 plain TTS 11,094 → 11,074 MiB bit-identical
CPU q4_k clone — bit-identical

That's close to your numbers (q8 15,434 → 13,766, bf16 22,266 → 20,592 on your setup). It also closes #687's one caveat: bf16 cloning now has about 2.5 GiB of headroom on a 24 GiB card instead of about 0.8 GiB.

A one-shot clone also gets 1.3 s faster: q8_0 session.wall_ms went from 3,942–3,965 ms to 2,623–2,642 ms over six interleaved runs each. The encoder is prepared lazily on the first clone, so its upload counts toward the session. It now uploads 1.65 GiB of f16 instead of widening to 3.3 GiB of f32 on the host first. I didn't re-measure warm steady state; your table shows it as neutral, which fits the mechanism.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KR9AUMpJhbrWijVoDacUDx

…e graph

0xShug0#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 0xShug0#687
thread.

The widening is exact, so the output is bit-identical to 0xShug0#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.

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

0xShug0 commented Sep 25, 2026

Copy link
Copy Markdown
Owner

@christopherthompson81 Thanks for the follow-up! 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.

2 participants