Skip to content

[Engine] AMD: int8 prompt kernel by default - #330

Open
okada-shogo wants to merge 3 commits into
simplexai-labs:mainfrom
okada-shogo:port/hip-int8-auto
Open

okada-shogo wants to merge 3 commits into
simplexai-labs:mainfrom
okada-shogo:port/hip-int8-auto

Conversation

@okada-shogo

Copy link
Copy Markdown
Contributor

⚠️ Merge order: #292 → this PR

Stacked on #292 (port/hip-int8-tiles). The diff shows #292's commit until it merges.

Problem and result

Since 0.2.20, prompt products on AMD run on Strata's own kernels instead of llama.cpp's MMQ. On RDNA3, the FP16 tiles cannot fit 256-value blocks in LDS, and on RDNA4 they are opt-in. Every K-quant on RDNA3, and every type on RDNA4, then falls back to a slow loop: dequantize each expert's matrix to FP16, then call rocBLAS once per expert. That loop is the prompt-speed drop in #289.

This PR turns on #292's int8 kernel by default on RDNA3 and RDNA4, for every type it takes. --no-prompt-int8 (Inkling 2) or STRATA_PF_I8MMA=0 (every model, the switch CUDA already has) restores 0.2.20's path bit for bit.

Prompt tok/s, Qwen3.6-35B-A3B UD-Q3_K_M, mean of 2 runs, same machine for all columns:

Card Model Measure main this PR alone Change
RX 7800 XT 16 GB Qwen3.6 UD-Q3_K_M prompt 839 (tok/s) 507 1,722 +240%
RX 7800 XT 16 GB Qwen3.6 UD-Q3_K_M prompt 4,096 (tok/s) 545 2,318 +325%
RX 7800 XT 16 GB Qwen3.6 UD-Q3_K_M prompt 16,384 (tok/s) 421 997 +137%
RX 7800 XT 16 GB Qwen3.6 UD-Q3_K_M prompt 19,000 (tok/s) 491 1,645 +235%

For reference, the same card with 0.1.45-poly.10 (llama.cpp MMQ): 1,582 / 2,112 / 967 / 1,525. This PR is faster at every length.

Prompt tok/s, Inkling 2 Mini, mean of 2 runs:

Card Model Measure main this PR alone Change
RX 7800 XT 16 GB IQ4_NL prompt 2,048 (tok/s) 506 1,213 +140%
RX 7800 XT 16 GB IQ4_NL prompt 8,192 (tok/s) 367 643 +75%
RX 7800 XT 16 GB UD-Q2_K_XL prompt 2,048 (tok/s) 456 1,074 +136%
RX 7800 XT 16 GB UD-Q2_K_XL prompt 8,192 (tok/s) 433 964 +123%
RX 9070 XT 16 GB IQ4_NL prompt 2,048 (tok/s) 1,192 1,780 +49%
RX 9070 XT 16 GB IQ4_NL prompt 8,192 (tok/s) 618 754 +22%
RX 9070 XT 16 GB UD-Q2_K_XL prompt 2,048 (tok/s) 1,273 1,895 +49%
RX 9070 XT 16 GB UD-Q2_K_XL prompt 8,192 (tok/s) 1,257 1,832 +46%
RX 9070 XT 16 GB UD-Q4_K_M prompt 2,048 (tok/s) 1,130 1,859 +65%
RX 9070 XT 16 GB UD-Q4_K_M prompt 8,192 (tok/s) 592 751 +27%

Decode is unchanged (within ±2%).

Accuracy: the activations become int8 with one scale per 32 values, where the old path used FP16. This is lossy against main. It is the same class as llama.cpp's MMQ, which the AMD build used up to 0.1.45, and as CUDA's default on Ampere and newer.

Card Model Against main's FP16 path KL mean KL median Same top-1
RX 7800 XT Qwen3.6 UD-Q3_K_M placement control (cache 4,000) 0.0012 4.9e-4 130/132
RX 7800 XT Qwen3.6 UD-Q3_K_M llama.cpp MMQ build (0.1.45's numbers) 0.0030 9.1e-4 128/132
RX 7800 XT Qwen3.6 UD-Q3_K_M this PR alone 0.0035 1.1e-3 129/132

Inkling 2 Mini: same top-1 as main's default when fed its tokens, 9 prompts (chat, code, prose, 302 to 4,096 tokens) × 160 = 1,440 rows per row of the table. "main again" is main's own run-to-run noise. The CUDA rows are the control: the same int8 kernel on an RTX 2070 Super (--prompt-int8), where it is CUDA's default on Ampere and newer.

Card Model main again this PR alone (int8) placement control
RX 9070 XT IQ4_NL 97.4% 97.5% 97.6%
RX 9070 XT UD-Q4_K_M 98.5% 97.6% 98.4%
RX 9070 XT UD-Q2_K_XL 100% 97.5% 97.1%
RX 7800 XT IQ4_NL 97.4% 97.0% 97.7%
RX 7800 XT UD-Q2_K_XL 100% 97.3% 97.8%
RTX 2070 Super (CUDA control) IQ4_NL 99.0% 97.6% 98.4%
RTX 2070 Super (CUDA control) UD-Q2_K_XL 99.4% 97.2% 98.2%

int8 changes top-1 by the same amount on AMD as CUDA's int8 kernel does on CUDA: 0-1 point, close to a placement change.

Against llama.cpp (29b52d3, which has Inkling 2) as the reference, on the same 1,440 rows (RTX 2070 Super, IQ4_NL; the
int8 kernel is byte-identical on CUDA, RDNA3 and RDNA4): int8 is as close to llama.cpp as main's FP16 path is.

Run Same top-1 as llama.cpp KL mean KL median
main FP16 98.0% 0.0290 5.8e-4
main again 97.8% 0.0290 5.8e-4
int8 (this kernel) 97.6% 0.0264 6.9e-4
placement control 98.0% 0.0301 6.0e-4
llama.cpp against itself (3 prompts) 98.8% 0.0314 1.6e-4

llama.cpp's own reference also uses 8-bit activations for these products, so part of that closeness is by construction.
An FP16-activation llama.cpp reference did not fit an 8 GB card (not run).

Related discussion

Where the regression came from (bisect, RX 7800 XT)

Prompt tok/s, Qwen3.6 UD-Q3_K_M, ROCm 7.2.4:

Build 839 4,096 16,384 19,000
0.1.45-poly.10 1,582 2,112 967 1,525
871a54a (Strata 0.2.16 merge + cmake, llama.cpp MMQ) 1,572 2,117 980 1,524
9f9b48f (just before Strata's own prompt kernels, MMQ) 1,531 2,120 980 1,528
main 36e654b 507 545 421 491
main, -DSTRATA_POLY_MMQ=ON 1,714 2,167 986 1,549
  • The Strata 2 rebase and the strata-poly commits are not the cause: main built with MMQ is as fast as 0.1.45.
  • The cause is the prompt-kernel switch on HIP (a94e923, after 09654c0 and 0421228): K-quants go to the per-expert BLAS loop.
  • ROCm 10 adds a separate slowdown; it is tracked outside this PR.

Approach

  • engine/src/poly/mmq_own.cu: the int8 kernel is the HIP default (i8m_turing starts true there; --no-prompt-int8 sets it false, STRATA_PF_I8MMA=0 turns the card off in i8m_card()). int8_rows() asks it through gemm_iq_i8_takes(). quantize(), mul(), reads_by_index() and split_exact() all ask int8_rows(), so they agree.
  • An earlier version kept the FP16 tiles for the types they take (Q8_0, IQ4_NL, Q2_0, NVFP4 on RDNA3). That gave 1,313 tok/s at 4,096 on Qwen, against 2,318 with int8 everywhere, so int8 is used for all types.
  • terminal/data/settings-register.json: the setting is now default-on.

Validation

Passed:

  • Frozen identity on HIP, run on the RX 9070 XT (native Fedora, ROCm 7.2.4 container, gfx1201), Inkling 2 Mini IQ4_NL, prompts of 302 and 2,048 tokens, 32 greedy tokens, --top-probs 20, STRATA_FREEZE_EXPERTS=1 --vram-reserve-mib 600; main 36e654b against this series' head (port/hip-int8-rdna2 93f58c2, which contains this PR's code): --no-prompt-int8 gives main's token ids and top-20 probabilities byte for byte (2 of 2, same 2,336 experts in VRAM); so does STRATA_PF_I8MMA=0 (2 of 2). The default and --prompt-int8 give the same output as each other (2 of 2) and differ from main (the int8 kernel is active; its prompt buffers are smaller, so it also keeps 27 more experts in VRAM).
  • Settings: STRATA_POLY_HIP_INT8 is gone (never merged). python3 tools/settings_register.py --check and tools/test_settings_register.py: OK at this commit.
  • Builds at this PR's head (on [Engine] AMD: --prompt-int8 runs prompts on the int8 matrix cores #292's new head): strata-poly's engine.cpp, main.cpp, inkling2.cpp, mmq_own.cu and i8_mma.cu, HIP gfx1201;gfx1100 and CUDA sm_75; the whole strata-poly on gfx1201 at the RDNA2 PR's head. An independent review found no bugs.
  • Qwen, 4 texts × 33 rows, RX 7800 XT: logits byte-identical to main with the earlier STRATA_POLY_HIP_INT8 switch at 0 (the same code gate as STRATA_PF_I8MMA=0 now). Inkling 2 with --no-prompt-int8 and with STRATA_PF_I8MMA=0 is in the next line.
  • KL and top-1 against main, the MMQ build, a placement control and a CUDA control: tables above.
  • RX 7800 XT Inkling IQ4_NL: int8 is also faster than the FP16 tiles main uses there (+140% at 2,048), so the tiles are not kept for any type.
  • The int8 kernel's bits are [Engine] AMD: --prompt-int8 runs prompts on the int8 matrix cores #292's: byte-identical to CUDA's int8 kernel for all 20 types (RTX 2070, gfx1100, gfx1101, gfx1201).
  • Builds for gfx1101 and gfx1201 (ROCm 7.2.4).
  • Preview tree with this PR, gfx1201: default and --prompt-int8 give the same ids and top lines (IQ4_NL, 302 and 2,048 tokens).
  • tools/settings_register.py --check.

Failed:

  • None.

Not run:

Limits

  • Lossy against main (int8 activations): top-1 moves by up to about 1 point (table above), the same as CUDA's int8 default. --no-prompt-int8 or STRATA_PF_I8MMA=0 restores the old path.
  • RDNA2 and older AMD cards are not changed by this PR; they keep the BLAS loop until the RDNA2 PR.

🤖 Generated with Claude Code

🤖 Generated with Claude Code

okada-shogo and others added 3 commits November 24, 2026 11:23
…_POLY_HIP_INT8=1)

The int8 prompt kernel (i8_mma.cuh) gets a HIP body: the same block (64 weight
rows x 16 NJ activation rows, 256 values a stage, the weights decoded to int8 in
LDS by the same decoders, the next stage read into registers while this one is
multiplied), with the products on v_wmma_i32_16x16x16_iu8 (gfx11: duplicated
16-value operands; gfx12: 8 values a lane) and LDS-only barriers.  The next
stage's reads are made without branches (put() zeros what is not there), so
the compiler counts them and does not wait for all of them in the middle.  Each 32-value
block's integer sum (16 for a type with a scale per 16) is scaled and added in
the same order as the CUDA m16n8k32 / m16n8k16 path, so a product has the same
bits as CUDA's int8 kernel: poly_mmq_paths_test's new STRATA_MMQ_TEST_DUMP dumps
are byte-identical between an RTX 2070 (--turing-int8) and an RX 9070 XT
(gfx1201), an RX 7900 XTX (gfx1100) and an RX 7800 XT (gfx1101 running the
gfx1100 code), for all 20 types the kernel takes.

A launch whose blocks pass the grid's y side (65,535) goes as runs of
matrices instead of failing (a row's product does not depend on its launch).
poly_mmq_paths_test also covers matrices of 500 rows (not whole tiles), launches
of 10 and 20 rows (the 16- and 32-row tiles), small experts, Q2_0, and 70,000
one-row matrices by offset; STRATA_MMQ_TEST_REF=DIR fails the test where a
product's bytes differ from another card's dump.

strata-poly takes it on HIP only with STRATA_POLY_HIP_INT8=1 (mmq_own.cu):
int8 activations are a rounding change against HIP's FP16 tiles and BLAS loop,
the same class as CUDA's default on Ampere and newer.  NVFP4 goes with it
unless STRATA_PREFILL_NVFP4 names a mode.  Unset, nothing changes.  gfx906
keeps the stubs.

The idea of int8 activations a 32-value block with per-block scaled integer
sums is llama.cpp/ggml's MMQ, which our inkling2-amd-preview branch (PR simplexai-labs#200's
AMD work) ran on HIP through llama.cpp; NVFP4 on the int8 tiles follows
Tako88's approach.  The code here is our own, on main's kernel.

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

--prompt-int8 / --no-prompt-int8 now turn the int8 prompt kernel on and off on
RDNA3 / RDNA4 too, as on Turing, in place of a separate STRATA_POLY_HIP_INT8
variable that the flag did not know about (on AMD the flag was accepted and did
nothing).  STRATA_PF_I8MMA=0 turns the kernel off on every card, as before.
STRATA_POLY_HIP_INT8 is no longer read and leaves the settings register.

The other models of strata-poly have no such flag, so on AMD they take the
FP16 tiles and the BLAS loop as on main.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ssue simplexai-labs#289)

On HIP a prompt's quantized products have run on Strata's own kernels since 0.2.20.
A matrix that the RDNA3 FP16 tiles do not take goes to a loop that dequantizes each
expert's matrix to FP16 and calls rocBLAS once per expert: every K-quant on RDNA3,
every type on RDNA4 and everything on cards without tiles.  This loop is simplexai-labs#289's
regression.

Measured on an RX 7800 XT with Qwen3.6-35B-A3B UD-Q3_K_M (issue simplexai-labs#289), 4,096-token
prompts: 546 tok/s on the old path, 2,104 on 0.1.45's MMQ build, 1,313 with the FP16
tiles kept for the matrices they take and int8 for the rest, 2,340 with int8 for every
type the kernel takes.  So the int8 kernel is now the default on AMD, for every type it
takes.  --no-prompt-int8 (Inkling 2) turns it off, and STRATA_PF_I8MMA=0 for every
model: the FP16 tiles and the BLAS loop, as in 0.2.20-poly.4.

Class: lossy against 0.2.20-poly.4 (the activations are int8 with one scale per 32
values), the same class as llama.cpp MMQ and CUDA's Ampere default.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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