Repository navigation
[Engine] Inkling 2: keep norm parameters out of local memory - #297
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
ink_cat_norm_kernel (the loop controllers' norms in a prompt, three pairs a launch) and ink_norm_many_q8_kernel (a token's three norms of a full layer's inputs) took their pointers as p[blockIdx.y]: an index into the kernel's parameters by a register, which nvcc compiles as a copy of the whole struct to local memory in every block (nine and twelve STL.64 on sm_75), and the loads through the pointers read back from there became generic loads (60 LD in ink_cat_norm_kernel) instead of global ones. ink_pick() picks the pointer by comparisons. Nothing else changes: the same threads add the same values in the same order, so the same bits. (rms_norm_many_kernel in kernels.cu has the same pattern; a separate change.) 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
This PR makes two Inkling 2 norm kernels pick their input pointer by comparisons instead of indexing the kernel's
parameter struct. The kernels get 27-38% faster; end-to-end prompt speed gains up to 0.5%. Same bits.
The kernels are
ink_cat_norm_kernel(the loop controllers' norms in a prompt, 3 pairs a launch) andink_norm_many_q8_kernel(a token's 3 norms of a full layer's inputs). Both read their pointers asp[blockIdx.y].When a kernel indexes its parameters with a register value, nvcc copies the struct to local memory in every block
(9 and 12
STL.64stores on sm_75), and the loads through those pointers become genericLDs.End-to-end, RTX 2070 Super 8 GB (Ryzen 5 3600XT), main's default flags on both sides, one
--serveengine per runwith one warm-up request, 3 rounds in alternating order. Prompt tok/s, mean of 3 runs:
Decode tok/s, the same runs, mean of 3 runs. The UD-Q2_K_XL decode rows are moved by a slow round 3 that hit every
build (see each run below); the decode kernel itself gains ~2 µs a layer.
Kernel time, RTX 2070 Super, n_embd 2304 (µs, lower is better; median of 7 × 50 launches, mean of 3 runs):
ink_cat_norm_set(3 pairs)ink_cat_norm_set(3 pairs)ink_norm_many_q8(3 inputs, decode)Each run (tok/s)
Prompt, each run (tok/s):
Decode, each run (tok/s):
Experts in VRAM at load: 917 in every IQ4_NL run and 1,967 in every UD-Q2_K_XL run, on both main and this PR.
Related discussion
none (one optimization per PR, as asked on #200)
Approach
ink_pick()returnsp[0],p[1]orp[2]by comparingblockIdx.y(both launchers allow 1 to 3 entries).Nothing else changes: the same threads add the same values in the same order. Only
inkling2.cuchanges. The samepattern is in
rms_norm_many_kernel(kernels.cu), fixed in a separate PR (#296, port/norm-many); the two areindependent.
Validation
All on branch 325c4dd = main 36e654b + this PR (the binaries measured were built from d549fa8b3, which
differs only in a comment).
Passed:
ink_cat_norm_set(3 pairs, 302 and 1,024 rows) andink_norm_many_q8(3 inputs, 1 row), main'sinkling2.cuagainst this PR's: byte-identical outputs, 2 runs each (RTX 2070 8 GB).poly_inkling2_test: 425 checks, 0 failed (RTX 2070 8 GB).STRATA_FREEZE_EXPERTS=1 STRATA_GPU_EXPERTS=850, token ids + top-20 of 32 greedy tokens: IQ4_NLand UD-Q2_K_XL, 302 and 2,048 tokens, each with main's defaults,
--no-graphs, and the int8/w4a8 prompt flags:same as main in all 12 cases (RTX 2070 8 GB).
strata-polyandpoly_inkling2_testcompile.Failed:
Not run:
Limits
ink_mix_many_kernel(decode, 12 jobs per launch) and the conv state kernel have the same pattern; they are notchanged here.
🤖 Generated with Claude Code