-
Notifications
You must be signed in to change notification settings - Fork 768
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
Add macOS Compatibility #69
base: main
Are you sure you want to change the base?
Conversation
…o#44) * Update text2video.py to reduce GPU memory by emptying cache If offload_model is set, empty_cache() must be called after the model is moved to CPU to actually free the GPU. I verified on a RTX 4090 that without calling empty_cache the model remains in memory and the subsequent vae decoding never finishes. * Update text2video.py only one empty_cache needed before vae decode
Hi @WanX-Video-1, I hope you're doing well. I've made some changes to adapt the Wan2.1 text-to-video model for macOS with M1 Pro chips. The key changes include:
Could you please review the pull request when you have a moment? Your feedback would be greatly appreciated. Thank you! Best regards, |
Thank you for your help, but I encountered the following error during the program execution. Could you please let me know how to resolve it? Thank you! |
This is just a warning message from macOS. I also encountered it. |
got it ! ths a lot |
I have successfully run your solution, thank you ^ ^ |
…o#44) * Update text2video.py to reduce GPU memory by emptying cache If offload_model is set, empty_cache() must be called after the model is moved to CPU to actually free the GPU. I verified on a RTX 4090 that without calling empty_cache the model remains in memory and the subsequent vae decoding never finishes. * Update text2video.py only one empty_cache needed before vae decode
Add model files download step
f8cca94
to
2beb726
Compare
Thanks @bakhti-uzb ! I was working on the same PR but ran into this error on my M4 Max: I'm hitting the same error on your PR, have you run into this? |
I haven't encountered that exact error on my M1 Pro, but it's related to tensor data type mismatches on the MPS backend. The model is trying to use half-precision weights (FP16) with full-precision inputs (FP32).
Let me know if you've found a solution that works consistently - I'd be happy to incorporate it into the PR to make it work better across different Apple Silicon chips. |
Thanks @bakhti-uzb, I managed to make it work. The issue was that I was trying to run the I2V while you focused on the T2V. Here's the change I made to get the I2V working:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File "/Users/me/Wan2.1/wan/modules/attention.py", line 186, in attention
out = torch.nn.functional.scaled_dot_product_attention(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.12/site-packages/torch/utils/_device.py", line 78, in __torch_function__
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Invalid buffer size: 47.98 GB
This pops up after making all these changes, on m3 pro.
Thanks for letting us know. I included this changes in the repo |
It would be easy to help if you provide some more information like how you are trying to generate with what kind of options ( For now I can suggest these:
|
not explicitly specifying frame numbers, just copied their example from readme:
Did this: Now it throws: Also set the
Setting the watermark ratio back to 0, and running this command:
throws:
|
It looks like you're encountering a series of memory-related issues that are common when running large AI models on Mac. Here's what I recommend trying:
The key insight is that when using large models, especially on Mac, you typically need to be much more conservative with generation parameters than the default examples suggest. Start with minimal settings that work, then gradually increase until you find your system's limit. |
it doesn't let me go below 480p |
Still get |
can we use this model in m3 Pro chip as well ? |
This should probably work, but I haven't tested it specifically on M3 Pro, I ran it on my M1 Pro and it worked. Let me know if you have any errors while trying it out |
You may try my fork, which will save few GB of RAM.
32GB M4 runs T2V-1.3B fine. |
Hi @bakhti-ai , thanks for your contribution to the Mac mod version, I just tried to install on my MacBook but it will kill the process itself after loading and creating pipeline and model, my MacBook is M2 and just having 8Gb Ram, would that be the reason it doesn't run? I already am using the 480p model, thanks!! |
Even if you use 480p video generation models are quite memory-intensive. Yes I think you are having out of memory issue. Can you provide any error message, warning or any logs from running it on your machine? |
Using --frame_num over 45 leads to: Error: total bytes of NDArray > 2**32' This is on a 128 GB M3 Max, with the options --task t2v-1.3B --size "480*832". Any idea whether this can be fixed? |
I am not sure if this will work. I asked chatgpt about this issue and here its response:
|
Haven't got enough RAM to test it, but may due to MPSNDArray limit. pytorch/pytorch#134177 May be solved by breaking up the array in generation process or try new software version. |
Overview
This pull request introduces compatibility improvements for running the Wan2.1 text-to-video model on macOS systems with M1 Pro chips. It also includes enhancements to the documentation to assist macOS users in setting up and using the model effectively.
Key Changes
PYTORCH_ENABLE_MPS_FALLBACK=1
to enable CPU fallback for operations not supported by MPS.Benefits
Testing
The changes have been tested on a MacBook Pro with an M1 Pro chip, ensuring that the model runs smoothly with the specified configurations.
Additional Notes