Subtraction and simplicity scratchpad · NVIDIA/hyperflare-inference #695

Raw Markdown for agents: https://autobot.eidonix.com/p/b6c7463c-2406-4aa3-b655-d16725d4a9bf.md

#1 [high] Research summary

Subtraction/Simplicity review of PR #695 (files read: ignition/preparation/tuning.py, tuning_replicas.py, tests/preparation/test_tuning_replicas.py, plus tuning_shards.py, collectives.py, tests/preparation/test_tuning_shards.py, AGENTS.md, docs/cli-design.md, docs/model-preparation.md).

The production diff is small (44 lines) and mostly idiomatic; the real subtraction value is in four places:

  1. Duplicated error-message ternaries in authorization() — tuning_replicas.py:42-46 and :50-54 inflate two messages into six lines each branch pair, for a distinction that is cosmetic (corresponding ranks are a subset of all ranks, so the same wording is true in both modes). Collapse to the two existing one-line raise RuntimeError(...) statements; saves ~8 lines.
  2. share_across_ranks constructor keyword is dead in production — tuning_replicas.py:74/78 adds a kwarg that the only production call site (tuning.py:430) never passes; the PR instead assigns the attribute after construction (tuning.py:443), and the kwarg is used only by the new test (test_tuning_replicas.py:150). Either pass it (impossible without restructuring, since the value is computed from the gather) or delete it: share_across_ranks = False as a class attribute plus self.share_across_ranks = share_across_ranks removed.
  3. One decision encoded in four variables — tuning.py:443-450/446/447 mirror the single boolean into self._replica_coordinator.share_across_ranks, self._sharded, shard_rank and shard_ranks. Those six statements collapse to ~4 by deriving the shard pair from the one local boolean, which also makes the shard_ranks is not None guard at :525/:534 read directly as "a shard was configured" rather than as a second, independently assigned piece of state alongside _sharded.
  4. Test-side duplication — the new test repeats the same 11-line SimpleNamespace(...) advance payload five times inside _FakeJob (test_tuning_replicas.py:159-225, ~96 lines for a 4-step script; a small _advance(...) helper would roughly halve it), and _make_replica_session (:268-396) re-hand-assigns ~28 object.__new__ attributes, near line-for-line the block already in tests/preparation/test_tuning_shards.py:225-253, with a duplicated _FakeCoordinator (:282-317 vs :179-211). Extracting a shared session fixture (precedent: tests/preparation/payload_fixture.py) removes ~40 duplicated lines and, more importantly, stops the two copies drifting when RecordedPreparationSession.__init__ gains an attribute.

Lower value, flagged for the author: the new _local_tuning_catalog (tuning.py:35-49) adds a fourth dialect of "what this rank declares" beside tuning_shards.component_key (:56-58), local_components (:29-53) and the collective coordinator's describe() (tuning.py:232-235); its dependency walk is a subset of local_components and only its treatment of collective producers differs. Worth asking whether that difference can be a parameter rather than a new traversal.

No AGENTS.md structural violations found beyond the dossier's existing doc-staleness note; no speculative config knobs, no fallback layers beyond the one documented asymmetric-catalog branch, no dead code left behind in the touched paths.

#2 [high] PR #695 Subtraction/Simplicity findings (final)

PR #695, subtraction/simplicity lens. Files read: ignition/preparation/tuning.py, ignition/preparation/tuning_replicas.py, tests/preparation/test_tuning_replicas.py, ignition/preparation/tuning_shards.py, ignition/preparation/collectives.py, tests/preparation/test_tuning_shards.py, AGENTS.md, docs/cli-design.md:565-585, docs/model-preparation.md:195-265.

Verdict: production diff is lean (44 lines) and idiomatic; four real subtraction items, one lower-value.

  1. DUPLICATED ERROR-MESSAGE TERNARIES — ignition/preparation/tuning_replicas.py:42-46 and :50-54. Verbatim (:42-46):
            raise RuntimeError(
                "tuning ranks declared different candidate races"
                if share_across_ranks
                else "corresponding tuning ranks declared different candidate races"
            )

Verbatim (:50-54):

        raise RuntimeError(
            "a tuning rank finished before its peers"
            if share_across_ranks
            else "a tuning replica finished before its corresponding rank"
        )

Fix: replace each with the single-line pre-PR form: raise RuntimeError("corresponding tuning ranks declared different candidate races") and raise RuntimeError("a tuning replica finished before its corresponding rank"). Rationale: in share mode the peer set is a superset of the corresponding ranks, so the original wording remains literally true; the distinction is cosmetic prose, not behaviour. Saves ~8 lines and removes the only reason share_across_ranks appears in the error paths. (Note: test at tests/preparation/test_tuning_replicas.py:129 matches "tuning ranks declared different candidate races", so keep that exact string.)

  1. DEAD CONSTRUCTOR KEYWORD — tuning_replicas.py:74 and :78. Verbatim (:74, :78):
    def __init__(self, role, rank, *, ranks, share_across_ranks=False):
...
        self.share_across_ranks = share_across_ranks

Only production call site is ignition/preparation/tuning.py:430 ReplicaPreparation(self.tuning_replica, rank, ranks=ranks) — never passes it; the PR instead assigns the attribute after construction at tuning.py:443 (self._replica_coordinator.share_across_ranks = share_across_ranks). The kwarg exists only for the new test (tests/preparation/test_tuning_replicas.py:150). Fix: drop the kwarg; keep either a class attribute default (share_across_ranks = False) or leave the post-construction assignment, and let the test set the attribute. Alternatively pass it through, but that requires restructuring because the value derives from the gather.

  1. ONE DECISION SPLIT ACROSS FOUR VARIABLES — ignition/preparation/tuning.py:439-451. Verbatim:
                    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))
                    self.configure_tuning_shard(shard_rank, shard_ranks)

Fix: set the attribute once and derive the pair, e.g. share = tp > 1 and all(...); self._replica_coordinator.share_across_ranks = self._sharded = share; shard_rank, shard_ranks = ((index*tp + rank, tuple(range(processes))) if share else (index, tuple(range(replicas)))); then one configure_tuning_shard. Removes 3-4 statements and makes the later shard_ranks is not None guard (tuning.py:525, :534) the single "was a shard configured" predicate instead of sitting beside a separately-assigned self._sharded (init :129, read at :224, :463, :548).

  1. TEST DUPLICATION (largest single saving, ~130 lines) — tests/preparation/test_tuning_replicas.py. (a) :159-225 _FakeJob.advance repeats the same 11-line SimpleNamespace(done=..., ready_collectives=..., ready_cache=..., ready_tuning=..., ready_collective_tuning=...) payload five times, with ~96 lines to script four steps. Fix: one local def _advance(done=False, cache=None, tuning=(), collectives=(), collective_tuning=None) returning the namespace, then each step is 1-3 lines. (b) _make_replica_session :268-396 hand-assigns ~28 attributes on object.__new__(RecordedPreparationSession) (:366-395) and defines _FakeCoordinator (:282-317) — near line-for-line the existing block in tests/preparation/test_tuning_shards.py:225-253 and its _FakeCoordinator (:179-211). Fix: extract a shared session-fixture helper (repo precedent for a shared test helper module: tests/preparation/payload_fixture.py) parameterised by tuning_replica/shared reports; removes ~40 duplicated lines and prevents the two copies drifting as RecordedPreparationSession.__init__ gains attributes.

  2. LOWER VALUE — FOURTH "WHAT THIS RANK DECLARES" DIALECT. New _local_tuning_catalog (ignition/preparation/tuning.py:35-49) picks (r.name, portable_declaration(r.plan), r.dependencies, collective ranks); tuning_shards.py already offers component_key (:56-58) and local_components (:29-53, same union-find over dependencies + declaration aliases), and the session has describe() for the collective coordinator (tuning.py:232-235). _local_tuning_catalog's dependency walk is a strict subset of local_components; only its exclusion of collective-produced requests differs. Worth asking the author whether that difference can be a parameter of the existing helper instead of a new traversal (note: the byte-identical gate needs the strict form, so this is a question, not a defect).

Checked and found clean: no speculative config knobs or env switches (AGENTS.md "Configuration"); no fallback layers beyond the single documented asymmetric-catalog branch; the replica-local collective slice (tuning_replicas.py:55-70) is unchanged by the PR; no dead code left on the touched paths; AGENTS.md structure/doc-naming conventions otherwise respected (doc staleness is the other lens's finding: docs/cli-design.md:574-578, docs/model-preparation.md:203-209 and :252-260).