Skip to content

fix: add pull to solve the problem that fsdp2 traninng in shared will timeout #68

Open
gygdh-001 wants to merge 2 commits into
OpenMOSS:mainfrom
gygdh-001:personal/main
Open

fix: add pull to solve the problem that fsdp2 traninng in shared will timeout #68
gygdh-001 wants to merge 2 commits into
OpenMOSS:mainfrom
gygdh-001:personal/main

Conversation

@gygdh-001

@gygdh-001 gygdh-001 commented Jun 29, 2026

Copy link
Copy Markdown

During multi-node multi-GPU FSDP training, checkpoint saving and resume frequently hit timeout errors.

The root cause is that accelerate_trainer.py uses FullStateDictConfig / FullOptimStateDictConfig for FSDP,
which gathers the full state dict from all ranks onto rank 0 during every save_state / load_state call.
Transferring the full parameter set across nodes over the network causes timeouts,
and rank 0 is also at risk of OOM.

This PR applies the following changes:

  1. Replaces FullStateDictConfig / FullOptimStateDictConfig with
    ShardedStateDictConfig / ShardedOptimStateDictConfig for FSDP,
    so each rank only holds its own shard without cross-node full-state gather.

  2. Under FSDP, save_checkpoint now saves per-rank files:
    optimizer_{rank}.bin and scheduler_{rank}.bin,
    bypassing accelerator.save_state() which would trigger full-state gather.

  3. Under FSDP, _resume_checkpoint now loads per-rank optimizer and scheduler
    state dicts independently, bypassing accelerator.load_state() and its full-state gather path.

Validation:

Verified on a multi-node (2 nodes × 8 Ascend 910B) FSDP training setup:

  • Checkpoint save time reduced from 400s+ to under 300s, no more timeouts.
  • Resume success rate 100%, each rank correctly restores optimizer/scheduler state.
  • Resume time reduced from 160s to 40s.
  • Loss continuity verified — the loss curve after resume is seamless with the original training run.

@gygdh-001 gygdh-001 changed the title add pull to solve the problem that fsdp2 traninng in shared will timeout fix: add pull to solve the problem that fsdp2 traninng in shared will timeout Jul 1, 2026
@gygdh-001 gygdh-001 marked this pull request as draft July 1, 2026 01:11
@gygdh-001 gygdh-001 marked this pull request as ready for review July 1, 2026 01:12
Previously _resume_checkpoint() only restored optimizer and scheduler
states but never loaded model weights. This caused resumed training to
use the original pretrained weights instead of the checkpointed trained
weights, making resume effectively a from-scratch restart.

Fix: add _load_model_weights_from_checkpoint() to load per-module
diffusion_pytorch_model.bin files for all trainable modules (video_dit,
video_dit_2, audio_dit, dual_tower_bridge) before restoring optimizer
and scheduler states.

Verified by: 50-parameter anchor comparison (max_diff=0), loss continuity
(step-6 loss=0.3047 → step-7 loss=0.3047), and optimizer state key
audit (3735 keys match).

Signed-off-by: gygdh-001 <leiliandong@foxmail.com>
@gygdh-001

Copy link
Copy Markdown
Author

@tianyilt Please review the current PR. If you have any questions, feel free to ask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant