Repository navigation
[Engine] Inkling 2 on AMD: fewer launches for attention projections - #294
Open
okada-shogo wants to merge 1 commit into
Open
okada-shogo wants to merge 1 commit into
okada-shogo wants to merge 1 commit into
Conversation
…type, inputs quantized once Same bits. On HIP native_mmvq_mixed() is not built, so with Unsloth's files (Q8_0 and K-quants in one layer) project() returned false and layer_head() ran five lin() calls, each quantizing its input again. HIP now takes the grouping the Metal path already has (VecSzn's): the inputs quantized once, native_mmvq_many() for each type it takes, lin() on the quantized inputs for the rest. On HIP the sink's and a full layer's taps join the same grouping where they are quantized matrices (the ggml-org files' Q8_0), as they join native_mmvq_mixed() on CUDA. CUDA and Metal unchanged. poly_project_mixed_test now builds on HIP too: there it checks native_mmvq_many() of Q8_0, Q4_0, Q5_0 and IQ4_NL against native_mmvq() of each matrix, and native_quantize_q8_1_many() against native_quantize_q8_1(), bit for bit (CUDA: the same cases as before, plus the quantize check). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and result
On AMD (HIP), each Inkling 2 decode token now runs its attention projections as one grouped launch per quant type,
with the input quantized once, instead of five separate launches that each quantize the input again. This removes
126-220 kernels per token and gives +1.4% to +4.2% decode on an RX 9070 XT and an RX 7800 XT, with the same bits.
CUDA and Metal are unchanged.
Background: for one decode token,
project()computes the Q, K, V, relative-position and gate products. On CUDA, filesthat mix quant types inside a layer (Unsloth's UD files: Q8_0 with K-quants) take one
native_mmvq_mixed()launch.That kernel is not built on HIP, so on AMD
project()gave up andlayer_head()ran fivelin()calls, eachquantizing its input again and launching its own product. The attention-sink and convolution-tap products (Q8_0 in
the ggml-org files) also quantized their inputs again on HIP.
This PR gives HIP the grouping Metal already has: the inputs are quantized once, then there is one
native_mmvq_many()launch for each quant type it supports, andlin()on the already quantized inputs for the rest.On HIP, the sink and tap products join the same grouping.
Kernels per decode token (rocprof, 64 tokens after a 302-token prompt): RX 9070 XT UD-Q2_K_XL 1,706 → 1,486 (−220),
IQ4_NL 1,584 → 1,458 (−126); RX 7800 XT UD-Q2_K_XL 1,706 → 1,486.
Decode tok/s (higher is better): 256 tokens after the prompt,
--serve, fp16 KV, 32K context, default flags, onewarm-up request first in each process. Mean of 3 runs, with the order of the builds rotated each round.
Prompt speed does not change, because a prompt batch never takes this path. It is within ±0.4% on both cards, except
IQ4_NL 8K on the RX 9070 XT (+1.9%, because main's first run was slow).
Each run (tok/s)
Related discussion
none
Approach
project(): the Metal block (VecSzn's per-typenative_mmvq_many()grouping) is now also built for HIP, for asingle token. On HIP it also takes the attention-sink product and a full layer's two convolution-tap products when
they are quantized matrices with
n_embdinputs, and reports them through*extrasas the CUDA path does.native_mmvq_many()gives each output the same bits as its own single launch, andlin()with thealready quantized input only skips quantizing the same values again. Metal behaves as before (it has no extras).
Validation
Passed:
poly_project_mixed_test, now also built on HIP:native_mmvq_many()of Q8_0, Q4_0, Q5_0 and IQ4_NL (in the shapesof the five-product and the eight-product groups) against
native_mmvq()of each matrix, andnative_quantize_q8_1_many()againstnative_quantize_q8_1(). 0 of ~8,600 values (and 7,776 bytes) differ: PASS onthe RX 7800 XT (gfx1101).
STRATA_GPU_EXPERTS=1500 STRATA_FREEZE_EXPERTS=1,--top-probs 20, fp16 KV, prompts of302, 2,048 and 8,192 tokens followed by 64, 16 and 16 generated tokens): SAME. UD-Q2_K_XL on the RX 9070 XT and RX 7800 XT, IQ4_NL on the RX 9070 XT.
gfx1100;gfx1101;gfx1201 and CUDA sm_75;sm_86 on our builders.
containers (WSL2, /dev/dxg).
poly_project_mixed_teston CUDA after this change: RTX 2070 Super (sm_75), the 8 mixed cases, 2 many cases, thequantize check and the declines: PASS, 0 failures.
Failed:
Not run:
Limits
native_mmvq_mixed()for HIP would need HIP's own K-quant row kernels (rdna_mmvq.cu) inside it to keep the bits.kernels) together add +9.8% (UD-Q2_K_XL) and +6.4% (IQ4_NL) decode after 302 tokens on the RX 9070 XT (83.7 → 91.9
and 44.0 → 46.8 tok/s), identity SAME.
Credits: VecSzn's per-type grouping (the Metal path); the HIP launch counts are from our gap profiles against amd-preview.
🤖 Generated with Claude Code