Add Apple Silicon / MLX training support (train_mlx.py)#202
Open
AKHegde22 wants to merge 1 commit intokarpathy:masterfrom
Open
Add Apple Silicon / MLX training support (train_mlx.py)#202AKHegde22 wants to merge 1 commit intokarpathy:masterfrom
AKHegde22 wants to merge 1 commit intokarpathy:masterfrom
Conversation
- train_mlx.py: full MLX port of train.py — same architecture (GQA, RoPE, value residuals, sliding-window SSSL pattern, squared-ReLU MLP), Muon + AdamW optimizer running on CPU/numpy, tuned defaults for Mac hardware. - prepare.py: add make_dataloader_mlx() (numpy, no pin-memory/CUDA) and get_token_bytes_np() so the MLX training script has zero CUDA deps. - pyproject.toml: add mlx>=0.18.0 dependency. Both train.py (CUDA) and train_mlx.py (MLX) are fully functional and independently runnable; no existing GPU code was removed or modified. Co-Authored-By: Oz <oz-agent@warp.dev>
5 tasks
Bug Report:
|
Author
|
Thanks for the update @tobiasoberrauch |
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
This PR adds native Apple Silicon support via MLX, allowing autoresearch to run on Macs without any CUDA dependency.
What's changed
New file:
train_mlx.pyA complete MLX port of
train.pythat mirrors the architecture exactly:The Muon optimizer runs on CPU via numpy since MLX does not have a
torch.compileequivalent. Defaults are tuned for Mac hardware (smaller batch size, smaller model depth).Modified:
prepare.pymake_dataloader_mlx()— numpy-based dataloader with no CUDA/pin-memory dependenciesget_token_bytes_np()— returns token byte-lengths as a numpy array (no CUDA required)Modified:
pyproject.tomlmlx>=0.18.0dependencyWhat's preserved
No existing GPU code was touched.
train.py(CUDA + Flash Attention 3) is completely unchanged. Both scripts are independently runnable:Usage