Skip to content

Fix CPU Fish DAC reference encoding for voice cloning - #936

Merged
0xShug0 merged 1 commit into
mainfrom
fix/935-fish-codec-cpu-reference
Oct 16, 2026
Merged

0xShug0 merged 1 commit into
mainfrom
fix/935-fish-codec-cpu-reference

Conversation

@0xShug0

@0xShug0 0xShug0 commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #935.

Fix CPU reference encoding in the shared Fish DAC codec by materializing two transposed inputs before normalization and residual subtraction.

The CPU ggml_div/ggml_sub implementation reads the first operand as contiguous elements when its shape matches the output. These encoder inputs were non-contiguous transposes, so it read the wrong elements. The patch uses the existing framework layout helper; it adds no kernels or precision overrides.

Only CPU encoding changes. CUDA, Vulkan, Metal, decoding, and backbone execution are unchanged. Fish Audio and Echo-TTS use the same shared encoder, but were not separately tested here.

Validation

Reproduced with the original Drama 3 Q4_K_S package using the server's encode_reference_only path. No backbone generation was needed. Debug builds, eight threads, sequential runs.

Reference CPU/CUDA code agreement before After
a.wav, 129 frames × 10 codebooks 0% 97.36%
b.wav, 304 frames × 10 codebooks Not measured 95.07%
  • Fixing normalization alone restored first-codebook agreement to 100% / 99.34%; residual codebooks remained incorrect. Materializing the residual input restored agreement across the remaining codebooks.
  • Official Fish Speech Python code and the original codec.pth independently encoded both references. Fixed CPU code agreement was 97.44% / 95.53%; CUDA agreement was 95.27% / 94.01%.
  • Python ran in F16; C++ uses F16 main weights with primarily F32 activations. These percentages are cross-precision code agreement, not exact numerical parity.
  • Decoding the before/after codes through the same official Python codec: ASR recovered no text from the old CPU codes, but recovered the full reference transcripts from fixed CPU, CUDA, and Python codes for both references. Speaker-embedding similarity was not measured.
  • Both CPU and CUDA passed a → b → a reference encoding with identical first/repeated a codes. CUDA a codes were also identical before/after the patch.
  • Debug CLI/server builds and git diff --check passed.

@0xShug0
0xShug0 merged commit de4f4c9 into main Oct 16, 2026
6 checks passed
5uck1ess added a commit to 5uck1ess/audio.cpp-fork that referenced this pull request Oct 16, 2026
@0xShug0
0xShug0 deleted the fix/935-fish-codec-cpu-reference branch October 16, 2026 17:15
5uck1ess added a commit to 5uck1ess/audio.cpp-fork that referenced this pull request Oct 17, 2026
ahmednabilfawzy89-cmyk added a commit to ahmednabilfawzy89-cmyk/audio.cpp that referenced this pull request Nov 5, 2026
…tokenizer encoder

On the CPU backend, the first ggml_sub in HiggsAudioV2EncoderGraph's RVQ loop
reads residual_bct (a ggml_permute view from transpose_btc_to_bct) as if it
were contiguous, so every codebook after the first is computed from a wrong
residual. The reference voice is encoded wrong and voice cloning on CPU loses
the speaker. Same bug class as 0xShug0#936.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
0xShug0 pushed a commit that referenced this pull request Nov 5, 2026
…tokenizer encoder (#1212)

On the CPU backend, the first ggml_sub in HiggsAudioV2EncoderGraph's RVQ loop
reads residual_bct (a ggml_permute view from transpose_btc_to_bct) as if it
were contiguous, so every codebook after the first is computed from a wrong
residual. The reference voice is encoded wrong and voice cloning on CPU loses
the speaker. Same bug class as #936.

Co-authored-by: Ahmed Nabil Fawzy <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

Drama 3: fish_drama3.codec_backend=cpu mis-encodes voice references, so cloning loses the speaker. Generation tracks Fish's code.

1 participant