Subtraction, Simplicity & Conventions — PR #678
Key findings
The diff is functionally lean: one 3-line accessor (current_source_roots()) plus two lines of argument plumbing, propagated through the two existing spawn sites. No new flags, env variables, config knobs, fallback branches, speculative abstractions or dead code are introduced, and nothing is left behind. The +233/−91 headline is misleading — 90% of rank_group.py's churn is re-indentation.
Two suggestions are worth acting on, both cheap and both on lines this PR itself touches:
- High — the new spawn argument's magic default
()re-arms the bug it fixes.rank_group.py:44-45,tuning_replicas.py:142. - High — 85 lines of re-indentation for a 3-line semantic change.
rank_group.py:59.
One low-priority cleanup (leftover private _EXTRA_ROOTS read in aot.py:845-848), plus a list of things I checked and deliberately did not flag.
Finding 1 (high) — extra_source_roots=() is a magic default on a private spawn entry point; make it required
ignition/preparation/rank_group.py:44-45:
def _peer(parent, snapshot, config, rank, rendezvous, connection, control, prepare, exporting, recording,
extra_source_roots=()):
ignition/preparation/tuning_replicas.py:142:
def _replica(parent, prepare, recipe_name, snapshot, values, gpu_uuids, options, extra_source_roots=()):
Both are module-private multiprocessing spawn targets (context.Process(target=_peer, ...) at rank_group.py:308-312, target=_replica at tuning_replicas.py:190-194) with exactly one production call site each, both of which now pass the argument. The default's only justification, per the PR body, is "backward compatibility for direct callers" — but the only such caller in the tree is a test.
Why it matters structurally, not cosmetically: the defect being fixed is "a spawn site silently started with an empty ContextVar". A defaulted () puts that exact failure mode back within reach — any future spawn site, or a hand-written Process(target=_peer, args=(...)) in a test or downstream recipe package, silently produces a peer that hashes no external roots and splits the ForwardCache key again, with no error and no diagnostic. A required argument makes the compiler-of-record (the call site) say what the child inherits.
Charter, How We Work: "Be explicit and pin everything. No magic defaults" (also cited by the same charter line for dependency pinning; read_charter).
Concrete change: delete =() from both signatures —
def _peer(parent, snapshot, config, rank, rendezvous, connection, control, prepare, exporting, recording,
extra_source_roots):
def _replica(parent, prepare, recipe_name, snapshot, values, gpu_uuids, options, extra_source_roots):
Blast radius, verified: one test caller must be updated, tests/preparation/test_native_processes.py:228-229, which calls rank_group._peer with 10 positional args and would need an 11th (()). tests/preparation/test_model_core.py:92-101 forwards *args to a private name and is unaffected. No production caller exists outside the two sites already passing the value. (Picklability of the argument is unchanged — it is the same tuple either way.)
Finding 2 (high) — the whole-body with source_roots(...) wrap buys nothing but 85 re-indented lines
ignition/preparation/rank_group.py:59, verbatim with its body at head e72ec0d:
with source_roots(extra_source_roots):
recorder = storage = None
if exporting:
from .module_images import ModuleImages
from .core_storage import CoreStorage
import torch
# Only an export needs module images; without one, a profiler may own CUPTI.
recorder = ModuleImages() if recording else None
with recorder if recording else contextlib.nullcontext():
torch.cuda.set_device(config.devices[rank])
storage = CoreStorage(rank=rank, world=len(config.devices), device=config.devices[rank])
with storage:
model = prepare(snapshot, config, rank=rank, group=dist.group.WORLD, core_storage=storage)
else:
model = prepare(snapshot, config, rank=rank, group=dist.group.WORLD)
The wrapper runs to rank_group.py:143 (dist.destroy_process_group()), re-indenting the entire ~85-line peer body: recorder/storage setup, manifest()/export_manifest(), the embedding-table handoff, export_model, serve_rank/serve_peer/benchmark, connection and region teardown. On main the same block sits 4 spaces shallower with no wrapper. That is where the PR's +91/−85 on this file comes from; the semantic content of the file is 6 lines (one import, one argument, one current_source_roots() capture, one pass-through, one with).
The ContextVar has exactly two readers in the tree, and neither is reachable after preparation from inside the peer:
ignition/preparation/aot.py:845-848—ForwardCache.__init__mixes every*.pyunder each bound root into the cache key and derivesself.root(aot.py:855). Constructed duringprepare(...)(ignition/preparation/capture.py:118).ignition/preparation/source_identity.py:48—combined_roots = (*_EXTRA_ROOTS.get(), *extra_roots). Its only in-tree caller path isrebuild_manifest.from_plan(rebuild_manifest.py:327(not opened)), reached fromignition/cli/serve.py:237(not opened) and:338— parent process only.
Inside _peer, nothing from model.manifest() onward reads it: export_model (runtime_core.py:344-440), serve_rank, ignition.direct.executor.serve_peer and ignition.bench.executor.serve_peer do not call source_identity() (verified by grep over source_identity(: the only Python call sites are cli/serve.py:193 (not opened),415,546, host_ranks.py:630, rebuild_manifest.py:327 (not opened), tests/cli/test_recipe_injection.py).
Concrete change — bind only around the two prepare(...) calls and de-indent the body back to base indentation:
with storage, source_roots(extra_source_roots):
model = prepare(snapshot, config, rank=rank, group=dist.group.WORLD, core_storage=storage)
else:
with source_roots(extra_source_roots):
model = prepare(snapshot, config, rank=rank, group=dist.group.WORLD)
and delete the outer with source_roots(extra_source_roots): at :59. That collapses the file's diff from +91/−85 to roughly +6/−1 and matches the charter's "Look for the smallest footprint in shared code".
Honest trade-off, which the report should state rather than hide: a whole-body wrap is more future-proof — if any peer-side handoff later grows a source-dependent computation, it stays covered without another edit. If the author keeps it, that is defensible; what is not defensible is shipping ~85 lines of review noise for 6 lines of behaviour without saying so in the body. Related, same family: tuning_replicas.py:158 already uses the narrow form —
with source_roots(extra_source_roots), CoreStorage(world=plan.world_size) as storage:
— so narrowing _peer also makes the two call sites consistent. (That line's placement, after _resolve_recipe(prepare, recipe_name) at tuning_replicas.py:155, is a correctness question owned by the Correctness & Contracts lens; noting only that narrowing _peer does not create it.)
Finding 3 (low) — the new accessor has a caller it was not used for: aot.py still reads the private ContextVar
ignition/preparation/aot.py:845-848, verbatim:
from .source_identity import _EXTRA_ROOTS
for label, extra_root in _EXTRA_ROOTS.get():
extra_root = Path(extra_root).resolve()
current_source_roots() (source_identity.py:17-19) exists precisely to be the public read of that ContextVar, with 5 callers added by this PR. This is the last private reader outside the defining module; after the PR the private import in aot.py is the only remaining _EXTRA_ROOTS touch outside source_identity.py (grep: aot.py:845,847, source_identity.py:12,19,26,30,48).
Concrete change: from .source_identity import current_source_roots … for label, extra_root in current_source_roots(): — deletes the private-attribute import, one line, same subsystem, no behaviour change. Optional/low; it is cleanup of the abstraction this PR just introduced, not a blocker.
Secondary, same file: ignition/preparation/source_identity.py:24 still reads
"""Bind external `(label, path)` source roots for the duration of a CLI invocation."""
which is now inaccurate — the two new callers use it around spawned-child preparation, not "a CLI invocation". Cheap docstring correction, but it is a documentation accuracy point rather than a structural one.
Checked and deliberately not flagged (negative results)
To be plain about the lens result: apart from Findings 1–3, I found no removable code, no duplication of an existing helper, and no structural AGENTS.md violation in this diff.
current_source_roots()(source_identity.py:17-19) is not speculative generality. Two production callers (rank_group.py:298,tuning_replicas.py:176) plus three test callers, and it is the exact shape of the existing patternregistry.current_recipes()(ignition/registry.py:29-31:return _ACTIVE_RECIPES.get()over a module-private ContextVar). Keeping it is the convention-conforming choice.- No dead code or unused argument left behind. Both new parameters are genuinely consumed:
rank_group.py:59andtuning_replicas.py:158. - The +129/−3 test growth contains no duplicated helper worth extracting. There is no
tests/conftest.py(not opened) in the tree at all, so inline recipe/plan builders are the established norm — cf.tests/cli/test_recipe_injection.py:17-42(a 22-lineRecipe(...)built in the test module) and thepytest.MonkeyPatch.context()stub pattern intests/preparation/test_model_core.py:92-101, which_cpu_replica_entry(test_forward_cache_sources.py:146-154) mirrors. Flagging these would be nitpicking, and the tests are good tests. - No new flags, env knobs, fallback branches or wrappers anywhere in the diff — the only new API surface is the defaulted trailing argument in Finding 1.
- Passing the roots through
context.Process(args=...)is not a reimplementation of an existing abstraction. Spawn children start with an emptyContextVar, and there is nocopy_context/contextvars-inheritance helper anywhere inignition/(searched). Pickling the tuple is the only available mechanism; nothing simpler exists to collapse into. - Nothing in the diff belongs in a different layer. Both edits are in the shared
ignition/preparationcode the bug lives in; nohyperflare_recipesimport, no plugin discovery, no CLI flag — consistent withAGENTS.md:382-387and the charter's "Keep the runtime small and model-agnostic".
Cross-PR note (redundant work, not redundant code): the rank_group.py hunk here is the same prepare_group → _peer → source_roots(...) edit already open in #670 (lukealonso), whose own review asked for exactly this split. That is a merge-order/duplication question for the maintainers, not something to delete from this diff — #678's genuine additions (current_source_roots(), the tuning_replicas.py propagation, three tests) are all in #670's blind spot.
Open questions
- Does the author intend #678 to supersede #670's
rank_group.pyhunk, or to stack on the same subsystem? Neither PR references the other (Dossier, "Related work"). This is the one process question that affects whether Finding 2 is worth arguing about at all — if #670 lands first, most of this file's diff evaporates regardless. - Is the whole-body wrap in
_peer(rank_group.py:59) deliberate future-proofing for a peer-side consumer that does not exist yet? If so it should be one sentence in the body; if not, Finding 2 applies as written. - Not checked here (other lenses / not reproducible in this environment): the author-reported "35 passed" and the SM120 end-to-end runs — no CI checks exist on head
e72ec0d.