Repository navigation
[tests] Use torchtitan Modules in the FSDP CPU-offload test fakes - #5795
Conversation
apply_fsdp_to_multimodal_encoder and apply_fsdp_to_decoder build the mixed-precision policy from Module.named_preserve_dtype_params() (#5774), so the test's plain nn.Module fakes failed with AttributeError. Make _VisionEncoder, _Block and _TinyVLM torchtitan Modules, as the real encoders and decoders are.
|
@claude review |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging -- the test fix is correct and in the right layer. The only gap is the empty human-written summary.
What this PR does. Since #5774, mixed_precision_policy() (torchtitan/distributed/fsdp.py:250) calls module.named_preserve_dtype_params() on the module passed to apply_fsdp_to_multimodal_encoder / apply_fsdp_to_decoder. Both helpers are typed to take a torchtitan Module, but the test fakes were plain nn.Modules, so the call raised AttributeError. The PR changes the three fakes to subclass torchtitan.models.base.module.Module. That matches the real encoders and decoders, and other GPU test fakes already do the same (test_activation_checkpoint.py, test_remat_all_to_all.py, test_deepep_activation_checkpoint.py).
Example.
# before: _VisionEncoder(nn.Module)
apply_fsdp_to_multimodal_encoder(model.vision_encoder, mesh, ...)
# -> AttributeError: '_VisionEncoder' object has no attribute 'named_preserve_dtype_params'
# after: _VisionEncoder(Module)
# -> _preserve_dtype_params == (), so preserved is empty,
# param_dtype_override_fn is None, and the policy is the same as before #5774Must fix
- PR description -- the "Summary (human-written)" section is empty. Per
CONTRIBUTING.md("AI-assisted contributions"), the author has to fill it in before merge.
Details
- Gate: the problem is real on
main.mixed_precision_policycalls theModule-only method with no fallback, and the helpers' declaredencoder: Moduletype is correct for every in-repo caller. So the fix belongs in the test, not in the helper (nogetattr/isinstancefallback is needed). No overlapping open PR. - Strictly, only
_VisionEncoderand_TinyVLMneed to change.named_preserve_dtype_paramsis only called on the roots and skips non-Modulechildren (torchtitan/models/base/module.py:84). Changing_Blockas well is harmless and mirrors real decoder blocks, so it's fine to keep. - Subclassing
Modulewithout a nestedConfigis the existing pattern for test fakes.Configurable.__init_subclass__does not require one. - Numerics are unchanged: the fakes have no preserved params, so the MP policy matches what it was before #5774.
Not verified: the GPU test run (6 passed on 2 GPUs per the description).
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the
problem, why
this approach, and what you checked yourself. -->
## Why
The Real PG integration suite (`8 GPU Integration (Real PG - full suite
- features)`) and the ROCm integration suite have failed the `sft` loss
check on main since #5757 (`899480301`; `a87db08ea` before it passed):
```
[sft] AssertionError: 7.889825820922852 != 7.887711524963379 : loss mismatch at step 1 # A10G
[sft] AssertionError: 7.890093803405762 != 7.887524604797363 : loss mismatch at step 1 # MI350X
```
#5757 renders `bos_token`/`eos_token` in Hugging Face chat templates, an
intended change to the SFT token stream. It regenerated
`tests/assets/losses/fake_pg/a10g/sft.txt` but not the real-PG A10G and
MI350X goldens.
## What changed
- `tests/assets/losses/real_pg/a10g/sft.txt` and
`tests/assets/losses/real_pg/mi350x/sft.txt`: steps 1-10 regenerated;
headers unchanged.
## Numerics
The new values are the full-precision TensorBoard metrics of the failing
main runs' baseline training (the same values `loss_compare.py
--export-result` writes), read with `scripts/loss_compare.py`'s own
extraction from the uploaded `integration-8gpu-features-outputs`
artifacts:
- A10G: run 41746280593 (`e6ca6d861`). Step 1 matches the log's baseline
(7.889825820922852, grad_norm 4.189799785614014).
- MI350X: the ROCm run on `73c4ebdac`. Step 1 matches the log's baseline
(7.890093803405762, grad_norm 4.189815998077393).
The commits between #5757 and those runs (#5572, #5787, #5776, #5774,
#5779, #5741, #5786) do not change SFT numerics.
## Testing
- CI: Real PG (`ciflow/real-pg`) and ROCm (`ciflow/rocm`) integration
suites.
- A manual `export_results` run of the integration workflow for `sft` on
main (run 41760303504) exported a real-PG A10G golden identical to this
one.
- `Multi-GPU Unit Tests` fails here with the `_VisionEncoder ...
named_preserve_dtype_params` error that is also on main; #5795 fixes it.
This PR was AI-assisted.
Summary (human-written)
Why
GPU unit tests have failed on main since #5774 (
a3e458c73).apply_fsdp_to_multimodal_encoderandapply_fsdp_to_decodernow build the mixed-precision policy fromModule.named_preserve_dtype_params().tests/unit_tests/gpu/distributed/test_fsdp_cpu_offload.pypasses plainnn.Modulefakes, so all threeTestVisionEncoderCPUOffloadtests fail:The real encoders and decoders are torchtitan
Modules (the helpers' declared type), so the fix belongs in the test.What changed
_VisionEncoder,_Blockand_TinyVLMin the test subclasstorchtitan.models.base.module.Moduleinstead ofnn.Module, like other test fakes (test_aux_loss.py,test_remat_all_to_all.py). Test-only.Testing
pytest tests/unit_tests/gpu/distributed/test_fsdp_cpu_offload.pyon 2 GPUs: 6 passed (3 failed on main).This PR was AI-assisted.