Skip to content

[Engine] Inkling 2: Q2_0 down products on the int8 prompt kernel - #329

Open
okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/i8m-q2_0-k64
Open

okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/i8m-q2_0-k64

Conversation

@okada-shogo

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

Copy link
Copy Markdown
Contributor

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 other
experts 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).

Card Model Measure main this PR alone Change
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 2,048 tokens 831.1 858.0 +3.2%
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 8,192 tokens 872.5 901.9 +3.4%
RTX 3060 12 GB UD-Q2_K_XL prompt 2,048 tokens 728.9 767.0 +5.2%
RTX 3060 12 GB UD-Q2_K_XL prompt 8,192 tokens 730.8 763.7 +4.5%
Each run (tok/s)
Card Model Measure Build Run 1 Run 2 Run 3
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 2,048 tokens main 831.2 831.4 830.7
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 2,048 tokens this PR alone 856.3 857.5 860.3
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 8,192 tokens main 872.6 872.2 872.7
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 8,192 tokens this PR alone 902.8 902.1 900.8
RTX 3060 12 GB UD-Q2_K_XL prompt 2,048 tokens main 721.9 734.2 730.6
RTX 3060 12 GB UD-Q2_K_XL prompt 2,048 tokens this PR alone 767.9 766.7 766.3
RTX 3060 12 GB UD-Q2_K_XL prompt 8,192 tokens main 731.5 730.5 730.5
RTX 3060 12 GB UD-Q2_K_XL prompt 8,192 tokens this PR alone 764.0 763.1 764.1

One GEN request per run on a fresh --serve engine, 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.

Card Model Prompt Measure main this PR
RTX 2070 Super 8 GB UD-Q2_K_XL 302 KL mean 0.00097 0.00079
RTX 2070 Super 8 GB UD-Q2_K_XL 1,024 KL mean 0.0112 0.0157
RTX 2070 Super 8 GB UD-Q2_K_XL 2,048 (code) * KL mean 0.166 0.082
RTX 2070 Super 8 GB UD-Q2_K_XL 2,048 (other text) * KL mean 0.094 0.059
RTX 2070 Super 8 GB UD-Q2_K_XL 4,096 KL mean 0.0122 0.0022
RTX 2070 Super 8 GB UD-Q2_K_XL 8,192 KL mean 0.000051 0.000073

* The 2,048-token prompts are hypersensitive: any rounding change moves them a lot, in either direction.

Accuracy: top-1 and largest KL
Prompt Measure main this PR
302 top-1 same 95.3% 95.3%
302 KL max 0.0134 0.0049
1,024 top-1 same 98.4% 100%
1,024 KL max 0.116 0.115
2,048 (code) top-1 same 93.8% 96.9%
2,048 (code) KL max 4.83 1.90
2,048 (other text) top-1 same 93.8% 95.3%
2,048 (other text) KL max 3.05 2.29
4,096 top-1 same 100% 100%
4,096 KL max 0.656 0.042
8,192 top-1 same 100% 100%
8,192 KL max 0.0012 0.0014

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 is
    asked 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 FP16
    kernel and compared, as for the other asked types.
  • The raw cp.async stage is unchanged and stays off for Q2_0 (its 72-byte stage is not whole 16-byte pieces).

Validation

Passed:

  • poly_mmq_paths_test on the RTX 2070 Super (with and without --turing-int8) and on an RTX 3060 (sm_86): PASS. Q2_0 int8 against its own
    int8 numbers: RMS 1.1e-7 (1,152) and 1.4e-7 (2,048).
  • Bytes across backends (the test's STRATA_MMQ_TEST_DUMP dumps, this commit on top of the HIP int8 branches,
    [Engine] AMD: --prompt-int8 runs prompts on the int8 matrix cores #292 + RDNA2 dot4):
    • CUDA on Turing (RTX 2070 Super, --turing-int8), CUDA on Ampere (RTX 3060) and HIP WMMA (RX 9070 XT,
      gfx1201): 161 of 161 products the same on all three.
    • HIP WMMA and the RDNA2 dot4 body (built for gfx1201 with -DSTRATA_I8M_DOT4_ON_WMMA): 175 of 175 the same.
    • Both include all 14 Q2_0 products (2,048 and 1,152 values a row).
  • Identity, main vs this PR (STRATA_FREEZE_EXPERTS=1 + a fixed cached set, 64 greedy tokens, token ids plus
    top-8 logprobs and logits hashes, RTX 2070 Super):
    • SAME: IQ4_NL and IQ3_S (Uncensored AD) at 302 and 8,192 tokens, at defaults and with --prompt-int8.
    • SAME: UD-Q2_K_XL at 302 and 8,192 tokens at defaults (int8 off on Turing).
    • Different, as intended: UD-Q2_K_XL with --prompt-int8 (accuracy table above).
    • This PR with --prompt-int8: graphs and --no-graphs give the same bits.
  • Identity on an RTX 3060 (sm_86, defaults, where int8 is on): IQ4_NL at 302 and 8,192 tokens SAME; UD-Q2_K_XL
    at 302 and 8,192 different, as intended; this PR's graphs and --no-graphs SAME.
  • Builds: CUDA sm_75 + sm_86 (CUDA 12.9: strata-poly, poly_mmq_paths_test); HIP (ROCm 7.2.4, gfx1201 + gfx1100):
    strata-poly and poly_mmq_paths_test build.
  • python3 tools/check --only docs: pass.
  • Independent code review: no correctness findings. Its comment nits are fixed.

Failed:

  • None.

Not run:

  • KL on Ampere (its products are the same bits as Turing's int8 ones, which the accuracy table measures).
  • AMD speed and AMD answers (only the kernel bytes).

Limits

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

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>
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