-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
MPS Support on Apple Silicon devices #547
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
base: main
Are you sure you want to change the base?
Conversation
…ilicon This commit adds full support for training AI models on Apple Silicon Macs using MPS, including fixes for multiprocessing tensor sharing issues and UI compatibility. Major changes: - Created toolkit/device_utils.py with comprehensive MPS device management - Fixed PyTorch multiprocessing issues on MPS by forcing num_workers=0 - Added Apple Silicon GPU detection in UI API - Fixed UI client-side errors with type checking and error handling - Added Apple Silicon-optimized training configs for Flux and Z-Image Key fixes: - Resolved "_share_filename_: only available on CPU" error - Fixed .toFixed() errors on string values from MPS API - Added defensive JSON parsing with fallbacks - Updated all training processes to use device-specific dataloader settings
- Update existing job configuration from adamw8bit to adamw for MPS compatibility - Add device-aware optimizer selection in UI (MPS shows compatible optimizers only) - Update default optimizer to use adamw on Mac, adamw8bit on CUDA - Add backend validation to automatically convert 8-bit optimizers for MPS - Fix multiple UI components with .toFixed() errors on string values - Add comprehensive MPS device utilities and detection
|
@jaretburkett you are the boss here, up to you if you want to integrate MPS support or not. For sure from PyTorch 2.9 things has improved a lot. |
|
I looked over the changes, I don't see anything that looks like it would cause an issue. I'll run some tests on it to make sure. @ivanfioravanti, how much ram on mac was needed to train z-image-turbo? I have a 24GB macbook I can test on. |
|
Let me try today. Keep you posted. |
|
~30GB I can grant you access to an M3 Ultra 512GB, but next week. |
|
Excellent. What settings are you using? I had to disable transformations to get going using PyTorch 2.7.0. |
|
Why is this not yet merged? is it waiting on more testing/feedback? |
|
Can we merge this? Does it work? |
|
Yes it worked, I fixed a conflict in the README file just now. @jaretburkett how would you like to proceed? |
|
sharing my experience: I run it successfully on an M4 pro with 48gb ram, trained already multiple LoRAs 👍 |
|
@ivanfioravanti Great work on enabling support for MPS. I tried to train the LoRA for z-image turbo on an M4 Pro 64GB and got stuck on two things. Seems like something specific to my setup so sharing the details here.
Sharing the config I used:
@lorand93 As the training worked on your M4 Pro, request you to share a working config which you tried on your device? That will help me identify if there is something missing. |
MPS Support on Apple Silicon devices. This should solve #127
Many changes had to be applied to make this work properly.