Add a minimal data-parallel distributed example (#2930)#3577
Closed
adityasingh2400 wants to merge 1 commit into
Closed
Add a minimal data-parallel distributed example (#2930)#3577adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
awni requested simple mlx.distributed examples in ml-explore#2930 in December 2025; nothing landed since. Add an examples/distributed/ data_parallel example: a small MLP trains on a synthetic classification task with gradients averaged via all_reduce after each step. README documents the mlx.launch invocation. A tensor-parallel example can follow in a separate PR if this structure works for you. Fixes ml-explore#2930 (data-parallel example; tensor-parallel to follow)
Collaborator
|
Closing since this is not even wrong. |
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
Closes (partially) #2930 — awni asked for a few short, standalone
mlx.distributedexamples back in December 2025 and nothing landed in the months since. This PR starts small with a single data-parallel example so we can lock in the structure before adding more.examples/distributed/data_parallel/main.py: ~80-line MLP trained on a synthetic classification task. Each rank gets a different data shard; gradients are averaged withnn.average_gradients(which batchesmx.distributed.all_sumcalls).examples/distributed/README.md: how to run withmlx.launch -n 2, plus a pointer to the existing distributed docs.The script also runs unchanged under plain
pythonbecausemx.distributedops are no-ops at world size 1, so it doubles as a smoke test.If this structure looks good, I'm happy to send a follow-up PR with a tensor-parallel inference example (and any others you have in mind).
Test plan
python3 -m py_compile examples/distributed/data_parallel/main.pymlx.launch -n 2 examples/distributed/data_parallel/main.py(maintainer-side, requires a built MLX with a distributed backend available)python examples/distributed/data_parallel/main.py(single process, should run with any MLX install)