Repository navigation
fix(strix): compile every Triton kernel copy at start-up, no first-request stalls - #51
Conversation
Triton compiles a kernel once per tile config and per class of each integer argument (1, a multiple of 16, other), and the row count picks both. The start-up warm-up ran two lengths only, so the first request whose length was a multiple of 16 in a tile-config range waited for new copies: in the request matrix the first timed pass of S with 1 question (208 tokens) and of M with 2 (720 tokens), on both machines of rkinas#14 / rkinas#21. The warm-up now runs the projections on zero rows of every range and class (one row: the last row chunk of qkv / o, one readout row) and six short forwards for attention and rotary (lengths other / multiple of 16 against readout rows 1 / other / 16). Kernels are unchanged. basal-2.0 on the 8060S, request matrix: the old code compiled 18 copies during the matrix (empty Triton cache: S-q1 pass 1 1.82 s against 0.18 s), now none. Start-up 8.8 s against 7.9 s with a filled Triton cache, 18.7 against 13.8 s at the first start on a machine. test_warmup_compiles_every_kernel_copy: no row count (20-5000 rows, 1-528 readout rows) compiles a kernel after the warm-up; it fails without it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
STRIX_HALO.md: the start-up warm-up and why it covers every size class, and the cause at the three places that report the stall (basal-2.0 matrix vs A/B, the ROG Flow Z13 section, the raw results). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The six short forwards of the start-up warm-up compile the attention and rotary copies. One inner layer (attention over every row) and the last (readout rows only) need all of them; the layers between run the copies the first one compiles. Running all 60 layers of basal-2.0 cost ~0.7 s per start. basal-2.0 on the 8060S: start-up with a filled Triton cache 6.0-6.1 s against 6.7-6.8 s (6.0-6.2 s before the warm-up of every shape); the same 34 kernel copies; none compiled during the request matrix from an empty cache; answers equal to the all-layer warm-up (460 probabilities). test_warmup_compiles_every_kernel_copy runs a 3-layer model, so the warm-up skips a layer, and checks that the backend keeps all its layers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…m-up STRIX_HALO.md: upstream 2.4.0 and 2.4.1 still ship the two-length warm-up, so the stall applies to 2.4.1 and earlier. Start-up remeasured on the 8060S with the first-and-last-layer warm-up (two runs each): 6.0-6.1 against 6.0-6.2 s with a filled Triton cache, 13.4-13.6 against 8.7-8.8 s at the first start on a machine. Co-Authored-By: Claude Opus 5.5 <[email protected]>
STRIX_HALO.md lists what tests/test_strix.py covers; it now includes test_warmup_compiles_every_kernel_copy (after the start-up warm-up, no row count of 20-5,000 tokens with 1-528 readout rows compiles a kernel). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HURKBzWocW2YSQkzdGE4N2
The fork point was 2.3.1; upstream main is at 2.4.1. No conflicts: upstream did not touch basal/strix.py, tests/test_strix.py or STRIX_HALO.md since. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NVMXYt7nYcWrTvYzDsd4kD
The start-up compiles every Triton kernel copy a request can need; the numbers are basal-2.0-4.5B on the Radeon 8060S (the request matrix in STRIX_HALO.md and the strix-warm-shapes test report). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NVMXYt7nYcWrTvYzDsd4kD
Reviewer's GuideThe PR changes Strix initialization to proactively compile all Triton kernel variants implied by projection, FFN, attention, rotary, and row-count classes, using representative warm-up inputs and only the first and last layers for attention. It adds a JIT-hook GPU regression test and documents the resulting elimination of first-request stalls alongside the increased cold-start cost. Sequence diagram for Strix startup kernel warm-upsequenceDiagram
participant Backend as StrixHaloFastBackend
participant Projection as Projection and FFN kernels
participant Attention as Attention and rotary kernels
participant Triton
participant Request as Request path
Backend->>Backend: run_shared(existing warm-up)
Backend->>Projection: warm_rows(LINEAR and FFN configs)
Projection->>Triton: compile row-count variants
Backend->>Attention: forward(WARM_FORWARDS) on first and last layers
Attention->>Triton: compile attention and rotary variants
Backend->>Triton: _wait()
Request->>Backend: forward(request)
Backend->>Triton: reuse warmed kernel copies
Flow diagram for Strix row-count coverageflowchart LR
Start[Warm-up row counts]
One[1 row]
Other[Non-multiple-of-16 row]
Multiple[Multiple-of-16 row]
Config[Each LINEAR and FFN configuration range]
Kernels[All projection and FFN kernel copies]
Start --> One
Start --> Config
Config --> Other
Config --> Multiple
One --> Kernels
Other --> Kernels
Multiple --> Kernels
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="basal/strix.py" line_range="302" />
<code_context>
+ # Start-up forwards for attention and rotary (one tile config each): sequence lengths other and a multiple of 16,
+ # each against readout rows 1, other and a multiple of 16 (the last layer's attention takes both counts). They run
+ # the first layer and the last only: every layer between needs the copies the first one compiles.
+ WARM_FORWARDS = ((17, 1), (32, 1), (17, 3), (32, 3), (17, 16), (32, 16))
+
+ @staticmethod
</code_context>
<issue_to_address>
**One-token requests compile kernels**
When a request packs to one token, the forwards in `_warm_shapes` cover only lengths 17 and 32, leaving the `L=1` specializations of `_rope` and `_attn_fwd` uncompiled; Triton compiles them on the first one-token request and stalls it.
Add an `L=1` forward to the startup warm-ups.
</issue_to_address>
### Comment 2
<location path="tests/test_strix.py" line_range="246" />
<code_context>
+ timed pass of S with 1 question and of M with 2 in the request matrix, before the warmup covered them). Three
+ layers: the warmup forwards skip the middle one, and the forwards below run all three."""
+ from basal import strix
+ if not hasattr(triton, "knobs"):
+ pytest.skip("Triton without knobs.runtime.jit_cache_hook")
+ for k in (strix._attn_fwd, strix._swiglu_mm, strix._linear, strix._rmsnorm, strix._rope):
</code_context>
<issue_to_address>
**Test errors without cache hook**
When triton exposes `knobs` but does not expose `knobs.runtime.jit_cache_hook`, `test_warmup_compiles_every_kernel_copy` later assigns `triton.knobs.runtime.jit_cache_hook` at line 258 and raises `AttributeError` instead of skipping, so the suite fails even when the backend is correct.
Check that the nested hook exists before accessing it, and skip when it does not.
</issue_to_address>
### Comment 3
<location path="tests/test_strix.py" line_range="249" />
<code_context>
+ if not hasattr(triton, "knobs"):
+ pytest.skip("Triton without knobs.runtime.jit_cache_hook")
+ for k in (strix._attn_fwd, strix._swiglu_mm, strix._linear, strix._rmsnorm, strix._rope):
+ k.device_caches.clear() # the copies other tests compiled in this process
+ be = make(tiny(layers=3), warm=True)
+ assert len(be.layers) == 3
</code_context>
<issue_to_address>
**Disk cache masks missing warm-up**
When the required kernel variants are already present in Triton’s persistent disk cache, triton serves those variants from disk without a compile event, so `built` stays empty and the final assertion passes even if `_warm_shapes()` does not compile them at startup.
Run the test with an isolated empty Triton disk cache, or otherwise ensure missing variants cannot be served from disk.
</issue_to_address>
### Comment 4
<location path="docs/benchmarks/STRIX_HALO.md" line_range="237" />
<code_context>
biases against separate bf16 forwards of every prompt (1–8 questions over one state, several requests in one sequence
-and the same request alone, several forwards per call with a request bisected, determinism), plus the mode dispatch of
+and the same request alone, several forwards per call with a request bisected, determinism), and the start-up warm-up
+(after it, no row count of 20–5,000 tokens with 1–528 readout rows compiles a kernel), plus the mode dispatch of
`basal-serve` and `basal-bench`. Full suite on this machine: 76 passed, 3 skipped (MLX / Apple only); on engine 2.0.0,
511 passed, 19 skipped (MLX and the extras not installed).
</code_context>
<issue_to_address>
**Published test count is stale**
When the listed full-suite total is read as describing the suite after this PR, the coverage paragraph now includes the new GPU warm-up test, but the following full-suite total still says “76 passed.” With that test passing on the documented GPU setup, the reported total undercounts the updated suite.
Update the full-suite totals to reflect the added test, or label them as results from a pre-PR run.
</issue_to_address>A request that packs to one token needed the L=1 copies of _rope and _attn_fwd, which the warm-up forwards (lengths 17 and 32) never compiled: WARM_FORWARDS now starts with (1, 1), and the warm-up test runs L=1 too. The test skips unless triton.knobs.runtime.jit_cache_hook exists (a Triton with knobs but no such hook raised AttributeError instead of skipping), and says why Triton's disk cache cannot hide a missing copy: the hook runs at every miss of the in-process cache, before the disk cache is read. STRIX_HALO.md: the warm-up test covers 1-5,000 tokens; the full-suite totals are labelled as the run from when --mode strix was added. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QxYyiinXyVC9b1Gf1vFgAx
STRIX_HALO.md, Tests: tests/test_strix.py 31 passed with Triton's disk cache filled and empty; full suite 834 passed, 7 failed, 25 skipped. The 7 also fail on 2.4.1 without the warm-up, in PyTorch's attention on ROCm: test_gemma4 needs efficient attention (experimental on ROCm, head size up to 256), test_cascade_cuda needs seqused_k and the packed log-sum-exp layout, and test_compact_varlen's bottom-right causal case differs. Start-up remeasured with the one-token warm-up, basal-serve to the first /health, two runs each: 12.7-12.8 against 7.7-7.8 s at the first start on a machine, 5.6 against 5.4-5.5 s with a filled Triton cache. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thank you, Michał! The start-up warm-up for We also tested it on a Strix Halo machine of our own (Radeon 8060S): your fix does what it says (no Triton compile during requests). Answers matched |
|
Thanks, got it It took me a while to take a little bit of time to start investigation on the matching. It seems it might be challenging to achieve 99.5%+ results (and keep the speed) as it seems eager mode might not agree with itself, raw report draft below |
Thanks @piotrkowski for finding this out 🙌
Originally uncovered in #21
--mode strixstalled on the first request whose length needed a Triton kernel copy it had not compiled yet. Tritoncompiles a kernel once per tile config and per class of each integer argument (1, a multiple of 16, other), and the row
count picks both. The start-up warm-up ran two lengths only, so a request in a new class waited 0.2–0.3 s per missing
copy. This is the one-off stall in the first timed pass of S with 1 question and M with 2 in the request matrix, on
both Strix Halo machines of #14 and #21. Engine 2.4.1 and earlier still have it.
What changes
StrixHaloFastBackend._warm_shapes()runs at the end of the existing warm-up:LINEAR/FFNand everyclass.
warm_rowsgives 1, then one count that is not a multiple of 16 and one that is, per range. They are calledthe way the forward calls them (same strides, residual for o / down).
WARM_FORWARDS: lengths 17 / 32 against 1 / 3 / 16 readout rows) compile attention androtary, over the first and the last layer only. The layers between need the copies the first one compiles; running
all 60 layers of basal-2.0 cost ~0.7 s per start.
Kernels and the request path are unchanged.
docs/benchmarks/STRIX_HALO.mdexplains the stall where the resultsreport it, and the start-up cost.
docs/WHATS_NEW.mdhas an entry under 2.4.2; rename it to the release this lands in.Results: basal-2.0-4.5B on the Radeon 8060S
/health1,550 and 1,600 tokens (1 kernel each).
basal-serve --mode strix,bench_matrix.py,edge_check.py): identical answers on all 20 matrix casesand the 12 edge-case requests; throughput the same at 1 and 8 clients (6.6 and 16.1 requests/s).
Tests
test_warmup_compiles_every_kernel_copy(GPU): hooks Triton'sjit_cache_hookand checks that after start-upno row count of 20–5,000 tokens with 1–528 readout rows compiles a kernel. It uses a 3-layer model, so the warm-up
skips a layer, and checks that the backend keeps all its layers. It fails without the warm-up, and 8 of 9 deliberate
breaks of the warm-up make it fail (the 9th, dropping
(17, 3), is covered by the older warm-up).tests/test_strix.py: 31 passed with a filled cache, an empty cache, in reverse order, and merged into main.this PR and comes from this machine's ROCm build: 4
test_gemma4cases need ROCm's experimental attention flag,test_compact_varlenhas an fp16 mismatch, and 2test_cascade_cudatests use flash-attention options ROCm lacks.Full test report: https://gist.github.com/kardysm/7ca58120d7cec18dff5f3f4fa74b4e79. It tested
a5a9011and itsmerge into 2.4.1; this PR's head is that same merge (identical tree) plus the WHATS_NEW entry.
Notes for review
(17, 3)inWARM_FORWARDSoverlaps the older two-length warm-up. I kept it as a guard; it costs one 17-tokenforward over 2 layers.
warm_rowsassumes each row-count range inLINEAR/FFNis at least 32 rows wide. All current ranges are.Triton pointer class (16-byte aligned, storage under 2 GB). That holds for all 60 layers of basal-2.0; the tiny test
model cannot show it.
Python 3.12.
🤖 Generated with Claude Code
Summary by Sourcery
Precompile every Triton kernel variant required by Strix requests at startup to remove first-request compilation stalls.
Bug Fixes:
Enhancements:
Documentation:
Tests: