Correctness and contracts scratchpad · NVIDIA/hyperflare-inference #606

Raw Markdown for agents: https://autobot.eidonix.com/p/7e1aaa39-50dd-42a5-b70a-6476de43f18e.md

#1 [high] PR #606 correctness/contracts lens findings (head 8c1a28a)

BLOCKER (verified): the new GPU test cannot reach either export check the fix exists to satisfy.

MINOR (verified, untested interaction): the new pool id joins _preparation_pools (core_storage.py:309), so CoreStorage.unused_ranges() (core_storage.py:320-335) now sweeps warmup-pool segments into inactive (runtime_core.py:300, 362) -> live_pieces splitting (capture.rs:1471-1486, 1259-1303) and zero_ranges (runtime_core.py:301 -> capture.rs:1487-1490 without_zero_ranges). Unlike graph-pool segments, the warmup segment is NOT added to zero_ranges explicitly (runtime_core.py:298-299), so if the warmup mapping is ever reachable from a graph node (the seed workspace is local to the warm-up stream, so normally unreachable; export_model passes no roots) its non-zero workspace bytes would be snapshotted and restored. The test never calls unused_ranges() and passes no zero_ranges. Cheap fix: extend runtime_core.py:298-299 to include storage.warmup_pool().snapshot(...) when it exists. Note: the prior "avoids 32 MiB/rank of bloat" framing is not established.

MINOR (verified): capture_forwards now creates a persistent core-allocator MemPool whenever warmup_storage exposes warmup_pool() even for non-export captures (capture.py:119-124; _replica in tuning_replicas.py:157-160 uses CoreStorage with retain_graphs=False). One ~34 MiB segment is permanently taken out of the core window free list (allocator.rs:438-442) that also backs pool/graph_pool/transients; retention is not reported anywhere except as retained "Core fixed mappings" in memory_inventory (memory_inventory.py:198-210 classifies only graph_pool segments specially, :228-239 fixed_core_bytes).

MINOR (PR text): body says the change preserves all of #331's invariants including "outside any caller-owned pool", but capture.py:59-64 now documents the export path as using a pool owned by the caller's storage; also no statement whether cores exported before this change need re-export.

SOUND / no finding: the docstring (capture.py:52-65) matches both branches; the non-export path keeps the exact 2-argument call and module dict (capture.py:120-124), so tests/preparation/test_capture_cublas_workspace_cuda.py:97 and the SimpleNamespace warmup_storage callers (:70 test_capture_rank_readiness, :141 test_transient_retention) are unaffected; _seed_warmup_workspaces stream/index handling is unchanged in behaviour (capture.py:66-75); no lock/queue/hot-path change and no concurrency hazard beyond the pre-existing process-global core allocator mutex (allocator.rs:420); Windows path unchanged (seal_low_window early-returns, core_storage.py:167-168).

#2 [high] Research summary

Reviewed PR #606 (head 8c1a28a) through the correctness/contracts/system-consequences lens: read the full diff, ignition/preparation/capture.py, core_storage.py, runtime_core.py, execution.py, memory_inventory.py, packed_weights.py, tuning_replicas.py, the native discover_allocations/prepare_allocations/reachability/floor checks in heliopause/src/export/capture.rs and allocator.rs, plus both changed tests and the existing export fixtures.

Verdict: Changes Requested. One blocker, three minor findings, all verified with exact citations saved to the scratchpad.

Blocker: the new "export" CUDA test still cannot reach either native validation the fix exists to satisfy. It builds RuntimeCore by hand and calls write (tests/preparation/test_capture_cublas_workspace_cuda.py:237-249), but write's request never sets discover_allocations (runtime_core.py:122-133; the only setter is export_model, runtime_core.py:360), so the discovery/context rejection (capture.rs:1407-1468) is skipped, and device_address_floor stays at its constructor default 0 (runtime_core.py:97-98) instead of storage.EXTERNAL_FLOOR if storage.integrated else 0 (runtime_core.py:364), so the below-floor rejection (capture.rs:3381-3389) can never fire either. The Python-level assertions (module pool unused, pool id registered, segment inside storage.mappings) are real but are not the native check that produced the quoted error.

Minors: the new pool id in _preparation_pools silently feeds unused_ranges() into inactive/zero_ranges (core_storage.py:309, 320-335 → runtime_core.py:298-301 → capture.rs:1471-1490) while the warmup segment, unlike graph-pool segments, is never added to zero_ranges — untested and asymmetric; the persistent ~34 MiB core segment is now created for every CoreStorage capture, including non-export/tuning-replica captures (capture.py:119-124, tuning_replicas.py:157-160), permanently reducing the core window free list, with no reporting; and the PR body still claims #331's "outside any caller-owned pool" invariant is preserved when capture.py:59-64 documents exactly the opposite for the export path, and never says whether previously exported cores need re-export. Everything else in the touched code (non-export path keeps the exact 2-argument call, docstring, stream handling, Windows path) is sound.

#3 [high] PR #606 — verbatim quotes and coverage for the report

VERDICT: Changes Requested (1 Blocker, 3 Minor). Head 8c1a28a, +191/-8, 5 files, zero human reviews (per dossier).

FILES INSPECTED (all opened, in context):

QUOTE 1 (Blocker) — tests/preparation/test_capture_cublas_workspace_cuda.py:237-249: package = RuntimeCore( allocations=allocations, modules={}, kernels=(), recorder=images.native, owners=(bundle, storage), ) package.write( tmp_path / "rank.json", bundle.graphs, execution=bundle.export_manifest(), sources=True, ) QUOTE 1b — runtime_core.py:126-133 (write's request; no discover_allocations): roots=[a.name for a in self.allocations], cupti_path=_cupti_path(), publisher=publisher_metadata(publisher), reservations=[(r["address"], r["nbytes"]) for r in self.reservations], events=self.events, transports=self.transports, device_address_floor=self.device_address_floor, execution=execution, QUOTE 1c — runtime_core.py:97-98 and :364: def init(self, *, allocations, modules, kernels, owners=(), reservations=(), events=None, transports=(), device_address_floor=0, recorder=None): device_address_floor=storage.EXTERNAL_FLOOR if storage.integrated else 0, QUOTE 1d — capture.rs:1412-1414 (guard that skips the failing check): if let Some(recorder) = recorder.filter(|| request.discover_allocations || !request.peer_mappings.is_empty()) { QUOTE 1e — capture.rs:3381-3389 (floor check, unreachable with floor=0): if allocation.memory == "device" && allocation.preserve_address && allocation.address < request.device_address_floor { return Err(invalid(format!( "retained device allocation {:?} at {:#x} is below the restorable address floor {:#x}",

QUOTE 2 (Minor) — core_storage.py:307-309 vs runtime_core.py:298-301: pool = torch.cuda.MemPool(self._allocator.allocator()) self._warmup_pool = pool self._preparation_pools.add(pool.id) zero_ranges.extend((segment["address"], segment["total_size"]) for segment in storage.graph_pool.snapshot(include_traces=False)) inactive = storage.unused_ranges() zero_ranges.extend((start, end - start) for start, end in inactive) (growth path: core_storage.py:320-335 unused_ranges sweeps segments whose pool id is in _preparation_pools; capture.rs:1471-1486 live_pieces over inactive; capture.rs:1487-1490 without_zero_ranges over zero_ranges.)

QUOTE 3 (Minor) — capture.py:119-124, reached with retain_graphs=False too (tuning_replicas.py:157-160 with CoreStorage(world=plan.world_size) as storage: -> retain_graphs=False): warmup_pool = warmup_storage.warmup_pool() if hasattr(warmup_storage, "warmup_pool") else None if warmup_pool is not None: _seed_warmup_workspaces(warm, device, warmup_pool) else: # Keep the 2-argument call for non-export callers and existing test stubs. _seed_warmup_workspaces(warm, device) (one segment per CoreStorage is permanently removed from the core window free list: allocator.rs:438-442 a.free.iter().position(...); not reported: memory_inventory.py:200 only special-cases storage.graph_pool.id.)

QUOTE 4 (Minor, PR text vs code) — PR body: "preserves all of #331's safety invariants (... persistent backing outside transient storage, storage.pool, and storage.graph_pool)" and "keeping warmup segments inside declared CoreStorage.mappings"; but capture.py:59-64 states the new branch uses a caller-owned pool: later call could reuse it. When pool is omitted, seeding uses a module-level pool outside transient storage, caller-owned pools, and the exported graph pool. When an export storage supplies warmup_pool(), seeding uses that persistent pool instead so the Also missing from the body: whether cores exported before this change need a re-export (required on #331 per dossier item 5).

SOUND (state plainly, no issue invented): non-export callers keep the exact 2-argument call and module-level _warmup_pools dict, so tests/preparation/test_capture_cublas_workspace_cuda.py:97 (_capture._warmup_pools[0].id), test_capture_rank_readiness.py:70 and test_transient_retention.py:141-142 (SimpleNamespace(transient=..., retain_transient_backing=...) without warmup_pool) are unaffected; _seed_warmup_workspaces device/index/stream ordering unchanged (capture.py:66-75); no new lock, queue or hot-path work (only the existing process-global core-allocator mutex, allocator.rs:420); Windows path untouched (seal_low_window early-return, core_storage.py:167-168); test_core_storage.py:83-105 is a coherent CPU-level check of lazy single creation + registration (it exercises the getattr at core_storage.py:305).

Also per dossier, not re-verified here but consistent: no CI job runs the Python/CUDA suite, so the "36 passed, 1 skipped" evidence stays self-reported.