Repository navigation
Reduce MOSS-TTS v1.5 GPU memory usage - #674
Conversation
|
@christopherthompson81 I think a simple change to reduce VRAM usage is to use the FP16 codec. An FP16 KV cache gives only a small VRAM reduction, but it was faster in my tests. I’m not sure about the parity impact compared with Python. Could you take a look at this? @pnnbao97 These two optimizations may also be relevant to Vieneu TTS. You can opt into FP16 in |
|
Tested both commits separately on an RTX 3090. They hold up and the PR does more than it claims — one thing I would change, and one number you asked for on #652 that I can now give you. The change I am suggesting is inline on the diff as review suggestions, so you can apply or dismiss each one. The one thing I would raise: this ships f16 to four backends on one backend's evidenceBoth gates read I raise it because the tree already declines to do this, in your own words in two places: And there is a mechanism to doubt, not only a principle: prefill writes its F32 layer K/V into the now-f16 cache through It turns bf16 cloning from OOM into workingWhile testing your f16 KV suggestion I had this case failing: bf16 cloning died asking for 3,546,439,680 bytes for
The base reproduces the OOM byte for byte on the current tree, and the codec commit alone is what fixes it. Worth putting in the body: the F32 clone figure is above what some 24 GiB cards have, not merely larger. The KV commit is bit-identical; the codec commit owns the changeq8_0 plain TTS at a fixed seed, with a determinism control run first so the comparison means something:
So the KV commit costs nothing measurable at all, and the codec commit owns both the numerical change and the whole memory win (1,692 MiB — the same figure you measured, on different hardware). The 46.3 dB is decode-only, and I transcribed all three anyway: identical text and identical word Also, Your codec change is a smaller precision step than it looksThe published v1.5 packages already store the codec at f16 — 1600/1600 tensors, 3.305 GiB — and
Plain TTS prepares only the decoder → 1.651 GiB ≈ the 1,692 MiB we both measured. Cloning prepares both → 3.3 GiB ≈ your 3,486 MiB. And 3.303 GiB is exactly the allocation that used to fail. The safetensors path is where a genuine new rounding enters, and there is an in-tree precedent for this same v1 codec in Speed: your RTF table and my wall-time number are both rightDrift-cancelled across four binaries (each rep forward then reversed, since this box drifts 20-30%), q8_0 plain TTS, 6 samples per build: base 4415 ms, codec f16 3166 ms, + KV f16 3147 ms — about 29% off one-shot wall time, which looks like it contradicts 0.2274 → 0.2286. Splitting it: Generation is unchanged; prepare is 41.7% faster. The encoder is a VRAM tenant, which prices your mem_saver ideaThree identical clone requests in one session ( Step compute is flat and the first request carries a 327.7 ms premium — the lazy So the encoder holds 1.651 GiB of VRAM to do about a tenth of a second of work per request, which prices the For the profile above: The PR also stops the cache allocating its host import mirror. This family never calls Unrelated, but it will confuse someone#664 merges cleanly with this. But the reporter on #663 suspected weight precision, and I ruled that out by reproducing the drift at f32. Once this lands, GPU v1.5 codec decode runs at f16, so anyone re-running that comparison measures both effects at once. Might be worth a line in the codec docs. |
christopherthompson81
left a comment
There was a problem hiding this comment.
Three suggestions, inline. The first two are the substantive one — gating the 16-bit storage on Cuda rather than on "not CPU" — split across the two sites so they can be applied independently. I wrote them without a shared helper variable so each is a self-contained hunk.
Reasoning is in my comment above; the short version is that != Cpu also hands f16 to Hip, Vulkan and Metal, the tree already declines to generalise a dtype decision that way (module.h:22, moss_tts_local's resolve_auto_weight_type()), and prefill's ggml_cpy into a strided 4-D view of the f16 cache is a per-backend property that fails at graph compute rather than at graph build.
I checked that this does not quietly drop the auto-selected path back to F32: execution_context.cpp:49 resolves BestAvailable through core::backend_type(backend_), which returns a concrete Cuda on a CUDA machine and only falls back to BestAvailable for a backend it cannot identify — where F32 is the right answer anyway.
There is a third change I could not make a suggestion out of, because it touches lines outside this diff: MossTtsDelayBackboneRuntime::log_timing() emits ten per-stage counters and nothing in the tree calls it, so the delay family has no stage profile. Adding the pair moss_tts_local uses — reset_timing() at the top of run(), log_timing() before session.wall_ms — is what produced the profile numbers in my comment. Both halves are needed: the counters accumulate, so reporting without resetting makes a second request in one session include the first one's time. Happy to send that separately or leave it to you.
| backbone_weight_context_bytes_, | ||
| weight_storage_type_); | ||
| weight_storage_type_, | ||
| execution_context().backend_type() == core::BackendType::Cpu ? GGML_TYPE_F32 : GGML_TYPE_F16); |
There was a problem hiding this comment.
Gate on the backend this was measured on, so Hip, Vulkan and Metal keep F32 until someone runs the same comparison there.
| execution_context().backend_type() == core::BackendType::Cpu ? GGML_TYPE_F32 : GGML_TYPE_F16); | |
| execution_context().backend_type() == core::BackendType::Cuda ? GGML_TYPE_F16 : GGML_TYPE_F32); |
core::uses_ggml_cuda_or_hip_backend is the natural widening point once HIP is measured, the way minimax_music3/depth_decoder.cpp:61 selects prefill_mode.
| execution_context().backend_type() == core::BackendType::Cpu | ||
| ? assets::TensorStorageType::F32 | ||
| : assets::TensorStorageType::F16, |
There was a problem hiding this comment.
Same change for the codec storage.
| execution_context().backend_type() == core::BackendType::Cpu | |
| ? assets::TensorStorageType::F32 | |
| : assets::TensorStorageType::F16, | |
| execution_context().backend_type() == core::BackendType::Cuda | |
| ? assets::TensorStorageType::F16 | |
| : assets::TensorStorageType::F32, |
|
@christopherthompson81 Good points! I actually ran the tests on both CUDA and Vulkan but only reported CUDA. Let me test on Mac. It should be safe as YuE2 has the same shape. And I will use cache_options.lazy_import_scratch = true. This API is very new (thanks to @mirek190) but it looks like it should become the default pattern for the relevent models. |
|
PR updated. Validated that the PR works on Mac. |
|
@christopherthompson81 Please consider updating your HF repo README...24 GB of VRAM should no longer be a blocker. |
|
@0xShug0 Done. The card is updated: https://huggingface.co/christopherthompson81/MOSS-TTS-v1.5-GGUF I re-measured on merged main (RTX 3090) and transcribed every clone rather than only checking that it ran:
The "bf16 can't clone on 24 GiB" warning is gone. The card also notes that builds from before #674 still run out of memory there, and explains why. MOSS-TTSD didn't pick this up, because its session never opted in. That's #687, with one twist: TTSD keeps the codec encoder at f32. The f16 encoder is fine for v1.5, whose clones transcribe exactly at every quantization. But TTSD continues directly from the reference codes, and with an f16 encoder a few seeds collapsed to silence or re-spoke the prompt. The details are in the PR. |
…f32 (#687) 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.
Use FP16 storage for the codec transformer on CUDA, Vulkan, and Metal because it substantially reduces the codec-stage memory peak without slowing inference. CPU and HIP storage remain F32.
Use FP16 KV cache on CUDA, Vulkan, and Metal because it is the fastest cache type tested. The framework default and the MOSS-TTS-v1.5 CPU and HIP paths remain F32. Unused host-side cache import scratch is allocated lazily.