Skip to content

HIP: one product for a 2D src0 broadcast over a contiguous src1 batch - #423

Open
paleluna82-del wants to merge 1 commit into
unslothai:base/upstream-418fe97b5from
paleluna82-del:hip-flat-batch
Open

paleluna82-del wants to merge 1 commit into
unslothai:base/upstream-418fe97b5from
paleluna82-del:hip-flat-batch

Conversation

@paleluna82-del

Copy link
Copy Markdown

On HIP, a mul_mat with a 2D src0 broadcast over a contiguous batched src1 runs as batched hipBLASLt GEMMs. When the per-batch products are small, those leave the GPU mostly idle. The product equals one GEMM over all src1 columns, so on HIP the batch is flattened into the columns before dispatch. CUDA is unchanged. GGML_CUDA_DISABLE_FLAT_BATCH=1 opts out.

This is the backend-side replacement for the graph change I dropped from #406 (the Inkling 2 relative bias table, 1024 x 24 x 16 per token, which regressed prefill on B200 when done in the graph). Since it is backend-only, CUDA keeps its batched cuBLAS path.

Results (R9700 gfx1201, ROCm 7.2.4, Inkling-2-Mini UD-Q4_K_M, q8_0 KV, on top of #386 + #406)

pp512 pp2048 pp8192 tg128
without (GGML_CUDA_DISABLE_FLAT_BATCH=1) 1485 825 724 37.8
with 1482 1424 1380 37.8

KLD with vs without: 0.000000 at -c 512 and -c 4096 (A/A floor, max 6e-5).

Testing

  • test-backend-ops -o MUL_MAT on ROCm0: new broadcast cases (F32/F16/Q8_0 src0, 512 and 7x3 batches, a permuted size-1 dim) pass. The one failure (f16 m=16 n=2105344 k=32) also fails on the base and with the flattening disabled. -o MUL_MAT_ID 1077/1077.
  • Not tested on NVIDIA: the change is under GGML_USE_HIP.

🤖 Generated with Claude Code

A mul_mat with a 2D src0 and a contiguous batched src1/dst is the same
product as one GEMM over all src1 columns. On HIP the batched form of such
small per-batch products goes to batched hipBLASLt GEMMs that leave the GPU
mostly idle (e.g. the Inkling 2 relative bias table, 1024 x 24 x 16 per
token). Flatten the batch into the columns on HIP. CUDA is unchanged.
GGML_CUDA_DISABLE_FLAT_BATCH=1 opts out.

R9700 (gfx1201), ROCm 7.2.4, Inkling-2-Mini UD-Q4_K_M, q8_0 KV:
pp2048 825 -> 1428, pp8192 724 -> 1383, pp512 and tg128 unchanged. KLD vs
unflattened 0.000000 at -c 512 and -c 4096. test-backend-ops MUL_MAT: new
broadcast cases (F32/F16/Q8_0, 512 and 7x3 batches, a permuted size-1 dim)
pass, no new failures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant