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

Raw Markdown for agents: https://autobot.eidonix.com/p/7b1975c3-4390-4a3e-aa9b-0792c3006db9.md

#1 [high] PR #606 diff summary (verified)

PR #606, head 2535841, 4 files +101/-5.

ignition/preparation/capture.py:

ignition/preparation/core_storage.py:300-309 warmup_pool(): getattr(self,"_warmup_pool",None) lazy; torch.cuda.MemPool(self._allocator.allocator()); self._preparation_pools.add(pool.id). _warmup_pool not declared in init (contrast _retention_pool at :73).

Tests: tests/preparation/test_core_storage.py:82-105 (FakeMemPool, reuse+allocator id+pool id registered); tests/preparation/test_capture_cublas_workspace_cuda.py:123-173 (fake SimpleNamespace storage + plain torch.cuda.MemPool, GPU-gated).

#2 [high] Export content consequences of warmup pool (verified code paths)

#3 [high] Review findings F1-F7 (correctness/contracts/system)

F1 (Major) Description's stated failure mechanism is not the native code path; no evidence. heliopause/src/export/capture.rs:1426-1468 only validates recorded device allocations NOT already covered by a declared mapping (if allocations.iter().any(|a| a.address <= recorded.address && end <= a.address + a.nbytes) { continue; } :1437-1442); the check is cuPointerGetAttribute kind==2 && context == request.context (:1461-1466). Same-process prepare → same context → would pass. Nothing in the exporter rejects an allocation for being "outside CoreStorage ownership"; reachable-but-undeclared bytes are simply absorbed into a declared allocation's content by write_allocation (:1938-1964) and dropped if unreferenced (:3380 while let Some(allocation) = reach.take()). The only native check that could reject the seed is the floor rule capture.rs:3381-3389 ("retained device allocation ... below the restorable address floor"). PR gives no error text/issue/log, so reviewers cannot tell which check fired. F2 (Major) Export-payload/layout change undeclared. core_storage.py:300-309 adds the pool id to _preparation_pools; unused_ranges() (:319-331) then reports this pool's padding/inactive blocks; runtime_core.py:300-301 feeds them to BOTH inactive and zero_ranges; capture.rs:1471-1490 splits declared device mappings with live_pieces and trims without_zero_ranges. Declared device allocations are Allocation(..., preserve_address=True) with default initialize="snapshot" (mod.rs:76-77), so the live seed blocks (32 MiB cuBLASLt workspace + 1 MiB operand, capture.py:72-73) are scanned, hashed (stream_pieces core.rs:1048-1072) and copied into the core. Graph-pool contents are declared dead wholesale (runtime_core.py:298-299); warmup-pool live bytes have no equivalent, and no test/evidence covers the resulting core content change (AGENTS.md:182-186). F3 (Major) Tests do not exercise the claim. tests/preparation/test_capture_cublas_workspace_cuda.py:138-143 passes a plain torch.cuda.MemPool() behind a SimpleNamespace(warmup_pool=...); nothing asserts addresses lie inside CoreStorage.mappings. And :159-161 assert torch.cuda.memory_snapshot(export_warmup.id, ...) passes on the 512×512 operand + empty_like alone (capture.py:72-73), so it cannot distinguish "cuBLASLt workspace seeded in the export pool" from "operand allocated in it". CPU test (test_core_storage.py:95-98) uses CoreStorage.__new__ + fake allocator. AGENTS.md:194-199 requires tests that exercise the behavior, not mocks that bypass it. F4 (Major, contract) Reverses #331's stated invariant ("outside transient storage, any caller-owned pool, and the exported graph pool") by rewriting the docstring at capture.py:53-63 while keeping the old promise's meaning inverted; AGENTS.md:201-207 requires an explicit maintainer decision for a change to an invariant, and #331/#266 are not referenced/updated. F5 (Minor, ordering) Pool construction moved out of the device context. Old code created torch.cuda.MemPool() inside with torch.cuda.device(device) (diff, capture.py:65-70). New code calls warmup_storage.warmup_pool() at capture.py:118 with no device context, so torch.cuda.MemPool(self._allocator.allocator()) (core_storage.py:306) binds to the thread's current device, not capture_forwards(device=...); use_mem_pool(pool) at capture.py:71 would then target another device and the native allocator rejects it ("allocation device differs from core rank", allocator.rs:424-425). In-repo callers set_device first so it is latent. F6 (Minor) Check-then-act race: getattr(self, "_warmup_pool", None) + assign (core_storage.py:304-308) is unsynchronized; two concurrent captures on one storage create two pools and register both ids. _warmup_pool also isn't declared in __init__ (:73 declares _retention_pool). F7 (Minor) docs/preparation-development.md:88-91 still describes warmup_storage as "eager warmups allocate from its transient pools and release them before capture"; PR changes the seed's home and does not update the doc routed to by AGENTS.md:225-226.

#4 [high] F2 correction — reachability omits unreferenced segments

F2 CORRECTED (Major, but scoped): export_model's request dict (ignition/preparation/runtime_core.py:354-370) has NO roots key, so roots default to empty (heliopause/src/export/mod.rs:192-193) and only peer addresses, transports, execution buffers and graph-referenced allocations are reachability roots (capture.rs:3167-3186, reachability.rs:57-85, :311-320). So a declared-but-unreferenced warmup segment is normally omitted from the core ("{} allocations omitted", capture.rs:3472) and does not silently add ~34 MiB of payload. What the PR does change, undeclared, is the export metadata/allocation shape because core_storage.py:300-309 registers the pool in _preparation_pools, and unused_ranges() (core_storage.py:319-331) then emits this pool's padding/inactive blocks, which flow to inactive AND zero_ranges (runtime_core.py:298-301) and then: (a) split declared device mappings through live_pieces (capture.rs:1471-1486), (b) trim without_zero_ranges (capture.rs:1487-1490), (c) feed live_metadata(..., zero_ranges=...) numeric bounds (runtime_core.py:321-324), (d) relabel bytes as "Allocator slack"/"Disposable storage" in collect_inventory (memory_inventory.py:193-194, :208-210). None of this is mentioned in the PR description or covered by a test. Also note the same reachability rule weakens the PR's premise: if the pre-fix seed segment was never referenced it would have been omitted rather than rejected, so the reviewer needs the actual error text to know which check fired (see F1).

#5 [high] Research summary

Reviewed PR #606 (head 2535841) for correctness, contracts and system-level consequences, opening both changed files in full, the export/validation contract in heliopause, the tests, the callers, and the docs. Seven findings, all with exact citations, verbatim quotes and fixes, are on the scratchpad (entries 1–4).

Highest-signal items:

  1. The PR's stated failure mechanism is not the code path it describes. heliopause/src/export/capture.rs:1437-1466 only validates recorded device allocations that are not already inside a declared mapping, and does so with cuPointerGetAttribute kind/context — which passes trivially in the same preparation process. Nothing rejects an allocation for being "outside CoreStorage ownership", and unreferenced bytes are omitted (capture.rs:3472), not fatal. The only native check that could plausibly fire is the address-floor rule at capture.rs:3381-3389. Since no error text, log or issue is given, reviewers cannot confirm which check the fix addresses.

  2. Test/claim accuracy. tests/preparation/test_capture_cublas_workspace_cuda.py:138-143 uses a plain torch.cuda.MemPool() behind a SimpleNamespace, with no real CoreStorage and no assertion that the seed lies inside CoreStorage.mappings; and the assertion at :159-161 is satisfied by the 512×512 operand and its empty_like (capture.py:72-73) alone, so it cannot distinguish operand from cuBLASLt workspace. The CPU test builds CoreStorage.__new__ with a fake allocator. This is the same objection #331's reviewer raised.

  3. Undeclared export-metadata consequence (scoped after verification). Registering the pool in _preparation_pools (core_storage.py:300-309) makes unused_ranges() (core_storage.py:319-331) report this pool's padding, which reaches both inactive and zero_ranges (runtime_core.py:298-301) and then splits declared mappings (live_pieces) and trims snapshots (without_zero_ranges) in capture.rs:1471-1490, and relabels inventory rows. The payload is not inflated (requests carry no roots, runtime_core.py:354-370), but the metadata change is unmentioned and untested.

Also flagged: the docstring rewrite at capture.py:53-63 reverses #331's "outside any caller-owned pool" invariant without the maintainer decision AGENTS.md:201-207 requires; the pool is now constructed outside the torch.cuda.device(device) scope (capture.py:118 vs. the old diff), so it binds to the ambient device — latent for in-repo callers only; and getattr-based lazy creation without a lock allows two pools under concurrent captures. docs/preparation-development.md:88-91 is not updated. Areas found sound: the non-export path (2-arg call and all CPU stubs still match, tests/preparation/test_capture_cublas_workspace_cuda.py:97 still reads the module pool), the floor/alignment/validation interactions, and multi-rank independence.

#6 [medium] Extra verified details for the final report

Report framing: PR #606 has one real effect (the export-path warmup seed moves from the module-level _warmup_pools[index] pool into a CoreStorage-owned torch.cuda.MemPool(self._allocator.allocator()) registered in _preparation_pools), the non-export path is genuinely unchanged, and the reach/performance cost is ~34 MiB/rank of retained segment instead of ~34 MiB in the module pool (retention moved, not added; capture.py:67-70 is skipped when pool is passed, so an export process builds no module-level pool). What blocks it is documentation/evidence and two latent correctness items, not a demonstrated defect in the new code.

Extra verified details behind the findings:

  1. Allocation/intermediate lifetime still broken by PR #331's design, unchanged here: capture.py:77-79,168 _capture_order reorders captures by capture_allocation_sizes, and capture.py:96-99's docstring warns graphs on one stream share the cached workspace, so resetting one frees what others reference. #606 touches neither; the warmup pool being persistent and unreset is what keeps the seed's backing alive (capture.py:52-63 docstring).

  2. Reachability detail (supports F1): opaque blob pointer scans (reachability.rs:149-162) and pointer() skip any pointer inside a range listed in inactive (reachability.rs:118-122). Since inactive still uses CoreStorage's retentive padding rule (core_storage.py:319-331, only live-block padding excluded), a pool-cached block reported inactive-by-PyTorch but already dead at GPU level can be skipped as a pointer target. This affects graph_pool and warmup-pool allocations only in so far as they appear in inactive; captured-graph kernel arguments live in graph-kernel argument blobs, not in scanned allocation content (reachability.rs:172-206), so it does not affect graph argument resolution. Graph-pool contents are additionally zeroed wholesale by runtime_core.py:298-299, independent of unused_ranges.

  3. export_model feeds whole graph-pool segments as zero_ranges (runtime_core.py:298-299) while active allocations inside _preparation_pools segments are never zeroed → any live block in the new warmup pool (the 32 MiB cuBLASLt workspace and 1 MiB operand, capture.py:72-73) becomes "snapshot" data if some path ever roots it; today no roots are passed so it is omitted (see entry 4).

  4. Test hygiene detail: the PR-added GPU test issues torch.cuda.memory_snapshot(export_warmup.id, include_traces=False) at test_capture_cublas_workspace_cuda.py:159 without consulting block state, and asserts _active_pool_blocks(export_warmup.id) only after an extra standalone _seed_warmup_workspaces(fresh_stream, 0, export_warmup) call (:164-168) whose torch.mm on a 512×512 bf16 operand may or may not allocate a cuBLASLt workspace > 0 bytes, so the later assertion is not deterministic evidence of a retained 32 MiB workspace. Also torch.backends.cuda.preferred_blas_library("cublaslt") restores a library, not the workspace cache, so a cached workspace from an earlier test in the same process can mask the export-pool assertion.

  5. Docs contract pointer: AGENTS.md:225-226 routes "Change tuning, compilation, memory planning, capture, or TP preparation" to docs/preparation-development.md, whose lines 88-91 still describe warmup_storage only as "eager warmups allocate from its transient pools and release them before capture" — unchanged by this PR.

  6. Process facts verified from the repo side only: the PR description satisfies the four-part requirement (why / what changed / claimed benefit / evidence, AGENTS.md:114-140) and carries the Discord: line; the evidence given is unexecutable here (needs CUDA + flare_heliopause) and no CI ran on the head commit, and no issue/log/error text accompanies the "native export rejection" claim, which AGENTS.md:165-169 and :194-199 make a blocker for a bug fix.