Repository navigation
[Engine] Inkling 2: Q2_0 down products on the int8 prompt kernel - #329
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
gemm_iq_i8_takes() refused Q2_0 where K is not a multiple of 256, so the 12 Q2_0 downs of Inkling 2 Mini UD-Q2_K_XL (K = 1,152, whole 64-value blocks) stayed on the FP16 grouped kernel while the file's other experts ran on the int8 one. The kernel already leaves out the sub-blocks past K in a row's last stage (as for MXFP4 and NVFP4 there), so Q2_0 now passes at K % 64 == 0. The raw cp.async stage still needs whole 256s and stays off for these rows. Such rows are an asked shape (gemm_iq_i8_allow(42)), as IQ1_S and MXFP4 are: Inkling 2 asks at load, other models' Q2_0 rows of that kind stay on the FP16 kernel, and Q2_0 rows of whole 256s are taken as before. The gates are the int8 kernel's own: Ampere and newer by default, Turing with --prompt-int8, STRATA_PF_I8MMA=0 off everywhere. Class: lossy in the same way as the kernel's other types (int8 activations with a scale per 32 values, exact int32 sums). The weights stay exact. Q2_0's block layout is ggml's. poly_mmq_paths_test covers Q2_0 at 2,048 and 1,152 values a row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
The int8 prompt kernel (
i8_mma.cuh) already takes Q2_0, but only when a row is a whole number of 256-value stages.In Inkling 2 Mini UD-Q2_K_XL, the down matrices of 12 expert layers are Q2_0 with rows of 1,152 values (18 blocks
of 64).
gemm_iq_i8_takes()refused them, so they stayed on the FP16 grouped kernel while the file's otherexperts ran on int8. On an RTX 2070 Super with
--prompt-int8, a 2K prompt spent 213 ms of GPU time there (nsys).On Ampere and newer this is the default path.
This PR lets Q2_0 through at K % 64 == 0. The kernel already skips the sub-blocks past K in a row's last stage,
as it does for MXFP4 and NVFP4 at 1,152, so no kernel code changes.
Speed: prompt tok/s, mean of 3 runs. Inkling 2 Mini UD-Q2_K_XL (loop file), fp16 KV. RTX 2070 Super with
--prompt-int8; RTX 3060 at defaults (every expert in VRAM).--prompt-int8, AMD wherethe int8 kernel runs ([Engine] gfx1032 (RX 6600): 0.2.20 prefill 1.5-2.5x below 0.1.45-poly.10 at every prompt size; poly.1 also oscillated the expert cache per request #289).
STRATA_PF_I8MMA=0turns it off everywhere.(
gemm_iq_i8_allow()). Only Inkling 2 asks. Q2_0 rows of whole 256s work as before.one scale per 32 values, the sums exact int32. Nothing is skipped.
Each run (tok/s)
One GEN request per run on a fresh
--serveengine, 3 rounds, order reversed every other round. main 36e654b.Experts in VRAM the same for both builds (2070 Super: 2,016 at load; 3060: all 3,072). The 3060 is a rented
Salad node (i7-12700E).
Accuracy against an all-FP16 reference (main with
STRATA_PF_I8MMA=0): KL over the reference's top 20 tokens,64 teacher-forced steps after the prompt, experts frozen (same cached set in every run). The FP16 noise floor
(FP16 run again) is exactly 0 on every prompt. "main" is main with
--prompt-int8.* The 2,048-token prompts are hypersensitive: any rounding change moves them a lot, in either direction.
Accuracy: top-1 and largest KL
Related discussion
PR #200, comment 7083908180 (one optimization per PR). Found while profiling UD-Q2_K_XL prompts on the RTX 2070
Super: with
--prompt-int8, the FP16 grouped kernel's time was the Q2_0 downs (213 ms) and the NVFP4 downs(423 ms, which stay on FP16 unless
STRATA_PREFILL_NVFP4=w4a8; not changed here).Approach
i8_mma.cu:gemm_iq_i8_takes()uses a K step of 64 for Q2_0, as for NVFP4.i8m_asked(t, K): Q2_0 isasked only when K % 256 != 0, so main's existing Q2_0 cases do not change.
gemm_iq_i8_allow(42)is accepted.inkling2.cpp: asks for Q2_0 at load, next to IQ1_S and MXFP4. No new setting.iq_kernels.hpp,i8_mma.cuh,mmq_own.cu: comments.docs/models/inkling.md: one paragraph.poly_mmq_paths_test: Q2_0 at 2,048 and at 1,152 values a row. At 1,152 its product is also made on the FP16kernel and compared, as for the other asked types.
Validation
Passed:
poly_mmq_paths_teston the RTX 2070 Super (with and without--turing-int8) and on an RTX 3060 (sm_86): PASS. Q2_0 int8 against its ownint8 numbers: RMS 1.1e-7 (1,152) and 1.4e-7 (2,048).
STRATA_MMQ_TEST_DUMPdumps, this commit on top of the HIP int8 branches,[Engine] AMD: --prompt-int8 runs prompts on the int8 matrix cores #292 + RDNA2 dot4):
--turing-int8), CUDA on Ampere (RTX 3060) and HIP WMMA (RX 9070 XT,gfx1201): 161 of 161 products the same on all three.
-DSTRATA_I8M_DOT4_ON_WMMA): 175 of 175 the same.STRATA_FREEZE_EXPERTS=1+ a fixed cached set, 64 greedy tokens, token ids plustop-8 logprobs and logits hashes, RTX 2070 Super):
--prompt-int8.--prompt-int8(accuracy table above).--prompt-int8: graphs and--no-graphsgive the same bits.at 302 and 8,192 different, as intended; this PR's graphs and
--no-graphsSAME.strata-poly,poly_mmq_paths_test); HIP (ROCm 7.2.4, gfx1201 + gfx1100):strata-polyandpoly_mmq_paths_testbuild.python3 tools/check --only docs: pass.Failed:
Not run:
Limits
other types there).
STRATA_PF_I8MMA=0keeps all prompt products on FP16.Today that is only the downs.
iq_kernels.hppandmmq_paths_test.cu.Credits: the int8 kernel is VecSzn's; this PR only widens what it takes. The Q2_0 block format is ggml's
(llama.cpp / ggml, MIT).
🤖 Generated with Claude Code
🤖 Generated with Claude Code