Repository navigation
[Engine] AMD: --prompt-int8 runs prompts on the int8 matrix cores - #292
Open
okada-shogo wants to merge 2 commits into
Open
okada-shogo wants to merge 2 commits into
okada-shogo wants to merge 2 commits into
Conversation
…_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>
okada-shogo
added a commit
to okada-shogo/PolyStrata
that referenced
this pull request
Nov 25, 2026
…gfx1036) RDNA2 has no matrix cores, so on HIP the int8 prompt kernel (i8_mma.cuh) had no pass for it. strata-poly then sent every prompt product on an RX 6000 card to the per-expert dequantize + rocBLAS loop: issue simplexai-labs#289's RX 6600 reads prompts at 215-275 tok/s, where the 0.1.45 build with llama.cpp's MMQ read 365-585. i8m_kernel gets a third body, I8M_DOT4, for gfx1030-gfx1036. It uses the same LDS stage, decoders and activation layout as the WMMA body, with the products on __dp4a (v_dot4_i32_i8). Thread tid takes weight row tid % 64 and activation rows tid / 64 + 4j, so a wave's 32 lanes read one activation row together and keep their weight row's 8 words of a block in registers. The integer sum of each 32-value block (16 for a type with a scale per 16) is exact, and it is scaled and added in the same order as the CUDA and WMMA bodies, so a product has the same bits. i8m_card() reports arch 1030 for these cards, and strata-poly's default (STRATA_POLY_HIP_INT8 unset) takes the kernel there. -DSTRATA_I8M_DOT4_ON_WMMA builds this body for an RDNA3/RDNA4 pass too (v_dot4_i32_iu8), so it can be checked on a card we have. On an RX 7800 XT, poly_mmq_paths_test gives byte-identical dumps for the dot4 body (built for gfx1101 with that flag) and the WMMA body: 168 of 168 products over all 20 types. The WMMA dumps are simplexai-labs#292's, which are byte-identical to CUDA's. A gfx1030;gfx1032 build compiles with v_dot4 in the kernels. Not run on an RDNA2 card: we have none. Class: same bits as the int8 kernel on CUDA and RDNA3/RDNA4. Against 0.2.20-poly.4's RDNA2 default (the BLAS loop) it is lossy, the same class as llama.cpp's MMQ, which RDNA2 used up to 0.1.45. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 25, 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, Inkling 2's prompt expert products run in FP16: RDNA3 uses the FP16 tiles (
gemm_iq_f16_grouped), and RDNA4 uses a loop that dequantizes each expert's whole matrix to FP16 and calls rocBLAS. On CUDA (Ampere and newer), the same products run on the int8 kernel (i8_mma.cuh). That kernel was CUDA-only (mma.sync,ldmatrix,cp.async), sogemm_iq_i8_takes()returned false on HIP.This PR ports the int8 kernel to the RDNA3 (gfx11) and RDNA4 (gfx12) int8 matrix-core (WMMA) instructions. It is opt-in with
--prompt-int8(Inkling 2; the flag already exists for RTX 20, where it did the same and on AMD did nothing). Without the flag nothing changes.--no-prompt-int8says the default, andSTRATA_PF_I8MMA=0turns the int8 kernel off on every card and model, as on CUDA. Prompts get 14-44% faster on an RX 9070 XT and 115-117% faster on an RX 7800 XT.The weight decoders, the activation quantizer and the host API are the same code as on CUDA, and the integer sums are scaled and added in the same order. So a product has the same bits as CUDA's int8 kernel on the same inputs; this was checked for all 21 types the kernel takes. With the flag, the activations are int8 with a scale per 32 values (FP16 keeps 11 bits). This is the same rounding class as CUDA's default on Ampere and newer.
Prompt tok/s, mean of 3 runs, default prompt batch, same machine for both columns:
--prompt-int8)HSA_OVERRIDE_GFX_VERSION=11.0.0on both sides (the build had no gfx1101 code object).Speed with --prompt-batch 2048 (tok/s)
Mean of 3 runs, same machines. The RX 9070 XT's main column is from the first A/B run on the same box and binary
(main's path is unchanged code).
Each run (tok/s)
Side order rotated each round; one warm-up per side first. One greedy request per run through
--serve,--prompt-cache 0 --conversation-cache-mib 0 --kv fp16.Accuracy, UD-Q2_K_XL on the RX 7800 XT with all experts in VRAM. Four different 2,048-token texts; for each, the last prompt row plus 32 decode rows (132 rows in all). The reference's greedy tokens are fed to the other engines:
--prompt-int8Related discussion
In PR #200's review, VecSzn asked to split the AMD work into separate PRs. The int8 tiles use the idea of llama.cpp/ggml's MMQ
(int8 activations per 32-value block, integer sums scaled per block). Our fork's
inkling2-amd-previewbranch used iton HIP through llama.cpp. This PR is our own code on main's kernel. NVFP4 on the int8 tiles follows Tako88's approach.
Approach
i8_mma.cuh, under__HIPCC__: the block keeps its shape (64 weight rows x 16 NJ activation rows, 256 values astage, codes in LDS, the next stage read into registers while this one is multiplied). The products use
v_wmma_i32_16x16x16_iu8: gfx11 takes duplicated 16-value operands, gfx12 takes 8 values a lane. For each32-value block (16 for a type with a scale per 16),
sum * (weight scale * activation scale)is added to the FP32sum, then the minimum's term, as on CUDA. Barriers are LDS-only. The next stage's reads have no branches, so the
compiler does not wait for all of them in the middle. HIP has no cp.async path and no 128-row tile.
i8_mma.cunow builds on HIP. gfx906 still takes the stubs iniq_kernels.cu.i8_mma.cuh,mmq_own.cu:--prompt-int8(gemm_iq_i8_turing(true), the switch RTX 20 uses) lets a matrix go to the int8 kernel where it takes it. NVFP4 goes with itunless
STRATA_PREFILL_NVFP4names a mode.product does not depend on its launch, so the bits are the same.
mmq_paths_test:STRATA_MMQ_TEST_DUMP=DIRwrites each int8 product's floats and the inputs' hashes.STRATA_MMQ_TEST_REF=DIRcompares them with another card's dump and fails on any byte. New int8 cases: matrices of500 rows (not whole tiles of 64), launches of 10 and 20 rows (the 16- and 32-row tiles), small experts, Q2_0, and
70,000 one-row matrices by offset (more blocks than a grid side).
Validation
Passed:
--top-probs 20,STRATA_FREEZE_EXPERTS=1 --vram-reserve-mib 600, on the head of the stack that builds on this PR (port/hip-int8-rdna2 93f58c2; it adds the default-on change, which--no-prompt-int8turns off again):--no-prompt-int8andSTRATA_PF_I8MMA=0both give main 36e654b's token ids and top-20 probabilities byte for byte (2 of 2 each, same 2,336 experts in VRAM), and--prompt-int8differs from main (the int8 kernel is active). Without the flag this PR changes no code path.STRATA_POLY_HIP_INT8is gone (never merged; it left the register). The speed and accuracy tables were measured with the earlierSTRATA_POLY_HIP_INT8switch, which selected the same kernel as--prompt-int8does now.python3 tools/settings_register.py --checkandtools/test_settings_register.py: OK at this commit.strata-poly'sengine.cpp,main.cpp,inkling2.cpp,mmq_own.cuandi8_mma.cufor HIP gfx1201;gfx1100 (ROCm 7.2.4) and CUDA sm_75 (CUDA 12.9). An independent review of the gate change found no bugs.STRATA_PREFILL_NVFP4=w4a8 STRATA_MMQ_TEST_REF=DIR poly_mmq_paths_test --turing-int8(the test's switch; it wasSTRATA_POLY_HIP_INT8=1when these runs were made, which gated the same code), DIR = the dumps ofpoly_mmq_paths_test --turing-int8on an RTX 2070 (sm_75). RX 7900 XT(gfx1100): 168/168 products byte-identical, 122 ok, PASS. RX 9070 XT (gfx1201): the same, 168/168, 122 ok, PASS. The 168 products
are dense, experts with ids, rows by index, 500-row matrices times 10, 20 and 256 rows, and small experts, for Q4_0
Q5_0 Q5_1 Q8_0 Q2_K Q3_K Q4_K Q5_K Q6_K IQ2_XXS IQ2_XS IQ3_XXS IQ1_S IQ4_NL IQ3_S IQ2_S IQ4_XS IQ1_M MXFP4 NVFP4
Q2_0 at K = 2,048, and Q8_0 IQ4_NL NVFP4 at K = 1,152. The 70,000-matrix launch gives the dense product's bits on
all three cards.
XTX (gfx1100) and RX 7800 XT (gfx1101 running gfx1100 code). Without the flag (main's path) on the RX 9070 XT:
23/23 ok.
7.2.4; CUDA sm_75 (strata-poly, poly_mmq_paths_test), CUDA 12.9. The speed and accuracy numbers are from the
same kernel code on main cdfae80.
Failed:
Not run:
--prompt-int8; the kernel code is unchanged, and the identity run above covers the engine end to end.i8_mma.cuhis unchanged code (the HIP parts are under#if), so only a build was done.Limits
On the same box, llama.cpp's MMQ build of our stack was 1,202 / 979 tok/s (IQ4_NL 2K / 8K) against 1,155 / 970 here;
the
inkling2-amd-previewbranch was faster (2,021 / 1,096), mostly outside the expert products.🤖 Generated with Claude Code
--prompt-int8is an Inkling 2 flag). Other strata-poly models on AMD keep the FP16 tiles and the BLAS loop until the default-on PR.