feat(training): default fp32 master weights for full-param torch.optim training#2379
Draft
yuhezhang-ai wants to merge 4 commits into
Draft
feat(training): default fp32 master weights for full-param torch.optim training#2379yuhezhang-ai wants to merge 4 commits into
yuhezhang-ai wants to merge 4 commits into
Conversation
1c25b15 to
c8b00f8
Compare
759ef93 to
57772fb
Compare
8 tasks
… training Wire resolve_storage_dtype into the llm, vlm, seq-classification, and bi-encoder retrieval recipes so full-parameter training with a torch.optim optimizer defaults model.torch_dtype to float32 (parameters act as the fp32 master copy). No-op for PEFT, TE FusedAdam, or an explicit model.torch_dtype. Signed-off-by: Yuhe Zhang <yuhez@nvidia.com>
Set torch_dtype: float32 (fp32 master) + compute_dtype: bfloat16 (FSDP compute) on the full-parameter diffusion finetune configs, matching wan2_1_t2v_flow. Signed-off-by: Yuhe Zhang <yuhez@nvidia.com>
Store the trainable EAGLE-1/EAGLE-3 draft in fp32 (storage_dtype) so torch.optim.AdamW keeps an fp32 master copy, and run forward/backward in bf16 on GPU via a _compute_autocast() context (no FSDP MixedPrecisionPolicy since the draft is not sharded). Autocast is applied in the train/val loops, the shared _forward_batch helper, and the P-EAGLE partitioned segment step. Signed-off-by: Yuhe Zhang <yuhez@nvidia.com>
Add a Default Behavior section explaining that full-parameter torch.optim training now defaults model.torch_dtype to float32 (with PEFT / TE FusedAdam / explicit-dtype no-ops), restore the bf16 Adam-state subsection (fp32 master + bf16 EMA, as used by DeepSeek-V3), update the Risky Pattern section to reflect that bf16 storage is now opt-in, and update the finetune guide note. Signed-off-by: Yuhe Zhang <yuhez@nvidia.com>
1bc67e2 to
1d03fa5
Compare
4 tasks
4 tasks
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.
Summary
Rebased onto
mainnow that the dtype bug fixes have merged (#2419). This PR keeps only the default-dtype behavior change: full-parameter training with atorch.optimoptimizer (e.g.torch.optim.Adam/AdamW) now defaultsmodel.torch_dtypeto float32, so the resident parameters act as the fp32 master copy and the Adam state stays full precision, while forward/backward stay bf16 through FSDP2 mixed precision. Previously, leavingmodel.torch_dtypeunset silently gave bf16 master weights + bf16 Adam state (lower-precision training than DeepSpeed/Accelerate/torchtitan defaults).The resolver itself (
resolve_storage_dtype), the HF load-dtype promotion, the per-param compute-dtype FSDP grouping, the pipeline-dtype default, and the frozen-module cast all landed in #2419 (whereresolve_storage_dtypewas merged but left unwired). This PR turns the default on and adds the matching config/doc changes.What changed
Wire the fp32-master default into the recipes. Calls
resolve_storage_dtype()before model construction in the LLM SFT (train_ft), VLM (finetune), sequence-classification (train_seq_cls), and bi-encoder retrieval (train_bi_encoder) recipes. No-op for PEFT/LoRA, TEFusedAdam(keeps its own fp32 master), and any explicitmodel.torch_dtype.EAGLE draft fp32 master. The DDP-trained EAGLE-1/EAGLE-3 draft is stored in fp32 (
storage_dtype) and runs its forward under a bf16 autocast context (_compute_autocast), matching the reference EAGLE setup (accelerate --mixed_precision=bf16). Autocast is applied in the train/val loops, the shared_forward_batchhelper, and the P-EAGLE partitioned segment step;backward()stays inside the DDPno_synccontext. CPU stays fully fp32.Diffusion configs. Full-param diffusion finetune configs (flux / qwen_image / hunyuan / wan2.1 t2v multinode) pinned to
torch_dtype: float32+compute_dtype: bfloat16, matchingwan2_1_t2v_flow. Benchmark/pretrain configs need no edits — they already resolve to fp32 master via the new default.Docs. Mixed-precision and finetune guides updated to document the new default (
Default Behaviorsection), restore the TEFusedAdambf16 Adam-state mode (fp32 master + bf16 EMA, as used by DeepSeek-V3), reflect that bf16 storage is now opt-in (Risky Pattern), and explain how to opt out.Validation notes
resolve_storage_dtypeis unit-tested in fix(precision): dtype contract bug fixes for FSDP2 mixed-dtype loads #2419; recipe wiring follows the existing convention (no dedicated setup test).Test plan