Skip to content

Fix PocketTTS Mimi decoder CPU crash: restore context-tensor backing removed in d98123e - #76

Merged
0xShug0 merged 3 commits into
0xShug0:mainfrom
adambenhassen:fix/pocket-tts-cpu-mimi-decoder-alloc
Jul 19, 2026
Merged

Fix PocketTTS Mimi decoder CPU crash: restore context-tensor backing removed in d98123e#76
0xShug0 merged 3 commits into
0xShug0:mainfrom
adambenhassen:fix/pocket-tts-cpu-mimi-decoder-alloc

Conversation

@adambenhassen

@adambenhassen adambenhassen commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Problem

On --backend cpu, every PocketTTS synthesis aborts with:

ggml-backend.cpp:327: GGML_ASSERT(buf != NULL && "tensor buffer not set") failed

The flow-LM stage runs fine; the crash is on entry to the Mimi codec decoder, deterministically, in both the server and the CLI. CUDA is unaffected.

Repro

scripts/build_linux.sh --backend cpu --target audiocpp_cli
audiocpp_cli --task tts --family pocket_tts --model <pocket-tts> --backend cpu \
  --load-option language=english --voice-id alba --text "hi" --out out.wav
# -> GGML_ASSERT abort on main; valid 24 kHz WAV with this PR

Cause

d98123e ("Harden PocketTTS Mimi decoder graph allocation") removed every ggml_backend_alloc_ctx_tensors(ggml_ctx_, backend_) call in mimi_decoder.cpp, leaving allocation to ggml_gallocr_alloc_graph alone. That call gave the decoder's context tensors (graph inputs plus persistent state: KV-cache prefixes, positions, attention mask, latents) stable lifetime-long backend buffers. The CPU path uses a persistent graph plan and repeated run() writes into those tensors; gallocr's graph-scoped allocation leaves them unbacked, so on CPU they hit buffer == NULL. CUDA's path kept them backed, hiding the regression.

Fix

Restore ggml_backend_alloc_ctx_tensors (buffer member + destructor free) in the 5 runtime constructors, while keeping d98123e's gallocr null-checks and release_partial_graph_runtime helper. +25/-0, no deletions.

Verification

CPU build; PocketTTS-100M english; --backend cpu, 4 threads on an Intel N100: valid 24 kHz mono WAV via both CLI and the OpenAI-compatible server (POST /v1/audio/speech), 3 back-to-back requests, no crash, RTF ~0.7.


UPDATE:

@0xShug0

0xShug0 commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Thank you @adambenhassen!

I validated the PR locally. The CPU issue is real, and this patch does fix the crash.

One concern: the restored ggml_backend_alloc_ctx_tensors(...) path also runs on CUDA, which causes the VRAM usage regression. d98123e was introduced to reduce the memory usage on CUDA #55

So I think the extra context tensor backing should be gated to CPU only. That should keep the CPU fix while avoiding a CUDA peak-memory regression.

@0xShug0

0xShug0 commented Jul 18, 2026

Copy link
Copy Markdown
Owner

@adambenhassen Let me know if the PR is ready (just testing and see updates...).

@adambenhassen

adambenhassen commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

@adambenhassen Let me know if the PR is ready (just testing and see updates...).

Ready! Gating done in a590f43: context-tensor backing now only runs when core::is_host_backend(backend_), so CUDA/Metal/Vulkan keep the gallocr-only allocation.

Also, while testing the failure paths I found a small leak: if graph allocation throws in a constructor, the destructor never runs and the params buffer leaked. c215af6 fixes that (cleanup helper now frees it) plus null-checks the alloc so it fails with a clear error instead of a later GGML_ASSERT. Verified with a standalone harness replaying the failure path 200x: peak RSS 490MB before vs 76 MB after.

If CUDA peak VRAM looks good on your side, should be all set 👍

@0xShug0
0xShug0 merged commit e1ccc35 into 0xShug0:main Jul 19, 2026
4 checks passed
@0xShug0

0xShug0 commented Jul 19, 2026

Copy link
Copy Markdown
Owner

@adambenhassen Thanks! Tested and worked well. Merged.

@adambenhassen
adambenhassen deleted the fix/pocket-tts-cpu-mimi-decoder-alloc branch July 19, 2026 00:41
dleiferives pushed a commit to dleiferives/audio.cpp that referenced this pull request Jul 25, 2026
…removed in 7decb4b (0xShug0#76)

* Restore PocketTTS Mimi decoder context tensor allocation

* Gate Mimi decoder context tensor backing to host backend

* Handle Mimi decoder context tensor allocation failure
Anc813 pushed a commit to Anc813/audio.cpp that referenced this pull request Jul 25, 2026
…removed in d98123e (0xShug0#76)

* Restore PocketTTS Mimi decoder context tensor allocation

* Gate Mimi decoder context tensor backing to host backend

* Handle Mimi decoder context tensor allocation failure
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