Repository navigation
[Engine] Inkling 2 on RTX 20: faster int8 prompt kernel - #286
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
…bits) On sm_75 the int8 prompt kernel's tile of 128 activation rows takes 59-63 KB of the multiprocessor's 64 KB, so one block decodes a stage and multiplies it by turns. For Inkling 2 Mini's types (IQ4_NL, Q8_0, NVFP4, IQ2_XXS, IQ2_XS, IQ2_S) in tiles of 32 and 128 rows, the Turing pass now takes stages of 128 values with 256 threads (two blocks a multiprocessor), half of the int32 sums made floats by an exact add in place of the conversion, and for the i-quants shared rows without padding (pieces swizzled by row). The passes for Ampere and newer compile these shapes empty. Each output's terms are added in the same order: the same bits. Other cards, and STRATA_I8M_TURING=0, take the tile as before. RTX 2070 Super, poly_i8m_shapes_test --time: IQ4_NL experts gate|up 5,489 -> 5,002 us, down 3,075 -> 2,551; Q8_0 dense [2304 -> 3072] 615 -> 543; NVFP4 down 3,391 -> 2,681; IQ2_XXS 5,876 -> 5,095. poly_i8m_shapes_test: each shape against the old one, bit for bit (--time: their times), and the launcher's own pick; also rows of 704 and 1,088 values, 2,280 outputs, rows read and written by index with experts without rows; it fails where a Turing shape fits fewer than two blocks a multiprocessor. The kernel is VecSzn's (i8_mma.cuh); this changes only its tile shape on Turing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Registered as a rollback of the 128-value int8 tile stages on Turing. 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
With
--prompt-int8on an RTX 20 card (sm_75), the int8 prompt kernel (i8m_kernel) took 55-66% of the time of an 8K prompt. Its 128-row tile uses 59-63 KB of the SM's 64 KB of shared memory, so only one block runs per SM. That block decodes a stage of weights, waits at a barrier, multiplies it, and waits again, so the tensor cores sit idle while it decodes.On Turing only, this PR gives the kernel stages of 128 values instead of 256, with 256 threads. A tile then uses about 32 KB, so two blocks share an SM and one decodes while the other multiplies. The outputs are the same bits. Prompts on an RTX 2070 Super get up to 9.1% faster (IQ4_NL at 32K); other cards are not affected.
Prompt speed, RTX 2070 Super 8 GB,
--prompt-int8withSTRATA_PREFILL_NVFP4=w4a8 STRATA_INK_FAST_CTRL=1(tok/s, higher is better, mean of 3 runs):
The UD-Q2_K_XL 2K and 32K means include one slow first-round run of this PR (684 and 773 tok/s). Its other runs are
3-5% faster than main (see "Each run" below).
Other cards are not affected: the new shape is chosen only when the running code is the sm_75 pass.
Related discussion
none
Approach
i8m_kerneltakes a shape parameterCF(template).CF = 0is the shape it had before, so every other card andtype launches the same tile, the same stage size and the same arithmetic.
i8m_cf75()picks the Turing shape for Inkling 2 Mini's prompt types (IQ4_NL, Q8_0, NVFP4, IQ2_XXS, IQ2_XS,IQ2_S), in tiles of 32 and 128 rows:
__launch_bounds__(256, 2));c + 0x4B400000as a float, minus 1.5·2^23) insteadof the conversion instruction. Turing runs that conversion at a quarter of the float rate;
sign tables would otherwise leave no room for a second block.
int-to-float step is exact (|sum| < 2^22).
STRATA_I8M_TURING=0restores the old shape.poly_i8m_shapes_test: every shape against the old one, bit for bit, on Inkling's real shapes (128experts with 1,024 tokens' top-8 picks, launched by row class as the engine does, and the dense attention
products). It also runs the launcher's own pick.
--timeprints each shape's µs.The kernel is VecSzn's (
i8_mma.cuh); this PR changes only its tile shape on Turing.Kernel times: RTX 2070 Super (µs, lower is better)
poly_i8m_shapes_test --time, best of 3 runs of 10:The old tile reaches 7-12 T MAC/s, roughly 15% of the card's int8 tensor rate. The single block per SM is the main
cause. Shapes that did not help on this card: 256 threads alone (-5%), two weight tiles per warp (-5%), tiles of 64
or 32 rows (-10% to -35%).
Each run (tok/s)
Each run is a fresh
--serveprocess, with one warm-up request before the measured one. The round order alternates(main first, then this PR first, then main first).
Validation
Passed:
STRATA_I8M_TURINGis registered as a rollback.python3 tools/settings_register.py --checkandtools/test_settings_register.py: OK at this commit. No engine code changed in this commit.poly_i8m_shapes_teston a second Turing card, an RTX 2070 (non-Super, 36 SMs): every shape, the same bits.poly_i8m_shapes_teston an RTX 3060 (sm_86): the launcher's own pick (main's cp.async stage copy included) givesthe same bits as the old shape. On sm_80+ the Turing shapes are compiled empty, and the test skips them there.
STRATA_FREEZE_EXPERTS=1, greedy, token ids plus top-20 logprobs, with andwithout CUDA graphs (RTX 2070 8 GB):
--prompt-int8+STRATA_PREFILL_NVFP4=w4a8 STRATA_INK_FAST_CTRL=1); IQ4_NL at 8,150 tokens with the speed-run flags;commit vs main cdfae80, with
STRATA_GPU_EXPERTS=1800 --max-context 8256, so the attention cache fits in 8 GB.i8_mmahas not changed upstream since), 3 rounds, CUDA 12.9.poly_i8m_shapes_teston the rebased commit (RTX 2070 Super): 18 products, all the same bits. Besides Inkling'sshapes, these include K = 704 and 1,088, 2,280 outputs, and rows read and written by index with empty experts.
Each Turing shape fits 2 blocks per SM; the test fails otherwise.
integer address arithmetic is scheduled differently.
Failed:
Not run:
i8_mma.cuis CUDA-only, and HIP builds compile it empty.Limits
NVFP4 gate·up, IQ2_S and IQ2_XS slower, within ±10% run noise. Ampere stays on the old shape.
are unchanged.
🤖 Generated with Claude Code