Subtraction, Simplicity & Conventions review — PR #606
Key findings
capture.py:118-122re-implements thepool=Nonefallback that_seed_warmup_workspacesalready contains atcapture.py:67-70. Four lines collapse to one call. Only caveat: seven CPU test stubs monkeypatch the function with a 2-argument lambda and would need the extra parameter.CoreStorage.warmup_pool()(core_storage.py:300-309) is a near-duplicate of the poolCoreStoragealready owns atcore_storage.py:113-117— same allocator, already persistent, already in_preparation_pools. Eitherreturn self.pooland delete 11 lines plus its 23-line unit test, or justify the third pool in one sentence.capture.py:59-63now states two contradictory rules in adjacent sentences ("outside … any caller-owned pool" and "seed inside it"), because the PR appended a sentence instead of replacing the #331 invariant it reverses.docs/preparation-development.md:88-91is also left stale.- The new GPU test (
test_capture_cublas_workspace_cuda.py:123-173) duplicates the setup of the adjacent test and asserts the same pool twice, one of them strictly weaker; ~25 lines are removable. - Verdict: the diff is small but not lean. 23 production lines; ~15 of them (
S14,S211) are removable duplication, and one 23-line unit test exists only to test the duplicated method. No flags, config knobs, env vars or dead code were introduced, and the non-export path is genuinely untouched.
Scope and method
Files checked in full: ignition/preparation/capture.py (changed region and docstrings), ignition/preparation/core_storage.py (constructor, transient, scratch_pool, packed_weights, unused_ranges, ScratchPool), tests/preparation/test_core_storage.py, tests/preparation/test_capture_cublas_workspace_cuda.py. Consumers checked for duplication/allowlist effects: ignition/preparation/runtime_core.py, ignition/preparation/memory_inventory.py, and the seven CPU test stubs found via search_code ".._seed_warmup_workspaces|warmup_pool\(\)".
Nothing in the diff adds a flag, configuration switch, environment variable, model-specific branch or speculative extension point — AGENTS.md:188-193 ("Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement") is respected on that axis. The subtraction findings below are about duplicated behaviour rather than added machinery.
S1 (high) — the capture_forwards branch duplicates the fallback inside _seed_warmup_workspaces
ignition/preparation/capture.py:118-122 (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:
_seed_warmup_workspaces(warm, device)
The callee already implements exactly this branch — ignition/preparation/capture.py:65-71:
with torch.cuda.device(device):
index = torch.cuda.current_device()
if pool is None:
pool = _warmup_pools.get(index)
if pool is None:
pool = _warmup_pools[index] = torch.cuda.MemPool()
with torch.cuda.device(index), torch.cuda.stream(stream), torch.cuda.use_mem_pool(pool):
Passing pool=None is byte-for-byte the same path as the two-argument call, so the caller-side if/else selects between two spellings of one behaviour. Replace the four lines with one:
_seed_warmup_workspaces(warm, device, warmup_storage.warmup_pool()
if hasattr(warmup_storage, "warmup_pool") else None)
Behaviour is identical (the None case falls into capture.py:67-70 unchanged), and the hasattr capability probe remains as the single expression it is.
Caveat found while checking, stated so the suggestion is actionable: seven CPU tests stub the function with a two-argument lambda and would fail with the collapsed 3-argument call — tests/preparation/test_capture_graph_metadata.py:181 (not opened), test_capture_rank_readiness.py:56, test_capture_roce_wait.py:40 (not opened), test_capture_stream_isolation.py:44, test_forward_compile_options.py:309 (not opened), test_preparation_reclamation.py:41 (not opened), test_transient_retention.py:131, e.g. monkeypatch.setattr(capture, "_seed_warmup_workspaces", lambda stream, device: None). Each needs pool=None added — seven one-token edits, still a net deletion (4 production lines → 2, plus 7 stub signatures unchanged in spirit).
The nested branch is the kind of "fallback layer without a concrete requirement" AGENTS.md:188-193 rejects: the export path never passes an empty pool, and the non-export path is the absence of warmup_pool, which None already encodes.
S2 (high) — CoreStorage.warmup_pool() duplicates a pool CoreStorage already owns
ignition/preparation/core_storage.py:300-309 (verbatim, the entire production change in this file):
def warmup_pool(self):
"""Own a persistent pool for cuBLAS warmup workspaces inside core mappings."""
import torch
pool = getattr(self, "_warmup_pool", None)
if pool is None:
pool = torch.cuda.MemPool(self._allocator.allocator())
self._warmup_pool = pool
self._preparation_pools.add(pool.id)
return pool
Every property this method produces already belongs to CoreStorage.pool, created in __init__ at ignition/preparation/core_storage.py:113-117:
self.pool = torch.cuda.MemPool(allocator.allocator())
self.graph_pool = torch.cuda.MemPool(allocator.allocator())
self._preparation_pools = {self.pool.id}
self._weight_arenas = []
self._scope = torch.cuda.use_mem_pool(self.pool, device=device)
- Same backing:
allocatorat:108-110isself._allocator, soself._allocator.allocator()and the existing pool's allocator are the same object. - Same lifetime: nothing shown in this class retires
self.pool—transient()creates/destroys its own pools (:277-282,:288-290),_retire_retention_pool()only clears_retention_pool(:254-256),ScratchPool.retire()only clears its own pool (:579-584).self.poolis process-persistent. - Same registration:
self.pool.idis already in_preparation_pools(:115), sounused_ranges()(:319-334) sweeps both identically — the new method adds a third pool id to a set that already contains the equivalent one, without changing whatunused_rangesdoes with it.
There is in fact a live question the method hides: :117 enters torch.cuda.use_mem_pool(self.pool, device=device) as a permanent ambient scope, so on the thread that constructed the CoreStorage a plain allocation already routes to self.pool. Either that scope does not reach the thread capture_forwards runs on (then the PR needs one sentence saying so), or the new pool is redundant outright. Two concrete options, both narrower than the PR:
- (a) Delete the method and the
_warmup_poolattribute, and havecapture_forwardsuse the existing owner:warmup_storage.poolis already exposed and public. This also deletestests/preparation/test_core_storage.py:83-105(23 lines), which exists only to test the duplicated lazy construction. - (b) If a separate pool is genuinely required (e.g. the seeded block must be independently observable), keep the method but declare
self._warmup_pool = Nonein__init__next toself._retention_pool = None(core_storage.py:73) andself._persistent_arena = None(:82), then drop thegetattr(self, "_warmup_pool", None)probe. Thatgetattrdeparts from the convention every neighbouring lazy member follows and is only load-bearing because the new unit test constructs the object viaCoreStorage.__new__(tests/preparation/test_core_storage.py:95) — a test enforcing a pattern the class itself does not use.
Supporting evidence that a third pool is a new entity every consumer must recognise: the export path enumerates pools by name — ignition/preparation/runtime_core.py:198-199 (pools = (storage.pool, storage.graph_pool)), ignition/preparation/memory_inventory.py:200 (graph_pool = tuple(segment["segment_pool_id"]) == tuple(storage.graph_pool.id)). A _warmup_pool is invisible to both; reusing self.pool keeps the model at two pools with one sentence of explanation.
S3 (medium) — the patched docstring now contradicts itself; the old invariant should be replaced, not appended to
ignition/preparation/capture.py:59-63 (verbatim, end of the _seed_warmup_workspaces docstring):
later call could reuse it; a dedicated pool keeps the seed's backing
mapped for the life of the cache entry, outside transient storage,
any caller-owned pool, and the exported graph pool. When an export
storage supplies a persistent warmup pool, seed inside it so the
allocation stays within declared core mappings.
The first sentence forbids landing in "any caller-owned pool"; the second instructs seeding inside exactly that. The first clause is #331's invariant (commit 1eb61e81), which this PR reverses; appending the new rule leaves both in the file and forces every later reader to work out which one wins. Replace both sentences with one statement of the surviving invariant, e.g.: "a dedicated pool keeps the seed's backing mapped for the life of the cache entry, outside transient storage and the exported graph pool — in the export storage's own core pool when one is supplied, so the allocation stays within declared core mappings." This also makes the deliberate reversal of #331 visible in the code, which the PR description does not state anywhere.
Same drift, untouched by this PR: docs/preparation-development.md:88-91 still says only that with warmup_storage "eager warmups allocate from its transient pools and release them before capture", which no longer describes where the warmup seed lives once a warmup_pool() is supplied. One clause fixes it. (AGENTS.md:43-50 requires the repo prose skill for docstrings; this is a structural contradiction, not a wording nit.)
S4 (medium) — the new GPU test duplicates the adjacent test's setup and double-asserts the same pool
tests/preparation/test_capture_cublas_workspace_cuda.py:123-173 re-derives the whole scaffold of :33-120 nearly line for line: torch.cuda.set_device(0), save/set/restore preferred_blas_library("cublaslt") (:127-129 vs :38-40), source/weight/output bf16 tensors and a forward closure (:131-136 vs :42-48), pool = torch.cuda.graph_pool_handle(), session = SimpleNamespace(capture=nullcontext), stream = torch.cuda.Stream(), the capture_forwards(...) call with the same {"decode": GraphSignature("decode", 1, 1)}, and the finally: graph.reset() loop. Extract one module-level helper or fixture (device + blas library + tensors + forward + session, yielding them) and use it in both tests: roughly 25 duplicated lines removed, and the second test shrinks to what it actually asserts.
Inside the new test, two of the three assertions are redundant — :158-168 (verbatim):
assert not _active_pool_blocks(transient.id)
assert torch.cuda.memory_snapshot(export_warmup.id, include_traces=False), (
"capture_forwards did not allocate warmup seed inside storage.warmup_pool()"
)
# On a fresh stream with no prior cached cuBLASLt workspace, seeding must
# retain the persistent workspace block inside export_warmup.
fresh_stream = torch.cuda.Stream()
_seed_warmup_workspaces(fresh_stream, 0, export_warmup)
assert _active_pool_blocks(export_warmup.id), (
"seeded cuBLASLt workspace did not land inside storage.warmup_pool()"
)
:159-161(any segment in the pool) is strictly weaker than:166-168(anactive_allocatedblock, via the existing_active_pool_blockshelper at:26-30). Once thecapture_forwardsresult is checked with_active_pool_blocks(export_warmup.id),:159-161can be deleted — it can pass on an empty-but-allocated segment.:164-165re-invokes the private_seed_warmup_workspacesdirectly to seed a second time on a fresh stream, duplicating whatcapture_forwardsalready did at:147. If the fresh-stream case is the point, make that the first call (passfresh_streamasstreamtocapture_forwards) instead of seeding twice; otherwise drop:164-165. Either way the test then imports one public entry point instead of also reaching into a private function (:124).
(AGENTS.md:494-495 / :512-513 — add only the checks the affected behaviour needs. This is a duplication/keep-tests-lean point, not a criticism of the test's coverage, which the Correctness lens covers.)
What is genuinely lean (no findings)
- No new knobs. No flag, config default, env var, dependency or metadata-schema change in the diff — AGENTS.md:452-455 respected.
- No dead code left behind. Module-level
_warmup_pools/_warmup_streamsare still exercised by the non-export path;tests/preparation/test_capture_cublas_workspace_cuda.py:97still reads_capture._warmup_pools[0].id, so the PR did not orphan them. - The non-export path is untouched in behaviour and its 2-argument call form is preserved, which is good subtractive hygiene for a
capture_forwardschange. - Scope is right: 23 production lines across two files, export path only, no per-model branch — consistent with "Keep the runtime small and model-agnostic".
Deliberately not raised here (Correctness & Contracts lens)
To avoid duplicating that lens: (a) the new GPU test fakes storage with SimpleNamespace (:140-143) and never asserts the seed lands inside real CoreStorage.mappings; (b) registering the pool id changes exported inactive/zero_ranges content via unused_ranges() → runtime_core.py:300-301; (c) whether reversing #331's invariant is an accepted design change; (d) the absent reproduction/error text for the GB10 rejection. Note that if S2(a) is taken, (b) disappears entirely, since no third pool id is registered.
Open questions
- If S1 is applied, are the seven two-argument test stubs (
test_capture_graph_metadata.py:181(not opened) and six siblings) acceptable to update, or is the current if/else retained to avoid touching them? (Retaining it means the duplicated branch is deliberate — worth one comment saying so.) - For S2: is
self.poolunusable, and if so why? Specifically, isself._scope = torch.cuda.use_mem_pool(self.pool, device=device)(core_storage.py:117) still active on the thread that runs_seed_warmup_workspaces? If yes, the seed already allocates from the core pool and the new method changes nothing; if no, one clause in the docstring explains it and option (a) collapses the change to nothing. - For S3: should #331/#266 carry a note that the "outside any caller-owned pool" invariant is intentionally reversed for the export path?
Not found
No existing repo helper named/positioned as a "warmup pool" outside CoreStorage; scratch_pool() (:294-298) and packed_weights() (:311-317) are the sibling patterns, and both return a distinct owner object with distinct semantics — which is precisely why warmup_pool() needs to say what makes it distinct from self.pool, or not exist.