Repository navigation
Conversation
8cefe41 to
ea77332
Compare
sure, let's do adversarial training on this |
5805da3 to
96916c5
Compare
|
@claude review |
There was a problem hiding this comment.
Verdict: Request changes -- An agent that follows this skill exactly will repeat most of the must-fix items from #5655's review. The skill tells it to commit golden provenance, add H100 tests and goldens where the repo uses A10G, and never warns it off single-consumer changes to models/common/. Its publishing step also conflicts with CLAUDE.md.
What this PR does. Adds a 1,097-line add_model skill: a phased workflow plus four reference files covering design and memory checkpoints, reference parity, test layers, goldens, and a local pr-review loop before submitting a PR stack. The API, path, and CLI claims are mostly accurate. Everything in the models/common table, the parallelize order, the loss_compare.py and run_tests flags, the ParallelismConfig fields and the EP mesh formula checks out.
Example. This is the one-shot test tianyu-l asked about. #5655 followed this skill, and here is where four of its must-fix items came from:
#5655 must-fix <- skill text that asks for it
1. MAST/Manifold provenance in golden + README <- SKILL.md:233 "commit ... golden and its provenance",
test_coverage.md:208 "run details ... beside the golden"
2. 3 single-consumer flags in models/common <- SKILL.md:87,220 (no "start in model folder" rule)
6. four new H100 entries, pp2 subset of all <- test_coverage.md:61-66,120 "add separate tests ..."
8. 374-line JSON report in tests/assets <- numerical_parity.md:44 "Commit small test fixtures"
Fixing these lines is the cheapest way to get a port through @claude review in one shot.
Must fix
-
test_coverage.md:236-252-- The golden workflow (H100 suite,real_pg/h100/only) doesn't match the repo, which keeps goldens inmodels.pyon A10G/MI350X with both fake-PG and real-PG files. Amodels.pyregistration would fail in CI because the file is missing. "Every port needs a golden" also contradictstests/README.md:106-113. -
test_coverage.md:61-66-- Requires an 8xH100 combined test plus separate tests per uncovered feature; that should be one entry on the cheapest hardware, extended before adding more. -
SKILL.md:232-234-- Tells the agent to commit provenance and fixtures. Provenance belongs in the PR description, and committed files must not contain internal-infra identifiers. -
SKILL.md:85-89-- Missing the "model-specific variants stay in the model folder; no flags inmodels/common/for one model" rule. -
SKILL.md:286-289-- The agent publishes the stack and writes the descriptions itself. CLAUDE.md requires user approval of the exact content, and the description format belongs to thepr-descriptionskill. -
SKILL.md:282-283--pr_reviewdoesn't exist, and pr-review's branch mode can't take a base ref for stacked PRs. -
code_style_checklist.md:52-54-- "must not default toNone" is weaker than the rule (no default). -
Duplication, no single line. The same rules are repeated across files, which makes drift like item 7 likely:
- the FSDP+EP / FSDP-for-dense baseline is stated in all five files;
- the repeatability-before-golden gate is stated in four;
- "record base/head" is stated in four;
- Phase 1 restates
torchtitan/models/README.md; - most of
code_style_checklist.mdparaphrases CLAUDE.md naming/style/config rules.
State each rule once, in one file. Link CLAUDE.md,
.claude/rules/, andmodels/README.mdinstead of restating them, and add only what they lack. My estimate is that this removes about a third of the text.
Should consider
SKILL.md:30-31--/pyrefly_ci_checkdoesn't exist.test_coverage.md:105-- "PP and checkpoint tests needuse_real_pg=True" only matters under fake PG (tests/integration_tests/__init__.py:91-106). The h100 suite is real-PG only.numerical_parity.md:39-42-- Give the scripts' directory (scripts/checkpoint_conversion/). All fivenumerical_tests_*.pyare tracked, so the "older or untracked" caveat doesn't apply.numerical_tests_example.pyis the generic starting point.numerical_parity.md:204-- "Reuse adapter support for omitted tied output weights": there is no shared helper; each adapter implements it (e.g.llama3/state_dict_adapter.py:114-142).test_coverage.md:118-120-- The Kimi K3 examples are inb200.py. K3's golden is on the 2-GPU DistMuon FSDP+EP test, not the combined one, which contradicts "use the combined recipe for the golden" (line 199).
Questions
- @tianyu-l: should pr-review's branch mode accept a base ref (
/pr-review branch <base>) so stacked PRs can be reviewed against their parent? Fixing that on the review side looks right to me.
Details
- Necessity: the problem is real. Ports currently re-learn the flavor/sharding/golden APIs, and #5655 shows both the value and the gaps. Docs-only, no core impact.
- Current golden practice: there are no H100 goldens. Model goldens are in
models.py/features.py, run on 8xA10G (.github/scripts/integration_test_real_pg.sh:40) and on MI350X, and are exported via theexport_resultsdispatch input of.github/workflows/integration_test.yaml. Onlykimi_k3_b200.txtlives outside that scheme. - Size: 1,097 lines, against pr-review (about 330 lines plus its checklist) and local_compile_perf (about 880 including references).
Not verified: none of the commands were executed (runner/loss_compare flags were checked by reading argparse).
| After the repeatability check passes and the test is registered in the `h100` | ||
| suite, export on the remote GPU node using its supported launcher and the | ||
| validated recipe. Replace the template names and paths. Use an empty output | ||
| directory for each run: | ||
|
|
||
| ```bash | ||
| python3 -m tests.integration_tests.run_tests outputs/new-model-export \ | ||
| --test_suite h100 --test_name new_model_fsdp+tp+ep+pp \ | ||
| --execution_mode real_pg --gpu_arch_type cuda --gpu_arch h100 \ | ||
| --ngpu 8 --no-parallel --export-numerics | ||
| ``` | ||
|
|
||
| Set the recipe's `training.steps` to at least 10 before export. The runner writes | ||
| the result to `outputs/new-model-export/real_pg/h100/` using the golden's filename. | ||
| Check every expected step, both metrics, run settings, and enabled features. Copy | ||
| the checked file into the registered `tests/assets/losses/real_pg/h100/` path. | ||
| Keep separate goldens for each GPU architecture and communication mode. |
There was a problem hiding this comment.
The golden workflow here doesn't match how the repo handles goldens:
- No H100 goldens exist, and
h100.pysets nogolden_numerics_path. - Every model golden lives in
models.py/features.py. Those suites run on 8xA10G (.github/scripts/integration_test_real_pg.sh:40) and on MI350X, with both fake-PG and real-PG files. - Goldens are exported through the
export_resultsinput ofintegration_test.yaml.
Following this text gives one of two bad outcomes. If the agent registers in h100.py as the template does, the golden lands on hardware no other golden uses, and it runs on the most expensive runner. If it registers in models.py (line 101 allows that), {gpu_arch} resolves to a10g/mi350x in CI. Only real_pg/h100/ was exported, so _read_golden_spec fails with file-not-found.
numerical_parity.md:157 ("Every model port needs a golden") also contradicts tests/README.md:106-113. That file says Qwen3.5 MoE and DeepSeek V4 deliberately ship without a golden because their A10G runs aren't bitwise-deterministic.
Fix: describe the current practice.
- Add or extend one
models.pyentry at a topology that fits 8xA10G. - Add a golden only when that run is bitwise-repeatable, otherwise keep the entry as end-to-end coverage.
- Regenerate both the fake-PG and real-PG files (
tests.md"Golden Numerics"). - Export through the CI dispatch.
- Use
h100.pyonly for paths A10G can't run (DeepEP, HybridEP, kernels that need sm90).
| Add the training test in the initial model PR with FSDP+EP for MoE models (FSDP | ||
| for dense models). Extend it as later PRs add TP+SP, PP, or CP. The completed | ||
| stack needs one test with FSDP, TP, EP, and PP together for an MoE model, normally | ||
| on a remote node with 8 H100s. For a dense model, cover FSDP/TP/PP and record EP as | ||
| not applicable. Use this run to catch interactions between parallelisms. Add | ||
| separate tests for features it cannot cover. |
There was a problem hiding this comment.
This requires every port to add an 8xH100 FSDP+TP+EP+PP test, plus "separate tests for features it cannot cover" and "another recipe if the combined test cannot cover a required feature or optimizer" (lines 66, 120). That pushes agents toward one new GPU entry per feature. It's how #5655 ended up with four new H100 entries, where pp2 was a subset of all_parallelism (its review, must-fix 6). None of the current h100.py model entries is a combined-parallelism test. The combined MoE tests run on A10G, e.g. qwen3_5_moe_fsdp+tp+ep and GPT-OSS FSDP4xTP2,EP4.
Fix: require one combined entry on the cheapest hardware that runs the debug model. Prefer an interleaved PP schedule with spmd_typechecking on. Fold features into that entry before adding another, and require a written reason for each extra entry (tests.md "Prefer Extending Existing Coverage").
| bitwise-identical full-precision loss and grad_norm at every step. Then export | ||
| and commit the small, architecture/mode-specific golden and its provenance, | ||
| register `golden_numerics_path`, and rerun without export. A deterministic |
There was a problem hiding this comment.
Several lines tell the agent to commit provenance and reports with the golden:
- here: "commit the ... golden and its provenance"
- line 316
test_coverage.md:208-209: "Record other run details in comments or documentation beside the golden"numerical_parity.md:44-45: "Commit small test fixtures"
Following those lines produced #5655's must-fix 1 and 8. The golden and the README contained MAST job IDs, torchx/metaconda images, and Manifold paths under a username, and a 374-line JSON report that no test reads was committed under tests/assets/.
Fix:
- Committed goldens contain only what
loss_compare.pyand the runner write. - Run provenance and parity reports go in the PR description.
- Commit a fixture only if a test reads it.
- Committed files must not contain internal infrastructure identifiers (job IDs, internal storage paths, internal images, usernames).
| Use `torchtitan/models/common/config_utils.py` factories such as `make_gqa_config`, | ||
| `make_ffn_config`, `make_moe_config`, and `make_router_config` when they express the | ||
| architecture. Keep new concrete shared components in `torchtitan/models/common/`, | ||
| lifecycle contracts in `torchtitan/models/base/`, distributed helpers in | ||
| `torchtitan/distributed/`, and model-specific computation in its model package. |
There was a problem hiding this comment.
The skill says where shared code goes, and line 220 says to "extend shared flavor/config and adapter contracts". It never states the rule that keeps a port out of models/common/. CLAUDE.md principles 4-5 and models.md "Don't Over-Specialize" say that model-specific variants start in the model folder, and that shared modules don't get branches or flags for one consumer. torchtitan/models/README.md:12 says the same.
Without that rule, #5655 added three single-consumer booleans to common/embedding.py, common/norm.py and common/rope.py (its review, must-fix 2).
Fix: add one bullet here. "A variant of a shared component needed by one model is a subclass or local copy in the model folder. Don't add flags, branches, or hooks to models/common/ for it. Promote to common only when a second model needs it."
| PRs after earlier changes. Submit the stack targeting `upstream/main` only when | ||
| every PR passes; include dependencies, numerical evidence, and review results. | ||
| If a required skill, resource, or decision is missing, report the blocker and | ||
| keep stack submission pending. |
There was a problem hiding this comment.
Here and in code_style_checklist.md:120-123, the agent submits the stack itself and writes "scope, numerical evidence, and local review results in each description". That conflicts with CLAUDE.md PR Expectations #2: agents don't open or edit PRs unless the user approved the exact content, and they leave the "Summary (human-written)" placeholder. The pr-description skill, which owns the description format, is never mentioned.
"The repository's supported stack tooling" isn't named. upstream also isn't a remote in a standard checkout (this one has only origin).
Fix: "Prepare the stack locally. Write each description with the pr-description skill. Show the user the exact descriptions and publish only after they approve them."
| Resolve and read the `pr_review` skill (TorchTitan also names it `pr-review`). | ||
| Use its local branch mode with the PR's actual base and head refs. Review, |
There was a problem hiding this comment.
There is no pr_review skill. The only one is pr-review (.claude/skills/pr-review/SKILL.md:2), so the "also names it" hedge sends the agent looking for a skill that doesn't exist. The same applies to lines 29 and 322 and code_style_checklist.md:107,113.
Also, pr-review's branch mode is hardcoded to git diff main...HEAD, so "local branch mode with the PR's actual base and head refs" isn't something it supports. code_style_checklist.md:108-109 admits this and asks the agent to override it. For stacked PRs, the review would include every parent PR's changes.
Fix: use pr-review everywhere. Either add an optional base ref to pr-review's branch mode (/pr-review branch <base>), which tianyu-l said is fair game, or tell the agent to pass git diff <parent>...HEAD as the diff.
| - Use `ValueError` for bad config or input and `assert` for internal programmer | ||
| errors. Required config fields must not default to `None`. Put important | ||
| arguments first and prefer keyword-only options. |
There was a problem hiding this comment.
This restates CLAUDE.md and config.md more weakly than they do. The rule is that required fields have no default at all, not "not None". This is the risk of paraphrasing the rules instead of linking them; see the duplication point in the review body.
| - Use `ValueError` for bad config or input and `assert` for internal programmer | |
| errors. Required config fields must not default to `None`. Put important | |
| arguments first and prefer keyword-only options. | |
| - Use `ValueError` for bad config or input and `assert` for internal programmer | |
| errors. Required config fields have no default. Put important | |
| arguments first and prefer keyword-only options. |
| - When available, use `/numerics_debugging` to localize unexplained drift and | ||
| `/pyrefly_ci_check` when local type checking disagrees with CI. Model-specific |
There was a problem hiding this comment.
Nothing in the repo is called /pyrefly_ci_check (it isn't under .claude/skills/ either). This is also referenced in code_style_checklist.md:94. Remove both references, or add the skill in its own PR.
| - When available, use `/numerics_debugging` to localize unexplained drift and | |
| `/pyrefly_ci_check` when local type checking disagrees with CI. Model-specific | |
| - When available, use `/numerics_debugging` to localize unexplained drift. | |
| Model-specific |
|
I used this skill at 96916c5 for the first version of Kimi K3.1 #6007. Two places caused most of my rework:
|
Document a model port workflow that starts with a pinned reference and unsharded numerical comparisons. Establish an FSDP+EP training baseline for MoE models (FSDP for dense models), then extend distributed execution before review. Use current MODEL_FLAVORS/build_model_config APIs, the BaseModel lifecycle, declarative sharding, and Python recipes. Reuse generic checkpoint converters and bind model-specific state dict adapters on the model class. Require tensor error checks with justified tolerances and backward comparisons for new components. Validate MoE router scores, selections, and weights independently of imposed-routing diagnostics. Keep numerical methodology and code-style audits in linked references. Require CPU tests of important features, combined real-GPU FSDP/TP/EP/PP training, and a remote debug-recipe numerical golden with an independent replay. Document histogram/state-update coverage for quantile balancing, mesh sizing, golden export and CI registration. Include exact loss and grad_norm comparisons for non-computation changes, convergence evidence for new computation, and scale validation when requested. Make training-hook, input metadata, and cross-stage state contracts explicit. Require independent remote debug-recipe repeatability checks before golden generation, comparing every full-precision loss and grad_norm step. Include scratch capture/comparison commands, then golden export and replay. Require component and full-model forward/backward parity, offline comparisons across parallelisms with gradient scaling checks, and a compact evidence table. Stage model enablement with FSDP+EP for MoE models, additional parallelisms/kernels, and optional performance work in a PR stack. Adapt the later parallelism order to model dependencies, with TP+SP, PP, then CP as a suggested progression. Require local pr_review/revision loops for every PR, including dependent re-reviews, before submitting the reviewed stack. Add evidence checkpoints from model-port reviews: review component reuse, parameter storage, optimizer policy, and ownership before implementation. Estimate training memory including saved backward tensors and transient weights; inspect reduced components and measure the intended baseline before qualification. Simplify wrappers and overrides before expensive validation, preserving compile and lifecycle contracts. Justify tests by uncovered invariants and existing coverage. Audit gradient participation, disabled objectives, auxiliary-loss resets, packed boundaries, and checkpoint values/optimizer moments. Qualify each PR's prerequisites, actual base/head, and supported axes independently. Use explicit config errors and HF compatibility plus current native round trips without promising old native schemas.
Thanks for trying it out and sharing feedback! You are absolutely right. I updated the skill incorporating your suggestions on reusable featurres/modules and attention-gym implementations. |
human notes:
Why
The add_model guidance predates current TorchTitan APIs and needs a concrete validation plan for new model ports. A numerical golden is useful only after the debug recipe is proven repeatable.
Recent model-port reviews found parameter/optimizer decisions, saved training memory, and redundant abstractions late. These checkpoints require evidence that the design, memory, and test plans were checked before proceeding.
Changes
Example
Before implementing a port, inventory a large per-layer parameter and its optimizer assignment.
For sparse attention, inspect selection/loss functions even when the surrounding model class differs.
Use a compatible attn-gym reference backend for eager attention and record the relevant contracts.
Estimate saved inputs/weights through backward, gradients, optimizer state, and transient gathers.
A reduced check finds a concatenated weight retained; simplify the composition before long GPU jobs.
The initial model PR measures FSDP+EP memory and checks logical values/moments after save/load.
Later TP/PP/CP PRs qualify the prerequisites and numerical checks for the paths they add.
Each PR is revised and reviewed on its current base/head before the stable stack is submitted.
Validation
pre-commit run --all-filespassed in an isolated checkout, including the new reference.Checked skill metadata, 23 local links, and eight unchanged Bash/Python examples.
Repeatability command checks previously verified rejection of a one-ULP grad_norm difference; those examples are unchanged.
Reviewed amendment
b93ac03e8against prior head14f47f03e: function-level reuse, compatible reference backends, and pre-implementation design evidence. The numerical parity workflow and executable examples are unchanged.This changes documentation only; no model training or memory measurement was run for this PR.