Repository navigation
[Engine] Inkling 2 on GTX 16: dp4a path for --prompt-int8 - #304
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
…res), same bits A GeForce GTX 16 (TU116 / TU117) is sm_75 but has no tensor cores: there the int8 kernel's m8n8k16 MMAs (--prompt-int8, i8_mma.cuh) run slowly, about 10 times the time of dp4a for the same work. On that card the kernel now makes each MMA's four int32 sums with dp4a, read from the same shared-memory tiles (multiply_dp, i8m_dot), and adds them into the float sums in the same order. The int32 sums are exact either way, so the products are the same bits as the MMAs'. Who takes it (i8m_dp4a_pick, once per card): Turing's code only, a name with "GTX 16" and no RTX / Quadro / Tesla / TITAN, and a probe that times MMAs against dp4a (dp4a only where the MMAs are not faster; the name alone if the probe cannot run). STRATA_I8M_DP4A=1 forces dp4a on any Turing code (bit tests on an RTX card), =0 keeps the MMAs. Other cards and the default (halves) path are unchanged. strata-poly says so at load. GTX 1660 SUPER: poly_i8m_dp4a_test (new) gives 224 of 224 products the same bits as the MMAs (21 types, K 2048 and 1152, every tile width) and the kernel 1.5-3.5x faster; Inkling 2 Mini UD-Q2_K_XL with frozen capped experts gives the same tokens and top-20 probabilities as main with --prompt-int8. The idea of int8 tiles in shared memory multiplied by dp4a on cards without int8 tensor cores is llama.cpp / ggml's MMQ (ggml-cuda mmq.cuh, its dp4a path); the code here is our own, in i8_mma.cuh's structure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
STRATA_I8M_DP4A is a rollback (0) and a test switch (1); _LOG is test only. Co-Authored-By: Claude Sonnet 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
A GeForce GTX 16 card (TU116 / TU117: GTX 1630, 1650, 1660, 1660 SUPER, 1660 Ti) is sm_75 like an RTX 20 card, but it has no tensor cores. The int8 prompt kernel (
--prompt-int8,i8_mma.cuh) uses int8 tensor-core instructions (mma.syncm8n8k16). On these cards those instructions run through a slow path, about 10 times slower thandp4afor the same work.On these cards, this PR computes the same int32 sums with
dp4a. The output is bit-identical, and the int8 prompt products are about 3 times faster. With--prompt-int8, an 8,192-token prompt is 18.2% faster on a GTX 1660 Ti.The engine picks the path at load. Other cards and the default FP16 ("halves") prompt path do not change.
Prompt tok/s, GTX 1660 Ti 6 GB (TU116, i5-9300H), Inkling 2 Mini UD-Q2_K_XL. Mean of 3 warm runs, main and this PR
in turn, the same flags on both sides:
--prompt-int8--prompt-int8--prompt-int8The default flags run the same code on both sides, so their rows show the noise on this machine. The 302-token prompt is
bound by the laptop CPU's experts, not the GPU.
With the two existing rounding opt-ins,
STRATA_PREFILL_NVFP4=w4a8andSTRATA_PREFILL_IQ1S=int8, on both sides,IQ1_S and NVFP4 also go to the int8 kernel, so to dp4a on these cards. Same build pair, mean of 3 runs:
--prompt-int8+ both opt-ins--prompt-int8+ both opt-insAgainst main's default flags (52.5 tok/s at 8,192), that is 3.6 times the prompt speed. It has the opt-ins' rounding.
Decode does not use this kernel: a decode call has fewer than 32 rows. Decode tok/s after 302 tokens, mean of 3 runs:
--prompt-int8Both rows move by about the same amount, and the default-flags row runs identical code on both sides. Decode on this machine is bound by the laptop CPU's experts (20-26 ms a token), so these are run-to-run variation. On the RTX 2070 Super
(below), decode is +0.1%.
Each run (tok/s), GTX 1660 Ti
--prompt-int8--prompt-int8--prompt-int8--prompt-int8--prompt-int8--prompt-int8--prompt-int8--prompt-int8Where the time goes: GPU profile of an 8,192-token prompt, GTX 1660 Ti (ms)
From the event profiler (
STRATA_PROFILE=1, bench-report branch plus this commit), one run each:HMMA kernel; this PR does not touch them. With the opt-ins they also take dp4a, and the experts fall to 22 s.
Output identity, experts frozen and capped (900 in VRAM), 302-token prompt, 64 greedy tokens,
--top-probs 20:--prompt-int8STRATA_I8M_DP4A=0(tensor-core instructions)The end-to-end gain without the opt-ins is smaller than the kernel's 3 times. In UD-Q2_K_XL, IQ1_S (6 layers) and
NVFP4 (11 layers) are about 32% of the experts' multiply-adds, and they stay on the FP16 kernel unless the opt-ins are set (see the GPU profile above).
Related discussion
Inkling 2 Mini port series (#200);
--prompt-int8on Turing is from main.Approach
i8m_kernel, a newmultiply_dpreplacesmultiplyon these cards. Each thread already owns four outputs of an MMA (tensor-core multiply): weight rows g and g + 8, activation rows 2 tg and 2 tg + 1. It reads those rows' int8 codes from the same shared-memory tiles (i8m_lds) and adds the products withdp4a(i8m_dot). The int32 sums are exact either way. The float epilogue is the MMA path's, term for term, in the same order, so every output has the same bits.i8m_dp4a_pick, once per card and process):keeps the MMAs.
STRATA_I8M_DP4A=1forces dp4a on any Turing code (for bit tests on RTX cards);=0keeps the MMAs.STRATA_I8M_DP4A_LOG=1prints the probe.on Turing is 560 of 576 top-1 tokens, 97.2%, under the 97.8% a default change needs. This path has the same bits as
that int8 path, so the same number applies. I recommend
--prompt-int8for GTX 16 users in the docs, not anautomatic switch.
MMQ (ggml-cuda
mmq.cuh, its dp4a path). The code here is our own, ini8_mma.cuh's structure.Validation
Passed:
STRATA_I8M_DP4A(rollback;=1is a test switch) andSTRATA_I8M_DP4A_LOG(test only) are registered.python3 tools/settings_register.py --checkandtools/test_settings_register.py: OK at this commit. No engine code changed in this commit.poly_i8m_dp4a_test(new): the int8 kernel by dp4a against its MMAs, bit for bit. It covers all 21 types the kerneltakes (UD-Q2_K_XL's Q2_0, IQ1_S, IQ2_XXS/XS/S, NVFP4, MXFP4; IQ4_NL, Q8_0; the K-quants and others), K = 2,048 and
1,152, every tile width, 200 and 512 outputs, uneven and empty experts, and scattered rows.
STRATA_I8M_DP4A=1: 0 of 224 differ, and each card'sown pick is the MMAs.
poly_mmq_k32_test --turing-int8andpoly_mmq_paths_test --turing-int8pass, both with the card's pickand with
STRATA_I8M_DP4A=1.STRATA_FREEZE_EXPERTS=1 STRATA_GPU_EXPERTS=900 STRATA_POLY_AHEAD=0 strata-poly --tokens <302> --max-new 64 --top-probs 20 --max-context 4096 --expert-swaps 0 --prompt-int8, compared withcmp.--prompt-int8: prompt 302 349.6 vs 354.1 tok/s (+1.3%), prompt 2,048 774.3 vs 773.2 (−0.1%);CMAKE_CUDA_ARCHITECTURES=75;86;STRATA_PORTABLE=ONfor the GTX 1660 SUPER kernel andidentity runs and the RTX runs;
STRATA_ISA_FLOOR=avxfor the GTX 1660 Ti e2e (the same commit).Kernel time, GTX 1660 SUPER (µs, lower is better; 459 rows over 4 matrices, 512 outputs)
The absolute times move with that machine's clocks; the ratio is the stable number. Across all cases on the three GTX
1660 SUPER machines the speedup was 1.4x to 4.2x. It is smallest at 10 rows a matrix.
Failed:
Not run:
iq_kernels.cu's HIP block andi8_mma.cucompiles empty there. HIP build notrun.
Limits
--prompt-int8changes. The default FP16 path (HMMA, also slow on these cards) is unchanged.--prompt-int8unless their existing rounding opt-ins are set(
STRATA_PREFILL_IQ1S=int8,STRATA_PREFILL_NVFP4=w4a8). With those set they take this same kernel, by dp4a onthese cards (both are covered by the bit test; +45% at 8,192 against main with the same opt-ins).
🤖 Generated with Claude Code