[GH-ISSUE #5202] [Engine] Opt-in FP16 tensor-core block scorer for long prompt reads (STRATA_SELECT_F16=1): 1M read selection 95 -> 62 s on an RTX 4090 #3099

Open
opened 2026-11-07 14:38:03 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @D-Ogi on GitHub (Nov 4, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/5202

Problem and result

At a 1M-token context, the QSA selection is the largest single phase of a prompt read on an RTX 4090. For a 976K-token prompt it takes 95 of 330 s (STRATA_PREFILL_TIMING=1, the n-gram table in RAM, --prefill auto:16384). About two thirds of that time is block_scores_tc_kernel (3xTF32).

An FP16 tensor-core scorer with a three-term hi/lo split (hi.hi + hi.lo + lo.hi, m16n8k16) does the same GEMM in about half the tensor time. In qsa_select_bench, a 256-query batch at 250,001 blocks takes 1.49 ms instead of 3.06 ms. In the engine, the selection phase goes from 95 to 62 s, and the prompt read from 2,954 to 3,270 tok/s. Needles 5/5.

The kernel is not bitwise. It sums in another order, as the TF32 kernel does against the warp kernel. So it would ship off by default, as a rounding-level switch STRATA_SELECT_F16=1, for reads of 8,192 blocks or more on sm_80+.

Accuracy against FP64: the test matrix spans 40K to 1M cells and 1 to 4,096 queries. Over it, the three-term kernel has a max error of 1.0e-6 to 1.4e-6 of the score scale. The 3xTF32 kernel has 1.4e-6 to 1.8e-6. At 1M cells and 256 queries its selections equal the warp reference's 256/256. Over the matrix it matches the reference as the TF32 kernel does, with one exception. At 600,000 cells it differs in 1 of 256 selections (0.0008% of cells). The TF32 kernel differs in none there. The one-term and two-term variants are faster (1.41 ms), but they land at 8e-5 of the scale and change 38 of 256 selections. They would stay bench-only.

#669 (RTX 5090 at 1M: the selection is a third of a 565K read). #4118 / #4119 (two-pass selection, 3xTF32 only near the cut-off, bitwise). This proposal is the other axis: cheaper arithmetic for the whole GEMM, rounding level, about 2x per call. It touches the same dispatch (qsa_block_scores_tc) and would conflict with #4119 textually.

Approach

The keys are the A operand of the MMA: a warp holds 16 blocks in registers for a whole key tile. The 32 queries x 4 heads of the CTA sit in shared memory as the B operand. The kernel reads a key once per 32 queries instead of once per 16. Opt-in, CUDA only (#if !defined(__HIPCC__)). It keeps the write set and the tail block of the TF32 kernel. It comes with a ctest qsa_select_bench_f16 (the FP64 gate) and a row under the rounding-level switches in docs/DETAILS.md. Measured on one card (RTX 4090, Windows, CUDA 13.0). Below sm_80, the engine ignores the switch.

Is this in scope as an opt-in switch? Would you rather see it before or after #4119? The patch is ready on v0.2.10 as a draft PR.

An LLM (Claude) helped to write the kernel and this text. The author reviewed the kernel and the results by hand. The author asked for more measurements, clarifications and A/B runs during the work. The author built, ran and checked every number above.

Draft PR: https://github.com/Niko1221/Strata/pull/5203

Originally created by @D-Ogi on GitHub (Nov 4, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/5202 ## Problem and result At a 1M-token context, the QSA selection is the largest single phase of a prompt read on an RTX 4090. For a 976K-token prompt it takes 95 of 330 s (`STRATA_PREFILL_TIMING=1`, the n-gram table in RAM, `--prefill auto:16384`). About two thirds of that time is `block_scores_tc_kernel` (3xTF32). An FP16 tensor-core scorer with a three-term hi/lo split (hi.hi + hi.lo + lo.hi, m16n8k16) does the same GEMM in about half the tensor time. In `qsa_select_bench`, a 256-query batch at 250,001 blocks takes 1.49 ms instead of 3.06 ms. In the engine, the selection phase goes from 95 to 62 s, and the prompt read from 2,954 to 3,270 tok/s. Needles 5/5. The kernel is not bitwise. It sums in another order, as the TF32 kernel does against the warp kernel. So it would ship off by default, as a rounding-level switch `STRATA_SELECT_F16=1`, for reads of 8,192 blocks or more on sm_80+. Accuracy against FP64: the test matrix spans 40K to 1M cells and 1 to 4,096 queries. Over it, the three-term kernel has a max error of 1.0e-6 to 1.4e-6 of the score scale. The 3xTF32 kernel has 1.4e-6 to 1.8e-6. At 1M cells and 256 queries its selections equal the warp reference's 256/256. Over the matrix it matches the reference as the TF32 kernel does, with one exception. At 600,000 cells it differs in 1 of 256 selections (0.0008% of cells). The TF32 kernel differs in none there. The one-term and two-term variants are faster (1.41 ms), but they land at 8e-5 of the scale and change 38 of 256 selections. They would stay bench-only. ## Related discussion #669 (RTX 5090 at 1M: the selection is a third of a 565K read). #4118 / #4119 (two-pass selection, 3xTF32 only near the cut-off, bitwise). This proposal is the other axis: cheaper arithmetic for the whole GEMM, rounding level, about 2x per call. It touches the same dispatch (`qsa_block_scores_tc`) and would conflict with #4119 textually. ## Approach The keys are the A operand of the MMA: a warp holds 16 blocks in registers for a whole key tile. The 32 queries x 4 heads of the CTA sit in shared memory as the B operand. The kernel reads a key once per 32 queries instead of once per 16. Opt-in, CUDA only (`#if !defined(__HIPCC__)`). It keeps the write set and the tail block of the TF32 kernel. It comes with a ctest `qsa_select_bench_f16` (the FP64 gate) and a row under the rounding-level switches in docs/DETAILS.md. Measured on one card (RTX 4090, Windows, CUDA 13.0). Below sm_80, the engine ignores the switch. Is this in scope as an opt-in switch? Would you rather see it before or after #4119? The patch is ready on v0.2.10 as a draft PR. An LLM (Claude) helped to write the kernel and this text. The author reviewed the kernel and the results by hand. The author asked for more measurements, clarifications and A/B runs during the work. The author built, ran and checked every number above. Draft PR: https://github.com/Niko1221/Strata/pull/5203
Author
Owner

@udqe commented on GitHub (Nov 5, 2026):

The thread's numbers are all 1M-class (yours 976 K, #669's 565 K) - and whether the switch matters depends on which phase actually owns the read at the context sizes people serve at. Our box can answer that with the existing STRATA_PREFILL_TIMING (no PR build needed), so we booted it once with that env and read the per-prompt summaries off the log.

Windows 11, 2x RTX 4090 under a layer split (22), engine 0.1.56 windows-cuda, --pcie-frac 0.20, chunk 8192, T=0, unique fresh prompts, pairs agreeing within 1 % of the phase ms:

prompt tokens GPU timeline qsa select share qsa proj the phases that do rule here
149,691 41.5 s 941 ms 2.3 % 1,198 ms (2.9 %) embed+steps 24 %, dequant 17 %
199,339 55.0 s 1,598 ms 2.9 % 1,600 ms (2.9 %) embed+steps 23.5 %, dequant 17 %
294,925 84.1 s 3,415 ms 4.0 % 2,372 ms (2.8 %) embed+steps 25 %, gemm gate/up 17.5 %, dequant 16 %

What we take from it, stated as ours and not as a verdict on your box:

The dominance of selection is topology-shaped, and your single card shows your number honestly. On a split pair the same phase runs under --pcie-frac 0.20 where the read's budget goes to embed, expert GEMMs and dequant - selection is 4 % of the read at 295 K here. A 2x-cheaper scorer saves ~1.7 s of an 84 s read at that size. On a single card where every phase queues on the same stream, and at a context where selection has grown quadratically, the same phase being the largest single one is exactly what your 95-of-330 line says.

The growth does look quadratic, which is the switch's own argument, well told by the numbers: our token x1.97 (150 K -> 295 K) moved selection x3.6 (941 -> 3,415 ms). Extrapolating that curve toward your 976 K regime lands the same phase near 37 s - an extrapolation, not a measurement - so framing the docs line around long contexts ("helps on very long reads") reads truer to both boxes than any "saves X % of prefill" phrasing would.

One phase-budget note for reviewers, no ask attached: at 150 K our qsa proj is bigger than qsa select (1,198 vs 941 ms) and it stays on the TF32 path under your switch, so the honest total for "GEMM-side scoring cost" at serving sizes is the pair proj+select (~5 % here, not 2.3) - the right thing if the PR description ever wants a share number instead of a per-call one.

Caveats, declared before this table left our machine: the canonical read rows during the TIMING run came in ~4 % under our non-TIMING runs of yesterday (event-record overhead or interleaved traffic from other users of the box - we cannot separate the two), so treat the shares (ratios) as the robust artifact, not the absolute tok/s; and one restart-each way means each point is n=2 pairs, not medians of many.

Scope: measurement-only probe (two restarts of a production box, protocol and abort rules declared before the data, config restored hash-identical afterwards - procedure style as disclosed in the #3976/#5031 footers); we have not built or run your patch, nothing here tests the FP16 path itself.

(ai-assisted; log excerpts: per-prompt strata prefill timing summaries, boot 2026-11-05 11:09 JST)

<!-- gh-comment-id:6648037563 --> @udqe commented on GitHub (Nov 5, 2026): The thread's numbers are all 1M-class (yours 976 K, #669's 565 K) - and whether the switch matters depends on which phase actually owns the read at the context sizes people serve at. Our box can answer that with the existing `STRATA_PREFILL_TIMING` (no PR build needed), so we booted it once with that env and read the per-prompt summaries off the log. Windows 11, 2x RTX 4090 under a layer split (22), engine 0.1.56 windows-cuda, `--pcie-frac 0.20`, chunk 8192, T=0, unique fresh prompts, pairs agreeing within 1 % of the phase ms: | prompt tokens | GPU timeline | qsa select | share | qsa proj | the phases that do rule here | |---:|---:|---:|---:|---:|---| | 149,691 | 41.5 s | 941 ms | **2.3 %** | 1,198 ms (2.9 %) | embed+steps 24 %, dequant 17 % | | 199,339 | 55.0 s | 1,598 ms | **2.9 %** | 1,600 ms (2.9 %) | embed+steps 23.5 %, dequant 17 % | | 294,925 | 84.1 s | 3,415 ms | **4.0 %** | 2,372 ms (2.8 %) | embed+steps 25 %, gemm gate/up 17.5 %, dequant 16 % | What we take from it, stated as ours and not as a verdict on your box: **The dominance of selection is topology-shaped, and your single card shows your number honestly.** On a split pair the same phase runs under `--pcie-frac 0.20` where the read's budget goes to embed, expert GEMMs and dequant - selection is 4 % of the read at 295 K here. A 2x-cheaper scorer saves ~1.7 s of an 84 s read at that size. On a single card where every phase queues on the same stream, and at a context where selection has grown quadratically, the same phase being the largest single one is exactly what your 95-of-330 line says. **The growth does look quadratic, which is the switch's own argument, well told by the numbers:** our token x1.97 (150 K -> 295 K) moved selection x3.6 (941 -> 3,415 ms). Extrapolating that curve toward your 976 K regime lands the same phase near 37 s - an extrapolation, not a measurement - so framing the docs line around long contexts ("helps on very long reads") reads truer to both boxes than any "saves X % of prefill" phrasing would. **One phase-budget note for reviewers, no ask attached:** at 150 K our `qsa proj` is bigger than `qsa select` (1,198 vs 941 ms) and it stays on the TF32 path under your switch, so the honest total for "GEMM-side scoring cost" at serving sizes is the pair proj+select (~5 % here, not 2.3) - the right thing if the PR description ever wants a share number instead of a per-call one. Caveats, declared before this table left our machine: the canonical read rows during the TIMING run came in ~4 % under our non-TIMING runs of yesterday (event-record overhead or interleaved traffic from other users of the box - we cannot separate the two), so treat the shares (ratios) as the robust artifact, not the absolute tok/s; and one restart-each way means each point is n=2 pairs, not medians of many. Scope: measurement-only probe (two restarts of a production box, protocol and abort rules declared before the data, config restored hash-identical afterwards - procedure style as disclosed in the #3976/#5031 footers); we have not built or run your patch, nothing here tests the FP16 path itself. (ai-assisted; log excerpts: per-prompt `strata prefill timing` summaries, boot 2026-11-05 11:09 JST)
Author
Owner

@D-Ogi commented on GitHub (Nov 5, 2026):

@udqe Thanks for the three points, that is a useful second topology. Since the switch's case rests on the growth you saw (x3.6 selection for x1.97 tokens), would you be willing to extend the same STRATA_PREFILL_TIMING probe to one or two long reads on your split pair, say 500K and 1M tokens, same engine, no patch build needed? The numbers we would read off are the qsa select and qsa proj shares of the GPU timeline at those sizes. That would turn your 37 s extrapolation into a measurement and show whether a layer split moves the crossover point at which selection becomes the largest phase. If your box cannot reach 1M, 500K alone already answers most of it. No obligation, the probe you ran is already helpful.

<!-- gh-comment-id:6653353678 --> @D-Ogi commented on GitHub (Nov 5, 2026): @udqe Thanks for the three points, that is a useful second topology. Since the switch's case rests on the growth you saw (x3.6 selection for x1.97 tokens), would you be willing to extend the same `STRATA_PREFILL_TIMING` probe to one or two long reads on your split pair, say 500K and 1M tokens, same engine, no patch build needed? The numbers we would read off are the `qsa select` and `qsa proj` shares of the GPU timeline at those sizes. That would turn your 37 s extrapolation into a measurement and show whether a layer split moves the crossover point at which selection becomes the largest phase. If your box cannot reach 1M, 500K alone already answers most of it. No obligation, the probe you ran is already helpful.
Author
Owner

@udqe commented on GitHub (Nov 5, 2026):

Straight answer first: 500 K and 1 M are not reachable on this box, and the ceiling is hard, not a config choice we could lift for the probe. Our pack launches at --max-context 307200; a 500 K read is 63 % beyond the limit the engine will even accept here, and 1 M is 3.3x it - the KV and residency budget that size implies does not fit alongside the expert arena this pair runs its plan in. So we cannot turn your crossover question into a measurement from this topology; anyone quoting our box for 500 K numbers would be quoting a fiction.

What we can hand you we went and got: two more points at the top of our range. Same engine, same split, STRATA_PREFILL_TIMING as a one-key config change, two fresh unique ~295 K prompts (synthetic numbered-scaffold text, noted below), T=0, 8 output tokens: GPU timeline 84.7 s and 85.0 s, qsa select 3,419 ms and 3,411 ms - 4.0 % both times, qsa proj 2,383 ms and 2,377 ms (2.8 % both). Against this morning's 3,415 ms at 294,925 tokens the three runs now span two boots and agree within 0.25 % on the select phase - the 4 % share is not noise. The growth holds at the ceiling too: 941 ms at 149.7 K -> ~3,415 ms at ~295.1 K is the x3.6 for x1.97 tokens your question leans on, now with the top pinned twice, and the synthetic text landing in the same 4 % band as the natural-document prompts says the phase's share is prompt-content-insensitive at this size.

And the honest redirect: the crossover question belongs to your topology, not ours. On a split pair under a fraction budget the read's wall goes to embed (23 %), the expert GEMMs (~28 %: gate/up 18 + down 10) and dequant (17 %) - selection grows quadratically into phases that were never the owner, so on this box the crossover may arrive in wall-clock terms only after the read itself has stopped being selection-shaped. On a single card, where every phase queues on one stream, your 976 K line and #669's 565 K line are the two measurements that settle it, on engines you already run, off the same two log columns - your machine at the long end, #669's mid-point, and my x3.6 either confirmed or embarrassed within three numbers. If you post your phase table in the shape above, we will run one of our 295 K prompts against your prompt text so the two topologies share a denominator.

Scope: our synthetic prompts differ in text from this morning's natural slices (noted, since "same prompt text" was your framing - the phase shares matched either way); our extrapolation to your regime (~37 s select at 1 M-class, which your question is right to distrust) stays labeled as what it is - a curve fit, not a measurement - and the ~4 % TIMING overhead caveat stands. No patch build, no new flags were needed for anything above.

(ai-assisted; measurements on our box; the three 295 K-class runs agreed within 0.25 % on the phase ms)

<!-- gh-comment-id:6654022336 --> @udqe commented on GitHub (Nov 5, 2026): Straight answer first: 500 K and 1 M are not reachable on this box, and the ceiling is hard, not a config choice we could lift for the probe. Our pack launches at `--max-context 307200`; a 500 K read is 63 % beyond the limit the engine will even accept here, and 1 M is 3.3x it - the KV and residency budget that size implies does not fit alongside the expert arena this pair runs its plan in. So we cannot turn your crossover question into a measurement from this topology; anyone quoting our box for 500 K numbers would be quoting a fiction. What we can hand you we went and got: two more points at the top of our range. Same engine, same split, `STRATA_PREFILL_TIMING` as a one-key config change, two fresh unique ~295 K prompts (synthetic numbered-scaffold text, noted below), T=0, 8 output tokens: GPU timeline 84.7 s and 85.0 s, `qsa select` **3,419 ms and 3,411 ms - 4.0 % both times**, `qsa proj` 2,383 ms and 2,377 ms (2.8 % both). Against this morning's 3,415 ms at 294,925 tokens the three runs now span two boots and agree within 0.25 % on the select phase - the 4 % share is not noise. The growth holds at the ceiling too: 941 ms at 149.7 K -> ~3,415 ms at ~295.1 K is the x3.6 for x1.97 tokens your question leans on, now with the top pinned twice, and the synthetic text landing in the same 4 % band as the natural-document prompts says the phase's share is prompt-content-insensitive at this size. And the honest redirect: the crossover question belongs to your topology, not ours. On a split pair under a fraction budget the read's wall goes to embed (23 %), the expert GEMMs (~28 %: gate/up 18 + down 10) and dequant (17 %) - selection grows quadratically into phases that were never the owner, so on this box the crossover may arrive in wall-clock terms only after the read itself has stopped being selection-shaped. On a single card, where every phase queues on one stream, your 976 K line and #669's 565 K line are the two measurements that settle it, on engines you already run, off the same two log columns - your machine at the long end, #669's mid-point, and my x3.6 either confirmed or embarrassed within three numbers. If you post your phase table in the shape above, we will run one of our 295 K prompts against your prompt text so the two topologies share a denominator. Scope: our synthetic prompts differ in text from this morning's natural slices (noted, since "same prompt text" was your framing - the phase shares matched either way); our extrapolation to your regime (~37 s select at 1 M-class, which your question is right to distrust) stays labeled as what it is - a curve fit, not a measurement - and the ~4 % TIMING overhead caveat stands. No patch build, no new flags were needed for anything above. (ai-assisted; measurements on our box; the three 295 K-class runs agreed within 0.25 % on the phase ms)
Author
Owner

@D-Ogi commented on GitHub (Nov 5, 2026):

@udqe Thank you for the two repeated points and for the clear limit of your box.

Our phase table is already public. PR #5203 holds it in bench/results/2026-11-04-rtx4090-qsa-select-f16/engine-1m-ab.txt. That file has the strata prefill timing lines of both arms: one RTX 4090, the same binary, the switch off and on, a 976K-token prompt. The README.md in the same folder shows the share of each phase. Those lines are the denominator you asked for.

The prompt text itself is not in the PR. It is a synthetic document with five planted codes.

<!-- gh-comment-id:6656486979 --> @D-Ogi commented on GitHub (Nov 5, 2026): @udqe Thank you for the two repeated points and for the clear limit of your box. Our phase table is already public. PR #5203 holds it in `bench/results/2026-11-04-rtx4090-qsa-select-f16/engine-1m-ab.txt`. That file has the `strata prefill timing` lines of both arms: one RTX 4090, the same binary, the switch off and on, a 976K-token prompt. The `README.md` in the same folder shows the share of each phase. Those lines are the denominator you asked for. The prompt text itself is not in the PR. It is a synthetic document with five planted codes.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3099
No description provided.