llama.cpp-hip-turboquant β€” ROCm port of the TurboQuant fork (turbo-tan) for AMD RX 7900 XTX

#1
by flamme-demon - opened

llama.cpp-hip-turboquant

Arch Linux PKGBUILD and minimal patch to build the
turbo-tan/llama.cpp-tq3 fork
with the HIP/ROCm backend, enabling TurboQuant-quantized models
(TQ3_1S, TQ3_4S) and TQ3_0 KV cache on AMD GPUs.

The upstream fork is CUDA-only β€” this patch only adds the HIP shims required
for the GPU kernels. No change to the TurboQuant logic itself.

GITHUB : https://github.com/flamme-demon/llama.cpp-hip-turboquant-tq3

Validated on

  • GPU: AMD Radeon RX 7900 XTX (gfx1100)
  • ROCm: 7.2.0 / HIP 7.2.26043
  • OS: Manjaro Linux (kernel 6.19)
  • Model: YTan2000/Qwen3.6-35B-A3B-TQ3_4S + BF16 mmproj

Measured performance (llama-server, 65k context)

Config Prompt Generation
-ctk q4_0 -ctv tq3_0 -fa on 238 t/s 78.2 t/s
Default f16 KV cache 159 t/s 89.6 t/s

VRAM usage: ~15 / 24 GB (full 35B model on GPU).

What the patch changes

112 lines, 4 files in ggml/src/ggml-cuda/:

  • vendors/hip.h β€” variadic __shfl_*_sync macros (3/4-arg), __ballot_sync,
    cudaEventCreate / cudaEventElapsedTime shims.
  • tq3-native.cuh β€” conditional HIP vs CUDA include for fp16.h and
    GGML_COMMON_DECL_*.
  • tq3-native.cu β€” include order (common.cuh before tq3-native.cuh).
  • vecdotq.cuh β€” replaces 4Γ— __dp4a with ggml_cuda_dp4a (portable wrapper
    that maps to v_dot4c on RDNA3).

Install

git clone <this-repo> llama.cpp-hip-turboquant                                                                                                                                                           
cd llama.cpp-hip-turboquant                                                                                                                                                                              
makepkg -si                                               
                                            
The package conflicts with llama.cpp and llama.cpp-hip (both ship
/usr/bin/llama-server). pacman will handle the transition.
                                                                                                                                                                                                         
Limitations                             
                                                                                                                                                                                                         
- GGML_RPC=OFF β€” the RPC backend is disabled because of a static_assert on                                                                                                                               
GGML_OP_COUNT that changed upstream. Patch separately if you need it.
- llama-cli: add --no-warmup to avoid a rare kernel that hangs during                                                                                                                                    
warmup. llama-server is not affected.                                                                                                                                                                    
                                        
Supported types in this build                                                                                                                                                                            
                                                                                                                                                                                                         
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          
β”‚  Type  β”‚ ID  β”‚      Role       β”‚                                                                                                                                                                       
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€                        
β”‚ TQ3_1S β”‚ 44  β”‚ Weights         β”‚                                                                                                                                                                       
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ TQ3_4S β”‚ 46  β”‚ Weights (4 bpw) β”‚                                                                                                                                                                       
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€                        
β”‚ TQ3_0  β”‚ 200 β”‚ KV cache        β”‚      
β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                                                                                                                                                                         
The TURBO2_0 / TURBO3_0 / TURBO4_0 / TQ4_1S variants from the
https://github.com/domvox/llama.cpp-turboquant-hip fork are not                                                                                                                                          
supported β€” the two KV cache designs have diverged.       
                                                                                                                                                                                                         
Credits
                                                                                                                                                                                                         
- Upstream TurboQuant (CUDA): https://github.com/turbo-tan/llama.cpp-tq3
- Original HIP port (different KV cache design):                                                                                                                                                         
https://github.com/domvox/llama.cpp-turboquant-hip        
- Base PKGBUILD: llama.cpp-hip by Orion-zhen / txtsd on AUR                                                                                                                                              
- Paper: https://arxiv.org/abs/2504.19874   
                                                                                                                                                                                                         
License                                                                                                                                                                                                  
                                                                                                                                                                                                         
MIT (same as upstream llama.cpp).    

                                                                                                                                                         

Nice work, I incorporate your change in this branch https://github.com/turbo-tan/llama.cpp-tq3/tree/experiment/hip-tq3-support
if it work, I will merged into main, your fork is outdated and miss a few enhancement

can you confirm it work?

I built the version on my machine and played around with the model, yes.

merged into master. thanks!

Sign up or log in to comment