Repository navigation
Conversation
[ghstack-poisoned]
[ghstack-poisoned]
|
@claude review this pr |
|
Claude finished @anshul-si's task in 4m 13s —— View job Request changes -- all three new entries pass the removed |
There was a problem hiding this comment.
Verdict: Request changes -- at HEAD, all three new entries pass skip_rocm_test, a field that #5735 removed in the base. So features.py and models.py fail to build their test lists, and every integration job is red before any FlexShard test runs.
What this PR does. It adds three integration entries:
- two Real PG FlexShard twins of FSDP2 entries that have goldens (
llama3_flex_shard+tp+cpanddeepseek_v3_flex_shard+ep), which must match the FSDP2 golden bitwise by loading the same seed checkpoint; - a 3-run 2-GPU entry,
flex_shard_checkpoint, in which FlexShard resumes an FSDP2 checkpoint and loads FSDP2's HF export.
It moves the flex_shard pin into .github/scripts/install_flex_shard.sh, installs flex_shard in the CUDA Real PG job, excludes the entries from release validation, and adds a user doc, FLEX_SHARD_FSDP.md. It changes no training code.
Example. The PR CI's "required subset" run (--test_scope real_pg_required) picks up the twin because it has use_real_pg=True:
loss_compare.py --baseline-config=llama3_debugmodel_fsdp2_tp2_cp2_flex_shard \
--seed-config=llama3_debugmodel --import-result=tests/assets/losses/real_pg/a10g/llama3.txt --assert-equal
The seed checkpoint comes from a single device, as for llama3_fsdp+tp+cp, so FlexShard has to reproduce FSDP2's golden bitwise. A regression in FlexShard's reductions or in clip-grad ordering fails here.
Must fix
- PR description. The "Summary (human-written)" section is empty, and the author has to write it. The description also says
test_integration_test_definitions.pypasses, but that run predates the base update that removedskip_rocm_test. tests/integration_tests/models.py:688,:742andtests/integration_tests/features.py:970--skip_rocm_testno longer exists, so each kwarg raises aTypeError. Move the three names torocmintests/integration_tests/hardware_skips/skipped_tests.toml(inline comments).torchtitan/distributed/flex_shard_fsdp.py:668(not in the diff) -- theImportErrorstill points users to.github/workflows/unit_test_gpu.yamlfor the pinned commit. This PR moves the pin to.github/scripts/install_flex_shard.sh, so change the message to name that script, as the doc does.
Should consider
tests/integration_tests/features.py:284-- fold the FlexShard resume and HF load into the existingfull_checkpointandmodel_only_hf_checkpointentries instead of adding a third checkpoint entry with its own FSDP2 save run (inline).torchtitan/distributed/FLEX_SHARD_FSDP.md:136-- "mesh dim" should be "mesh axis" (inline).
Details
Gate.
- Problem: nothing in CI trains with
FlexShardConfig()throughtorchtitan.train. The gap is real. - Layer: tests, CI and docs only.
- Dependency: flex_shard is a meta-pytorch repo, which
.claude/CLAUDE.mdallows. - Smallest alternative: the twins are the cheapest way to check bitwise parity at a recipe layout. Turning the FSDP2 entries over to FlexShard would lose FSDP2's golden coverage.
- Precedent: sharing a golden between two entries already exists (
llama3_fsdp+tp+cp+region_acsharesllama3.txt).
Twins.
- The seed config is right for both twins.
loss_compare.py:1171defaults the seed config to the baseline config, sodeepseek_v3_fsdp+ep's seed isdeepseek_v3_debugmodel_fsdp8_ep8, which the twin passes explicitly. _filter_testsskipsuse_real_pgentries under Fake PG (run_tests.py:403), so the 1-GPU job doesn't need flex_shard.- The Real PG matrix is nightly-only (
set-matrix.yaml:75), which meets flex_shard's requirement of a 2.16 nightly.
flex_shard_checkpoint.
- Run 1's last save goes to
checkpoint/exports/step-10(model-only, HF), so run 2 resumes the full checkpointcheckpoint/step-5. - Run 3 gets a folder of its own, so it doesn't resume those checkpoints. That's correct.
Not verified: that the twins match the FSDP2 goldens at HEAD. They haven't run on this stack, and CI's Real PG job will be their first run.
| ), | ||
| loss_compare_seed_config=deepseek_v3_debugmodel_fsdp8_ep8, | ||
| use_real_pg=True, | ||
| skip_rocm_test=True, |
There was a problem hiding this comment.
This is the same removed skip_rocm_test field as at line 688, and it raises a TypeError the same way. Move it to hardware_skips/skipped_tests.toml.
| skip_rocm_test=True, |
[ghstack-poisoned]
|
@claude review this pr |
|
Claude finished @anshul-si's task in 2m 25s —— View job Approve -- the earlier blockers are fixed at HEAD; only the empty human-written summary remains; see the review. |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. The earlier blockers are fixed at HEAD. The three entries now skip ROCm through skipped_tests.toml, and the ImportError names install_flex_shard.sh. What's left is the author's summary. A maintainer (weifengpy, fsdp area) still needs to review.
What this PR does. It adds three Real PG integration entries for fsdp_backend=FlexShardConfig():
llama3_flex_shard+tp+cpanddeepseek_v3_flex_shard+epare twins of FSDP2 entries. Each loads its counterpart's seed checkpoint and has to reproduce that counterpart's golden bitwise.flex_shard_checkpointruns on 2 GPUs. FlexShard resumes an FSDP2 checkpoint and then loads FSDP2's HF export.
It also moves the flex_shard pin into one script, which the multi-GPU unit job and the CUDA Real PG job call, excludes the entries from release validation (torch 2.15), and adds FLEX_SHARD_FSDP.md.
Example. With TEST_SCOPE=real_pg_required on a ready PR, the runner picks up the twin and runs:
loss_compare.py --baseline-config=llama3_debugmodel_fsdp2_tp2_cp2_flex_shard \
--seed-config=llama3_debugmodel \
--import-result=tests/assets/losses/real_pg/a10g/llama3.txt --assert-equal
Before this PR, a FlexShard regression in reductions, grad clipping or CheckpointManager had no torchtitan.train coverage. Now that run fails on it.
Must fix
- PR description. The "Summary (human-written)" section is still empty, and only the author can write it. The CPU check it reports (
test_integration_test_definitions.py, 52 passed) also ran before theskip_rocm_testfix, so rerun it and update the numbers.
Status of the earlier review
skip_rocm_testkwargs (models.py,features.py): resolved. The names are now underrocminskipped_tests.toml.- The
ImportErrorpointing atunit_test_gpu.yaml: resolved (flex_shard_fsdp.py:668). - "mesh dim" in the doc: resolved.
- Folding into
full_checkpoint/model_only_hf_checkpoint: the author's reason holds. Those entries run on ROCm and in release validation, andskipped_tests.tomland--excludework on whole entries, so a separate entry is the only way to skip just the FlexShard runs.
Details
- Install coverage.
integration_test_real_pg.shinstalls flex_shard only forcuda. ROCm skips all three entries through the toml, and the XPU job isn't wired up yet. Fake PG skipsuse_real_pgentries (run_tests.py:403). The H100 and B200 workflows run their own suites, notfeaturesormodels. The CUDA Real PG matrix uses the nightlycu132index with no pinned torch (set-matrix.yaml:75-76), which meets flex_shard's 2.16-nightly requirement. - Validation. None of the FlexShard configs sets
spmd_typechecking, HSDP, PP, MTP orlast_save_in_hf.llama3_debugmodel_checkpoint_and_hf_saveinheritstypechecking=Trueandlast_save_in_hf, but it's the FSDP2 run, sovalidate_flex_shard_trainingdoesn't apply to it. flex_shard_checkpoint. Run 1's last save is model-only HF, written tocheckpoint/exports/step-10, so run 2 resumes the fullcheckpoint/step-5. Run 3 usesfolder="hf_load"withload_only=True.initial_load_model_onlydefaults to True (checkpointer/base.py:650), so run 3 loads only the model from the export.- Doc. The rejection table matches
validate_flex_shard_training(flex_shard_fsdp.py:536-656) row by row, and the links (FSDP.md,ACCELERATOR_GRAPH.md,flex_shard/README.md) resolve. - Shared golden. In export mode, a twin writes to the same result path as its counterpart, so whichever runs last wins. That matches the existing precedent (
llama3_fsdp+tp+cp+region_acsharesllama3.txt), and since the twins must be bitwise identical, it's harmless.
Not verified: that the twins match the FSDP2 goldens at HEAD. They haven't run on this stack, so CI's 8-GPU Real PG job is their first run. I couldn't run the CPU definition tests in this environment either.
Stack from ghstack (oldest at bottom):
Stacked on #5842, the expert-parallelism PR, the chunked-loss PR, the
checkpointing PR, the Hugging Face load PR, the tensor- and context-parallelism PR,
the DeepSeek V3 PR and the accelerator-graphs PR.
Summary (human-written)
Description
No integration test trains with
parallelism.storage=FlexShardConfig(). Thestack's checks are the multi-GPU unit tests in
test_flex_shard_fsdp.py, which buildmodels with
model.parallelize, and one-offloss_compareruns. Nothing in CI trainsthrough
torchtitan.trainwith FlexShard, so a change that breaks it there (configvalidation, the training engine,
CheckpointManager, the accelerator-graph wrappers),or breaks its parity with FSDP2 at a recipe's layout, would land unnoticed. FlexShard
also has no user docs beyond the
storagedocstring. This PR adds threeintegration entries and a doc. It changes no training code.
Two entries in the models suite are FlexShard twins of FSDP2 entries that have goldens:
llama3_flex_shard+tp+cp(Llama 3 debug,dp_shard=2, tp=2, cp=2, sequence parallel)and
deepseek_v3_flex_shard+ep(DeepSeek V3 debug without MTP layers,dp_shard=8, ep=8), both withChunkedLossWrapperand 8 GPUs. Each config is its counterpart's(
llama3_fsdp+tp+cp,deepseek_v3_fsdp+ep) withstorage=FlexShardConfig(), and each entry checks loss and grad normagainst the counterpart's golden, bitwise. So the guarantee the stack makes,
bitwise-identical training from the same weights, is what CI checks at a recipe's
layout, and a numerics change that regenerates an FSDP2 golden has to keep the twin
matching it.
The twins match only if both backends start from the same weights. Since #5842's
rework, FlexShard initializes each shard as its slice of one device's initialization,
while FSDP2's DTensor init draws each shard on its own, so from the same seed they
start from different weights. The runner gives both the same weights only under Real
PG: there, an entry with a golden runs through
loss_compare.py, which creates a seedcheckpoint on one device, without sharding, from
loss_compare_seed_config, and loadsit before step 1. Each twin's seed config is its counterpart's (
llama3_debugmodelfor Llama 3, as
llama3_fsdp+tp+cpsets; the FSDP2 config itself for DeepSeek V3,which sets none), so the twin loads the same seed checkpoint as its counterpart's
golden run. Under Fake PG, the runner passes
--no-seed-checkpointand rejectscheckpointing (
validate_fake_pg_compatibility), so each backend would train from itsown initialization and the twin couldn't match the Fake PG golden. The twins
are therefore Real PG only (
use_real_pg=True, which marks the tests that need acheckpoint load): they run in the 8-GPU Real PG job on every ready PR, in its
real_pg_requiredsubset, and in the full suite on main. Real PG also performs thereductions, which the Fake PG backend skips (it returns each rank's own chunk), so a
reduction bug in FlexShard can't pass there. The earlier revision of this PR ran the
twins under Fake PG too, which relied on FlexShard initializing through DTensor views
of its parameters (
as_fsdp2_dtensor), which #5842 deleted. The 1-GPU Fake PG job nowruns no FlexShard test, so it doesn't install flex_shard.
The features suite gets
flex_shard_checkpoint(2 GPUs, Real PG), three runs in oneoutput directory:
10. FSDP2 writes both because FlexShard can't save Hugging Face checkpoints yet.
initial_load_in_hf, from a checkpointfolder of its own, so that it doesn't resume the full checkpoints.
The configs are the Llama 3 debug recipe's: varlen attention,
ChunkedLossWrapper,local compile, activation remat, and accelerator graphs, which are on without EP. The
entry checks that each run completes. The multi-GPU unit tests compare checkpoints and
Hugging Face loads with FSDP2's bitwise; this entry covers the trainer around them.
Both FlexShard runs start from checkpoints, so initialization doesn't matter here.
The runs are an entry of their own, not appended to
full_checkpointandmodel_only_hf_checkpoint, which run on ROCm and in release validation, whereflex_shard isn't installed.
All three entries skip ROCm, where FlexShard is unvalidated, through
hardware_skips/skipped_tests.toml. Every config passes FlexShard's validation(
FlexShardConfig.validate_modelandFlexShardConfig.validate_trainer) at thiscommit: none has MTP layers, uses HSDP or PP, or captures graphs under EP.
CI installs flex_shard through a new
.github/scripts/install_flex_shard.sh, whichholds the pin,
d6bb546, and the--no-depsgit install that the multi-GPU unit-testjob had inline (#5842). That job and the 8-GPU Real PG script
(
integration_test_real_pg.sh, for CUDA only, since ROCm shares the script) call it.Release validation (
validate_release_gpu.sh) runs the features and models suitesagainst the RC's torch, 2.15.0, and flex_shard needs ops from 2.16 nightlies
(pytorch#197204). So it doesn't install flex_shard and
--excludes the three entries,with a TODO to drop that once the release torch is 2.16 or later. The 8-GPU Real PG
job's timeout goes from 60 to 70 minutes: its models job took 50 to 58 minutes in the
last five runs on main (November 13 to 15), and the twins add two 8-GPU runs.
FlexShardConfig.validate_model'sImportErrorfor a missing flex_shard now names thescript for the pinned commit, in place of
unit_test_gpu.yaml.The new
torchtitan/distributed/FLEX_SHARD_FSDP.md, next toflex_shard_backend.py,covers how to enable and install FlexShard, how it shards, and the contract: outside
forward and backward, parameters, grads and optimizer states are plain local shards,
whose state dicts declare their layouts through DCP's
CheckpointableTensorprotocol,with no DTensor. It explains the initialization difference and how to compare the
backends from the same seed checkpoint, where memory and timing differ from FSDP2,
what's supported, and every rejection in FlexShard's validation with its reason, plus
the two raised elsewhere (graphs under EP, and
ChunkedLossWrapperwith a frozendecoder). The name keeps it apart from
distributed/flex_shard/README.md, whichdocuments DistMuon's in-tree package.
README.md,distributed/README.md(which alsogains a row for #5842's
storage.py) and thestoragedocstring linkto it, and
area_reviewers.ymladds it to the fsdp area. It replaces the README editsof the FlexShard fork (weifengpy#7, #16, #43), which the
upstreaming plan left for this PR.
The twins haven't run on this stack: they need 8 GPUs, and this machine has 2. The
earlier revision ran them on 8 GB300 GPUs, against their FSDP2 counterparts from the
same seed checkpoint, bitwise, but #5842 and the TP/CP and EP PRs have since reworked
initialization and the grad norm. CI's Real PG job will be their first run. What ran
here, on 2 GB200 GPUs:
scripts/loss_compare.py . . --baseline-config llama3_fsdp2 --test-config llama3_flex_shard --assert-equal --metrics loss,grad_norm(Llama 3 debug with flex attention,dp_shard=2, 100 steps,accelerator graphs, both runs loading the seed checkpoint that
loss_comparecreates) reports equal loss and grad norm at every step (step-100 loss 2.76104).
This is the mechanism the twins rely on, through
torchtitan.train. With--no-seed-checkpoint, as under Fake PG, the step-1 loss already differs (8.11912for FSDP2, 8.21909 for FlexShard), and so does the grad norm.
flex_shard_checkpointthrough the runner'srun_single_test, with flex attentionin place of varlen, because the environment has no FA4: all three runs pass. FSDP2
saves
step-5andexports/step-10. FlexShard loadsstep-5, records itsforward-backward graph and saves
step-10. The Hugging Face run loadsexports/step-10(step-1 loss 4.08220, against 8.04280 from scratch) and records itsgraph.
__post_init__, whichruns FlexShard's validation for the FlexShard ones, and
validate_fake_pg_compatibility, and both twins' seed configs are FSDP2 configs.test_integration_test_definitions.pyandtest_context_parallel_validation.pypass(52 passed, 39 subtests); the latter validates every CP recipe in the suites, the
Llama 3 twin included.
rule for supported models against which model classes resolve
_apply_fsdptoDecoder._apply_fsdp. pre-commit passes on the changed files.Not covered end to end: FlexShard's expert buckets on more than one rank (the DeepSeek
V3 twin has
edp_shard=1; a twin ofgpt_oss_fsdp+tp+epwould cover it for another8-GPU entry), resuming a FlexShard checkpoint, and FlexShard's own initialization,
since every entry loads a checkpoint. The multi-GPU unit tests check the first and
the last at CI's 4 GPUs, and that FlexShard saves the same checkpoints as FSDP2,
whose checkpoints FlexShard loads.