Skip to content

Feature: Add macOS MPS support#69

Open
ldspnbf wants to merge 1 commit into
coendevente:mainfrom
ldspnbf:feature/mps-support
Open

Feature: Add macOS MPS support#69
ldspnbf wants to merge 1 commit into
coendevente:mainfrom
ldspnbf:feature/mps-support

Conversation

@ldspnbf
Copy link
Copy Markdown

@ldspnbf ldspnbf commented Nov 11, 2025

Closes #68

This PR adds support for PyTorch MPS (Metal Performance Shaders) acceleration on macOS devices.

Changes included:

  • Upgraded PyTorch dependency in requirements.txt and pyproject.toml to support MPS operations.
  • Modified server/nninteractive_slicer_server/main.py to automatically detect and use torch.device("mps") when available.

This allows Mac users to utilize their GPU for inference.

@coendevente
Copy link
Copy Markdown
Owner

Thank you for your contribution. I think it'd be great to have the server work on macOS.

I tried out your code on my MacBook (M1 Pro) and it doesn't seem to work, though. When I try to build using build.sh, I get the following error:

[+] Building 4.5s (6/18)                                                                                                                                   
 => [internal] load build definition from Dockerfile                                                                                                  0.0s
 => => transferring dockerfile: 37B                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                     0.0s
 => => transferring context: 2B                                                                                                                       0.0s
 => [internal] load metadata for docker.io/library/ubuntu:20.04                                                                                       0.4s
 => CACHED [ 1/14] FROM docker.io/library/ubuntu:20.04@sha256:8feb4d8ca5354def3d8fce243717141ce31e2c428701f6682bd2fafe15388214                        0.0s
 => [internal] load build context                                                                                                                     0.0s
 => => transferring context: 262B                                                                                                                     0.0s
 => ERROR [ 2/14] RUN apt-get update && apt-get install -y wget python3.12 python3.12-pip                                                             4.0s
------                                                                                                                                                     
 > [ 2/14] RUN apt-get update && apt-get install -y wget python3.12 python3.12-pip:                                                                        
#5 0.416 Get:1 http://ports.ubuntu.com/ubuntu-ports focal InRelease [265 kB]                                                                               
#5 0.957 Get:2 http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease [128 kB]                                                                       
#5 1.091 Get:3 http://ports.ubuntu.com/ubuntu-ports focal-backports InRelease [128 kB]                                                                     
#5 1.219 Get:4 http://ports.ubuntu.com/ubuntu-ports focal-security InRelease [128 kB]                                                                      
#5 1.350 Get:5 http://ports.ubuntu.com/ubuntu-ports focal/multiverse arm64 Packages [139 kB]
#5 1.393 Get:6 http://ports.ubuntu.com/ubuntu-ports focal/restricted arm64 Packages [1317 B]
#5 1.393 Get:7 http://ports.ubuntu.com/ubuntu-ports focal/main arm64 Packages [1234 kB]
#5 1.614 Get:8 http://ports.ubuntu.com/ubuntu-ports focal/universe arm64 Packages [11.1 MB]
#5 2.092 Get:9 http://ports.ubuntu.com/ubuntu-ports focal-updates/main arm64 Packages [3822 kB]
#5 2.293 Get:10 http://ports.ubuntu.com/ubuntu-ports focal-updates/universe arm64 Packages [1505 kB]
#5 2.330 Get:11 http://ports.ubuntu.com/ubuntu-ports focal-updates/restricted arm64 Packages [82.9 kB]
#5 2.331 Get:12 http://ports.ubuntu.com/ubuntu-ports focal-updates/multiverse arm64 Packages [14.9 kB]
#5 2.331 Get:13 http://ports.ubuntu.com/ubuntu-ports focal-backports/universe arm64 Packages [27.8 kB]
#5 2.332 Get:14 http://ports.ubuntu.com/ubuntu-ports focal-backports/main arm64 Packages [54.8 kB]
#5 2.333 Get:15 http://ports.ubuntu.com/ubuntu-ports focal-security/restricted arm64 Packages [77.0 kB]
#5 2.338 Get:16 http://ports.ubuntu.com/ubuntu-ports focal-security/universe arm64 Packages [1214 kB]
#5 2.361 Get:17 http://ports.ubuntu.com/ubuntu-ports focal-security/main arm64 Packages [3425 kB]
#5 2.449 Get:18 http://ports.ubuntu.com/ubuntu-ports focal-security/multiverse arm64 Packages [8083 B]
#5 2.805 Fetched 23.4 MB in 3s (9032 kB/s)
#5 2.805 Reading package lists...
#5 3.338 Reading package lists...
#5 3.803 Building dependency tree...
#5 3.890 Reading state information...
#5 3.943 E: Unable to locate package python3.12-pip
#5 3.943 E: Couldn't find any package by glob 'python3.12-pip'
#5 3.943 E: Couldn't find any package by regex 'python3.12-pip'
------
executor failed running [/bin/sh -c apt-get update && apt-get install -y wget python3.12 python3.12-pip]: exit code: 100

Does the build.sh actually work in your case on a macOS machine?

The fact that you use a different base image seems to cause issues. Furthermore, since you don't use a base image with cuda installed already anymore, I expect this will fail on machines with CUDA supported GPUs, now. Haven't tested this yet, though.

Also, I spotted another issue in your PR. You update the torch version to 2.9.0. However, the nnInteractive authors explicitly instruct not to use this version:

⚠️ Temporary Compatibility Warning
There is a known issue with PyTorch 2.9.0 causing OOM errors during inference in nnInteractive (related to 3D convolutions — see the PyTorch issue pytorch/pytorch#166122).
Until this is resolved, please use PyTorch 2.8.0 or earlier.

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.

Feature: Add macOS MPS support

2 participants