mlx icon indicating copy to clipboard operation
mlx copied to clipboard

fsdp: improve state saving determinism and tree reconstruction

Open coder-jayp opened this issue 7 months ago • 3 comments

Addresses #3401.

Changes:

  • Made parameter grouping deterministic by sorting keys returned from tree_flatten(). This fixes the non-deterministic grouping issue that could cause incorrect state loading.
  • Added intermediate reconstruction of the original parameter tree before calling optimizer.apply_gradients. This ensures optimizer state is no longer tied to the number of communication groups or communication_size.

This change improves the reliability of saving and loading FSDP optimizer states while preserving the performance benefits of grouped reduce-scatter / all-gather operations.

Checklist

Put an x in the boxes that apply.

  • [x] I have read the CONTRIBUTING document
  • [ ] I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [ ] I have updated the necessary documentation (if needed)

coder-jayp avatar Apr 13 '26 18:04 coder-jayp

Hi @nastya236, it would be great to get some feedback. Thanks.

coder-jayp avatar Apr 15 '26 15:04 coder-jayp

Thanks for your contribution! Will look at it as soon as possible.

nastya236 avatar Apr 15 '26 21:04 nastya236

Hi @nastya236,

Just a quick follow-up on this PR. Happy to make any changes if needed. Thanks.

coder-jayp avatar Apr 23 '26 16:04 coder-jayp