Repository navigation
Conversation
Reviewer's GuideThe fast CUDA graph backend now performs exactly one side-stream warm-up call per graph before capture instead of three calls for regular graphs and two for pass-2 graphs, while preserving graph ordering, deferred capture, shapes, and runtime behavior. Tests and release notes were updated; the reported RTX 4060 Ti measurements show 31–38% shorter warm-up with identical probabilities and GPU memory. Sequence diagram for single CUDA graph warm-up and capturesequenceDiagram
participant GraphBackend
participant SideStream as CUDA side stream
participant Function as Graph function
participant Compiler as torch.compile
participant Capture as CUDA graph capture
GraphBackend->>GraphBackend: _capture(key, fn, static)
GraphBackend->>GraphBackend: _warm_up(fn, static)
GraphBackend->>SideStream: wait_stream(current_stream)
SideStream->>Function: fn(*static)
Function->>Compiler: compile or recompile if needed
Function->>Function: Initialize cuBLAS and Triton kernels
SideStream-->>GraphBackend: warm-up complete
GraphBackend->>Capture: _record(key, fn, static)
Capture->>Function: capture fn(*static)
Capture-->>GraphBackend: CUDA graph ready
Flow diagram for fast CUDA graph warm-up optimizationflowchart LR
A[Graph requested] --> B{Deferred capture active?}
B -->|Yes and key is new| C["_warm_up(fn, static)"]
B -->|No| C
C --> D[One call on side stream]
D --> E{Deferred capture active?}
E -->|Yes| F[Queue fn and static]
E -->|No| G["_record(key, fn, static)"]
F --> H[Capture later]
G --> I[CUDA graph ready]
H --> I
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 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/test_engine16.py" line_range="209" />
<code_context>
return self._record(key, fn, static)
- def _warm_up(self, fn, static, n):
+ def _warm_up(self, fn, static):
+ """One call of fn on the side stream before its capture: what a capture cannot do happens at a forward's first
+ call (torch.compile compiles, or recompiles for a shape its guards reject; cuBLAS sets up its handle and
</code_context>
<issue_to_address>
**Repeated graph warm-ups go undetected**
When `GraphBackend._warm_up` is changed to invoke `fn` more than once, `test_warm_captures_largest_first_after_every_warm_up` and `test_warm_captures_largest_first_then_long_pass2` replace `_warm_up` with overrides that log one event and call `fn` once. Their event-count assertions still pass if `GraphBackend._warm_up` regresses to multiple calls, so the startup regression goes undetected.
Add a test that exercises the production `_warm_up` and counts invocations of `fn`.
Also at `tests/test_gemma4_graph.py:319`.
</issue_to_address>d5361bd to
30639ea
Compare
Plain graphs were warmed up 3 times and pass-2 graphs twice. What a capture cannot do (torch.compile compiling, cuBLAS handle and workspace, Triton loading kernels) happens at the first call; the further calls ran the same kernels again and only took start-up time.
30639ea to
0acb6a8
Compare
|
Thank you, Miłosz! #43 is in basal 2.4.1: https://github.com/rkinas/basal/releases/tag/v2.4.1 We rebased it on 2.3.5 and then on 2.4.0, and ran our H100 identity check, including basal-omni as you asked:
It's credited to you in the 2.4.1 notes, the README and WHATS_NEW. Closing this PR as merged there. Thanks again! |
… are captured without a warm-up call warm() ran every grid shape once before its capture (rkinas#43: one call instead of three). What only a first call does happens at a family's first shapes: the forwards are compiled with dynamic shapes (one-row shapes specialised), and pass 2 runs uncompiled. Warmed up as before, in the grid's order: plain shapes of the first two lengths, compact shapes of the first two, pass-2 shapes of every (rows, branch length) at their first root length. The others are captured directly under torch.compiler.set_stance("fail_on_recompile"): a shape that would compile again (or fail in the capture for another reason) is warmed up and captured again, with a line. Gemma 4, Qwen3.5 (fla tunes per shape) and fast-exit warm up every shape as before.
Problem
GraphBackend._captureran every graph's function 3 times (plain and compact graphs) or 2 times (pass-2 graphs)before capturing it. What a capture cannot do happens at the first call: torch.compile compiles (or recompiles for a
shape its guards reject), cuBLAS sets up its handle and workspace, Triton loads its kernels. The second and third
calls run the same kernels on the same shapes again. On a consumer card that is most of start-up: basal-2.0-4.5B has
169 plain graphs over 796,928 padded tokens and 264 pass-2 graphs, and on an RTX 4060 Ti the repeated calls took 414 s
of its 1,094 s warm-up (phase timers below).
Change
_warm_up(fn, static)callsfnonce on the side stream;_capture,_graph_sfxand 2.4.0'sGDNGraphBackend._graph_sfx(Qwen3.5) lose theirwarmupargument. Nothing else changes: the same shapes are warmedup in the same order (so torch.compile builds the same kernels, and fla's kernels pick their launch configs at the
same first call), and the captures are the same.
Measurements
torch 2.13.0+cu130,
GraphBackendbuilt as--mode fastbuilds it (warm()timed, compile caches cleared beforeevery run), then the identity items of
basal.identity.build(200 single questions in batches of 16, 40five-question requests, 20 long), probabilities compared with the run before the change on the same machine.
Measured on 47ae982 (2.3.3), the 4.5B with #41 (now in 2.3.5); the branch is rebased on 2.4.0, which leaves basal-2.0
bit-identical to 2.3.5 (4,960 of 4,960 readouts, its release notes).
main)basal-omni-pico (Qwen3.5, 2.4.0's
GDNGraphBackend),basal-serve --mode faston one RTX 4060 Ti, fla 0.5.2,TRITON_CACHE_AUTOTUNING=1so that starts sharing a cache reuse fla's timed launch configs; answers to 10 requests(compress over 1.5k-6k tokens, 5-40 questions; 679 probabilities) per start:
main(2.4.0)mainNot measured: basal-omni (Gemma 4), whose graphs go through the same
_warm_up. My rented 40-48 GB hosts failed(a driver too old for torch's CUDA 13 build, two that never finished loading), and basal-omni-1.0-mini does not load
in this probe on a 24 GB card. Could you run your usual H100 identity check on basal-omni with this branch?
Where the time goes now (RTX 4060 Ti, 4.5B, after): the first call of the 54 plain graphs up to 2,048 tokens takes
450 s (compiling), the first call of the 115 longer ones 171 s (running them once), the pass-2 graphs 45 s, the
captures 8 s. The identity items took the same time before and after (77 s on the 4.5B, 27 s on mini), so nothing is
compiled late at run time.
basal-serve --model Remek/basal-2.0-4.5Bwith #41 on the same RTX 4060 Ti: ready in 689 s, 14,424 MiB afterstart,
basal-loadtest21.6 decisions/s on single questions and 9.6 questions/s five at a time over 1.5k-tokenstates, 0 errors.
Tests
test_each_graph_warmed_up_once_before_its_capture(tests/test_engine16.py): the engine's_capture/_warm_upwith torch.cuda's stream calls as no-ops; each graph's function runs once before its capture, a waitingkey is not warmed up again. Three calls, or a waiting key warmed up again, make it fail.
tests/test_engine16.py(perf(fast): pass-2 graphs only while GPU memory stays free (basal-2.0-4.5B on 16 GB cards) #41's budget tests included),tests/test_gemma4_graph.py: the stubs follow the newsignatures.
tests/(withouttest_gguf.py): CPU 739 passed, 81 skipped (on 2.4.0).ExitGraphBackend(--mode fast-exit) keeps its own 3-call warm-up loop (not measured here).