Skip to content

[Engine] Inkling 2 on AMD: fewer launches for attention projections - #294

Open
okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/hip-proj-group
Open

okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/hip-proj-group

Conversation

@okada-shogo

@okada-shogo okada-shogo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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, files
that 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 and layer_head() ran five lin() calls, each
quantizing 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, and lin() 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, one
warm-up request first in each process. Mean of 3 runs, with the order of the builds rotated each round.

Card Model Measure main this PR alone Change
RX 9070 XT 16 GB UD-Q2_K_XL decode after 302 60.0 61.0 +1.7%
RX 9070 XT 16 GB UD-Q2_K_XL decode after 8K 56.5 57.6 +2.0%
RX 9070 XT 16 GB IQ4_NL decode after 302 41.4 41.9 +1.4%
RX 9070 XT 16 GB IQ4_NL decode after 8K 36.4 37.1 +1.9%
RX 7800 XT 16 GB UD-Q2_K_XL decode after 302 38.0 38.6 +1.6%
RX 7800 XT 16 GB UD-Q2_K_XL decode after 8K 34.9 36.3 +4.2%

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)
Card Model Measure Build Run 1 Run 2 Run 3
RX 9070 XT 16 GB UD-Q2_K_XL decode after 302 main 60.9 59.8 59.3
RX 9070 XT 16 GB UD-Q2_K_XL decode after 302 this PR 60.9 60.9 61.3
RX 9070 XT 16 GB UD-Q2_K_XL decode after 8K main 56.5 56.6 56.4
RX 9070 XT 16 GB UD-Q2_K_XL decode after 8K this PR 57.5 57.8 57.6
RX 9070 XT 16 GB IQ4_NL decode after 302 main 41.4 41.5 41.2
RX 9070 XT 16 GB IQ4_NL decode after 302 this PR 42.9 42.1 40.8
RX 9070 XT 16 GB IQ4_NL decode after 8K main 36.4 36.4 36.4
RX 9070 XT 16 GB IQ4_NL decode after 8K this PR 37.0 37.0 37.3
RX 7800 XT 16 GB UD-Q2_K_XL decode after 302 main 39.4 39.6 35.1
RX 7800 XT 16 GB UD-Q2_K_XL decode after 302 this PR 40.0 40.9 35.0
RX 7800 XT 16 GB UD-Q2_K_XL decode after 8K main 38.1 32.5 34.0
RX 7800 XT 16 GB UD-Q2_K_XL decode after 8K this PR 37.4 37.7 33.9

Related discussion

none

Approach

  • project(): the Metal block (VecSzn's per-type native_mmvq_many() grouping) is now also built for HIP, for a
    single 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_embd inputs, and reports them through *extras as the CUDA path does.
  • Same bits: native_mmvq_many() gives each output the same bits as its own single launch, and lin() with the
    already 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 shapes
    of the five-product and the eight-product groups) against native_mmvq() of each matrix, and
    native_quantize_q8_1_many() against native_quantize_q8_1(). 0 of ~8,600 values (and 7,776 bytes) differ: PASS on
    the RX 7800 XT (gfx1101).
  • Identity, main vs this PR (STRATA_GPU_EXPERTS=1500 STRATA_FREEZE_EXPERTS=1, --top-probs 20, fp16 KV, prompts of
    302, 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.
  • Builds: HIP on the boxes (ROCm 7.2.4, gfx1201, gfx1101); after the rebase onto 36e654b, HIP
    gfx1100;gfx1101;gfx1201 and CUDA sm_75;sm_86 on our builders.
  • Measured on main cdfae80 + this PR; the branch is now rebased onto 36e654b. The AMD runs were on SaladCloud
    containers (WSL2, /dev/dxg).
  • poly_project_mixed_test on CUDA after this change: RTX 2070 Super (sm_75), the 8 mixed cases, 2 many cases, the
    quantize check and the declines: PASS, 0 failures.

Failed:

  • none observed

Not run:

  • IQ4_NL timing on the RX 7800 XT: the host has 23 GB of RAM, so the file is read from disk.
  • Metal: the Metal block's behavior is unchanged; only its arrays grew to 8 entries.

Limits

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

…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>
@okada-shogo okada-shogo changed the title [Engine] Inkling 2 on AMD: a token's attention projections in a launch per type, inputs quantized once [Engine] Inkling 2 on AMD: group the attention projections into one launch per quant type Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] Inkling 2 on AMD: group the attention projections into one launch per quant type [Engine] Inkling 2 on AMD: group the attention projections into one launch per quant type (+1.4-4.2% decode, same bits) Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] Inkling 2 on AMD: group the attention projections into one launch per quant type (+1.4-4.2% decode, same bits) [Engine] Inkling 2 on AMD: one launch per quant type for attention projections Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] Inkling 2 on AMD: one launch per quant type for attention projections [Engine] Inkling 2 on AMD: fewer launches for attention projections Nov 24, 2026
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