Repository navigation
campplus: write the graph's constants before every run, not only the first - #1284
Conversation
|
@magnus-dev-melin Thanks for the PR. The issue is real. However, the original PR calls I updated the PR directly to preserve the constants’ storage instead of uploading them before every run. Both approaches fix the correctness issue. The updated approach avoids that overhead, with correctness verified on CPU, CUDA, and Vulkan. 50 measured runs per setting after warmup:
PR merged! |
|
Great catch, preserving the storage is the better fix. Thanks for verifying it on CUDA and Vulkan, and for merging both! |
The CAMPPlus graph creates its constant tensors (the segment-pooling correction factors) with
DeferredTensorWriter, which writes them once, right after the graph is allocated. They are not graph inputs, soggml_gallocrmay hand their memory to intermediate results during the compute. The runner is cached per frame count and reused, andrun()only rewrote the input tensor, so every embedding after the first one on a runner was computed with whatever the previous compute left in those tensors.run()now flushes the writer before every compute. Shared framework module; affects every model that uses it (Chatterbox cloning and VC, IndexTTS2, Seed-VC). No API or option changes.Affects outputs: the first embedding on a runner is unchanged; every later one now equals what a fresh runner gives.
Validation (macOS, M1 Max, Metal,
chatterbox_q8_0, legacy server,OMP_NUM_THREADS=4;mainat a91e36b against this branch):conditionals_cache_slots0, so every request prepares again; embedding dumped fromChatterboxConditionalsComponent::prepare): onmainthe first embedding had a norm of 16.49 and later ones 21.8–22.4, with cosine similarity to each other as low as 0.89 (against 0.49–0.59 between two different speakers). With this branch every preparation of that reference gave the bit-identical embedding of the first one, and the other voice its own, also stable. The other prepared conditionals (prompt mel, prompt tokens, voice-encoder embedding, T3 prompt tokens) were already identical onmain./v1/tasks/run,vc_reference_cache_slots0,seed7 in the request, targets A, A, B, A):maingave a different WAV for each A after the first, and its B, prepared after A, differed from this branch's; this branch gave the first A's WAV every time (SHA-256 equal tomain's first A) and a stable B./v1/audio/speech,seed7, the same voice in de three times and da three times):maingave a different WAV on each request; this branch gave the same WAV every time, equal to the onemaingives with its default cache (one slot), where the voice is prepared once.model_spec_system_test,cli_request_options_testandtools/check_loader_catalog_sync.pypass.Not measured: CUDA/Vulkan (the change is backend-independent); IndexTTS2 and Seed-VC were not built or run here (this build has Chatterbox only).
tests/glm_tts/campplus_shared_default_probe.cppcomputes a single embedding, so it could not catch this; running the encoder twice there, with another input in between, would. I did not change it, as I have no standalone CAMPPlus weights here to run it with.