Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable distributed LoRA training #821

Merged
merged 5 commits into from
Nov 3, 2024
Merged

Enable distributed LoRA training #821

merged 5 commits into from
Nov 3, 2024

Conversation

angeloskath
Copy link
Member

The updates to LORA.md are missing but TL;DR we can now do

$ echo "m2-ultra-0 slots=1" >>hostfile
$ echo "m2-ultra-1 slots=1" >>hostfile
$ mpirun --hostfile hostfile -- python -m mlx_lm.lora --train --model mlx-community/Mistral-7B-v0.2-4bit --data /path/to/data --batch-size 16

to train across two nodes (or more really nothing needs to change).

@mzbac
Copy link
Contributor

mzbac commented Jul 7, 2024

Is that possible to do distributed inference as well?

@awni
Copy link
Member

awni commented Jul 7, 2024

Is that possible to do distributed inference as well?

Possible yes, but getting a nice speedup is more challenging. That's something we're looking at, but don't have an ETA on right now.

yeahdongcn added a commit to yeahdongcn/mlx-examples that referenced this pull request Aug 6, 2024
Signed-off-by: Xiaodong Ye <yeahdongcn@gmail.com>
@angeloskath angeloskath requested a review from awni September 12, 2024 23:06
@angeloskath
Copy link
Member Author

@awni feel free to review and then we can merge. I split the launcher to a different branch.

loss=mock_default_loss,
iterate_batches=mock_iterate_batches,
)
with swapped_with_identity(mx.distributed, "all_sum"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why do we need this for the test to work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm I see the magicmock thing is messing up the all_sum.

f"Val loss {val_loss:.3f}, "
f"Val took {val_time:.3f}s",
flush=True,
)

if training_callback is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably tha tshould go under the rank==0 condition as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah ok, it makes sense. I was thinking in general callbacks should always run and if the callback is about reporting then it can choose to only run on rank=0. But our callbacks here are only about reporting so it makes sense to just run them only on node 0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good point actually. It's more flexible that way. I'm on board leaving it to the user to specify the rank.

f"Trained Tokens {trained_tokens}, "
f"Peak mem {peak_mem:.3f} GB",
flush=True,
)

if training_callback is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same there.

Copy link
Member

@awni awni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!! Let's 🚢

@angeloskath angeloskath merged commit 331148d into main Nov 3, 2024
2 checks passed
@angeloskath angeloskath deleted the distributed-lora branch November 3, 2024 01:02
@ivanfioravanti
Copy link
Contributor

This works perfectly! Great job 👏

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.

4 participants