Correctness, Contracts & System-Level Consequences — review of PR #695
Scope actually inspected: full diff of the 3 changed files; ignition/preparation/tuning.py (28-52, 405-720); ignition/preparation/tuning_replicas.py (all 217 lines); ignition/preparation/collectives.py (320-430); ignition/preparation/rank_group.py (100-200); the new tests/preparation/test_tuning_replicas.py; and the doc passages the change invalidates.
Key findings
- Major — the motivating failure was never re-run, and nothing in the diff touches the failure site. The PR's own limitation line admits the TP=8 Ergo/16-GPU export was not retried, and the diff is only
tuning.py,tuning_replicas.py,tests/preparation/test_tuning_replicas.py— noaot.py(not opened)/ForwardCache. TheBindingMismatchis not exercised anywhere. - Major — the R-way → R*TP-way scaling claim has no measurement (
tuning.py:446-450), exactly the objection that held #383. Charter #210. - Major — on the asymmetric fallback path there is no cross-replica agreement check at all.
_shardedstays False andspans_hostsis False for local replicas, soagree_selectionsnever runs, and only replica 0 reconciles (tuning.py:521-522,546-549). The PR text claims coverage "for asymmetric TP catalogs". - Major — reconciliation is additionally gated on a non-None multi-rank coordinator. With
_coordinator is None,ranks = (0,)(tuning.py:428) andlen(self._coordinator.ranks) > 1(:521) is unreachable, so no reconciliation happens at all; this needs confirmation against the single-host 16-GPU repro. - Major (contract/doc) — two doc passages that describe exactly the changed behaviour are now false (
docs/cli-design.md:574-578,docs/model-preparation.md:203-209,:252-260); no doc file is in the diff. - Minor→Major (operator cost, undocumented) — shard width moves from
range(replicas)torange(replicas*tp), invalidating partial tuning checkpoints perdocs/model-preparation.md:224-229. - Minor —
authorization()now blocks on allreplicas*tppeers (tuning_replicas.py:34,49-54): per-step head-of-line coupling widens from R-1 to R*TP-1 processes; the description presents the change as pure benefit. - Minor — contract/API hygiene and cost items:
share_across_ranksconstructor kwarg is production-dead (attribute assigned post-construction,tuning.py:430/:443); the whole local catalog is pickled and allgathered (tuning.py:431-433+tuning_replicas.py:84-96) instead of a digest; the new Gloo test leaks four spawned processes on failure.
Areas I checked and found sound are listed at the end (shard arithmetic, collective scoping, barrier symmetry, TP=1, --autotune-effort off, multi-host rejection) so they are not reported as defects.
1. Correctness, Safety & Platform Parity
F1a. Major — the fallback (asymmetric-catalog) path has no cross-replica agreement, contradicting the PR's claim
ignition/preparation/tuning.py:438-451 (verified):
if self.autotune:
share_across_ranks = (
self.tuning_replica.tensor_parallel > 1
and all(item == reports[0] for item in reports[1:])
)
self._replica_coordinator.share_across_ranks = share_across_ranks
if share_across_ranks:
self._sharded = True
shard_rank = self.tuning_replica.index * self.tuning_replica.tensor_parallel + rank
shard_ranks = tuple(range(self.tuning_replica.processes))
else:
shard_rank = self.tuning_replica.index
shard_ranks = tuple(range(self.tuning_replica.replicas))
ignition/preparation/tuning.py:521-522 and :546-549 (verified):
if (self._coordinator is not None and len(self._coordinator.ranks) > 1
and (self.tuning_replica is None or self.tuning_replica.index == 0)):
configs, changed = self._coordinator.reconcile_selections(requests)
...
if (self._coordinator is not None
and (self.tuning_replica is None or self.tuning_replica.index == 0)
and (self._sharded or self._coordinator.spans_hosts)):
self._coordinator.agree_selections(selections)
On the fallback branch self._sharded is left False and spansts_hosts is False for local replicas (collectives.py:332-334: return len(set(self.hosts)) > 1), so agree_selections — the check that converts silent kernel divergence into an error before compilation (collectives.py:374-395) — never runs anywhere in the run. Replica 1..N additionally skip reconcile_selections entirely because of self.tuning_replica.index == 0. The PR's own test asserts this absence: tests/preparation/test_tuning_replicas.py:456 — assert all(ev[0] != "agree_selections" for ev in events).
Impact: on an asymmetric catalog (the rank-0-only-encoder shape #383 exists for) or on a warm retry where catalogs differ, ranks of replicas 1..N keep whatever their per-rank races chose, save independently (per docs/model-preparation.md:216-222 "Tensor-parallel ranks save independently"), and can reproduce the exact scratch_layout divergence this PR targets on the next warm run. The PR text claims the fix covers "asymmetric TP catalogs … (via serving-replica reconcile_selections)"; in code it covers only replica 0's TP group and not across replicas.
Fix: either run agree_selections (and broadcast the agreed selections to replica peers over the existing _replica_coordinator gather channel) on the fallback path too, or restrict the claim in the description/docs to "within replica 0".
F1b. Major (needs confirmation) — reconciliation depends on a non-None, multi-rank coordinator
ignition/preparation/tuning.py:428-430 (verified):
ranks = (0,) if self._coordinator is None else self._coordinator.ranks
rank = 0 if self._coordinator is None else ranks.index(dist.get_rank())
self._replica_coordinator = ReplicaPreparation(self.tuning_replica, rank, ranks=ranks)
Combined with self._coordinator is not None and len(self._coordinator.ranks) > 1 at :521, a single-host replica run whose _coordinator is None takes ranks = (0,) and skips reconcile_selections unconditionally, so the fallback half of the PR's claimed repair never executes. Either the reported 16-GPU run has a multi-rank coordinator (then this is only a documentation/robustness note) or it does not (then the fallback repair is inert in exactly the reported configuration). Fix: assert/verify in the repro which branch is taken and, if a coordinator is not guaranteed, drive reconciliation through ReplicaPreparation instead of self._coordinator.
F1c. Minor — share_across_ranks is a constructor kwarg in name only; production mutates it after construction
ignition/preparation/tuning.py:430 + :443 (verified):
self._replica_coordinator = ReplicaPreparation(self.tuning_replica, rank, ranks=ranks)
...
self._replica_coordinator.share_across_ranks = share_across_ranks
versus ignition/preparation/tuning_replicas.py:73-78 (verified):
class ReplicaPreparation:
def __init__(self, role, rank, *, ranks, share_across_ranks=False):
import torch.distributed as dist
self.role, self.rank, self.ranks = role, rank, tuple(ranks)
self.share_across_ranks = share_across_ranks
Impact: the kwarg exists for the tests only; in production the attribute is False through gather() at tuning.py:431-433 and is flipped afterwards. It is harmless today because gather() does not read it, but any later reader inside gather/prepare sees a stale False, and the documented contract does not describe the real flow. Also note the flag is computed per process from reports[0] equality: identical reports make all processes agree, but nothing asserts the mode is agreed (a mixed non-identical report yields all-False, which happens to be consistent). Fix: construct ReplicaPreparation after the catalog comparison (or make share_across_ranks a required argument), and have authorization() raise if peers disagree about the mode.
F1d. Minor — test hygiene: spawned Gloo workers are not reaped on failure
tests/preparation/test_tuning_replicas.py:254-259 (from research notes):
for p in procs:
p.start()
for p in procs:
p.join(timeout=30)
assert [p.exitcode for p in procs] == [0, 0, 0, 0]
results = dict(queue.get(timeout=5) for _ in range(4))
If a worker deadlocks in the Gloo allgather — the exact failure this test exists to catch — join(timeout=30) returns with exitcode is None, the assert fires, and four processes holding live Gloo sockets and a FileStore survive into the rest of the CPU pytest session. ReplicaPreparation.prepare itself is careful here (tuning_replicas.py:126-135), and prepare_recipe terminates/kills its workers (tuning_replicas.py:209-216). Fix: wrap join/assert in try/finally that terminates, then kills, then joins each process.
F1e. Platform parity
No Unix/Windows-specific code is touched (no path, signal, or fork semantics change in the diff; the spawn context at tuning_replicas.py:185 is pre-existing). Nothing to report here.
2. Unintended System-Level Consequences
F2a. Minor — wider rendezvous: per-step readiness now spans all replicas*tp processes
ignition/preparation/tuning_replicas.py:32-37 (verified):
def authorization(states, *, replica, rank, tensor_parallel, ranks, share_across_ranks=False):
"""Release replica-local collectives and local candidate exchanges across replicas or all ranks."""
peers = states if share_across_ranks else states[rank::tensor_parallel]
if all(item[3] is not None for item in peers):
return {"cache": tuple(item[3] for item in peers)}
if all(item[4] for item in peers):
and :49-54 (verified):
if any(item[0] for item in peers) and any(item[3] is not None or item[4] for item in peers):
raise RuntimeError(
"a tuning rank finished before its peers"
if share_across_ranks
else "a tuning replica finished before its corresponding rank"
)
ReplicaPreparation.prepare is a busy loop of full ProcessGroupGloo allgathers (tuning_replicas.py:103-125), so in homogeneous mode every process must report ready_cache (then ready_tuning) before any proceeds: the per-step coupling widens from replicas-1 corresponding ranks to replicas*tp-1 processes. A thermally throttled card, or the slowest of 16 ranks in the reported 2×TP=8 configuration, now gates all 16 ranks' races, not just its own replica's. This is the deliberate price of one global winner and not a defect — but the description presents the change as pure benefit and does not name the trade-off, nor does any doc. Fix: state the trade-off in the description and in docs/model-preparation.md's --tuning-gpus section.
F2b. Minor — memory amplification: the whole local catalog is pickled and allgathered per process
ignition/preparation/tuning.py:35-49 builds the catalog as (r.name, portable_declaration(r.plan), r.dependencies, ranks) for every request with a local consumer; tuning.py:431-433 now gathers (self.device.identity, _local_tuning_catalog(requests)) where previously only self.device.identity was gathered. The transport, tuning_replicas.py:87-96 (verified):
payload = pickle.dumps(value, protocol=5)
size = torch.tensor([len(payload)], dtype=torch.int64)
lengths = [torch.empty_like(size) for _ in range(self.role.processes)]
self.group.allgather([lengths], [size]).wait()
buffer = torch.zeros(max(item.item() for item in lengths), dtype=torch.uint8)
buffer[:len(payload)] = torch.frombuffer(bytearray(payload), dtype=torch.uint8)
buffers = [torch.empty_like(buffer) for _ in lengths]
Impact: one buffer per process sized to the largest catalog, plus the unpickled copy on every process, held live simultaneously → a transient processes × catalog_bytes peak on the preparation path (large catalogs at GLM/Kimi scale). It is a one-shot cost before tuning, not a hot path, so Minor — but a digest would have answered the equality question in O(1) per rank. Fix: gather (identity, sha256(pickled catalog).digest()), materialising catalogs only in the mismatch error path (the comparison at tuning.py:441 is pure equality; nothing needs the contents).
F2c. Minor→Major (operator-visible) — shard count changes, invalidating partial tuning checkpoints
ignition/preparation/tuning.py:444-451 (verified) sets shard_ranks = tuple(range(self.tuning_replica.processes)) on the homogeneous branch and tuple(range(self.tuning_replica.replicas)) on the fallback; self.configure_tuning_shard(shard_rank, shard_ranks) (:451) is what keys both the checkpoint and selection cache (also :466, :526, :535). docs/model-preparation.md:224-229 states: "Partial checkpoints require the same candidate program identities, effort, tuning shard count, and measurement settings. … Completed selection caches remain usable independently of the tuning shard count."
Impact: an interrupted --tuning-gpus TP>1 run started on main (R-way) and resumed on this branch (R*TP-way) silently re-measures every unfinished race; and because the branch flips on whether every replica reported an identical (DeviceIdentity, catalog) tuple, a later GPU swap (device-name strictness, cf. #150) flips the width back mid-project. Completed selection caches survive, so the cost is one full re-measure of partials. Not mentioned in the PR body or in the --tuning-gpus docs. Fix: one sentence in docs/model-preparation.md:252-260 and in the PR's "What changed".
F2d. Metric/scope span check
The agreement metric/check scope changes: on main, agree_selections was skipped for every tuning-replica rank (and self._replica_coordinator is None); after this PR it samples replica 0's ranks only (tuning.py:546-547). That is a widening versus main for replica 0, but it still leaves replica 1..N's selections unsampled — there is no post-hoc check anywhere that replicas>0 agree with replica 0 on the fallback path (see F1a), and on the homogeneous path agreement is structural (one _tuning_results winner, collectives.py:182-193 min by (latency_us, candidate_index)), not verified. No rate/latency metric changes; coverage and selections construction at tuning.py:536-545 is untouched.
3. Architecture, Contracts & Charter Compliance
F3a. Major — no GPU evidence for the motivating bug; the scaling claim is unmeasured (charter #210)
PR text, verbatim:
- "Limitations: Multi-GPU end-to-end
ignition export --tuning-gpushas not yet been re-run on this commit." - "Scales local candidate sharding from
R-way to(R * TP)-way when all tuning GPUs and local catalogs match, avoidingTP-way redundant local races."
Verified: the diff contains no aot.py (not opened) or ForwardCache change, so the BindingMismatch on decoder.layers[0|3].attention.attention.scratch_layout is never exercised; the only shard-width assertions are configured tuples (tests/preparation/test_tuning_replicas.py:418 assert shard_calls == [(1, (0, 1, 2, 3))], :479), and the Gloo test's winner is scripted latency ((320.0, 315.0, 318.0, 302.5)), not measured.
Impact: the two claims an operator depends on — "the export no longer fails" and "tuning is ~TP× less redundant" — are both unverified; reviewer precedent is #383, held on "The benefit is not measured". Fix: re-run the TP=8 Ergo/16-GPU --tuning-gpus export on ccb9f5b and paste selection-agreement (16/16 identical selections) plus tuning wall-clock before/after; otherwise drop the scaling claim to "removes redundant work" without a number and mark the fix as unvalidated.
F3b. Major — docs that name this exact behaviour are now wrong, and no doc file is in the diff
docs/cli-design.md:574-578, verbatim:
"For TP2,
--gpus 0,1 --tuning-gpus 0-5creates three independent TP2 groups. Corresponding ranks share candidate results while collectives stay within each replica. …"
After tuning.py:439-447 the default for homogeneous TP>1 catalogs is that all replicas*tp processes share candidate results and adopt one winner; "Corresponding ranks share candidate results" is now the fallback, not the rule. Only "collectives stay within each replica" remains true (tuning_replicas.py:55: local = states[replica * tensor_parallel:(replica + 1) * tensor_parallel]).
docs/model-preparation.md:203-209, verbatim first sentence: "Without extra tuning replicas, tensor-parallel ranks on identical GPUs divide the candidates of a shared local kernel race and adopt its measured winner." — now wrong in scope when replicas exist.
docs/model-preparation.md:252-260 (--tuning-gpus LIST) never mentions the global winner, the R*TP shard width, or reconciliation on serving replica 0.
Impact: the only documented TP>1 --tuning-gpus example teaches the old semantics; charter line 42 requires checking "every supported … parallel layout … named in the docs". Fix: one paragraph each in the two files, in this PR.
F3c. Sound: layer placement, no new flag, no runtime surface
All 44 production lines are inside ignition/preparation/; no CLI flag, no per-model branch, no Helios/runtime change, no wire/proto/captured-graph contract change, no dependency change. Multi-host interleaving remains rejected twice (tuning.py:426-427, tuning_replicas.py:181-182). No owner sign-off seems required beyond normal review, and --tuning-gpus + --ranks remains mutually exclusive, so this cannot interleave with #668's path.
4. Tests & Claim Accuracy
F4a. What the new 482 lines test, and what they do not
Six tests: two authorization() unit tests (both modes, mismatched race keys RuntimeError), one 4-process 2 replicas × TP=2 Gloo test of ReplicaPreparation.prepare() with a scripted _FakeJob (latencies (320.0, 315.0, 318.0, 302.5) → process 3 wins), and three RecordedPreparationSession.tune() tests that bypass __init__ via object.__new__, hand-assign attributes, monkeypatch dist.get_rank/torch.cuda.get_device_properties, and substitute _FakeReplicaPreparation/_FakeCoordinator(ranks=(0, 1), spans_hosts=False). They verify scheduling decisions and event order (shard_calls == [(1, (0, 1, 2, 3))] at :418; [(0, (0, 1)), (0, (0,)), (0, (0, 1))] at :479) — not b12x, not CUDA, not AOT loading, not ForwardCache. They are a genuine improvement — this is the first in-tree CPU coverage of the tuning-replica path (main has no tests/preparation/test_tuning_replicas.py) — but they cannot substantiate the two headline claims (F3a).
F4b. Description accuracy
Two imprecisions versus the diff:
- The description says the replay does a "temporary reset/restore of
configure_tuning_shard(0, (0,))"; the diff actually changes the predicate fromif self._shardedtoif shard_ranks is not None(tuning.py:525,:534) and newly assignsshard_ranksin the pre-existing multi-host branch (tuning.py:463-466). Effect-equivalent (both are set together there), but the reset condition is no longer the same predicate and the restore now usesshard_ranksrather thanself._coordinator.ranks. - The description says
share_across_ranksis a newReplicaPreparationparameter; in production it is set by attribute assignment after construction (tuning.py:443), and the kwarg (tuning_replicas.py:74-78) is used only by the new tests.
Both are Minor as description defects, but they are the two places a reviewer would otherwise trust.
Positive verifications (checked, no issue)
- Shard index ↔ Gloo member index match.
tuning.py:446shard_rank = self.tuning_replica.index * self.tuning_replica.tensor_parallel + rankequals the member index intuning_replicas.py:81dist.ProcessGroupGloo(self.store, role.index * role.tensor_parallel + rank, role.processes, timedelta(minutes=5));range(self.tuning_replica.processes)covers every process exactly once, andcollectives.py:182-193picks a deterministic winner (min(..., key=lambda item: (item.latency_us, item.candidate_index))). - Replica-local collectives genuinely unchanged —
tuning_replicas.py:55-69still sliceslocal = states[replica * tensor_parallel:(replica + 1) * tensor_parallel]and validatesitem[5].ranks != tuple(ranks), so collectives never span replicas. TuningCompleteexit is collective-symmetric per replica family.tuning.py:637-643gates onself.tuning_replica.indextruthiness, identical for every rank of a replica, and each replica owns a separateProcessGroupGloo(tuning_replicas.py:79-82), so all ranks of a non-serving replica reachbarrier("tuning_complete", ...)together and replica 0 never joins it;rank_group.py:144-150consumes it (control.send("tuning_complete"), thenos._exit(1)unless"close").- No stale-state-across-reset bug.
shard_ranks is not None(tuning.py:525,:534) is equivalent to the oldself._shardedin the multi-host branch (both set at:463-466); in the replica fallback branch the temporary reset/restore is harmless because nothing afterwards consults the shard (results are only closed at:599-616). - TP=1 unaffected —
tuning.py:440requirestensor_parallel > 1, and with tp=1 the new tuple collapses to(replica.index, range(replicas)), byte-identical tomain; the documented TP1 example is untouched. --autotune-effort offunaffected — the whole block is underif self.autotune:(tuning.py:438), soconfigure_tuning_shardis never called andshard_ranksstays None.- Serving-group symmetry for agree/reconcile —
(self.tuning_replica is None or self.tuning_replica.index == 0)is identical on every rank of the serving group, so the all-gather members ofagree_selections/reconcile_selections(collectives.py:374-395,397-426) match; no collective-entry asymmetry there.
Open questions / not found
- Does the reported single-host 16-GPU repro have a multi-rank
_coordinator? If not, the fallback reconciliation never runs (tuning.py:428,:521) and the asymmetric-catalog half of the fix is inert (F1b). - Is the missing cross-replica agreement on the fallback path intended? With
share_across_ranks=False, replicas>0 are never checked against replica 0 (F1a); the PR text reads as if they are. - Are replicas>0's homogeneous selections ever diverging in practice? Structural equality should guarantee it, but no test or runtime check covers replica 1..N after the global-winner exchange.
- No number for the sharding-scaling claim, and no GPU re-run of the repro (F3a).
- Commit trailers (
Design-Signed-Off-By) could not be verified from this vantage point;githistory for the touched files was unreadable (object-graph error), so this is unverified rather than failing.