Subtraction and simplicity scratchpad · NVIDIA/hyperflare-inference #606

Raw Markdown for agents: https://autobot.eidonix.com/p/4ce9c5cf-c193-4cd5-845c-92a53818100d.md

#1 [high] PR #606 subtraction/simplicity lens — findings with citations

PR #606 (head 8c1a28a), lens = Subtraction/Simplicity/Conventions. Verdict: diff is small and mostly lean (+12/−0 production in core_storage.py, +16/−7 in capture.py); 2 real deletions, 2 optional collapses.

F1 (HIGH, biggest): tests/preparation/test_capture_cublas_workspace_cuda.py:208-249 is dead weight — nothing reads package or tmp_path/"rank.json" after package.write(...); the block re-implements tests/preparation/test_recorded_export_graph_cuda.py:66-83 almost verbatim (same buffers dict / PreparedExecution / Allocation-from-graph-pool / RuntimeCore / write). Verbatim 208-249 (42 lines). Per dossier it also cannot reach the validations it targets (RuntimeCore.write never sets discover_allocations, ignition/preparation/runtime_core.py:108-133 & sole setter :360; device_address_floor default 0 at :97-98 vs real :364). Concrete: delete 208-249 and the now-unused imports at :152-154 (PreparedExecution, Allocation, RuntimeCore; ModuleImages at :153 only supplies images.native for the export) — or, if native coverage is wanted, replace the whole helper body with export_model(...) created inside the test (precedent helios/tests/fixed_core_fixture.py:171, ignition/preparation/model_core.py:49). Deleting also removes the with ModuleImages() as images: wrapper (:156) and its nesting.

F2 (MED-HIGH): ignition/preparation/core_storage.py:305 pool = getattr(self, "_warmup_pool", None) — defensive read for an attribute the same PR declares at :74 (self._warmup_pool = None). Sibling transient() reads its declared field directly (:276 pool = self._retention_pool, declared :73) and _retire_retention_pool too (:256). The getattr exists only because tests/preparation/test_core_storage.py:95-97 builds the object with CoreStorage.__new__ and sets _allocator/_preparation_pools but not _warmup_pool. Concrete: pool = self._warmup_pool, plus one test line storage._warmup_pool = None (mirroring :46-47 which already set _weight_arenas = []).

F3 (MED): ignition/preparation/capture.py:119-124 — 6 lines to express one call. Verbatim: 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) _seed_warmup_workspaces already resolves pool=None to the module pool (:68-71), so the else branch passes exactly the default. The branch exists only because 7 stubs use 2-arg lambdas: tests/preparation/test_capture_graph_metadata.py:181, test_capture_rank_readiness.py:56, test_capture_roce_wait.py:40, test_capture_stream_isolation.py:44, test_forward_compile_options.py:309, test_preparation_reclamation.py:41, test_transient_retention.py:131 (all lambda stream, device: None; they would TypeError on a 3rd positional). Concrete: widen those stubs to lambda stream, device, pool=None: None and capture.py becomes _seed_warmup_workspaces(warm, device, warmup_storage.warmup_pool() if hasattr(warmup_storage, "warmup_pool") else None) Test-only arity in production control flow is also an AGENTS.md "fallback layer for mocks" smell. Note: production never passes warmup_storage=None in export paths, but bench/gather callers do (ignition/bench/observations.py:87, ignition/bench/study.py:48, helios/tests/gather_core_fixture.py:85) so the module-pool fallback itself is live and must stay.

F4 (LOW-MED, coupled to dossier finding 4): ignition/preparation/core_storage.py:309 self._preparation_pools.add(pool.id) is the only line whose effect escapes the warmup path — _preparation_pools is read solely by unused_ranges() (:320-335, membership test :327), which export_model turns into inactive + zero_ranges (ignition/preparation/runtime_core.py:298-301, :362) feeding live_pieces/without_zero_ranges in heliopause/src/export/capture.rs:1259-1305. So the registration silently changes exported content and nothing tests it (helper never calls unused_ranges). Concrete choice for author: either drop the .add(...) line (and the assertion at tests:189) keeping the diff strictly allocator-local, or keep it and add one unused_ranges() assertion.

F5 (MINOR, prose/convention): tests/preparation/test_capture_cublas_workspace_cuda.py:4-13 module docstring still claims "The test uses plain MemPools for transient storage and the shared graph pool handle so it needs no package-export resources" — false since the PR added ModuleImages/CoreStorage/RuntimeCore use (:151-154). AGENTS.md requires documents state implemented behavior. One-line rewrite.

Already lean / do NOT ask for deletion (state plainly so downstream doesn't over-cut): no new flags, env vars, config knobs or wrappers were added; warmup_pool() mirrors scratch_pool() (:295-299) and must stay a method because it must register with _preparation_pools; the pool=None default and module _warmup_pools dict are still used by non-export callers; in-method import torch (:303) matches every other method in core_storage.py; CoreStorage.init change is one line. docs/preparation-development.md:92-94 restates the capture.py docstring nearly verbatim and reflows awkwardly ("mappings. Ranks" at :94) but is prose-only — optional merge into one clause.

Lens boundary note: F1 is a deletion, not a patch of the test's missing native coverage (that correctness gap is the other lens's blocker).

#2 [high] Research summary

Subtraction/Simplicity/Conventions lens done on PR #606 (5 changed files read in full; repo helpers, AGENTS.md, and all _seed_warmup_workspaces / _preparation_pools call sites checked). Findings saved to scratchpad entry 1 with verbatim quotes and line citations.

The production diff is genuinely lean (+12/−0 in core_storage.py, +16/−7 in capture.py): no new flags, config knobs, or wrappers; warmup_pool() mirrors scratch_pool(); the module-pool fallback is still live for bench/gather callers. Most of the removable mass is in the 134-line new GPU test.

Five suggestions, ranked: (1) delete tests/preparation/test_capture_cublas_workspace_cuda.py:208-249 — 42 lines whose package/rank.json (not opened) output is never read and which duplicate test_recorded_export_graph_cuda.py:66-83; this also removes three imports and drops the file back to its narrow scope; if native coverage is truly wanted, replace the helper with one export_model(...) call instead. (2) Drop getattr(self, "_warmup_pool", None) at core_storage.py:305 — the PR declares the attribute two lines-set earlier at :74, and sibling pools read declared fields directly; add one storage._warmup_pool = None line to the CPU test instead. (3) Collapse the 6-line if warmup_pool is not None: ... else: ... branch at capture.py:119-124 into one call, since pool=None already means the module pool; the branch exists only for seven 2-arg lambda stream, device: None test stubs, so widen those instead. (4) The self._preparation_pools.add(pool.id) at core_storage.py:309 is the only line whose effect leaves the warmup path (unused_ranges() → inactive/zero_ranges → exported content); author should either drop it or add the missing unused_ranges() assertion. (5) Rewrite the stale test module docstring (:4-13) that still claims the file needs no package-export resources. Docs reflow at docs/preparation-development.md:94 noted as optional prose-only.

I did not re-raise the correctness blockers (the test's missing discover_allocations/device_address_floor coverage); per the lens rules I framed that as "delete rather than patch" where it applies.

#3 [high] PR #606 lens — verbatim evidence lines for F1/F5 and sibling patterns

Exact quotes to cite in the report (PR #606 head 8c1a28a). Line numbers are at the PR head.

F1 — tests/preparation/test_capture_cublas_workspace_cuda.py, dead tail of the helper (quote these ranges): :208-215 buffers = dict( source=source, weight=weight, output=output, frame_index=frame, submission_sequence=sequence, completion_records=records, ) :216-222 PreparedExecution(device=0, graphs=graphs, buffers=buffers, max_active=1, signatures={"decode": GraphSignature("decode", 1, 1, ("source",))}) :223-236 allocations = [Allocation(name, tensor.data_ptr(), tensor.nbytes) for name, tensor in buffers.items()] + graph-pool segments via storage.graph_pool.snapshot(include_traces=False) :237-243 package = RuntimeCore( allocations=allocations, modules={}, kernels=(), recorder=images.native, owners=(bundle, storage), ) :244-249 package.write( tmp_path / "rank.json", bundle.graphs, execution=bundle.export_manifest(), sources=True, ) Nothing after :249 reads package or the file → the 42 lines have no assertion. Near-verbatim duplicate of tests/preparation/test_recorded_export_graph_cuda.py:66-83 (same buffers dict at :66-67, PreparedExecution at :68-70, Allocation-from-graph-pool at :79-80, RuntimeCore at :81-82, package.write(path, bundle.graphs, execution=manifest, sources=True) at :83) — wrote "manifest" there vs bundle.export_manifest() here. Imports that become unused if :208-249 goes: :152 from ignition.preparation.execution import GraphSignature, PreparedExecution → GraphSignature only; :154 from ignition.preparation.runtime_core import Allocation, RuntimeCore (both) deleted; :153 ModuleImages only supplies images.native at :241. tmp_path then only feeds the subprocess arg at :140 (harmless, but the with ModuleImages() as images: wrapper at :156 loses its purpose). Replacement if native coverage is kept: one export_model(...) call created in the test (precedents: helios/tests/fixed_core_fixture.py:171 core = export_model(prepared, images, storage, root / "rank.json", options={}, ...); ignition/preparation/model_core.py:49; ignition/preparation/runtime_core.py:280 signature).

F5 — stale module docstring, tests/preparation/test_capture_cublas_workspace_cuda.py:4-13, final sentence verbatim: :11-12 "pool. The test uses plain MemPools for transient storage and the" :12 "shared graph pool handle so it needs no package-export resources." False since :151-154 import CoreStorage / ModuleImages / RuntimeCore. AGENTS.md:52-60 requires documents state implemented behavior.

Sibling patterns for F2 (core_storage.py): :73-74 declared: self._retention_pool = None / self._warmup_pool = None :276 direct read: pool = self._retention_pool :256 direct read: pool, self._retention_pool = self._retention_pool, None → so :305 pool = getattr(self, "_warmup_pool", None) is the odd one out; the only reason is tests/preparation/test_core_storage.py:95-97 (CoreStorage.__new__, sets _allocator, _preparation_pools, not _warmup_pool); that test already sets a list field explicitly at :46 storage._weight_arenas = [].

F4 — core_storage.py:295-299 scratch_pool() is the pattern warmup_pool() copies: def scratch_pool(self): """Own zero-initialized scratch whose physical backing can be released during compilation.""" pool = ScratchPool(self) self._preparation_pools.add(pool.pool.id) return pool So the .add(...) at :309 is consistent with siblings; its only consumer is unused_ranges() membership at :327.

Docs nit — docs/preparation-development.md:88-94 verbatim tail: "their workspaces do not coexist with retained graph intermediates, while / cuBLAS warmup workspaces are seeded into CoreStorage.warmup_pool() so they / stay outside transient and graph pools while remaining inside declared core / mappings. Ranks" — restates capture.py:59-64 and breaks the sentence.

Lean-points evidence (for the "do not over-cut" paragraph): capture.py:68-71 module pool still needed by ignition/bench/observations.py:87, ignition/bench/study.py:48, helios/tests/gather_core_fixture.py:85 (retain_graphs=True with no warmup_storage); import torch inside methods matches core_storage.py:259, :272, :303, :322.