Correctness, Contracts & System-Level Consequences review — PR #658
Reviewer lens: correctness/safety/platform parity, system-level consequences, architecture & contracts, tests & claim accuracy.
Head reviewed: f4851b3, base main. Files opened in full or in the cited ranges: ignition/preparation/capture.py (40-249), ignition/preparation/core_storage.py (38-300), ignition/components/sampling.py (118-138), ignition/preparation/tensor_metadata.py (100-125), tests/preparation/test_core_storage.py, tests/preparation/test_capture_graph_metadata.py, tests/preparation/test_low_window.py, tests/preparation/test_capture_cublas_workspace_cuda.py, the export-side contract (heliopause/src/export/capture.rs, reachability.rs), ignition/preparation/runtime_core.py, and the three design docs.
Key findings
- Major — the new low-window reseal runs one graph too late, and not at all on the non-exporting retain path (
ignition/preparation/capture.py:222-228). The defect being fixed is "capture reopens low spans, then an external allocation lands there"; the seal placed after capture N can only help capture N+1, so every serving capture still runs with the previous capture's reopened spans available. The added test locks in the wrong order. - Major — the stated 24 GiB external band and its upper bound are arithmetically wrong (
core_storage.py:67-70, repeated in the PR description).0xf_0000_0000isDEVICE_BASE − RESERVATION_BYTES, notDEVICE_BASE; the band is 36 GiB. The new assertion (tests/preparation/test_core_storage.py:113) is too loose to catch it. - Major — the cuRAND root cause is asserted, never evidenced, the live SM87 evidence is self-reported on a pre-rebase checkout, and the CUDA tests covering the changed path are env-gated and were not run or extended.
- Minor — a redundant second full low-window sweep per export (
capture.py:177-184vscore_storage.py:287-296), and the sweep itself got 4× more expensive (12 GiB → 36 GiB floor, scan still starts at 4 GiB) with no measurement. - Minor — no new test fails on
main: the GA10B test fakes the CUDA probe to raise, so_reserve_low_window()(the only real effectiveness check) never executes; the other three assert configuration or call ordering only. - Minor — platform asymmetry and stale docs: the probe capture is gated on
integratedalone (capture.py:173) whileseal_low_window()no-ops on Windows (core_storage.py:170);docs/runtime-core-design.md:113-116anddocs/windows.md:225-227still say the floor is 256 GiB. - Minor —
addmmseeding does not pin the BLAS library, so which workspace gets warmed depends on ambientpreferred_blas_library().
Areas verified sound (detailed at the end): no wire/Protobuf/CLI/Rust/build change; device_address_floor semantics and existing-core load compatibility preserved; new constants stay inside the 128 GiB GA10B VMM window with disjoint rank windows; the (8,7) branch is correctly gated on device_window is None; the sampling change is inert outside CoreStorage numeric scope; the addmm seed does not read uninitialised memory.
F1 — Major — Reseal is one graph too late, and the elif retain_graphs: path never reseals
ignition/preparation/capture.py:222-228:
with communication, session.capture(), torch.cuda.graph(graph, pool=pool, stream=stream):
function()
if exporting:
graph = record_export_graph(graph, warmup_storage, owners=(function,))
if getattr(warmup_storage, "integrated", False):
warmup_storage.seal_low_window()
elif retain_graphs:
Impact. The stated failure mode (capture.py:174-176) is "the first CUDA graph capture trims CUDA's pre-init low allocation slab, reopening free spans below EXTERNAL_FLOOR", after which "subsequent external allocations during serving-graph capture could land below EXTERNAL_FLOOR". The seal at :226-227 is emitted after the capture that reopened the spans has already run function() inside torch.cuda.graph(...) — i.e. after cuBLAS/cuDNN/native libraries had their chance to allocate into the reopened region for this graph. It only closes the spans for the next iteration, so the window the PR describes as dangerous is still open during every capture. At the end of the loop the last capture's reopenings are sealed, but nothing reseals between the reopen and the allocations that use it.
Second half of the same defect: the seal is inside if exporting:, where exporting = retain_graphs and warmup_storage is not None (capture.py:202). The elif retain_graphs: branch (:228) instantiates graphs on the same integrated device and never reseals, so a retain-graphs/explicit-window session on GA10B gets no low-window protection at all.
The added test enshrines the late order — tests/preparation/test_capture_graph_metadata.py (added block, roughly :536-569) asserts the event sequence ending serving_capture, seal_low_window, serving_capture, seal_low_window, i.e. seal after each capture.
Fix. Call warmup_storage.seal_low_window() immediately after the torch.cuda.graph(...) context exits and before record_export_graph(...), in both the exporting and retain_graphs branches (not gated on exporting); update the ordering assertion accordingly.
F2 — Minor — The probe-path seal duplicates the one transient() already performs
ignition/preparation/capture.py:177-184:
with warmup():
probe_buf = torch.empty((1,), dtype=torch.int8, device=device)
probe_graph = torch.cuda.CUDAGraph()
with torch.cuda.graph(probe_graph, stream=stream):
probe_buf.zero_()
del probe_graph, probe_buf
stream.synchronize()
warmup_storage.seal_low_window()
warmup = warmup_storage.transient (capture.py:116), and CoreStorage.transient.__exit__ already does exactly this (core_storage.py:287-296):
finally:
torch.cuda.synchronize(self.device)
if not shared:
del pool
torch.cuda.empty_cache()
# Returned segments may reopen low addresses that later library allocations would take.
self.seal_low_window()
Impact. Two full sweeps of the low window per export instead of one (see F3 for the cost). Not a correctness bug — the ordering of stream.synchronize() then seal is harmless — but it doubles the most expensive part of this new code path.
Fix. Delete capture.py:184 and add a comment pointing at transient()'s exit seal, or state why a second sweep is required (e.g. if the probe capture's own segments are released only after del probe_graph).
F3 — Minor (potentially Major on export latency) — Sweep cost grew 4×, and the number of sweeps grew to 1 + one per exported graph
ignition/preparation/core_storage.py:42-44:
# Keep library-owned device storage above the ranges occupied by Linux and WDDM contexts.
EXTERNAL_FLOOR = 0x4000000000
# Where sealing below the floor starts; a context's own storage lies above it.
LOW_SCAN_START = 1 << 32
core_storage.py:172-191 then walks from LOW_SCAN_START to self.EXTERNAL_FLOOR, granule by granule for taken spans, calling cuMemAddressReserve/cuMemAddressFree per probe via _reserve_at/_release_last (:146-162).
Impact. With EXTERNAL_FLOOR = 0x900000000 (core_storage.py:71) each sweep covers 32 GiB instead of 8 GiB — 4× the scan and up to 4× the driver calls. The PR adds 1 probe sweep plus 1 sweep per exported graph (capture.py:226-227), so the reported 9-graph export performs ~10 sweeps over the larger range versus 1 sweep of the small range on main. The existing bound-test only covers the class default: tests/preparation/test_low_window.py:73 assert space.calls - calls < 2 * (context[1] // GRANULE) + 50. Neither the description nor the tests give a wall-clock number for this.
Fix. Give the measured cost of the 9-graph GA10B export (before/after), and consider hoisting the post-capture seal to once after the capture loop — the export pointer scan happens later anyway — or at minimum extend test_low_window.py with a 36 GiB-floor fixture so the call-count bound covers the new geometry.
F4 — Major (claim accuracy) — The stated 24 GiB band and its upper bound are wrong
ignition/preparation/core_storage.py:67-73:
# Jetson Orin (GA10B) exposes a 128 GiB CUDA VMM address window (below 0x20_0000_0000).
# Place EXTERNAL_FLOOR at 0x9_0000_0000 (36 GiB) so external library allocations lie in
# the 24 GiB [0x9_0000_0000, 0xf_0000_0000) range free of cuRAND precalc_xorwow_offset_matrix
# false-positive 64-bit pointer patterns (such as 0x3_0000_0000 and 0x3_0300_0000).
self.EXTERNAL_FLOOR = 0x900000000
self.DEVICE_BASE = 0x1200000000
self.RESERVATION_BYTES = 48 << 30
The PR description repeats it: "placing external library allocations in the 24 GiB [0x9_0000_0000, 0xf_0000_0000) window below DEVICE_BASE (0x12_0000_0000)".
Impact. 0xf_0000_0000 == 0x12_0000_0000 - 0x3_0000_0000, i.e. DEVICE_BASE - RESERVATION_BYTES — the end of the rank-0 window, not DEVICE_BASE. The band from the new floor to DEVICE_BASE is 36 GiB (0x9_0000_0000 .. 0x12_0000_0000), and the rank-0 reserved window is 48 GiB. The band does not stop at 0xf_0000_0000. The constants themselves are internally consistent (DEVICE_BASE + 48 GiB = 0x1E_0000_0000 = 120 GiB, inside the 128 GiB window named in the comment at :67), so this is a documentation/claim defect rather than a miscomputation — but it is the sentence reviewers and future maintainers will use to reason about which addresses are safe, and it is wrong in both the code and the PR text.
The added assertion cannot catch it — tests/preparation/test_core_storage.py:113:
assert 0x303000000 < owner.EXTERNAL_FLOOR < owner.DEVICE_BASE
Fix. State 36 GiB and drop or correct the 0xf_0000_0000 bound in both the comment and the description, and replace the loose inequality with an exact assertion on the intended span (e.g. assert owner.DEVICE_BASE - owner.EXTERNAL_FLOOR == 36 << 30).
F5 — Major (evidence for a bug-fix claim) — The cuRAND collision and the live-run verification are unbacked in the repository
The only trace of the cuRAND claim in the tree is the new comment quoted above and the new test name test_ga10b_integrated_window_places_external_floor_above_curand_table (tests/preparation/test_core_storage.py:83) with its re-statement at :108-113. There is no fixture, address dump, export log, or quoted error string showing precalc_xorwow_offset_matrix words at 0x3_0000_0000 / 0x3_0300_0000.
The headline live evidence (SM87 export of Inkling-2-Mini, ga10b-tp1-202612010822, 9 graphs; flare run --memory-limit -16m on Orin Nano 8 GB) is self-reported, has no log or artifact link, and the serving run was explicitly on a checkout prior to the rebase onto a747a5a5 while the reviewed head is f4851b3. The CUDA tests that cover the changed capture path are env-gated and were not extended by this PR — tests/preparation/test_capture_cublas_workspace_cuda.py:22-23:
pytestmark = pytest.mark.skipif(os.environ.get("FLARE_RUN_CUDA_TESTS") != "1",
reason="requires an explicitly assigned CUDA device")
Impact. The charter asks bug fixes to address the root cause with real evidence. Raising the floor relocates one colliding band instead of removing the false-positive mechanism (see "Residual risk" below), and neither the collision nor the post-capture leak has a reproducible in-repo demonstration. CI cannot exercise any of it.
Fix. Attach the export/allocation dump showing the colliding words, re-run the SM87 export on f4851b3, and add a CUDA-marked regression that reproduces the low-span reopen on main (fails) and passes here.
F6 — Minor (tests) — None of the four new tests is a regression test, and the GA10B one bypasses the only effectiveness check
tests/preparation/test_core_storage.py:95-113 (added):
class FakeCuda:
def __init__(self):
recorded["called"] = True
raise StopAfterWindow
...
owner = CoreStorage.__new__(CoreStorage)
with pytest.raises(StopAfterWindow):
CoreStorage.__init__(owner, rank=0, world=1, device=0)
...
assert 0x303000000 < owner.EXTERNAL_FLOOR < owner.DEVICE_BASE
Because _Cuda() raises, _reserve_low_window() never runs — and that is the only code that verifies allocations actually landed above the floor (core_storage.py:139-144):
self.cuda.call("cuMemAlloc_v2", C.byref(probe), C.c_size_t(self.granularity))
above = probe.value
self.cuda.call("cuMemFree_v2", probe)
if above < self.EXTERNAL_FLOOR:
raise RuntimeError(f"device allocations still start at {above:#x} below {self.EXTERNAL_FLOOR:#x}")
The mm/addmm test runs real torch.mm/torch.addmm on cpu and asserts events == ["mm", "addmm", "sync"] (added block in tests/preparation/test_capture_graph_metadata.py, roughly :475-519); the probe test mocks torch.cuda.graph and asserts the event list (roughly :536-569). Both prove call ordering only. The vocab_ids test asserts record_numeric_tensor was called once with that tensor, not that export would have misbehaved without it.
Impact. The four tests would pass on main with the production changes reverted except for the constant/ordering assertions they encode, so none demonstrates a fixed defect.
Fix. Extend tests/preparation/test_low_window.py with a fixture whose EXTERNAL_FLOOR is 0x900000000 so the sweep geometry and call-count bound cover the new code; add an assertion that the seal precedes the next capture rather than following the last one; and, for vocab_ids, assert the exported numeric spans contain (or exclude) the tensor via tensor_metadata's registry rather than asserting the call.
F7 — Minor (platform parity + docs) — The probe capture is not gated the way the seal is, and the docs still say 256 GiB
capture.py:173: if getattr(warmup_storage, "integrated", False):
core_storage.py:170-171:
if not self.integrated or os.name == "nt":
return
and core_storage.py:110-111 only reserves on non-Windows: if self.integrated and os.name != "nt": self._reserve_low_window().
Impact. An integrated Windows (WDDM) host satisfies the capture.py:173 gate, so it performs an extra CUDA graph capture and synchronize per export and then reseals nothing (seal_low_window returns immediately). WDDM retains its low pool by design (core_storage.py:109), so the probe is pure overhead there.
Docs now contradict the code — docs/runtime-core-design.md:113-116 (reserves low window "through 256 GiB"; export rejects reachable external storage below 256 GiB) and docs/windows.md:225-227 ("the base must lie at or above EXTERNAL_FLOOR (256 GiB)"); for GA10B the floor is now 36 GiB.
Fix. Gate the probe on os.name != "nt" as well (or comment the deliberate no-op), and add a one-line GA10B exception to both doc sentences.
F8 — Minor — addmm seeding does not pin which BLAS library is warmed
capture.py:68-74:
with torch.cuda.device(index), torch.cuda.stream(stream), torch.cuda.use_mem_pool(pool):
operand = torch.empty((512, 512), dtype=torch.bfloat16, device=device)
bias = torch.empty((512,), dtype=torch.bfloat16, device=device)
out = torch.empty_like(operand)
torch.mm(operand, operand, out=out)
torch.addmm(bias, operand, operand, out=out)
stream.synchronize()
Impact. Whether this warms cuBLASLt or legacy cuBLAS epilogue workspaces depends on the ambient torch.backends.cuda.preferred_blas_library() (tests/preparation/test_capture_cublas_workspace_cuda.py:39-40 shows that switch being flipped in tests). If the capture path runs under a different setting than the seed, the intended workspace is not the one seeded — the PR does not say which path is targeted or assert it.
Not a bug, checked: out is fully written by torch.mm before torch.addmm reads it, so there is no uninitialised read despite addmm with out= typically being a beta/gamma-scaled in-place update dependent on out's prior contents.
Fix. Seed under the same preferred_blas_library used during capture (or pin it explicitly), and extend the existing CUDA workspace test rather than leaving this unstated.
Explicitly verified sound
- No contract change. The diff touches no Protobuf, Rust, CLI, build or dependency file. Core load compatibility is preserved:
ignition/preparation/runtime_core.py:428still recordsdevice_address_floor=storage.EXTERNAL_FLOOR if storage.integrated else 0, and the export check still rejects only preserve-address allocations below that floor (heliopause/src/export/capture.rs:3417-3425). Existing GA10B cores keep the floor they were exported with. - Constants stay inside the hardware window.
DEVICE_BASE (0x12_0000_0000) + RESERVATION_BYTES (48 GiB) = 0x1E_0000_0000 = 120 GiB < 0x20_0000_0000(128 GiB), matchingcore_storage.py:67; rank windows stay disjoint viacore_storage.py:77-78(window = (self.DEVICE_BASE, self.RESERVATION_BYTES);self.DEVICE_BASE += rank * self.RESERVATION_BYTES), and the new floor is strictly below the rank-0 base. - Explicit-window paths untouched. The
(8, 7)branch requiresdevice_window is None(core_storage.py:66), so GB10-class explicit-window users keep their existing geometry and thebase >= EXTERNAL_FLOORvalidation at:60-62still runs against the 256 GiB class default. vocab_idschange is inert outside preparation.record_numeric_tensoris a no-op unless a registry is active (ignition/preparation/tensor_metadata.py:112-115:registry = _NUMERIC_STORAGE.get(); if registry is not None: registry.record(tensor)), and the registry is entered only insideCoreStorage(core_storage.py:404). Sampler semantics are unchanged —vocab_idsis still a cached persistentint64arange, same tensor, same device.- No lock/queue/hot-path concurrency change. The added work happens in the per-rank preparation path before serving; nothing in Helios, the request path, or the scheduling loop is touched, so there is no new contention, buffering or failure-propagation surface in serving.
Residual risk worth flagging (not a defect to fix here)
The fix removes one address band rather than the false-positive mechanism. heliopause/src/export/reachability.rs:118-131 treats any allocation whose interval contains a scanned word as a pointer, and a false positive becomes a hard error. Raising the floor only guarantees that this class of static table (0x3_0000_0000 band) no longer overlaps; any other static table with pointer-shaped words in [36 GiB, 72 GiB) would collide the same way. Scoping the pointer scan to registered/preservable allocations would address the root cause. I did not trace the downstream copy behaviour of a matched pointer, so this is reported as "same class remains", not as a new bug.
Open questions / not found
- What evidence exists for the cuRAND pattern range
[0x3_0000_0000, 0x3_0300_0000]? Nothing in the repository — a dump or export log is needed. - Is the intended external band 24 GiB or 36 GiB, and can the comment, the PR text and the test assertion be corrected together?
- Was defect #4 (
vocab_ids) ever observed?vocab_idshas no in-tree consumer, and the reported Inkling-2-Mini export succeeded without this half of the change. - Which BLAS path (cuBLAS vs cuBLASLt) does the bf16
addmmwarm, and shouldtest_capture_cublas_workspace_cuda.pybe extended? - Is the Windows asymmetry (probe capture not gated, seal a no-op) intentional?
- Overlap: open PR #606 rewrites
_seed_warmup_workspacesand inserts tests at the sametests/preparation/test_core_storage.py:83+region; whoever merges second must rebase by hand. No design conflict, but the interaction (the seededaddmmworkspace living in whatever pool #606 introduces) is addressed by neither PR. - I did not open
AGENTS.md(not opened), so this review makes no claim about a required owner sign-off for a per-architecture constant in shared preparation code; the(8,7)block follows existing precedent in the same file (the Windows/WDDM branch atcore_storage.py:109-111).