Fit the TrainerRank layout cost model (coefficient version 2) with a calibration campaign - #836
Conversation
Groundwork for recalibrating the prefix-tree layout score (whose constants the research thread confirmed were hand-set, not fitted). - _planner_cost.layout_features: integer O(segments) features that differ between a call's layouts (packed tokens, segments, shared segments, levels, shared tokens, fan-out, small/tiny segments, causal attention area). Shared by the harness and the future scorer. Unit-tested on the sealed GRPO shape. - --phase cost-calibrate: times every mandatory candidate layout of a cell through the public API (forward + backward, active LoRA), forcing each with the test-only anchor hook; max-rank timings, compile status, plan-cache planning time, peak memory, subforward count, features, topology and model facts (including the actual GDN layer count) to JSONL. Warm-ups run until a forward is compile-free; measured rounds rotate candidate order. - dev/trainer_rank_cost_fit.py: paired within-cell deltas, non-negative least squares over interpretable feature x topology terms, whole-cell holdouts, and the review's noise-qualified gates (pairwise ordering, regret). - Sky recipes for CP4 and 2-GPU (TP2, Ellavox CP2) cells; local 1-GPU runner. - The compile watch used by the TP2 gate attached to a guessed logger name and observed nothing; it now takes the telemetry module's logger. The TP2 cell's compile-free claim in #832 was therefore unverified (its fixed warm-ups made it true in practice); the TP2 calibration cell re-establishes it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The layout cache key and select_prefix_tree_layout now carry the full planner facts (cp, tp, layers, gdn_layers, uses_gdn) as a NamedTuple; the GDN layer count is taken from the model (Qwen3.5-4B: 24 of 32) with a fallback to the layer count. The coefficient-version-1 formula ignores the new inputs, so selection is unchanged; the recalibrated model will consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… by fitter and scorer ScoringFacts + TERM_FUNCTIONS in _planner_cost define every interpretable term as an integer function of (layout features, topology facts) in feature-units x WORK_PER_US; the fitter regresses on exactly these, so a fitted microsecond-per-unit table is consumed verbatim by score_terms. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…d fit, second-campaign cells - Terms carry explicit CP/TP interactions (per-rank token work, cross-rank exchange, GDN level costs with (cp-1)/(tp-1) factors, per-rank segment cost); layout features gain segment-length and token-length histograms so small-M effects are read per rank (threshold x cp). - Fitter: exact active-set NNLS on per-cell-normalized, pair-scaled deltas, then a deterministic regret-minimizing coordinate refinement (least squares alone misranked close candidates); --refresh-features recomputes features for existing evidence from the reproducible workloads. - Second campaign cells: two more heterogeneous shapes, Ellavox at CP4, GRPO and heterogeneous shapes at CP2 (the CP4 heterogeneous decision only ranks correctly with such cells in training). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… constants prefix_tree_layout_score now prices a layout with the fitted term table (integer milli-microseconds per feature unit over the shared TERM_FUNCTIONS), keyed by the full planner facts (cp, tp, layers, GDN layers). The version-1 constants were hand-set (confirmed by the research thread); the table here is the campaign-1 fit and is replaced by the final fit once the second campaign (heterogeneous variants, Ellavox at CP4, GRPO at CP2) is in. The landing gates hold unchanged: the sealed GRPO win shape still selects deep sharing, the heterogeneous control and the tiny sealed families still decline sharing, selection stays deterministic. Two width-search unit tests relied on the old score sharing 40- to 1,000-token toy prefixes; their inputs are scaled to prefixes where sharing genuinely pays (2,000 tokens on the GDN model; 500 tokens on the attention model, where one saved copy does not pay but two do, preserving the non-monotone premise). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…eck; multi-start regret refinement The harness times the shipped selector's own choice (label "automatic") next to the mandatory candidates, so the fit report carries the production selector's measured regret. The fitter's --selector-check runs the shipped table through select_prefix_tree_layout (beam search included) on every measured cell and flags selections outside the measured family. The regret refinement runs from several deterministic starts and keeps the best. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Token work is priced per layer type (attention vs GDN layers, per rank, with CP/TP exchange terms), which resolves the attention-model CP4 cells where the shared level saves more than its token count: over the 38 measured cells the table ranks 99.0% of separated pairs correctly with p95 regret 2.0% and max 4.0%, passes the held-out Ellavox groups, and passes ablations that hold out every heterogeneous cell, every TP2 cell, or the whole attention model. The production selector (beam search included) on the same cells: median regret 0%, max 4.0%, never a layout outside the measured family. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…s and findings Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Campaign 2 added heterogeneous variants at CP1/CP2/CP4/TP2, Ellavox groups at CP4 and GRPO shapes at CP2 (56 cells, 3,844 within-cell pairs). The final table ranks 98.1% of separated pairs correctly, p95 regret 2.9%, max 4.2%, no clear misses; the pre-registered holdout (odd Ellavox groups, 11 cells) passes. The campaign-1 table run through the real selector on the 18 new cells was already within 4.2% everywhere, and the production selection timed in the campaign-2 CP2/TP2 cells had median regret -0.2%, max 0.4%. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… with the 56-cell metrics Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Final table installed (fitted on all 56 cells, 3,844 within-cell pairs) and the PR description now carries the complete evidence. Summary for review:
|
Codex review — request changesThe scoring implementation is much stronger, but I found two blockers and one evidence gap. [P1] Gate the fitted model to its validated domain
[P1] Calibration failures are reported as successThe trailing [P2] Check in a reproducible calibration certificateThe coefficient table comment says the table can be regenerated with the fitter, but the PR contains no evidence aggregate, fitted report, command manifest, or hash binding these exact constants to the claimed 56-cell result. The synthetic fitter tests cannot verify the production table or reported regret. Please retain a compact artifact containing per-cell/per-candidate features, medians, counts and fingerprints, the exact fit arguments, and the expected integer-table/report hash; raw tokens and full samples are unnecessary. Minor cleanup: Verification: the 30 targeted planner-feature, fitter, and weird-shape tests pass; GitHub CI is also green. I did not find a runtime correctness defect in the new feature algebra itself. |
…oudly on calibration gaps; certificate - Calibration profile (capability-based): the fitted table applies on compute capability 9.0, bf16, hidden size 2,048-3,072, non-MoE runtimes; outside it TrainerRank keeps the version-1 score (kept verbatim as the fallback) and logs once. The version is part of the planner facts, so the layout cache key and telemetry carry it. CPU-only planning (unit tests) uses the fitted table. Unit tests cover the profile edges and that the fallback reproduces the landing formula. - Runners no longer mask failures: pipefail carries torchrun's status through tee and the log filter, failed cells are recorded, and the run exits nonzero. The fitter's --require-complete N fails unless every mandatory candidate of every cell has N usable rows; --exclude-cells makes any exclusion explicit and recorded. Two Ellavox CP4 cells whose torchrun jobs hung in NCCL all-to-alls in the context-parallel group are excluded this way pending re-measurement. - dev/trainer_rank_cost_calibration_certificate.json: per-cell candidate features, medians, counts, spreads and fingerprints (no tokens, no samples), the exact fit arguments, the integer table and its hash, and the headline metrics; --from-certificate re-fits from it. Tests assert the shipped table is the certified table and that the certified metrics hold on the recorded aggregates (opt-in full refit reproduction). - Stale "no TP terms" comment in _impl.py updated; design brief and README describe the calibrated domain, failure propagation and the certificate. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Thanks — all three points addressed in 3f9ee53, plus one finding the second point surfaced. [P1] Calibrated domain. Added [P1] Masked failures. The three runners now carry torchrun's status through [P2] Certificate. Minor: the stale "no TP terms" comment in |
|
Re-measurement result: both Ellavox CP4 cells (groups 1 and 4) hung again on a fresh cluster at the identical NCCL collective sequence numbers, so this is a deterministic CP4 execution bug, not a compile-cache race. Group 4 hangs on the first execution of its |
…#840) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Codex re-review — two residual changes requestedThe original three findings are substantially addressed: the version-1 fallback is faithful, the runners now propagate failures, the certificate is compact and useful, and the full certificate refit reproduces the shipped integer table locally. I found two remaining evidence/scope gaps and one documentation correction. [P1] The calibrated profile still admits unmeasured hardware and model widths
[P2] Completeness still cannot detect a missing whole cell or mixed cell identities
Documentation correctionThe PR repeatedly says the final table was “fitted on all 56 cells,” but the checked-in refit uses 45 training cells and preserves 11 odd-Ellavox cells as holdout; I ran Verification on head |
…pected-cell manifest - CalibrationProfile admits exactly what the certificate measured: compute capability 9.0 with an H200-class memory system (device memory >= 120 GiB; the 80 GB H100 shares the capability and is excluded), bf16, hidden size 2,560 (hidden size is not a score feature, so neighbouring widths are not admitted), dense models. TrainerRank passes the device memory; the certificate test binds the profile's device names, dtypes and hidden sizes to the certified evidence. - dev/trainer_rank_cost_calibration_manifest.json lists the exact cells each recipe launches (58 identities, 2 explicit exclusions). The fitter's --manifest validation requires every non-excluded cell to be present, rejects unexpected cells and cells recorded with differing execution fingerprints (source, workload hash, device, dtype, hidden size), and the certificate records the manifest and the measured envelope. The certificate test asserts the exact 56 retained identities plus the two exclusions. - Wording: the table is fitted on 45 cells (odd Ellavox groups held out) and evaluated on all 56; the checked-in refit reproduces it from that procedure. - Harness records device capability and total memory for future evidence. Table unchanged; certificate regenerated with the manifest. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Re-review items addressed in 624d46c:
The integer table is unchanged; the certificate was regenerated with the manifest (validation: 58 expected, 2 excluded, fingerprints consistent, every mandatory candidate ≥ 8 rows). Targeted tests: 380 passing plus the opt-in full refit. |
Codex re-review — one residual evidence fixThe prior findings are otherwise resolved on [P2] The checked-in recipes do not produce three cells required by the manifestThe manifest says it is the exact union of the checked-in recipes, but it contains three Please add those three invocations to Verification on |
The local runner now includes the three heterogeneous-variant TP1xCP1 cells (hetero2 on both models, hetero3) that were run ad hoc; the manifest's campaign labels name checked-in recipes; a test parses the three runners (both CELL_SET modes, Ellavox loops expanded, layers=0 resolved) and asserts they launch exactly the manifest's 58 cells. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…certificate - _planner_cost keeps only the ten term functions that carried weight in the calibration (per-rank token work with CP-exchange and TP-collective terms, a GDN per-token surcharge, attention KV exchange across CP ranks, tiny-per-rank segments per layer, dependency levels crossing CP or TP ranks, GDN level hand-offs and their TP interaction) and the four layout features they read (packed tokens, segment count, dependency levels, a segment-length histogram). The table is refitted on exactly those terms: identical metrics (98.1% pairwise, p95 regret 2.9%, max 4.2%, holdout pass, selector check median 0% / max 4.2%), every coefficient non-zero. - The certificate and manifest are written one line per cell (81 and 68 lines instead of 17,368 and 601) with identical content; recorded features are projected onto the current field set. - The fitter drops the rejected reweighting rounds, the one-off feature refresh, and the version-1 comparison report. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Two more commits: [P2] Recipes ↔ manifest (090e19b). The local runner now launches the three heterogeneous-variant TP1×CP1 cells (hetero2 on both models, hetero3) that had been run ad hoc; the manifest's campaign labels name checked-in recipes; and Right-sizing pass (7d76cfc), at the author's request. The PR was ~21k lines, 83% of it the pretty-printed certificate. Now 2,974 insertions:
The profile envelope, manifest validation, exclusions and wording from the previous round are unchanged. 557 planner-related tests pass; |
Summary
Replaces the TrainerRank layout scorer's constants with a fitted cost model (coefficient version 2) and lands the calibration tooling that produced it.
The landing (#826) shipped the research thread's layout score. The research thread has since confirmed its constants were hand-set, not fitted: 1 µs per token per layer as a structural scale,
96 + 32·cpper segment and64 + 32·cpper shared edge hand-shaped, 768 µs per GDN layer as the smallest quantum preserving four measured winners, 256 µs as a launch-floor proxy — applied to the total layer count instead of the GDN layer count (Qwen3.5-4B: 24 of 32), and blind to TP. This PR fits the score from measurements.What changed in production
_planner_cost.py: the score isΣ coefficient[term] · term(features, facts)over ten interpretable integer term functions (TERM_FUNCTIONS) of four O(segments) layout features (layout_features: packed tokens, segment count, dependency levels, a segment-length histogram) and the planner facts (cp, tp, layers, GDN layers). The ten terms are the ones that carried weight: per-rank token work with CP-exchange and TP-collective terms, a GDN per-token surcharge, attention KV exchange across CP ranks, tiny-per-rank segments per layer, dependency levels crossing CP or TP ranks, and GDN level hand-offs with their TP interaction; candidates that fitted to zero were dropped (a future campaign can reintroduce them). Coefficients are integer milli-microseconds per feature unit (COEFFICIENTS_MILLI_US); everything stays integer and bit-identical across ranks.COEFFICIENT_VERSION = 2invalidates cached recipes.select_prefix_tree_layoutcarry (cp, tp, layers, gdn_layers, uses_gdn, coefficient_version); the GDN layer count is read from the model.CalibrationProfile, which is exactly the measured envelope and bound to the certificate by test — compute capability 9.0 and an H200-class memory system (device memory ≥ 120 GiB; the 80 GB H100 shares the capability and is excluded), bf16, hidden size 2,560 (hidden size is not a score feature, so neighbouring widths are not admitted), dense models. TrainerRank keeps the version-1 score (kept verbatim as the fallback) outside it, logging once. Capability-based, never model-name-based; CPU-only planning (unit tests) uses the fitted table. Extending the domain means running the calibration cells on the new device or width and regenerating the certificate.Calibration protocol (new tooling)
dev/trainer_rank_landing_acceptance.py --phase cost-calibrate: for one cell (workload × model × layers × topology), forces every mandatory candidate layout through the public API with the test-only anchor hook, times forward + backward through an active LoRA slot (compile-free, max-rank), and also times the production selector's own choice; records features, topology and model facts to JSONL. Sky recipes for 4× and 2× H200 cells, a local 1-GPU runner.dev/trainer_rank_cost_fit.py: paired within-cell timing deltas (cells weighted equally, pairs by scale), exact non-negative least squares over the production term functions, then a deterministic regret-minimizing coordinate refinement; whole-cell holdouts; the review's noise-qualified gates;--integerizeemits the production table;--selector-checkruns the shipped table through the real selector on every measured cell.pipefail, record failed cells and exit nonzero; the fitter's--require-complete Nrefuses evidence where any mandatory candidate has fewer than N usable rows,--exclude-cellsmakes every exclusion explicit and recorded in the certificate, and (re-review)--manifestvalidates exact cell identities againstdev/trainer_rank_cost_calibration_manifest.json— a missing whole cell, an unexpected cell, or duplicate cells with differing execution fingerprints (source, workload hash, device, dtype, hidden size) fail the fit.dev/trainer_rank_cost_calibration_certificate.json(compact: one line per cell, ~80 lines) binds the shipped table to its data — per-cell candidate features, median timings, counts, spreads and fingerprints (no tokens, no per-sample rows), the exact fit arguments, the integer table and its hash, the headline metrics.tests/unit/test_planner_cost_certificate.pyasserts the shipped table is the certified table and that the certified metrics hold on the recorded aggregates;--from-certificatere-fits from it (opt-in full reproduction in the test viaART_COST_CERTIFICATE_REFIT=1).What the data showed
tp × cp; GDN layers cost more per token than attention layers; rows in segments that are short per rank (threshold × cp) run inefficient kernels.Gates and evidence
Held-out gates (per the review): pairwise ordering ≥ 90% on pairs separated by more than 3%, median regret ≤ 2%, p95 ≤ 5%, none above 10%, clear winners selected within 5%.
Final table: fitted on 45 cells and evaluated on all 56 (3,844 within-cell pairs); the 11 odd Ellavox groups are the pre-registered holdout, never used in the fit. The checked-in certificate refit reproduces the shipped integer table from exactly this procedure.
The final table run through the real selector (beam search included) on every measured cell: median regret 0%, max 4.2%, never a layout outside the measured family. The four cells above 2% are all decisions between two deep-sharing layouts a few percent apart (a 2-layer attention CP4 cell, an Ellavox group at CP2, a heterogeneous shape at CP4, an Ellavox group at CP4).
Landing gates re-derived and passing: the sealed win-cell shape still selects deep sharing (prompt-level sharing at CP4, where it measures fastest; full sharing at CP1), the heterogeneous control and the tiny sealed families still decline sharing, selection is deterministic. Two width-search unit tests that relied on the old score sharing 40–1,000-token toy prefixes now use prefixes where sharing genuinely pays.
Also in this PR
Known limitations
🤖 Generated with Claude Code