Skip to content

perf(fish_audio): add HIP Fast-AR top-k sampler - #386

Merged
0xShug0 merged 1 commit into
0xShug0:mainfrom
reezex0-ux:feat/fish-hip-fast-sampling
Sep 2, 2026
Merged

perf(fish_audio): add HIP Fast-AR top-k sampler#386
0xShug0 merged 1 commit into
0xShug0:mainfrom
reezex0-ux:feat/fish-hip-fast-sampling

Conversation

@reezex0-ux

Copy link
Copy Markdown
Contributor

Summary

This is the first small HIP-scoped piece from the Fish S2 Pro AMD optimization work discussed in #317.

Fish Fast-AR produces a 4096-entry logits tensor for each acoustic codebook step. On the HIP path this PR:

  • adds an exact device-side top-k helper for the Fast-AR logits;
  • copies only the compact top-k result back to the host instead of all 4096 logits;
  • keeps the existing temperature/top-p filtering and RNG selection path, so sampling behavior stays aligned with the current implementation;
  • gates the new code on Linux HIP and only links it when fish_audio is part of the model composite.

Other backends keep the existing path unchanged.

This intentionally does not include the more aggressive experiments from the original patch set: chained Fast-AR, resident embedding gather, device-side mask/position updates, backend stream access, or the GGML convolution fixes. Those can be reviewed separately if useful.

Validation

Tested against current main at 3497b7cc44753e2c141d8fe60ac42cec433e3281.

System:

  • AMD Radeon RX 7900 XTX (gfx1100)
  • ROCm 7.2.1 / HIP
  • Linux
  • Fish Audio S2 Pro Q8_0 GGUF (fish-audio-s2-pro-q8_0.gguf)

Build:

bash scripts/build_linux.sh \
  --backend hip \
  --gpu-targets gfx1100 \
  --model-set custom \
  --models fish_audio \
  --target audiocpp_cli

Benchmark input:

This benchmark measures speech generation on an AMD graphics card. The same sentence, random seed, and sampling settings are used for every run so that the timing results can be compared fairly.

Generation settings:

language=en
seed=1234
max_tokens=96
temperature=0.8
top_k=50
top_p=0.8

Five identical requests were run in one loaded process. Request 1 was treated as graph/model warmup; requests 2-5 are the warm measurements below. Each output was 4411.79 ms of audio.

Path Warm #2 Warm #3 Warm #4 Warm #5 Warm mean
current main 4252.08 ms 4316.97 ms 4232.65 ms 4229.31 ms 4257.75 ms
HIP Fast-AR top-k 4064.28 ms 4133.41 ms 4059.36 ms 4055.67 ms 4078.18 ms

That is about 4.22% lower warm wall time for this isolated optimization.

Output parity: all five baseline WAVs and all five patched WAVs were bit-identical:

SHA-256: dfbc6ec75603a05c85d97e5dbf24b75a77dcc2386e5087159cd9d7d673989533

After a small code cleanup/refactor, I rebuilt/relinked and reran three requests; the warm times were 4038.98 / 4106.59 ms and the same SHA-256 was preserved for all three outputs.

I also compiled src/models/fish_audio/ar.cpp with the HIP Fish sampler macro removed to verify the existing non-HIP fallback path still compiles.

Known limitations

  • Runtime benchmark coverage is currently RX 7900 XTX / Linux HIP only.
  • The fast path is used for positive top_k <= 256; unsupported values fall back to the existing full-logits path.
  • This is intentionally only the Fast-AR top-k/readback optimization; the larger GPU-resident/chained work is not part of this PR.

Select exact Fast-AR top-k candidates on HIP and copy only the compact sampling data back to the host while preserving the existing sampling distribution and RNG path.
@0xShug0

0xShug0 commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Thanks @reezex0-ux! It overall looks good to me. One minor concern: the HIP sampler CMake block runs unconditionally whenever ENGINE_ENABLE_HIP is enabled, regardless of whether fish_audio is selected in AUDIOCPP_LINKED_MODELS, but fish_audio is the only consumer. If this sampler is general and can benefit other models on HIP we could consider promote it to framework so other models can also use it.

@IIIIIllllIIIIIlllll Could you take a look at this PR?

@0xShug0
0xShug0 merged commit 31a47d4 into 0xShug0:main Sep 2, 2026
6 checks passed
@0xShug0

0xShug0 commented Sep 2, 2026

Copy link
Copy Markdown
Owner

@reezex0-ux I'm going to merge it now and follow-up PRs are appreciated!

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