#1 [high] Research summary
Subtraction / Simplicity review — PR #668
The diff is mostly justified (three coupled defects), but it leaves five concrete removable things. Scratchpad was unavailable on the final turn, so the full findings with citations are here.
1. New _save_compiled_function helper duplicates four existing inline atomic-save blocks — and the PR left the fifth inline one, which it also edited. aot.py:90-100:
def _save_compiled_function(artifact, path):
"""Write a compiled forward archive via a sibling temporary file and atomic rename."""
path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
with tempfile.NamedTemporaryFile(dir=path.parent, suffix='.tmp', delete=False) as file:
temporary = Path(file.name)
try:
artifact.save_compiled_function(str(temporary))
os.replace(temporary, path)
finally:
temporary.unlink(missing_ok=True)
The same six-line dance already exists at aot.py:270-278 (guards build), aot.py:1185-1193 (lent jobs) and compile_pool.py:115-123 (byte-identical to the new helper, artifact.save_compiled_function(str(temporary)) + os.replace + unlink), and this PR grew rather than removed the one in _share_artifacts (aot.py:870-877: with tempfile.NamedTemporaryFile(...) → temporary = Path(file.name) → try: file.write(...); file.close(); os.replace(...) → finally: temporary.unlink(...)). Fix: add one _write_atomic(path, write) in aot.py (write-callback form covers both bytes payloads and save_compiled_function) and delete the four inline copies plus compile_pool.py:115-123, which currently reimplements the same helper across a module boundary. As written the PR introduces a helper without retiring a single duplicate.
2. The peer b12x env is transmitted and applied twice for no added effect. host_ranks.py:344-347 sends it before the checkpoint commands so import-time reads see it:
with phase(progress, "Admit checkpoint range readers"):
if b12x_env:
for control in controls:
send_object(control, ("b12x-environment", b12x_env))
then host_ranks.py:376-377 repeats the same dict inside assignment, and serve_peer applies it a second time at host_ranks.py:666-668:
b12x_env = _validate_b12x_environment(assignment.get("b12x_environment"))
if b12x_env:
os.environ.update(b12x_env)
The early command is unconditional whenever b12x_env is non-empty, so the assignment copy can never carry anything the peer does not already have. Remove "b12x_environment": b12x_env from assignment and the block at :666-668 (and the parallel arm at :646-648 collapses to apply-once). That is one channel instead of two, one validation instead of two, and one documented protocol instead of two undocumented ones.
3. _validate_b12x_environment re-validates what the recipe already guarantees. host_ranks.py:201-209:
def _validate_b12x_environment(environment):
if not environment:
return {}
resolved = dict(environment)
if any(not isinstance(name, str) or not name.startswith("B12X_")
or name == "B12X_COMPILE_CACHE_DIR" or not isinstance(value, str)
for name, value in resolved.items()):
raise ValueError("b12x environment settings must map non-cache B12X_ names to string values")
Recipe.__post_init__ (ignition/declaration.py:251-253) already rejects non-B12X_ names and non-string values, and the only value passed in is model.recipe.b12x_environment (serve.py:197, :420). The only genuinely new rule is the B12X_COMPILE_CACHE_DIR exclusion (because environment.apply already points it at the peer-local kernel_cache/b12x, ignition/cli/environment.py:47). Collapse the function to that single check (or inline it at the one send site) and drop the two dict() copies.
4. _remap_peer_config's non-dataclass branch is speculative. host_ranks.py:212-219:
def _remap_peer_config(config, *, kernel_cache):
if config is None or kernel_cache is None or not hasattr(config, "kernel_cache"):
return config
local_cache = Path(kernel_cache)
if is_dataclass(config) and not isinstance(config, type):
return replace(config, kernel_cache=local_cache)
setattr(config, "kernel_cache", local_cache)
return config
Every preparation config in the repo derives from BasePreparationConfig, a @dataclass(frozen=True) (ignition/preparation/bootstrap.py:25-38) — a setattr on it raises FrozenInstanceError, so the fallback is unreachable-in-practice code that AGENTS.md ("Do not add … speculative compatibility, fallback layers") rejects. Reduce to return replace(config, kernel_cache=Path(kernel_cache)) if kernel_cache is not None else config, and bring is_dataclass/setattr imports along (only is_dataclass, replace from dataclasses is newly imported at host_ranks.py:35).
5. Dead parameter and dead exception arm. (a) HostRendezvous.prepare grew an override nobody uses — host_ranks.py:313-314 b12x_environment=None plus :325-326
b12x_env = (self.b12x_environment if b12x_environment is None
else _validate_b12x_environment(b12x_environment))
The only caller is prepare_group → ranks.prepare(...) (ignition/preparation/rank_group.py:286), which passes snapshot, config, prepare, checkpoint, progress, core_storage and nothing else; no call site anywhere passes b12x_environment=. Delete the kwarg and use self.b12x_environment. (b) In _load (aot.py:1376-1377):
except _CORRUPT_ARTIFACT_ERRORS as error:
if required or isinstance(error, (MemoryError, torch.OutOfMemoryError)):
MemoryError is not a member of _CORRUPT_ARTIFACT_ERRORS (aot.py:64-76), so that half of the test can never be true; only torch.OutOfMemoryError (a RuntimeError subclass) can arrive there. Drop MemoryError from the tuple — and while narrowing, drop OSError/RuntimeError/TypeError/KeyError/AttributeError, which are what makes the arm broad enough to need this guard at all (the Correctness lens owns that judgment; the subtraction point is that the guard exists only to patch over an over-wide tuple).
Secondary note (not a required change): _NON_EXECUTION_B12X_ENV (aot.py:47-62) is a 14-name blacklist plus a B12X_LOG_ prefix rule inside _b12x_forward_env. It is correct and tested, but every future b12x knob silently lands on the "execution-relevant" side; since the recipe already declares exactly the settings it prepares with (ignition/declaration.py:231) and the PR now ships that declared set to peers, keying ForwardCache on the declared bindings would remove the blacklist entirely. Worth raising as a follow-up rather than blocking.
Everything else — the request-name-first reconcile rewrite, the _selected_plan_catalog name key, and the reconcile test — is compact and idiomatic; I found no removable abstraction there beyond the light redundancy in reconcile_selections computing target_for in two traversals (collectives.py:436-449), which is not worth churn.
#2 [high] Simplicity review PR #668 — 5 subtraction findings with citations
PR #668 (fix(ignition) multi-host reconcile + peer b12x env/kernel cache + ForwardCache hardening). Verdict: mostly justified, but 5 concrete subtractions.
-
NEW HELPER DUPLICATES 4 EXISTING INLINE ATOMIC-SAVE BLOCKS; PR even grew the 5th. aot.py:90-100: def _save_compiled_function(artifact, path): """Write a compiled forward archive via a sibling temporary file and atomic rename.""" path = Path(path) path.parent.mkdir(parents=True, exist_ok=True) with tempfile.NamedTemporaryFile(dir=path.parent, suffix='.tmp', delete=False) as file: temporary = Path(file.name) try: artifact.save_compiled_function(str(temporary)) os.replace(temporary, path) finally: temporary.unlink(missing_ok=True) Existing identical patterns: aot.py:270-278 (guards build), aot.py:1185-1193 (lent jobs), compile_pool.py:115-123 (byte-identical, same
artifact.save_compiled_function(str(temporary))+ os.replace + unlink), and _share_artifacts aot.py:870-877 which the PR edited to add temp cleanup: with tempfile.NamedTemporaryFile(dir=target.parent, suffix=".tmp", delete=False) as file: temporary = Path(file.name) try: file.write(payload[0]) file.close() os.replace(temporary, target) finally: temporary.unlink(missing_ok=True) Fix: one_write_atomic(path, write)in aot.py (write-callback form covers bytes and save_compiled_function), delete the 4 inline copies + compile_pool.py:115-123. As written the PR adds a helper without retiring one duplicate. -
PEER b12x ENV TRANSMITTED+APPLIED TWICE, second copy unreachable. host_ranks.py:344-347 sends early (so import-time reads see it): with phase(progress, "Admit checkpoint range readers"): if b12x_env: for control in controls: send_object(control, ("b12x-environment", b12x_env)) host_ranks.py:376-377 repeats in assignment:
"exporting": core_storage is not None, "b12x_environment": b12x_env}serve_peer re-applies at host_ranks.py:666-668: b12x_env = _validate_b12x_environment(assignment.get("b12x_environment")) if b12x_env: os.environ.update(b12x_env) Early send is unconditional when b12x_env non-empty, so assignment copy can never add anything. Remove assignment key + :666-668 block; one channel, one validation, one documented protocol. -
validate_b12x_environment RE-VALIDATES WHAT THE RECIPE GUARANTEES. host_ranks.py:201-209: def validate_b12x_environment(environment): if not environment: return {} resolved = dict(environment) if any(not isinstance(name, str) or not name.startswith("B12X") or name == "B12X_COMPILE_CACHE_DIR" or not isinstance(value, str) for name, value in resolved.items()): raise ValueError("b12x environment settings must map non-cache B12X names to string values") Recipe.post_init already rejects non-B12X_ names and non-string values (ignition/declaration.py:251-253). Only new rule is the B12X_COMPILE_CACHE_DIR exclusion (environment.apply sets it to peer-local kernel_cache/b12x, ignition/cli/environment.py:47). Collapse to that single check, drop the two dict() copies. Only inputs: serve.py:197 and serve.py:420 (
b12x_environment=model.recipe.b12x_environment). -
_remap_peer_config NON-DATACLASS BRANCH IS SPECULATIVE. host_ranks.py:212-219: def _remap_peer_config(config, *, kernel_cache): if config is None or kernel_cache is None or not hasattr(config, "kernel_cache"): return config local_cache = Path(kernel_cache) if is_dataclass(config) and not isinstance(config, type): return replace(config, kernel_cache=local_cache) setattr(config, "kernel_cache", local_cache) return config All preparation configs derive from BasePreparationConfig, a @dataclass(frozen=True) (ignition/preparation/bootstrap.py:25-38) — setattr raises FrozenInstanceError, so the fallback is unreachable. AGENTS.md rejects "speculative compatibility, fallback layers". Reduce to
return replace(config, kernel_cache=Path(kernel_cache)) if kernel_cache is not None else config; drop is_dataclass/setattr (new dataclasses import at host_ranks.py:35).
5a) DEAD PARAMETER. host_ranks.py:313-314 prepare(..., core_storage=None, b12x_environment=None) and :325-326 b12x_env = (self.b12x_environment if b12x_environment is None else _validate_b12x_environment(b12x_environment)) Only caller: prepare_group → ranks.prepare(snapshot, config, prepare, checkpoint=..., progress=..., core_storage=...) at ignition/preparation/rank_group.py:286 — never passes b12x_environment. Delete kwarg, use self.b12x_environment. 5b) DEAD EXCEPT ARM. aot.py:1376-1377: except _CORRUPT_ARTIFACT_ERRORS as error: if required or isinstance(error, (MemoryError, torch.OutOfMemoryError)): MemoryError is not in _CORRUPT_ARTIFACT_ERRORS (aot.py:64-76), so that half can never be true; only torch.OutOfMemoryError (RuntimeError subclass) arrives. Drop MemoryError — and narrow the tuple (OSError/ValueError/TypeError/KeyError/AttributeError/RuntimeError are what force the guard to exist; aot.py:64-76). Correctness lens owns breadth judgment; subtraction point is the guard exists to patch an over-wide tuple.
SECONDARY (follow-up, not blocking): NON_EXECUTION_B12X_ENV (aot.py:47-62) is a 14-name blacklist + B12X_LOG prefix rule in _b12x_forward_env (aot.py:79-87). Correct and tested, but every future b12x knob silently lands on "execution-relevant" side. The recipe already declares exactly what it prepares with (ignition/declaration.py:231) and the PR now ships that declared set to peers, so keying ForwardCache on declared bindings would delete the blacklist.
LEAN (no change needed): request-name-first reconcile rewrite (collectives.py:398-449), _selected_plan_catalog name key (collectives.py:196-224), and the 2-rank gloo test (test_tuning_shards.py:262-325) are compact/idiomatic. Minor: reconcile_selections computes target_for in two traversals (collectives.py:436-449) — not worth churn.
AGENTS.md rules cited: "Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement"; "Flags, enums, callbacks, optional paths, and temporary implementations cannot be used to bypass"; "Reject weakened guarantees … Do not remove validation, suppress errors".
Repo context: only ForwardCache construction site is ignition/preparation/capture.py:118. AGENTS.md:452-472 config rules (no env-var-selected behavior; environment.apply owns b12x vars).