Skip to content

cuda: enable fused TQ3_1S mul_mat on HIP (gfx1100) — the disable is CUDA-only - #283

Merged
TheTom merged 1 commit into
TheTom:feature/turboquant-kv-cachefrom
jasstrong:tq3-fused-hip
Aug 13, 2026
Merged

TheTom merged 1 commit into
TheTom:feature/turboquant-kv-cachefrom
jasstrong:tq3-fused-hip

Conversation

@jasstrong

Copy link
Copy Markdown

ggml_cuda_mul_mat unconditionally sets tq3_1s_fused_disabled for TQ3_1S weights, routing every TQ3_1S mul_mat to the dequant → cuBLAS fallback instead of the fused mmvq-tq kernel. Per the comment, this was root-caused and confirmed only on CUDA0 (DeepSeek-V4): a reduction-order / cancellation sensitivity in the fused kernel's per-lane accumulation that compounds (~2%/layer) into incoherent generation on real weight/activation distributions.

That failure mode is specific to the CUDA warp reduction. RDNA3 (wavefront-32) is a different FP-accumulation regime and was never tested. On gfx1100 / RX 7900 XTX, ROCm 7.2.3 the fused kernel is correct:

  • Coherence — full-inference output is coherent. A greedy A/B (fused vs. the verified dequant path, temp 0) diverges only via the expected butterfly effect of a sub-noise numerical difference; both paths stay sensible for the whole generation.

  • Perplexity (Qwen3.6-35B-A3B TQ4-opt, wikitext-2, -ctk q8_0 -ctv turbo4 -fa on):

    • fused on: PPL = 5.6999 ± 0.113
    • fused off: PPL = 5.7037 ± 0.113

    Identical within error (Δ ≈ 0.004, ~30× under the error bar; fused-on is if anything marginally lower).

  • Speed — +33% decode (9.9 → 13.2 tok/s) by staying on the fused path rather than dequant → hipBLAS, on a mixed TQ3_1S / TQ4_1S + q8_0 model.

So the disable is over-conservative for HIP. This gates it to non-HIP (#if defined(GGML_USE_HIP)), leaves CUDA behavior untouched, and keeps a TQ3_FUSE_OFF=1 env escape hatch so the dequant path is one env var away if a future gfx target does trip it.

The tq3_1s_fused_disabled guard was root-caused and confirmed only on CUDA0
(DeepSeek-V4): a reduction-order/cancellation sensitivity that is hardware-
specific and does not reproduce on RDNA3. Gate it to non-HIP so gfx1100 uses
the fused mmvq-tq path instead of dequant+hipBLAS. Coherent, PPL-neutral
(5.6999 vs 5.7037 +/- 0.113), +33% decode. TQ3_FUSE_OFF=1 forces the dequant path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@TheTom
TheTom merged commit fca3093 into TheTom:feature/turboquant-kv-cache Aug 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants