feat(flux): FSDP2 fp32/bf16 optimizers + fp8 all-gather#808
Merged
Conversation
wenxie-amd
approved these changes
Jul 8, 2026
botaohu001
added a commit
that referenced
this pull request
Jul 10, 2026
…DP2 refactor (#808) PR #808 (FSDP2 fp32/bf16 optimizers + fp8 all-gather) replaced Megatron's FSDP2 wrapper with PrimusTorchFullyShardedDataParallel (installed as megatron.training.training.torch_FSDP). ODC still hooked the stock megatron.core...TorchFullyShardedDataParallel.__init__, which is no longer instantiated, so odc_init/_ensure_odc_ready never ran, reduction_service stayed None, and odc_nopad crashed at iter2 with NoneType.clear_accumulations. Hook the class the trainer actually uses, with an ImportError fallback to the stock class. Verified: single-node 1.5B odc_nopad runs 100/100 (lm loss 9.970).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of an 18-PR series splitting the Flux diffusion-training feature (training Flux, a DiT text-to-image diffusion model, on Primus/Megatron) out of one large branch for reviewability. Targets
feat/flux/core— review after it. The diff here is only this layer.What this changes
The FSDP2 optimization layer used by Flux training: fp32 and bf16-master-weight optimizer variants, incremental grad-norm, the FSDP2 fp8 all-gather path, and the related torch-FSDP2 / fp8-cache / optimizer-registration patches.
Dependencies
Sequenced after the CI-pins PR (
feat/flux/ci-env); builds onfeat/flux/core. It is the parent of the turbo layer, whose float8 extension lazily imports this layer's fp8 all-gather.Test plan
pytest tests/unit_tests/optimizer tests/unit_tests/backends/megatron/diffusion/distributed. Validated locally on an AMD GPU container: 87 passed.Files
14 (FSDP2 optimizers, fp8 all-gather, optimizer/FSDP2 patches + tests).