Repository navigation
Fix ChunkedCELoss final FSDP wrapping - #3229
iamzainhuda wants to merge 1 commit into
Conversation
|
|
a1678b0 to
5069287
Compare
Hi thanks for this. Did you run this test with latest pytorch nightly? We have CI to guard this which is passing on ChunkedLoss change. ChunkedLoss depends on PyTorch changes pytorch/pytorch#180428 |
|
The custom autograd function change is an additional thing I added that isn't actually needed to make this work but thought we could simplify. I'm happy to remove it if you want to keep it in. There is a small transient memory tradeoff because |
Just ran it on the latest pytorch nightly, the issue is gone - so this PR is no longer needed. Thank you for the response! |
Summary
normandlm_headin separate FSDP units whenChunkedCELossis activelm_headreshard at the end of the chunked loss forwardChunkedCELossruns backward throughlm_headchunk-by-chunk before the outer decoder backward reaches finalnorm. Whennormandlm_headshare one FSDP unit,lm_headbackward/reshard can affect storage thatnormstill needs later in the same backward pass. On the 8-GPU DeepSeek V3 debug model this fails during the first backward pass with an unallocated tensor error.Splitting
normandlm_headonly for the chunked-loss path isolates their FSDP storage lifecycle while preserving the existing grouped wrapping for the standard loss path.The zero-value gradient bridge keeps the same forward value as the old custom autograd Function while attaching the accumulated chunk gradient to
hidden_statesthrough regular PyTorch ops. The added unit test recreates the legacy bridge locally and verifies both approaches produce identical scalar values and hidden-state gradients.Validation
PYTHONPATH=/home/dev/ao pytest -q tests/unit_tests/test_loss.pyorigin/mainfails withNGPU=8 MODULE=deepseek_v3 CONFIG=deepseek_v3_debugmodel ./run_train.sh --training.steps 3