Skip to content

Conversation

LucasSte
Copy link
Contributor

@LucasSte LucasSte commented Nov 20, 2023

Fixes #77818

I saw that PR #99246 was approved, but no one fixed the rebase conflicts, so I am bringing this up again to be merged.
I am leveraging @mattiaspaul work. Quoting the description here:

  • this pull request enables 3D convolutions (forward/backward) for MPS (Apple Silicon) within the same Convolution.mm file as conv2d.
  • does not support channel_last (since pytorch doesn't implement channel_last for 3D tensors)
  • does not support conv3d_transpose and treats depth-separable convolutions not as normal case (there are no MPS kernels available for either of those so far)
  • requires MacOS >=13.2 (Ventura)

Please, let me know if there are any other changes needed and I'll be happy to implement them.

cc @kulinseth @albanD @malfet @DenisVieriu97 @razarmehr

Signed-off-by: Lucas Steuernagel <lucas.tnagel@gmail.com>
@LucasSte LucasSte requested a review from kulinseth as a code owner November 20, 2023 22:49
@pytorch-bot pytorch-bot bot added ciflow/mps Run MPS tests (subset of trunk) release notes: mps Release notes category labels Nov 20, 2023
Copy link

linux-foundation-easycla bot commented Nov 20, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

pytorch-bot bot commented Nov 20, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/114183

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (3 Unrelated Failures)

As of commit 61b2bae with merge base 8c4812b (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

UNSTABLE - The following job failed but was likely due to flakiness present on trunk and has been marked as unstable:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@LucasSte
Copy link
Contributor Author

LucasSte commented Nov 20, 2023

If someone can reopen #99246 and merge it, I would be happy to close this PR, as #99246 is from the original author.

@LucasSte LucasSte marked this pull request as draft November 21, 2023 19:07
@LucasSte LucasSte force-pushed the conv-3d-mps branch 3 times, most recently from ae32e68 to de4da94 Compare November 21, 2023 21:02
Signed-off-by: Lucas Steuernagel <lucas.tnagel@gmail.com>
@LucasSte LucasSte marked this pull request as ready for review November 27, 2023 21:25
@LucasSte
Copy link
Contributor Author

LucasSte commented Nov 27, 2023

Either the build CI does not have the newer MacOS SDK or it is still running MacOS 12, because it does not work without the conditional compilation statement I added: #ifdef MAC_OS_VERSION_13_2.

On the other hand, the CI test job is on MacOS 13.2.1. This means the code for Conv3D is not compiled, but the test for it is executed, leading to a segmentation fault.

@kulinseth
Can someone explain how the CI jobs are configured? (MacOS version and SDK version)

@LucasSte LucasSte force-pushed the conv-3d-mps branch 2 times, most recently from e85e47b to c81e901 Compare November 27, 2023 22:42
Signed-off-by: Lucas Steuernagel <lucas.tnagel@gmail.com>
@LucasSte LucasSte force-pushed the conv-3d-mps branch 2 times, most recently from 8a4849f to c9950e1 Compare November 28, 2023 13:41
@malfet malfet added the ciflow/periodic Trigger jobs ran periodically on master (periodic.yml) on the PR label Dec 15, 2023
@malfet
Copy link
Contributor

malfet commented Dec 15, 2023

@pytorchbot merge -f "Lint + MPS are green"

@pytorchmergebot
Copy link
Collaborator

The merge job was canceled. If you believe this is a mistake, then you can re trigger it through pytorch-bot.

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@motannhoff
Copy link

how do i make this work? still getting same "Conv3d is not supported on MPS" error when using SVD on comfyUI on M2 MBP Ventura 13.5.2 thank you :)

@cwallen
Copy link

cwallen commented Dec 17, 2023

@motannhoff SVD in comfyUI is now working for me on my M2, though it feels really slow.
If you are still seeing the same error, my first guess would be to make sure you have the latest nightly with it included. I ran pip3 install --force-reinstall --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu and look for version numbers of at least the 16th.

@laochake
Copy link

@motannhoff SVD in comfyUI is now working for me on my M2, though it feels really slow. If you are still seeing the same error, my first guess would be to make sure you have the latest nightly with it included. I ran pip3 install --force-reinstall --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu and look for version numbers of at least the 16th.

I followed your instructions and ran 'pip3 install --force-reinstall --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu' on M2. However, when running svd, I still encountered the error 'RuntimeError: Conv3D is not supported on MPS'. I have been stuck for a few days now. Could you please provide more details on how you managed to run it?

@motannhoff
Copy link

@motannhoff SVD in comfyUI is now working for me on my M2, though it feels really slow. If you are still seeing the same error, my first guess would be to make sure you have the latest nightly with it included. I ran pip3 install --force-reinstall --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu and look for version numbers of at least the 16th.

I followed your instructions and ran 'pip3 install --force-reinstall --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu' on M2. However, when running svd, I still encountered the error 'RuntimeError: Conv3D is not supported on MPS'. I have been stuck for a few days now. Could you please provide more details on how you managed to run it?

same for me. still getting error.

@LucasSte LucasSte deleted the conv-3d-mps branch December 17, 2023 18:26
@reforia
Copy link

reforia commented Dec 18, 2023

Managed to run successfully on M3 Max w/ ComfyUI on 12/16, for ppl. still see the Conv3D is not supported, make sure that the torchvision and torchaudio is installed w/ --no-dep flag, otherwise they will force uninstall the dev231216 version and install back dev231215 version of torch nightly.

So my approach is force install torch 231216 (and upwards)
pip install https://download.pytorch.org/whl/nightly/cpu/torch-2.3.0.dev20231216-cp311-none-macosx_11_0_arm64.whl

then
pip install torchvision==0.18.0.dev20231215 torchaudio==2.2.0.dev20231215 --no-deps

Prob. soon they will update their dependency to something higher than 20231215, then it should just work with normal installation method

Speed is around 11s/it for a 768*512 image, so a 14 frams vid took bout 3 mins

guilhermeleobas pushed a commit to guilhermeleobas/pytorch that referenced this pull request Dec 18, 2023
Fixes pytorch#77818

I saw that PR pytorch#99246 was approved, but no one fixed the rebase conflicts, so I am bringing this up again to be merged.
I am leveraging @mattiaspaul work. Quoting the description here:

> * this pull request enables 3D convolutions (forward/backward) for MPS (Apple Silicon) within the same Convolution.mm file as conv2d.
> * does not support channel_last (since pytorch doesn't implement channel_last for 3D tensors)
> * does not support conv3d_transpose and treats depth-separable convolutions not as normal case (there are no MPS kernels available for either of those so far)
> * requires MacOS >=13.2 (Ventura)

Please, let me know if there are any other changes needed and I'll be happy to implement them.

Pull Request resolved: pytorch#114183
Approved by: https://github.com/malfet
@MoranARM
Copy link

MoranARM commented Dec 19, 2023

Managed to run successfully on M3 Max w/ ComfyUI on 12/16, for ppl. still see the Conv3D is not supported, make sure that the torchvision and torchaudio is installed w/ --no-dep flag, otherwise they will force uninstall the dev231216 version and install back dev231215 version of torch nightly.

So my approach is force install torch 231216 (and upwards) pip install https://download.pytorch.org/whl/nightly/cpu/torch-2.3.0.dev20231216-cp311-none-macosx_11_0_arm64.whl

then pip install torchvision==0.18.0.dev20231215 torchaudio==2.2.0.dev20231215 --no-deps

Prob. soon they will update their dependency to something higher than 20231215, then it should just work with normal installation method

Speed is around 11s/it for a 768*512 image, so a 14 frams vid took bout 3 mins

Tried this method and got it to work for a single run, but when trying to generate another video I'm getting an error about a leaked semaphor, not sure if anyone else is getting this or how to force it to de-allocate the semaphor:

/AppleInternal/Library/BuildRoots/0032d1ee-80fd-11ee-8227-6aecfccc70fe/Library/Caches/com.apple.xbs/Sources/MetalPerformanceShaders/MPSCore/Types/MPSNDArray.mm:761: failed assertion `[MPSNDArray initWithDevice:descriptor:] Error: total bytes of NDArray > 2**32'
Abort trap: 6           python main.py --force-fp16
/lib/python3.10/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown 

Tried on M3 Max 128G, python 3.10.12

Also if there is a better place to discuss this than a closed github merge I'll gladly move the discussion there

@gabrie
Copy link

gabrie commented Dec 19, 2023

Managed to run successfully on M3 Max w/ ComfyUI on 12/16, for ppl. still see the Conv3D is not supported, make sure that the torchvision and torchaudio is installed w/ --no-dep flag, otherwise they will force uninstall the dev231216 version and install back dev231215 version of torch nightly.

So my approach is force install torch 231216 (and upwards) pip install https://download.pytorch.org/whl/nightly/cpu/torch-2.3.0.dev20231216-cp311-none-macosx_11_0_arm64.whl

then pip install torchvision==0.18.0.dev20231215 torchaudio==2.2.0.dev20231215 --no-deps

Prob. soon they will update their dependency to something higher than 20231215, then it should just work with normal installation method

Speed is around 11s/it for a 768*512 image, so a 14 frams vid took bout 3 mins

This solution seems working, I got one extra error, then set env with "PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0"
Then it is working, but slow.

dmenig pushed a commit to dmenig/pytorch that referenced this pull request Dec 21, 2023
Fixes pytorch#77818

I saw that PR pytorch#99246 was approved, but no one fixed the rebase conflicts, so I am bringing this up again to be merged.
I am leveraging @mattiaspaul work. Quoting the description here:

> * this pull request enables 3D convolutions (forward/backward) for MPS (Apple Silicon) within the same Convolution.mm file as conv2d.
> * does not support channel_last (since pytorch doesn't implement channel_last for 3D tensors)
> * does not support conv3d_transpose and treats depth-separable convolutions not as normal case (there are no MPS kernels available for either of those so far)
> * requires MacOS >=13.2 (Ventura)

Please, let me know if there are any other changes needed and I'll be happy to implement them.

Pull Request resolved: pytorch#114183
Approved by: https://github.com/malfet
@YexiongLin
Copy link

Managed to run successfully on M3 Max w/ ComfyUI on 12/16, for ppl. still see the Conv3D is not supported, make sure that the torchvision and torchaudio is installed w/ --no-dep flag, otherwise they will force uninstall the dev231216 version and install back dev231215 version of torch nightly.

So my approach is force install torch 231216 (and upwards) pip install https://download.pytorch.org/whl/nightly/cpu/torch-2.3.0.dev20231216-cp311-none-macosx_11_0_arm64.whl

then pip install torchvision==0.18.0.dev20231215 torchaudio==2.2.0.dev20231215 --no-deps

Prob. soon they will update their dependency to something higher than 20231215, then it should just work with normal installation method

Speed is around 11s/it for a 768*512 image, so a 14 frams vid took bout 3 mins

It works, the versions are

torch 2.3.0.dev20231216
torchaudio 2.2.0.dev20231116
torchvision 0.18.0.dev20231216

Tried on M3, python 3.11.5

@bmh2127
Copy link

bmh2127 commented Mar 19, 2025

@mattiaspaul @LucasSte Why is this closed? I am able to successfully use ConvTranspose3D when following the directions here:
https://biofrenk.hashnode.dev/running-convtranspose3d-with-mps-acceleration-on-apple-silicon-macs
Is there a way it can be merged to main?

@p-iosifidis
Copy link

p-iosifidis commented Apr 16, 2025

@mattiaspaul @LucasSte Why is this closed? I am able to successfully use ConvTranspose3D when following the directions here: https://biofrenk.hashnode.dev/running-convtranspose3d-with-mps-acceleration-on-apple-silicon-macs Is there a way it can be merged to main?

How did you manage to compile that? It's crashing and burning over here.
Huh, figured it out ... apparently it couldn't find it, not sure why. I set the flags manually.

export SDKROOT=$(xcrun --show-sdk-path)
export CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
export CXX=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++

-- the original error --

-- The OBJC compiler identification is AppleClang 16.0.0.16000026
-- The OBJCXX compiler identification is AppleClang 16.0.0.16000026
-- Detecting OBJC compiler ABI info
-- Detecting OBJC compiler ABI info - failed
-- Check for working OBJC compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working OBJC compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - broken
CMake Error at /Users/petros/_tmp/pytorch_MPS/venv/lib/python3.10/site-packages/cmake/data/share/cmake-3.25/Modules/CMakeTestOBJCCompiler.cmake:67 (message):
  The Objective-C compiler

    "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Users/petros/_tmp/pytorch_MPS/pytorch/build/CMakeFiles/CMakeScratch/TryCompile-FpJpx8
    
    Run Build Command(s):/Users/petros/_tmp/pytorch_MPS/venv/bin/ninja cmTC_3171c && [1/2] Building OBJC object CMakeFiles/cmTC_3171c.dir/testObjCCompiler.m.o
    [2/2] Linking OBJC executable cmTC_3171c
    FAILED: cmTC_3171c 
    : && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -arch arm64 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -L/opt/homebrew/opt/qt@5/lib: -rdynamic CMakeFiles/cmTC_3171c.dir/testObjCCompiler.m.o -o cmTC_3171c   && :
    ld: warning: search path '/opt/homebrew/opt/qt@5/lib:' not found
    ld: library 'System' not found
    cc: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  caffe2/CMakeLists.txt:816 (enable_language)


-- Configuring incomplete, errors occurred!

@openSourcerer9000
Copy link

@LucasSte @malfet @kulinseth is conv3d supported on mps now in the latest version or not? All video generation models are broken on mps, I'm wondering if this is the reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/mps Run MPS tests (subset of trunk) ciflow/periodic Trigger jobs ran periodically on master (periodic.yml) on the PR ciflow/trunk Trigger trunk jobs on your pull request Merged module: mps Related to Apple Metal Performance Shaders framework open source release notes: mps Release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

torch.nn.Conv3D on MPS backend