#1 [high] Research summary
Correctness, Contracts & System-Level review of PR #695
I read the full diff plus ignition/preparation/tuning.py (1-720), tuning_replicas.py (all), collectives.py (all), tuning_shards.py (all), rank_group.py (30-363), serve.py:280-340, bootstrap.py:123-137, the new test file, and the two docs passages the change invalidates.
What I verified as sound. The shard-index arithmetic is consistent: shard_rank = replica*tp + rank (tuning.py:446) matches the Gloo member index role.index * role.tensor_parallel + rank (tuning_replicas.py:81), and range(processes) covers every process, so a homogeneous TP>1 replica run does become a replicas*tp-way race with one deterministic winner (_tuning_results min by (latency_us, candidate_index)). Replica-local collectives are genuinely unchanged — local = states[replica*tensor_parallel:(replica+1)*tensor_parallel] (tuning_replicas.py:55) is still used for cache-reconcile-adjacent collective/collective-tuning authorization, so the "collectives stay in the replica TP group" invariant holds. TP=1 is unaffected (tensor_parallel > 1 gate at tuning.py:440, and (replica.index, range(replicas)) is byte-identical to the shared scheme when tp=1). The new TuningComplete path stays collective-symmetric per replica family: every rank of a non-serving replica satisfies tuning_replica.index truthiness at tuning.py:637, so all of them enter barrier("tuning_complete", ...) and none is stranded; separate replica families own separate ProcessGroupGloos, so replica 0 never joins replica N's barrier. Post-tuning agree_selections/reconcile_selections remain symmetric within the serving group because they are gated on the same predicate on every rank of that group. I found no deadlock, no stale-state-across-reset bug (the shard_ranks is not None guard at tuning.py:525/534 is equivalent to the old self._sharded in the multi-host branch and correctly enables the reset in the replica fallback branch, where the final restore is harmless because no further tuning follows), and no error-handling regression.
Findings (details and fixes are in the scratchpad notes): (1) two docs passages that name this exact behaviour are now false — docs/cli-design.md:574-578 still says "Corresponding ranks share candidate results while collectives stay within each replica", and docs/model-preparation.md:203-209/:252-260 never mention cross-replica winner sharing, contradicting the changed code and charter line 42; (2) the shard count moves from range(replicas) to range(replicas*tp) (tuning.py:446-450) which invalidates partial tuning checkpoints per docs/model-preparation.md:224-229 ("Partial checkpoints require the same … tuning shard count"), an undocumented operator cost; (3) the central claim — eliminating the TP=8 Ergo/16-GPU BindingMismatch — is unverified: the author states the repro was not re-run, no file in the diff touches aot.py (not opened)/ForwardCache._prepare_ranks, and the R-way → RTP-way scaling benefit has no measurement (charter #210, the same objection that blocked #383); (4) on the asymmetric fallback path (share_across_ranks=False) replica-N ranks skip both reconcile_selections and agree_selections (tuning.py:521-522, 546-549), so they can write per-rank divergent selections into a kernel/selection cache directory keyed by device identity that their GPUs share with the serving GPUs, while the PR text claims coverage "for asymmetric TP catalogs"; (5) smaller items — share_across_ranks is set by attribute assignment after ReplicaPreparation.__init__ (tuning.py:443) so the new constructor kwarg (tuning_replicas.py:74,78) is production-dead and only serves the test; the wider authorization() peer set now requires all replicas*tp processes to report ready_cache before any proceeds, widening per-step head-of-line coupling from R-1 to RTP-1 processes; the extra pickled _local_tuning_catalog gather (tuning.py:431-433 via tuning_replicas.py:84-96) allocates one buffer per process sized to the largest catalog; and the new 4-process Gloo test has no terminate()/kill() cleanup if an assertion fails after join(timeout=30) (tests/preparation/test_tuning_replicas.py:254-259).
#2 [high] Docs falsified by #695 (two passages name the changed behaviour)
Severity: Major.
-
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. The resulting core still contains two ranks. Additional GPUs must match the corresponding serving GPU model and have enough free memory for a replica. Both GPU lists useCUDA_VISIBLE_DEVICESordinals." After #695 the default for homogeneous TP>1 catalogs is that all replicas*tp processes share candidate results (ignition/preparation/tuning.py:439-447 sets share_across_ranks=True and shard_ranks=range(processes)), so "Corresponding ranks share candidate results" is now the exception, not the rule. Only "collectives stay within each replica" remains true (tuning_replicas.py:55 still sliceslocal = states[replica * tensor_parallel:(replica + 1) * tensor_parallel]). -
docs/model-preparation.md:203-209 — verbatim: "Without extra tuning replicas, tensor-parallel ranks on identical GPUs divide the candidates of a shared local kernel race and adopt its measured winner. When the model catalogs differ, preparation groups together each local request, its dependencies and its declaration aliases. ... This applies within one host and across hosts." The first sentence is now wrong in scope: with replicas the dividing also spans replicas.
-
docs/model-preparation.md:252-260 (
--tuning-gpus LIST) — verbatim fragment: "--tuning-gpus LISTadds local GPU replicas for benchmarking b12x candidates. The list begins with--gpusand continues in complete TP groups: ... Corresponding GPUs in each replica must match in model and architecture and have enough free memory for the model and preparation storage." Never mentions the new global winner, the R*TP-way shard width, or the reconcile on serving replica 0.
Impact: the one documented TP>1 --tuning-gpus example (docs/cli-design.md:574) tells operators the
old semantics; charter line 42 requires checking "every supported ... parallel layout ... named in the docs".
Fix: update both passages in this PR (one paragraph each): default homogeneous behaviour = one global
winner across all replicas, collectives still per-replica, asymmetric catalogs fall back to
corresponding-rank sharing + serving-replica-0 reconciliation.
#3 [high] #695 central claim unverified: repro not re-run, no measurement, no aot.py change
Severity: Major (claim accuracy / charter "Bring real evidence").
PR text verbatim: "Limitations: Multi-GPU end-to-end ignition export --tuning-gpus has not yet been re-run on this commit."
PR text verbatim: "Scales local candidate sharding from R-way to (R * TP)-way when all tuning GPUs and local catalogs match, avoiding TP-way redundant local races."
Verified: the diff (pr_files) is exactly 3 files — ignition/preparation/tuning.py, ignition/preparation/tuning_replicas.py,
tests/preparation/test_tuning_replicas.py. Nothing touches ignition/preparation/aot.py or
ForwardCache._prepare_ranks, the function named as the failure site, so the BindingMismatch is never exercised by
this PR or its tests.
Measured benefit: none. The only assertions about shard width are
tests/preparation/test_tuning_replicas.py:418 assert shard_calls == [(1, (0, 1, 2, 3))] and :479
assert shard_calls == [(3, (0, 1, 2, 3))] — a configured tuple, no b12x race, no wall-clock.
The Gloo test scripts latencies (320.0, 315.0, 318.0, 302.5) (tests/preparation/test_tuning_replicas.py, _gloo_replica_worker)
so the "winner = process 3" result is scripted, not measured.
Precedent: #383 was held on "The benefit is not measured" (yatesdr). Charter: performance claims need a
served-workload A/B (#210).
Fix: re-run the TP=8 Ergo / 16-GPU --tuning-gpus export on this commit and paste the before/after
(selection agreement + tuning wall-clock), or drop the "scales R→R*TP" claim to "removes redundant work" without a number.
#4 [high] Fallback (asymmetric) path has no cross-replica agreement check at all
Severity: Major (gap in the claimed benefit; PR text overstates coverage).
Code — ignition/preparation/tuning.py:438-451:
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
...
else:
shard_rank = self.tuning_replica.index
shard_ranks = tuple(range(self.tuning_replica.replicas))
and ignition/preparation/tuning.py:546-549:
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 path _sharded stays False and spans_hosts is False for local replicas, so
agree_selections never runs anywhere — the one check in collectives.py:374-395 that turns silent
cross-rank kernel divergence into an error before compilation. Non-serving replicas
(tuning_replica.index > 0) additionally skip reconcile_selections (tuning.py:521-522).
Verified by the PR's own test, tests/preparation/test_tuning_replicas.py:456:
assert all(ev[0] != "agree_selections" for ev in events)
Impact: on asymmetric catalogs (the rank-0-only-encoder case #383 exists for) the PR's claim
"for asymmetric TP catalogs or warm retries (via serving-replica reconcile_selections)" holds only
inside replica 0's TP group; replica 1..N keep whatever their per-rank races chose, save it
independently (docs/model-preparation.md:216-222: "Tensor-parallel ranks save independently"), and can
re-introduce the exact scratch_layout divergence on a later warm run — the symptom this PR targets.
Fix: either keep a cross-replica agreement on the fallback path (e.g. run agree_selections on the
serving group and broadcast the agreed selections to replica peers through the existing
_replica_coordinator.gather channel), or amend the PR text to say the fallback path only repairs
within-replica divergence and is unchanged across replicas.
#5 [medium] Shard count R → R*TP invalidates partial tuning checkpoints (undocumented)
Severity: Minor → Major for operator-visible cost.
Code — ignition/preparation/tuning.py:444-451 (homogeneous branch vs fallback):
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))
docs/model-preparation.md:224-229, verbatim: "Partial checkpoints require the same candidate program identities, effort, tuning shard count, and measurement settings. A kernel or predicate change invalidates the affected race's checkpoint. Completed selection caches remain usable independently of the tuning shard count."
Impact: an interrupted --tuning-gpus TP>1 run on main (R-way) resumed on this branch (R*TP-way) silently
re-measures every unfinished race; and because the gate flips with the GPU inventory, a run that was
homogeneous and later isn't (e.g. one replica GPU replaced, cf. #150 device-name strictness) flips the shard
width back mid-project. Completed selection caches survive, so the cost is one full re-measure of partials.
Undocumented in the PR body and in docs/model-preparation.md:216-229.
Fix: add one sentence to the --tuning-gpus docs (docs/model-preparation.md:252-260) that the shard count now
depends on whether every replica reports the same device identity and local catalog, and mention it in the PR's
"What changed".
#6 [medium] authorization() widens cache/race exchange to all R*TP peers → head-of-line coupling
Severity: Minor.
Code — ignition/preparation/tuning_replicas.py:32-37:
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):
plus :49-54 which now raises "a tuning rank finished before its peers".
Impact: in homogeneous mode every process must report ready_cache (and then ready_tuning) before any
process may proceed, so the per-step rendezvous widens from TP-1 peer ranks to replicas*tp-1 processes.
ReplicaPreparation.prepare (tuning_replicas.py:98-125) is a busy loop of full allgathers, so the coupling is
tight: one replica GPU that is slower (a thermally throttled card, a rank whose compile pool is short of
workers — note pools = self.tuning_replica.processes at tuning.py:482 already divides the CPU budget across
all of them) stalls every other rank's candidate race. Before the PR the same-shaped coupling existed but only
across replicas-1 corresponding ranks. This is the deliberate price of one global winner, so it is not a
defect; it should be named as a trade-off (the PR text presents the change as pure benefit).
Fix: state the trade-off in the description/docs; no code change strictly required.
#10 [medium] Checked and sound: ordering, symmetry, edge flags, tp=1, no stale state
These areas I opened and found correct; the report should say so plainly.
-
Shard index ↔ Gloo member index match. tuning.py:446
shard_rank = self.tuning_replica.index * self.tuning_replica.tensor_parallel + rankequals tuning_replicas.py:81dist.ProcessGroupGloo(self.store, role.index * role.tensor_parallel + rank, role.processes, ...), sorange(self.tuning_replica.processes)really covers every process exactly once. Winner selection is deterministic: collectives.py:182-193_tuning_results→min(completed, key=lambda item: (item.latency_us, item.candidate_index)), so all ranks adopt one candidate. -
Replica-local collectives unchanged, as claimed. tuning_replicas.py:55
local = states[replica * tensor_parallel:(replica + 1) * tensor_parallel]governs collective_tuning (:56-59), ready collectives (:60-67) and the finished-before-collective guard (:68-69) — a replica's collectives still span only its serving TP group, checked byif any(item[5].ranks != tuple(ranks) ...)at :57. -
tuning_completebarrier is symmetric per replica family. tuning.py:637-643 gates onself.tuning_replica.indextruthiness, which is the same for every rank of a replica, and each replica owns a separateProcessGroupGloo(tuning_replicas.py:79-82), so replica 0 never joins replica N'sbarrier("tuning_complete", ...); all ranks of a non-serving replica reach it together. rank_group.py:144-150 consumesTuningComplete, and rank_group.py:345-359/rank_group.py:171-174 handle it on the worker path. -
shard_ranks is not None(tuning.py:525, 534) is equivalent to the oldself._shardedin the pre-existing multi-host branch — tuning.py:463-466 sets both together — so no behaviour change there; in the replica fallback branch the temporary reset/restore is harmless because nothing after it uses the shard again (resultsclosing at tuning.py:599-616 only closes job results). No stale-state-across-reset bug. -
TP=1 is untouched: tuning.py:440
self.tuning_replica.tensor_parallel > 1, and with tp=1 the new tuplerange(replica.index*1 + 0 ... )collapses to(replica.index, range(replicas))— identical to the old sharding. The documented TP1 example (docs/cli-design.md:566, docs/model-preparation.md:254) is unaffected. -
--autotune-effort offunchanged: the whole block is insideif self.autotune:(tuning.py:438), so configure_tuning_shard is never called and shard_ranks stays None → no reconcile reset. -
Multi-host interleaving still rejected twice: tuning.py:426-427 and tuning_replicas.py:181-182. Agree/reconcile for the serving group stay symmetric because the gate
(self.tuning_replica is None or self.tuning_replica.index == 0)is identical on every rank of that group (tuning.py:521-522, 546-547). members of collectives.py:374-395 and :397-426 all_gathers therefore match.
#7 [low] share_across_ranks kwarg is dead in production; set by attribute assignment
Severity: Minor (contract/API hygiene).
ignition/preparation/tuning.py:430-443:
self._replica_coordinator = ReplicaPreparation(self.tuning_replica, rank, ranks=ranks)
...
self._replica_coordinator.share_across_ranks = share_across_ranks
ignition/preparation/tuning_replicas.py:74-78:
def __init__(self, role, rank, *, ranks, share_across_ranks=False):
...
self.role, self.rank, self.ranks = role, rank, tuple(ranks)
self.share_across_ranks = share_across_ranks
Impact: the new keyword argument exists only for tests/preparation/test_tuning_replicas.py:320 (_FakeReplicaPreparation)
and :238 (the Gloo worker); production assigns the attribute after construction, so the documented
constructor contract and the real flow differ and the attribute is briefly False during gather() at
tuning.py:431-433 (harmless today because gather() does not read it, but a later reader would see stale False).
Note also the case differs per rank: on a mixed report any process whose reports[0] differs computes
share_across_ranks=False for itself only — the value is not itself agreed, so a non-byte-identical catalog
across replicas yields all-False (fine), but nothing enforces that all processes agree on the flag.
Fix: pass share_across_ranks= at construction once the catalog comparison is done (construct after
gather, or make it a property), and assert in authorization() that peers agree on the mode.
#8 [low] New per-run cost: whole local catalog pickled and allgathered
Severity: Minor (memory amplification on the preparation path, not a hot path).
ignition/preparation/tuning.py:431-433:
reports = self._replica_coordinator.gather(
(self.device.identity, _local_tuning_catalog(requests))
)
_local_tuning_catalog (tuning.py:35-49) builds (r.name, portable_declaration(r.plan), r.dependencies, ranks)
for every request that has a local consumer. tuning_replicas.py:87-96 then:
payload = pickle.dumps(value, protocol=5)
...
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 replica process sized to the largest catalog, plus the pickle of every rank's catalog,
held live simultaneously — on a large catalog (GLM/Kimi scale, hundreds of requests) this is a transient
processes × catalog_bytes allocation on every process, once per export. Previously only self.device.identity
was gathered here. Acceptable, but it is a new peak on the preparation path and should be mentioned; a digest
(sha256 of the pickled catalog) instead of the catalog itself would have answered the equality question with
O(1) per rank.
Fix: gather (identity, sha256(pickled catalog).digest()) and only materialise catalogs in the error path.
#9 [low] Gloo test leaves spawned processes unkilled on failure
Severity: Minor (test hygiene / CPU-CI flake surface).
tests/preparation/test_tuning_replicas.py:254-259:
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))
Impact: if a worker deadlocks in the Gloo allgather (the exact failure mode this test is meant to catch), join
returns with exitcode is None, the assert fires, and the four processes — each holding a CUDA-free but live
Gloo socket and a FileStore — survive into the rest of the pytest session. The rest of this file's style
(e.g. ReplicaPreparation.prepare's own try/finally at tuning_replicas.py:126-135) is careful about exactly
this. Every sibling multi-process test in this area needs the same treatment.
Fix: wrap the join/assert in try/finally that terminates and joins each process, then re-raise.