Conversation
Two bugs caused NCCL deadlocks when saving diffusion model checkpoints with `model_save_format: safetensors`: 1. **SequentialBucketSampler padding bug** (`sampler.py`): When a bucket had fewer samples than `padding_size` (e.g., 2 samples needing 6 padding elements to reach 8), `indices[:padding_size]` only returned `len(indices)` elements instead of `padding_size`. This made ranks 0-3 get 15 batches and ranks 4-7 get 14 batches per epoch. At epoch boundary, ranks 0-3 entered checkpoint save (DCP/NCCL ops) while ranks 4-7 continued training (FSDP2 allgather), deadlocking on mismatched NCCL collectives. Fixed by cycling through indices with modular indexing. 2. **FrozenDict config serialization** (`addons.py`): Diffusers models use `FrozenDict` for their config, which lacks the `to_json_string()` method that HF `PretrainedConfig` provides. This caused an `AttributeError` on rank 0 during `pre_save`, while other ranks waited at a barrier — another deadlock. Fixed by falling back to `json.dump()` when `to_json_string` is unavailable. Closes #1574 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: adil-a <adil.asif2000@hotmail.com>
Collaborator
Author
|
/ok to test cc63fca |
akoumpa
approved these changes
Mar 24, 2026
linnanwang
pushed a commit
that referenced
this pull request
Apr 24, 2026
…mat (#1601) Two bugs caused NCCL deadlocks when saving diffusion model checkpoints with `model_save_format: safetensors`: 1. **SequentialBucketSampler padding bug** (`sampler.py`): When a bucket had fewer samples than `padding_size` (e.g., 2 samples needing 6 padding elements to reach 8), `indices[:padding_size]` only returned `len(indices)` elements instead of `padding_size`. This made ranks 0-3 get 15 batches and ranks 4-7 get 14 batches per epoch. At epoch boundary, ranks 0-3 entered checkpoint save (DCP/NCCL ops) while ranks 4-7 continued training (FSDP2 allgather), deadlocking on mismatched NCCL collectives. Fixed by cycling through indices with modular indexing. 2. **FrozenDict config serialization** (`addons.py`): Diffusers models use `FrozenDict` for their config, which lacks the `to_json_string()` method that HF `PretrainedConfig` provides. This caused an `AttributeError` on rank 0 during `pre_save`, while other ranks waited at a barrier — another deadlock. Fixed by falling back to `json.dump()` when `to_json_string` is unavailable. Closes #1574 Signed-off-by: adil-a <adil.asif2000@hotmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
sampler.py):indices[:padding_size]silently under-pads whenpadding_size > len(indices), causing uneven batch counts across ranks (e.g., ranks 0-3 get 15 batches, ranks 4-7 get 14). At epoch boundary, some ranks enter checkpoint save while others continue training — mismatched NCCL collectives deadlock. Fixed with modular cycling.addons.py): Diffusers models useFrozenDictfor config (noto_json_string()), causingAttributeErroron rank 0 duringpre_savewhile other ranks wait at barrier. Fixed by falling back tojson.dump().Closes #1574
Test plan
model_save_format: safetensorsandsave_consolidated: falseon 8 GPUs — checkpoint should save without deadlockpytest tests/unit_tests/ -vs -m "not pleasefixme"for unit test regression🤖 Generated with Claude Code