Skip to content

[Engine] Inkling 2: prompt flash attention picks its block size by the last wave, same bits - #262

Merged
VecSzn merged 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/flash-fill
Nov 23, 2026
Merged

VecSzn merged 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/flash-fill

Conversation

@okada-shogo

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

Copy link
Copy Markdown
Contributor

Same bits as main. No regression was measured on Turing, Ampere (RTX A5000) or Blackwell (RTX 5070). On Turing (RTX 2070) nothing changes by construction: the call goes to ink_mma75_kernel / ink_flash75_kernel, whose SASS matches main's, and identity is SAME.

What it speeds up: cards whose SM count leaves a ragged last wave for a 1,024-row chunk (about 60 SMs). The gain was measured on an RTX 5080 Laptop (60 SMs), against an older main (labelled below).

On every card: a prompt's last, shorter chunk can get a smaller block. On the A5000 a 256-row last chunk takes 32-row blocks and is 45–47% faster per call.

Head b2e2a95, rebased onto main 4664424. It is one commit on top of #230's ink_flash_kernel<G, LEAN>. The RTX 5070 and RTX A5000 runs used a547e4a against its parent f0ab63a. That is the same change before the last rebase, which only merged #278's test cases and did not touch this code. The 5080 Laptop gain is from this PR's first version (37670fc, against main d1f711e).

Problem and result

ink_flash_kernel (Inkling 2's prompt attention, sm_80+; without LEAN, so every card but sm_80) takes 64 query rows a block, so a 1,024-row prompt call is 128 blocks (16 × 8 key heads) at one block per multiprocessor. On an RTX 5080 Laptop (60 SMs) that is 2.13 waves, and the third wave has only 8 blocks. The grid-fill audit flagged this as the largest single fill loss on RTX 50 cards.

The block size is now a template argument. ink_flash_tokens() picks the size whose launch ends soonest, counted in waves. On the 5080 Laptop it picks 48 rows (176 blocks, 2.93 waves): one layer's attention is 4% to 16% faster. End to end, the 32K prompt is 7% faster. At 8K the measured +7% is mostly noise (see below). The 2K prompt is mostly expert copies over the bus and varies by ±12% from run to run.

Head on an RTX 5070 (48 SMs), prompt tok/s, higher is better. main = parent f0ab63a. IQ4_NL, fp16 cache, 1,771 of 3,072 experts in VRAM in every run; mean of 3 interleaved runs. On 48 SMs the rule keeps 64 rows for full 1,024-row calls, and only a prompt's last, shorter chunk changes, so no change is expected:

Card Model Measure main (tok/s) this PR alone (tok/s) Change
RTX 5070 12 GB IQ4_NL prompt 2K 1785.4 1784.6 0%
RTX 5070 12 GB IQ4_NL prompt 8K 2584.1 2582.4 −0.1%
RTX 5070 12 GB IQ4_NL prompt 32K 2601.3 2601.0 0%

Head on an RTX 5070, decode tok/s, higher is better (128 tokens written after each prompt, same runs; decode does not use this kernel):

Card Model Measure main (tok/s) this PR alone (tok/s) Change
RTX 5070 12 GB IQ4_NL decode after 2K 68.9 68.7 −0.3%
RTX 5070 12 GB IQ4_NL decode after 8K 63.2 63.0 −0.3%
RTX 5070 12 GB IQ4_NL decode after 32K 50.8 50.6 −0.4%

Head on an RTX A5000 (sm_86, 64 SMs), prompt tok/s, higher is better. main = parent f0ab63a. IQ4_NL, fp16 cache, all 3,072 experts in VRAM; mean of 3 interleaved runs. On 64 SMs a 1,024-row chunk is exactly 2 full waves of 64-row blocks, so the rule keeps 64 there. Only the 32K prompt's last 256-row chunk changes (to 32 rows):

Card Model Measure main (tok/s) this PR alone (tok/s) Change
RTX A5000 24 GB IQ4_NL prompt 2K 2137.5 2158.4 +1.0%
RTX A5000 24 GB IQ4_NL prompt 8K 2267.8 2260.4 −0.3%
RTX A5000 24 GB IQ4_NL prompt 32K 2057.2 2053.6 −0.2%

Head on an RTX A5000, decode tok/s, higher is better (128 tokens written after each prompt, same runs):

Card Model Measure main (tok/s) this PR alone (tok/s) Change
RTX A5000 24 GB IQ4_NL decode after 2K 85.7 85.4 −0.4%
RTX A5000 24 GB IQ4_NL decode after 8K 81.9 81.6 −0.4%
RTX A5000 24 GB IQ4_NL decode after 32K 70.9 70.2 −1.0%

Head on an RTX A5000, one call (µs, lower is better): poly_ink_flash_test --bench --rows 256, mean of 3 runs. "main" is 64 rows fixed (STRATA_INK_FLASH_TOKENS=64):

Card Model Measure main (µs) this PR alone (µs) Change
RTX A5000 24 GB Inkling 2 Mini shape full layer, 256 rows, 2K keys (32 picked) 536 285 −46.8%
RTX A5000 24 GB Inkling 2 Mini shape full layer, 256 rows, 8K keys (32 picked) 1504 820 −45.5%
RTX A5000 24 GB Inkling 2 Mini shape full layer, 256 rows, 32K keys (32 picked) 6078 3263 −46.3%
RTX A5000 24 GB Inkling 2 Mini shape window layer, 256 rows, 32K keys (32 picked) 396 218 −44.9%

First version on an RTX 5080 Laptop (60 SMs), prompt tok/s, higher is better. main = d1f711e. IQ4_NL, fp16 cache, 2,445 of 3,072 experts in VRAM in every run; mean of 5 interleaved runs:

Card Model Measure main (tok/s) this PR alone (tok/s) Change
RTX 5080 Laptop 16 GB IQ4_NL prompt 2K 494.2 477.4 −3.4%
RTX 5080 Laptop 16 GB IQ4_NL prompt 8K 1240.5 1330.2 +7.2%
RTX 5080 Laptop 16 GB IQ4_NL prompt 32K 1910.3 2043.8 +7.0%

First version on an RTX 5080 Laptop, decode tok/s, higher is better (128 tokens written after each prompt, same runs; decode does not use this kernel):

Card Model Measure main (tok/s) this PR alone (tok/s) Change
RTX 5080 Laptop 16 GB IQ4_NL decode after 2K 63.0 64.0 +1.6%
RTX 5080 Laptop 16 GB IQ4_NL decode after 8K 60.7 60.5 −0.3%
RTX 5080 Laptop 16 GB IQ4_NL decode after 32K 47.6 47.9 +0.6%

What this PR itself saves is the kernel time. Inside the engine (nsys, mean of 2 runs), the flash kernel's total drops by 5.3% at a 2K prompt (4 ms) and by 10.7% at 8K (44 ms of a 6.2 s prompt). So most of the +7% at 8K is this box's run-to-run spread, not this change. At 32K, attention is a larger share of the prompt, and all 5 runs of this PR are faster than all 5 of main. The runs are below.

Each run (tok/s)

Head on the RTX A5000, prompt tok/s, binaries of a547e4a and f0ab63a (sm_86, portable CPU code); round order alternates:

Card Model Measure Build Run 1 Run 2 Run 3
RTX A5000 24 GB IQ4_NL prompt 2K main 2181.3 2117.3 2113.8
RTX A5000 24 GB IQ4_NL prompt 2K this PR alone 2173.5 2152.1 2149.5
RTX A5000 24 GB IQ4_NL prompt 8K main 2301.3 2249.7 2252.3
RTX A5000 24 GB IQ4_NL prompt 8K this PR alone 2290.9 2239.3 2251.1
RTX A5000 24 GB IQ4_NL prompt 32K main 2091.6 2016.2 2063.8
RTX A5000 24 GB IQ4_NL prompt 32K this PR alone 2066.3 2056.2 2038.3

Head on the RTX A5000, decode tok/s, the same runs:

Card Model Measure Build Run 1 Run 2 Run 3
RTX A5000 24 GB IQ4_NL decode after 2K main 87.6 84.9 84.5
RTX A5000 24 GB IQ4_NL decode after 2K this PR alone 87.0 84.6 84.5
RTX A5000 24 GB IQ4_NL decode after 8K main 83.0 81.3 81.3
RTX A5000 24 GB IQ4_NL decode after 8K this PR alone 82.4 81.2 81.2
RTX A5000 24 GB IQ4_NL decode after 32K main 72.1 69.5 71.1
RTX A5000 24 GB IQ4_NL decode after 32K this PR alone 70.5 70.3 69.7

Head on the RTX 5070, prompt tok/s, binaries of a547e4a and f0ab63a (sm_120); round order alternates (main first in rounds 1 and 3):

Card Model Measure Build Run 1 Run 2 Run 3
RTX 5070 12 GB IQ4_NL prompt 2K main 1785.4 1785.8 1784.9
RTX 5070 12 GB IQ4_NL prompt 2K this PR alone 1786.9 1783.7 1783.2
RTX 5070 12 GB IQ4_NL prompt 8K main 2586.0 2585.1 2581.2
RTX 5070 12 GB IQ4_NL prompt 8K this PR alone 2583.5 2582.5 2581.3
RTX 5070 12 GB IQ4_NL prompt 32K main 2600.5 2602.2 2601.2
RTX 5070 12 GB IQ4_NL prompt 32K this PR alone 2603.8 2600.6 2598.5

Head on the RTX 5070, decode tok/s, the same runs:

Card Model Measure Build Run 1 Run 2 Run 3
RTX 5070 12 GB IQ4_NL decode after 2K main 69.0 69.0 68.6
RTX 5070 12 GB IQ4_NL decode after 2K this PR alone 68.8 68.5 68.8
RTX 5070 12 GB IQ4_NL decode after 8K main 63.2 63.4 63.1
RTX 5070 12 GB IQ4_NL decode after 8K this PR alone 63.4 63.1 62.5
RTX 5070 12 GB IQ4_NL decode after 32K main 50.9 50.8 50.7
RTX 5070 12 GB IQ4_NL decode after 32K this PR alone 50.7 50.5 50.5

Prompt tok/s, RTX 5080 Laptop 16 GB, IQ4_NL, binary of 37670fc; round order alternates (main first in rounds 1, 3, 5):

Card Model Measure Build Run 1 Run 2 Run 3 Run 4 Run 5
RTX 5080 Laptop 16 GB IQ4_NL prompt 2K main 533.8 412.0 544.5 492.5 488.0
RTX 5080 Laptop 16 GB IQ4_NL prompt 2K this PR alone 520.6 484.2 495.4 468.3 418.7
RTX 5080 Laptop 16 GB IQ4_NL prompt 8K main 1206.1 1333.1 1215.6 1309.8 1137.8
RTX 5080 Laptop 16 GB IQ4_NL prompt 8K this PR alone 1312.3 1310.0 1395.2 1330.3 1303.3
RTX 5080 Laptop 16 GB IQ4_NL prompt 32K main 1886.2 1960.7 1947.2 1934.9 1822.5
RTX 5080 Laptop 16 GB IQ4_NL prompt 32K this PR alone 2028.0 1982.3 2033.5 2083.9 2091.3

Decode tok/s, the same runs:

Card Model Measure Build Run 1 Run 2 Run 3 Run 4 Run 5
RTX 5080 Laptop 16 GB IQ4_NL decode after 2K main 58.8 65.0 63.9 63.5 63.8
RTX 5080 Laptop 16 GB IQ4_NL decode after 2K this PR alone 64.4 63.7 63.0 63.3 65.5
RTX 5080 Laptop 16 GB IQ4_NL decode after 8K main 61.3 61.0 60.4 60.4 60.6
RTX 5080 Laptop 16 GB IQ4_NL decode after 8K this PR alone 59.3 60.4 60.8 60.5 61.6
RTX 5080 Laptop 16 GB IQ4_NL decode after 32K main 48.0 46.9 47.9 47.5 47.9
RTX 5080 Laptop 16 GB IQ4_NL decode after 32K this PR alone 48.1 48.0 47.7 48.4 47.2

An earlier 3-round run of the same comparison (binary of an earlier revision whose rule made the same choices on this card: 48 rows for every call of these prompts), prompt tok/s:

Card Model Measure Build Run 1 Run 2 Run 3
RTX 5080 Laptop 16 GB IQ4_NL prompt 2K main 510.7 393.4 473.9
RTX 5080 Laptop 16 GB IQ4_NL prompt 2K this PR alone 494.7 494.4 471.3
RTX 5080 Laptop 16 GB IQ4_NL prompt 8K main 1083.3 1159.3 1329.2
RTX 5080 Laptop 16 GB IQ4_NL prompt 8K this PR alone 1284.8 1344.6 1254.6
RTX 5080 Laptop 16 GB IQ4_NL prompt 32K main 1963.2 2021.0 2020.9
RTX 5080 Laptop 16 GB IQ4_NL prompt 32K this PR alone 2018.0 2006.3 2059.7

Decode tok/s, that run:

Card Model Measure Build Run 1 Run 2 Run 3
RTX 5080 Laptop 16 GB IQ4_NL decode after 2K main 64.3 63.0 63.6
RTX 5080 Laptop 16 GB IQ4_NL decode after 2K this PR alone 63.5 63.8 64.3
RTX 5080 Laptop 16 GB IQ4_NL decode after 8K main 60.9 60.3 60.5
RTX 5080 Laptop 16 GB IQ4_NL decode after 8K this PR alone 61.2 60.9 60.7
RTX 5080 Laptop 16 GB IQ4_NL decode after 32K main 47.2 48.4 48.4
RTX 5080 Laptop 16 GB IQ4_NL decode after 32K this PR alone 48.0 48.2 47.4
Kernel times (µs, lower is better)

Head on the RTX 5070, one call: poly_ink_flash_test --bench [--rows 256], best of 5 calls a run, mean of 3 runs. "main" is the same binary with 64 rows fixed (STRATA_INK_FLASH_TOKENS=64), whose SASS is main's. µs, lower is better:

Card Model Measure main (µs) this PR alone (µs) Change
RTX 5070 12 GB Inkling 2 Mini shape full layer, 1,024 rows, 2K keys (64 picked) 1051 1049 −0.2%
RTX 5070 12 GB Inkling 2 Mini shape full layer, 1,024 rows, 8K keys (64 picked) 3374 3376 +0.1%
RTX 5070 12 GB Inkling 2 Mini shape full layer, 1,024 rows, 32K keys (64 picked) 12816 12722 −0.7%
RTX 5070 12 GB Inkling 2 Mini shape window layer, 1,024 rows, 32K keys (64 picked) 804 806 +0.2%
RTX 5070 12 GB Inkling 2 Mini shape full layer, 256 rows, 2K keys (48 picked) 381 322 −15.5%
RTX 5070 12 GB Inkling 2 Mini shape full layer, 256 rows, 8K keys (48 picked) 1170 1021 −12.7%
RTX 5070 12 GB Inkling 2 Mini shape full layer, 256 rows, 32K keys (48 picked) 4353 3816 −12.3%
RTX 5070 12 GB Inkling 2 Mini shape window layer, 256 rows, 32K keys (48 picked) 262 222 −15.3%

On the 5070 the rule's choices hold. At 1,024 rows, forcing 48 or 32 would be slower: full layer at 32K keys, 14945 µs with 48 rows and 15504 µs with 32, against 12816 µs with 64. At 256 rows, 48 is fastest.

Head on the RTX 5070, in the engine: total ink_flash_kernel time per prompt under nsys 2026.5.2, 2 runs each. ms, lower is better:

Card Model Measure main (ms) this PR alone (ms) Change
RTX 5070 12 GB IQ4_NL prompt 2K, flash kernel total (96 launches) 67.4 67.4 0%
RTX 5070 12 GB IQ4_NL prompt 8K, flash kernel total (384 launches) 382.3 382.3 0%
Card Model Measure Build Run 1 Run 2
RTX 5070 12 GB IQ4_NL prompt 2K, flash kernel total (ms) main 67.3 67.4
RTX 5070 12 GB IQ4_NL prompt 2K, flash kernel total (ms) this PR alone 67.3 67.4
RTX 5070 12 GB IQ4_NL prompt 8K, flash kernel total (ms) main 382.2 382.4
RTX 5070 12 GB IQ4_NL prompt 8K, flash kernel total (ms) this PR alone 382.2 382.4

The tables below are the first version on the RTX 5080 Laptop.

In the engine: total time of ink_flash_kernel in one prompt under nsys profile --trace=cuda (2026.5.2). Values are ms, lower is better. RTX 5080 Laptop, IQ4_NL, fp16 cache, --tokens N --max-new 1, 2 runs:

Card Model Measure main (ms) this PR alone (ms) Change
RTX 5080 Laptop 16 GB IQ4_NL prompt 2K, flash kernel total (96 launches) 77.5 73.4 −5.3%
RTX 5080 Laptop 16 GB IQ4_NL prompt 8K, flash kernel total (384 launches) 410.5 366.5 −10.7%
Card Model Measure Build Run 1 Run 2
RTX 5080 Laptop 16 GB IQ4_NL prompt 2K, flash kernel total (ms) main 77.3 77.6
RTX 5080 Laptop 16 GB IQ4_NL prompt 2K, flash kernel total (ms) this PR alone 70.6 76.2
RTX 5080 Laptop 16 GB IQ4_NL prompt 8K, flash kernel total (ms) main 413.4 407.5
RTX 5080 Laptop 16 GB IQ4_NL prompt 8K, flash kernel total (ms) this PR alone 366.6 366.4

The flash kernel is 10% of the prompt's kernel time at 2K and 16% at 8K on this card (doorbell kernels left out).

One call: poly_ink_flash_test --bench [--rows 256], one call of Inkling 2 Mini's shape (24 query heads on 8 key heads, window 1,024), best of 5 calls a run, mean of 3 runs. "main" is the same binary with the block size fixed at 64 rows (STRATA_INK_FLASH_TOKENS=64): main's kernel, the same code. µs, lower is better:

Card Model Measure main (µs) this PR alone (µs) Change
RTX 5080 Laptop 16 GB Inkling 2 Mini shape full layer, 1,024 rows, 2K keys 1005 962 −4.3%
RTX 5080 Laptop 16 GB Inkling 2 Mini shape full layer, 1,024 rows, 8K keys 3668 3091 −15.7%
RTX 5080 Laptop 16 GB Inkling 2 Mini shape full layer, 1,024 rows, 32K keys 12851 11642 −9.4%
RTX 5080 Laptop 16 GB Inkling 2 Mini shape window layer, 1,024 rows, 2K keys 834 717 −14.0%
RTX 5080 Laptop 16 GB Inkling 2 Mini shape window layer, 1,024 rows, 8K keys 835 717 −14.1%
RTX 5080 Laptop 16 GB Inkling 2 Mini shape window layer, 1,024 rows, 32K keys 841 726 −13.7%
RTX 5080 Laptop 16 GB Inkling 2 Mini shape full layer, 256 rows, 2K keys 395 341 −13.7%
RTX 5080 Laptop 16 GB Inkling 2 Mini shape full layer, 256 rows, 8K keys 1179 1054 −10.6%
RTX 5080 Laptop 16 GB Inkling 2 Mini shape full layer, 256 rows, 32K keys 4586 3906 −14.8%
RTX 5080 Laptop 16 GB Inkling 2 Mini shape window layer, 256 rows, 2K keys 272 236 −13.2%
RTX 5080 Laptop 16 GB Inkling 2 Mini shape window layer, 256 rows, 8K keys 274 235 −14.2%
RTX 5080 Laptop 16 GB Inkling 2 Mini shape window layer, 256 rows, 32K keys 271 236 −12.9%

Each run of the 1,024-row full-layer calls (µs):

Card Model Measure Build Run 1 Run 2 Run 3
RTX 5080 Laptop 16 GB Inkling 2 Mini shape full, 2K keys 64 rows (main) 1006 1005 1003
RTX 5080 Laptop 16 GB Inkling 2 Mini shape full, 2K keys this PR alone (48) 956 963 967
RTX 5080 Laptop 16 GB Inkling 2 Mini shape full, 8K keys 64 rows (main) 3446 3719 3838
RTX 5080 Laptop 16 GB Inkling 2 Mini shape full, 8K keys this PR alone (48) 3096 3088 3088
RTX 5080 Laptop 16 GB Inkling 2 Mini shape full, 32K keys 64 rows (main) 12863 12854 12837
RTX 5080 Laptop 16 GB Inkling 2 Mini shape full, 32K keys this PR alone (48) 11644 11647 11635

Each size forced, mean of 3 runs (µs, lower is better). Rows of 32 are slower than 64 at 1,024 rows on this card, so the rule does not take them there:

Card Measure 64 rows 48 rows 32 rows
RTX 5080 Laptop 16 GB full, 1,024 rows, 32K keys 12851 11657 13466
RTX 5080 Laptop 16 GB window, 1,024 rows, 32K keys 841 725 796
RTX 5080 Laptop 16 GB full, 256 rows, 32K keys 4586 3966 5419

All per-run logs are listed under Validation.

Related discussion

Approach

  • ink_flash_kernel<G, LEAN, TOKENS>: the rows a block are now a template argument. It defaults to main's value (32 with LEAN, 64 without), and without LEAN it can also be 48 or 32. The kernel body is [Engine] Inkling 2: flash attention: 32-token blocks on A100-class cards (sm_80), same bits #230's.
  • The default kernels are main's, instruction for instruction. This was checked by comparing cuobjdump SASS: <G, false, 64> against main's <G, false> and <G, true, 32> against <G, true>, for G = 1 to 4 on sm_86, sm_89 and sm_120. The 4 Turing ink_flash75_kernels match too.
  • ink_flash_tokens() picks a size per call:
    • For each size, it counts waves: blocks over the resident slots (SMs × cudaOccupancyMaxActiveBlocksPerMultiprocessor), rounded up.
    • It weights each wave by the block's time relative to a 64-row block: 0.9 for 48 rows and 0.65 for 32, measured on the 5080 Laptop. In this build nvcc gives both 48 and 64 rows 168 registers (with spills); 32 rows get 250 and do not spill.
    • A size other than 64 is taken only when it is at least 5% cheaper.
    • For Inkling 2 Mini's 1,024-row calls (one block per SM), it moves to 48 on cards with 59 to 63, 88 to 127 or 176 to 199 SMs, and keeps 64 on every other SM count. Of those, only the 5080 Laptop (60 SMs) was measured. The others include the RTX 5000 Ada (100) and RTX PRO 6000 Blackwell (188). The A100 (108) runs LEAN and is not affected.
    • Short calls (the last chunk of a prompt) can take 48 or 32 on other cards too.
  • Why the bits stay the same: a row's scores, weights and sums do not depend on which block holds it. Its key tiles still start at multiples of 64 and go in the same order. The tiles that a wider block adds for its other rows give this row weights of 0 and a scale of 1, or keep its zeros before its first key.
  • STRATA_INK_FLASH_TOKENS=64/48/32 fixes the size. 64 is main's shape, so it is the off switch. It is registered in the settings register as rollback.
  • ink_attend_batch_rows(a, stream, tokens) takes a forced size, for the test. ink_attend_batch() keeps its signature, because Metal defines its own.
  • poly_ink_flash_test ([Engine] Inkling 2: flash attention: 32-token blocks on A100-class cards (sm_80), same bits #230's) now checks each case at every size, with fp16 caches and, with hashes only, FP8 and Q8_0 caches. It also has 1,024-row prompt-chunk cases and --bench [--rows N] per size.
  • Unchanged: LEAN on sm_80, STRATA_FAST_ATTN's ink_fast_kernel, Turing's ink_flash75_kernel, HIP's RDNA4 kernel, Metal (its own ink_attend_batch(), same signature), and every other model.
  • ink_flash_tokens() returns 0 when a call goes to one of those other kernels. The test then skips its size loop.

Validation

Passed (head b2e2a95, on main 4664424):

  • Build: CUDA 12.9, 75;86;89;120, strata-poly and poly_ink_flash_test. python3 tools/settings_register.py --check: exit 0. python3 tools/check --only docs: passed.
  • SASS (cuobjdump): the 8 Turing kernels (ink_mma75_kernel, ink_flash75_kernel) match main 4664424 instruction for instruction.
  • Turing, RTX 2070 8 GB (sm_75, Bazzite), b2e2a95 against main 4664424. Nothing changes by construction: the call goes to ink_mma75_kernel / ink_flash75_kernel, whose SASS matches main's.
    • poly_ink_flash_test: rc=0 for both. The output hashes are the same in 14 of 14 shared cases, including [Engine] Inkling 2: prompt attention on Turing in attn_mma_kernel's shape, 2.8 -> 1.0 ms a layer #278's split-call cases. ink_flash_tokens() returns 0 there, so no size loop runs.
    • Identity, --tokens 2,048 and 8,192 + 64 greedy, --top-probs 20, fp16 cache, STRATA_GPU_EXPERTS=850 STRATA_FREEZE_EXPERTS=1, --expert-swaps 0: ids and every top-20 line are the same, against main and against each forced size: 8 / 8 SAME. Both builds refuse --kv fp8 on Turing.

Passed (a547e4a, on main f0ab63a; the same change before the last rebase):

  • RTX A5000 24 GB (sm_86, 64 SMs, driver 580.178.04, i9-10900X), rented vast.ai box, sm_86 binaries with portable CPU code (RB_MARCH=v3, both builds):
    • poly_ink_flash_test: rc=0, 117 / 117 calls give the same bits at every size (fp16, FP8 and Q8_0 caches).
    • Identity against f0ab63a, --tokens 2,048 and 8,192 + 64 greedy, --top-probs 20, frozen experts, fp16 and FP8 at 2,048: 11 / 11 SAME.
    • Speed and per-call times: the tables above, every run rc=0.
  • RTX 5070 12 GB (sm_120, 48 SMs, driver 595.99.02, Ryzen 7 5800XT), rented vast.ai box, binaries of a547e4a and f0ab63a (CUDA 12.9, sm_120):
    • poly_ink_flash_test: rc=0, 39 ok and 0 FAIL. Every call with each of 64, 48 and 32 rows gives the bits of the chosen size: 117 / 117 calls (13 cases × 3 sizes × fp16, FP8 and Q8_0 caches).
    • Identity in the engine against f0ab63a. Setup: --tokens 2,048 and 8,192 + 64 greedy, --top-probs 20, STRATA_GPU_EXPERTS=1300 STRATA_FREEZE_EXPERTS=1, --expert-swaps 0, fp16 cache, plus FP8 at 2,048. Result: ids and every top-20 line are the same, against main and against each forced size: 11 / 11 SAME.
    • Speed, kernel times and nsys: the tables above, every run rc=0. --serve with one greedy request per run, 32K context, default flags, no expert profile. The 32K prompt is the 8,192-token test prompt repeated to 32,000 tokens.
  • Build: CUDA 12.9, CMAKE_CUDA_ARCHITECTURES=75;86;89;120, strata-poly and poly_ink_flash_test (local). main f0ab63a was built the same way.
  • SASS (cuobjdump, CUDA 12.9): this PR's default kernels are main's, instruction for instruction. That is ink_flash_kernel<G, false, 64> against main's <G, false> and <G, true, 32> against <G, true>, for G = 1 to 4 on sm_86, sm_89 and sm_120: 24 of 24 the same. The 4 sm_75 ink_flash75_kernels are the same too.
  • Register usage (cuobjdump, G = 3): 48 and 64 rows get 168 registers (with spills) on sm_86, sm_89 and sm_120; 32 rows get 232 to 254 and do not spill. The same as in the first version.
  • python3 tools/settings_register.py --check: exit 0. python3 tools/check --only docs: 6 of 6 passed.
  • Turing, RTX 2070 8 GB (sm_75, driver 610.43.03), a547e4a against f0ab63a: there the call goes to ink_flash75_kernel, which this PR leaves alone.
    • poly_ink_flash_test: rc=0 for both main f0ab63a and this head. The ink_flash75_kernel output hashes are the same in 11 of 11 shared cases. ink_flash_tokens() returns 0, so no size loop runs.
    • Identity, --tokens 2,048 and 8,192 + 64 greedy, --top-probs 20, fp16 cache, STRATA_GPU_EXPERTS=850 STRATA_FREEZE_EXPERTS=1, --expert-swaps 0: ids and every top-20 line are the same, main against this PR and against each forced size: 8 / 8 SAME. Turing has no FP8 cache, and both builds refuse --kv fp8 there.

Passed (first version 37670fc, on main d1f711e, the same rule and the same per-size kernel code then):

  • Kernel bits, RTX 5080 Laptop (sm_120, driver 621.24). poly_ink_flash_test ran 13 cases: groups of 1 to 4 query heads, full and window layers, ring caches, the gate, calls past position 0, and 1,024-row prompt chunks. The fp16 cases are checked against float64, and the same cases also run with FP8 caches. Every call with each of 64, 48 and 32 rows gives the bits of the chosen size: 78 / 78 calls, 0 failed.
  • Identity in the engine, RTX 5080 Laptop, against main d1f711e. Setup: --tokens 2,048 and 8,192 + 64 greedy, --top-probs 20, experts frozen (STRATA_FREEZE_EXPERTS=1, --expert-swaps 0; the same 2,445 experts in VRAM in every run), fp16 cache, plus FP8 cache at 2,048. Result: ids and every top-20 line are the same, main against this PR and against each forced size: 11 / 11 comparisons SAME.
  • Speed and nsys: the tables above. Salad container (RTX 5080 Laptop 16 GB, Core Ultra 9 275HX, a consumer host, not a controlled timing box), --serve with one greedy request per run, 32K context, default flags, no expert profile. The 32K prompt is the 8,192-token test prompt repeated to 32,000 tokens. Every run rc=0.
  • An independent review found that the first version broke the Metal link: the header gave ink_attend_batch() a third argument that Metal's definition lacks. The head keeps ink_attend_batch()'s signature and adds ink_attend_batch_rows().

Failed:

  • none observed

Not run:

  • The gain case on the head: a card with about 59–63 SMs, such as the RTX 5080 Laptop. The Salad node is unreachable, and vast's only ~60-SM offers are Ada cards at $0.40–0.44/h, so it was skipped. The 5080 Laptop numbers are from the first version, which had the same rule and per-size kernel code, against the older main.
  • RTX 3060 (28 SMs) and RTX 4060 Ti (sm_89, 34 SMs): not run. Ampere is covered by the A5000.
  • Ampere follow-up, not in this PR: on the A5000, 32-row blocks are also faster for full 1,024-row chunks (32K keys: 12827 µs with 32 rows against 15189 µs with 64, −15.5%). There the 64-row kernel spills and the 32-row one does not. The rule's relative costs were measured on sm_120, so it keeps 64 on that card. A per-arch cost, or an autotune at load as [Engine] Inkling 2: autotuned kernel for prompt F32 products #224 did, would pick 32 for full chunks on Ampere.
  • HIP build: not compiled here. The HIP path only gains ink_attend_batch_rows(), which hands a size-free call to ink_attend_batch() and returns false for a fixed size, and ink_flash_tokens(), which returns 0.
  • Metal build: not compiled. The shared header keeps ink_attend_batch()'s signature, which Metal defines. The new functions are declared but never called on Metal.
  • No card other than the 5080 Laptop was measured. The relative block costs (0.9 and 0.65) come from sm_120 with G = 3 (Inkling 2 Mini). On full 1,024-row calls the rule also picks 48 on 88 to 127 SMs (the A100 is excluded: it runs LEAN) and on 176 to 199 SMs, for example RTX 5000 Ada (100) and RTX PRO 6000 Blackwell (188). Neither was measured.

Limits

  • The end-to-end gain depends on the card's SM count. Most cards keep main's 64 rows for full prompt chunks, and the gain shows mainly on long prompts, where attention is a larger share.
  • On this 16 GB laptop card the 2K prompt is dominated by expert copies, so its tok/s moves by ±12% between runs. The kernel saving there (about 4 ms) is below that noise.
  • The same-bits argument assumes finite cache values. With NaN or Inf already in a cache row that a block reads but a row does not attend, which rows turn NaN would depend on the block size; main has the same exposure inside one block. A zero's sign (−0 against +0) could also differ after a score jump of more than about 70 nats onto exact −0 values. Neither came up in any test.

🤖 Generated with Claude Code

…last wave

ink_flash_kernel without LEAN took 64 query rows a block, so a
1,024-row call of Inkling 2 Mini is 128 blocks (16 x 8 key heads) at one
block a multiprocessor.  On an RTX 5080 Laptop (60 multiprocessors)
that is 2.13 waves, the third with 8 blocks: the tail the grid-fill
audit found.

ink_flash_kernel<G, LEAN, TOKENS>: without LEAN the rows a block are
now 64, 48 or 32, and ink_attend_batch() picks them per call: the size
whose launch ends soonest by its waves (blocks over the resident slots,
rounded up, times a block's time against one of 64: 0.9 for 48, 0.65
for 32, measured on the 5080 Laptop).  Another size than 64 is taken
only when that is at least 5% less, so cards whose last wave is full or
nearly so keep 64.  For 1,024-row calls that moves to 48 on 59 to 63,
88 to 127 and 176 to 199 multiprocessors.  On the 5080 Laptop one
layer's attention is 4% to 16% faster (full 32K keys 12.85 -> 11.64 ms,
window 0.84 -> 0.73 ms), and the flash kernel's time in an 8K prompt
10.7% less.  LEAN (sm_80), STRATA_FAST_ATTN's kernel, Turing's
ink_flash75_kernel and HIP's kernel are unchanged.

Class: same bits.  A row's scores, weights and sums do not depend on
which block it is in: its key tiles still start at multiples of 64 and
go in the same order, and the tiles a wider block adds for the row's
neighbours give it weights of 0 and a scale of 1 (or keep its zeros
before its first key).  poly_ink_flash_test now runs every case with
each size and fails unless all give the same bits (fp16, FP8 and Q8_0
caches; 1,024-row prompt chunks added), and its --bench times each size
(--rows N for other call sizes).  STRATA_INK_FLASH_TOKENS=64/48/32 fixes
the size (64 = main's shape); ink_attend_batch_rows() takes one for the
test, and ink_attend_batch() keeps its signature (Metal defines its
own).  ink_flash_tokens() says which size a call gets (0 where the call
goes to another kernel).

The finding is the grid-fill audit's (candidate 6); the per-card rule
follows simplexai-labs#233's launch-shape pattern.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@okada-shogo
okada-shogo marked this pull request as ready for review November 23, 2026 20:41
@VecSzn
VecSzn merged commit cdfae80 into simplexai-labs:main Nov 23, 2026
2 checks passed
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.

2 participants