Repository navigation
[Engine] Inkling 2: larger tiles for prompt F32 products (controllers, routers) - #224
Draft
okada-shogo wants to merge 1 commit into
Draft
okada-shogo wants to merge 1 commit into
okada-shogo wants to merge 1 commit into
Conversation
…tiles, loaded two steps ahead Inkling 2 Mini's prompt batches send its controllers' down products (4,608 inputs to 64 outputs) and its routers (2,304 to 128) through gemm_f32(). gemm_f32_tiles() takes one group of 33 to 256 outputs in gemm_ahead_kernel: a template on the block's and a thread's tokens and outputs that reads a step's inputs and weights into registers two steps before it works on them and stores them so that a warp's writes fill the 32 banks, in the largest of four tiles that still gives half the SMs a block. Other shapes go to gemm_f32(). Each output is still one fmaf after the other in the inputs' order, so the bits are gemm_f32()'s: poly_gemm_small_test checks both against the host on Inkling 2 Mini's shapes too, and its --bench times both and prints a hash of each product. Only Inkling 2 takes it (Engine::f32_tiles_); the other families' products are unchanged. CUDA and HIP; Metal keeps its own gemm_f32. Ported from our Inkling engine (simplexai-labs#200, a34789a), adapted to main's gemm_f32(). 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.
Speed-neutral end to end. The two F32 products themselves get 12% (one slow run; 25% without it) to 47% faster on an RTX 2070 Super, but prompt
tok/s moves only +0.2% to +0.9% there, and −0.5% to +0.1% on an RTX 3060. Same bits as main.
Problem and result
For prompts with Inkling 2 Mini (CUDA and HIP). It adds a faster kernel for the two F32 matrix products of a
prompt batch. Same bits. The two products get faster, but end-to-end prompt speed does not move (see the top line).
What it changes, in plain words: in a prompt batch, Inkling 2 Mini sends two F32 products through
gemm_f32():the loop controllers' down products (4,608 inputs -> 64 outputs) and the routers (2,304 -> 128). This PR adds
gemm_f32_tiles(), which takes one group of 33 to 256 outputs in a new kernel,gemm_ahead_kernel. The kernel usesbigger tiles, reads values into registers two steps ahead, and stores to shared memory without bank conflicts. Other
shapes go to
gemm_f32()as before.Prompt speed, this PR alone against main, in tokens per second (tok/s), higher is better, mean of 3 runs (
--serve, oneGEN 1request, fp16 KV; same experts in VRAM both ways: RTX 2070 SuperIQ4_NL 929, UD-Q2_K_XL 1,988 of 3,072):
Each run (tok/s)
Prompt tok/s, higher is better, each run:
strata-poly --serve --prompt-cache 0 --conversation-cache-mib 0 --max-context 32768 --kv fp16; main d1f711e andthis branch alternated, order swapped each round. RTX 2070 Super: local card, sm_75 build. RTX 3060: rented box,
both builds for
86;89on that box.Kernel time in µs:
poly_gemm_small_test --benchKernel time, in microseconds (µs), lower is better. What it times: one prompt-batch F32 product of Inkling 2 Mini's shapes (routers 2304 inputs -> 128 outputs, loop controllers 4608 -> 64) for a batch of 333, 1024 or 4096 prompt rows. Mean of 3 runs; a negative Change is faster.
RTX 2070 Super, 2304 -> 128, 333 rows, this PR alone: run 2 (191.1 µs) was an outlier against 125.2 and 125.5.
Without it the mean is 125.35 µs, −25.1% against main; the smallest other gain on that card is then −14.3%.
Kernel time in µs, lower is better, each run:
Both functions print the same hash of the product in every case. These two products are a small part of a prompt
batch, which is why the end-to-end change is small.
Related discussion
Split out of #200, as the maintainer asked there:
#200 (comment)
Independent of the other split PRs (based on main, not stacked).
Approach
fmafafter the other in input order, likegemm_small_kernelandgemm_tile_kernel.of 19 tiles (64 outputs) and of 27 tiles (128 outputs) measured on the 2070 Super in our earlier engine.
Engine::f32_tiles_, set inInkling2::load_geometry()). Other families do not change. CUDA and HIP;Metal keeps its own
gemm_f32.poly_gemm_small_testchecks both functions against the host, bit for bit, and--benchtimes Inkling 2's shapes.Validation
Tested tree: 17a95fe9b (the engine diff to the PR head 2cc8c18 is empty); main d1f711e.
Passed:
strata-polyandpoly_gemm_small_testbuild at this commit.poly_gemm_small_test(both functions vs the hostfmachain, bit for bit) and--bench, 3 runs each: all passed,0 FAIL lines, on the RTX 2070 Super (sm_75) and an RTX 3060 12 GB (sm_86).
gemm_f32andgemm_f32_tilesprintthe same product hash in all 6 shapes.
--top-probs 20, fp16 KV,--expert-swaps 0,IQ4_NL and UD-Q2_K_XL, main twice and this PR twice): token ids and top-20 lines the same as main at 2,048 and
8,192 tokens on both cards, and UD-Q2_K_XL 302 on the RTX 3060. At 302 tokens (IQ4_NL on both cards, UD-Q2_K_XL on
the 2070 Super) the top-20 lines differ, but main vs main differs there as well, so those cases are not conclusive.
Failed: none observed.
Not run:
Limits
slower. Not measured on larger cards or AMD.
Credits: ported from our Inkling engine in #200.
🤖 Generated with Claude Code