Skip to content
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

[Discussion] Spleeter works natively on Apple Silicon Macs if you use Apple's version of TensorFlow #696

Open
argsnd opened this issue Dec 22, 2021 · 15 comments
Labels
question Further information is requested

Comments

@argsnd
Copy link

argsnd commented Dec 22, 2021

Spleeter is working for me natively on my M1 Max MacBook Pro, built against Apple's Metal version of TensorFlow.

Screenshot

Instructions from memory:

  1. brew install miniforge
  2. conda init "$(basename "${SHELL}")"
  3. conda install -c apple tensorflow-deps numpy scipy llvmlite librosa pandas
  4. pip install tensorflow-macos tensorflow-metal
  5. git clone https://github.com/Deezer/spleeter && cd spleeter
  6. pip install poetry
  7. open the pyproject.toml and get rid of tensorflow/numpy/scipy/llvmlite/librosa/pandas
  8. poetry update
  9. poetry install
  10. poetry build
  11. pip install ./dist/spleeter-2.3.0-py3-none-any.whl

You might have to adapt some of these instructions, but it should broadly set you on the right path.

@romi1502
Copy link
Member

Hi @argsnd,
that's great news thanks for this solution!
we also managed to make it work on M1 but haven't communicated yet. We'll update the documentation very soon probably taking inspiration of this.

@ecb2c
Copy link

ecb2c commented Dec 25, 2021

// fixed by doing (conda install -c conda-forge poetry) not the pip install, though numpy error has shown in poetry update/install process, but it works well in poetry build for conda "base" case but I've tried several times, it's not working for conda "env" case. if you want to use multi "env" case, I think not available this moment. please let me know if succeed.

#grpcio fails to install on Apple Silicon
"grpc/grpc#25082 (comment)"

image

I've got some error message related to numpy library while progressing "poetry update/install/build", there might be conflicting with the other libraries?
-M1Pro: Monterey 12.1
-numpy: 1.19.5

image

@jkohlin
Copy link

jkohlin commented Jan 4, 2022

Puh, I finally got spleeter running, thanks for the guide @argsnd
But now I get this, and I'm stuck. What can I do?

UserWarning: resource_tracker: There appear to be 6 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '

@AlexanderPavlenko
Copy link

Got it running too. MacBook Air (M1, 2020), macOS 12.2

# https://developer.apple.com/metal/tensorflow-plugin/

conda install -c apple tensorflow-deps==2.5.0
python -m pip install tensorflow-macos==2.5.0
python -m pip install tensorflow-metal
conda install -c apple llvmlite==0.36.0 numba pandas==1.3.3

git clone --depth 1 --branch v2.3.0 https://github.com/deezer/spleeter.git
# edit pyproject.toml :
# -tensorflow = "2.5.0"
# +tensorflow-macos = "2.5.0"
python -m pip install ./spleeter

brew install libsndfile
sudo ln -s /opt/homebrew/lib/libsndfile.dylib /usr/local/lib/

@Moebits
Copy link

Moebits commented Apr 14, 2022

I haven't been able to install this. Running the commands exactly as stated in the OP results in an error in the final step that complains that tensorflow 2.5.0 was not found. I installed version 2.5.0 as shown by @AlexanderPavlenko but in the final step the build fails for all packages.

× Building wheel for numpy (pyproject.toml) did not run successfully.
× Encountered error while trying to install package.
  ╰─> llvmlite
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> grpcio

I don't want to post full output because it is quite long. I'm on macOS 12.3 M1 Pro MBP.

@sclsj
Copy link

sclsj commented Jun 28, 2022

I haven't been able to install this. Running the commands exactly as stated in the OP results in an error in the final step that complains that tensorflow 2.5.0 was not found. I installed version 2.5.0 as shown by @AlexanderPavlenko but in the final step the build fails for all packages.

× Building wheel for numpy (pyproject.toml) did not run successfully.
× Encountered error while trying to install package.
  ╰─> llvmlite
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> grpcio

I don't want to post full output because it is quite long. I'm on macOS 12.3 M1 Pro MBP.

@Tenpi Check out the new instructions here: #607 (comment)

Following the exact steps, I can get it to work on macOS 12.3.1 M1 Max MBP.

@daslicht
Copy link

is it normal that resolving dependencies takes that long and counting

Resolving dependencies... (398.9s)

@cmdecker95
Copy link

cmdecker95 commented Sep 2, 2022

Got it running too. MacBook Air (M1, 2020), macOS 12.2

# https://developer.apple.com/metal/tensorflow-plugin/

conda install -c apple tensorflow-deps==2.5.0
python -m pip install tensorflow-macos==2.5.0
python -m pip install tensorflow-metal
conda install -c apple llvmlite==0.36.0 numba pandas==1.3.3

git clone --depth 1 --branch v2.3.0 https://github.com/deezer/spleeter.git
# edit pyproject.toml :
# -tensorflow = "2.5.0"
# +tensorflow-macos = "2.5.0"
python -m pip install ./spleeter

brew install libsndfile
sudo ln -s /opt/homebrew/lib/libsndfile.dylib /usr/local/lib/

@AlexanderPavlenko
This worked for me, thanks!

@sudocurse
Copy link

Hey, if anyone's willing to experiment, I got it working over here using m1 native tensorflow but couldn't get past what i believe was a circular dependency issue. If you can figure out how to do it using those instructions on my fork, patches are welcome!

@WMRamadan
Copy link

Is this not officially supported for arm64?

@prince-ravi-leow
Copy link

Got it running too. MacBook Air (M1, 2020), macOS 12.2

# https://developer.apple.com/metal/tensorflow-plugin/

conda install -c apple tensorflow-deps==2.5.0
python -m pip install tensorflow-macos==2.5.0
python -m pip install tensorflow-metal
conda install -c apple llvmlite==0.36.0 numba pandas==1.3.3

git clone --depth 1 --branch v2.3.0 https://github.com/deezer/spleeter.git
# edit pyproject.toml :
# -tensorflow = "2.5.0"
# +tensorflow-macos = "2.5.0"
python -m pip install ./spleeter

brew install libsndfile
sudo ln -s /opt/homebrew/lib/libsndfile.dylib /usr/local/lib/

Thank you SO much for this.
I'm a novice coder, so python and dependency debugging is very difficult for me.
You won't believe it, but I've been trying for around a YEAR to get it to work on apple silicon, and only after following (and slightly adapting your steps to newer dependency versions) was I able to get it to work.
Again thanks so much, I'm so happy!

@hqt98
Copy link

hqt98 commented Feb 10, 2023

@prince-ravi-leow Hi, could you share how you adapt the steps to newer dep versions? I'm kinda struggling to make it work on M1 with the steps listed.

@prince-ravi-leow
Copy link

prince-ravi-leow commented Feb 12, 2023

Hi there. 👋

I've done my best to adapt the steps, I took to get spleeter running on my machine.

My installation info:

  • macOS Ventura 13.1, 8C M1 Pro
  • Python version 3.10.8
  • conda subdir osx-64 - (see Conda env section for more info)
  • Carried out on 28th Jan 2023
  • Successfully installed spleeter version 2.3.3

Pre-requisites:

  • You have installed and set up conda
  • You have installed and set up homebrew

Adapted From AlexanderPavlenko’s answer on: #696

Conda environment

Create new conda env (Note: I used tested this with 3.10, so adjust the installation as needed)

If you go through my instructions and they don't work the first time, try create a new env, re-configure it to subdir: osx-64, and try again.
This is assuming that your conda environment is configured in to run in 'ARM mode'. You can verify this by by running:
conda config --show. If you're in ARM mode, it'll display: subdir: osx-arm, if you're in x86 mode, it'll display: subdir: osx-64. You can change from subdir ARM to x68 at an environment level, with: conda config --env --set subdir osx-64

Tensorflow dependancies for apple silicon

Install latest tensorflow-deps (conda couldn't find them by default, so I had to manually install the tarballs directly from https://anaconda.org/apple/tensorflow-deps/files (2.10.0 at time of installation)):
conda install package.tar.gz

Install latest tensorflow-macos (2.11.0 at time of installation):
python -m pip install tensorflow-macos==2.X.X (adjust according to need)

Install latest tensorflow-metal (0.7.0 at time of installation):
python -m pip install tensorflow-metal

Run:
conda install -c apple llvmlite numba pandas
(Honestly, I don't know why this step is necessary, but I followed Alex's instructions and it worked)

It may say that tensorflow-deps dependencies are causing an error - ignore and allow installation to proceed

Clone spleeter repo

cd <spleeter_env_location>

git clone https://github.com/Deezer/spleeter

Configure poetry file

pip install poetry

Edit pyproject.toml (located in cloned spleeter directory):
Remove: tensorflow = "2.X.X"
Remove: llvmlite (Alex's guide specified to remove numpy and pandas, but in my experience, they were not present)
Add: tensorflow-macos = “<version_installed>”

Install the d*mn thing

python -m pip install ./spleeter

Finishing touches (for media encoding/export)

brew install libsndfile (if not already)

(Optional: sudo ln -s /opt/homebrew/lib/libsndfile.dylib /usr/local/lib/)

Epilogue

If this STILL doesn't work for you, find Alex's original comment, and try and adapt them on your own - they are much more general than my case, and maybe a different operation will suit you best.

Hope you get it up and running! 🙏

@junlan0050
Copy link

Hi there. 👋

I've done my best to adapt the steps, I took to get spleeter running on my machine.

My installation info:

  • macOS Ventura 13.1, 8C M1 Pro
  • Python version 3.10.8
  • conda subdir osx-64 - (see Conda env section for more info)
  • Carried out on 28th Jan 2023
  • Successfully installed spleeter version 2.3.3

Pre-requisites:

  • You have installed and set up conda
  • You have installed and set up homebrew

Adapted From AlexanderPavlenko’s answer on: #696

Conda environment

Create new conda env (Note: I used tested this with 3.10, so adjust the installation as needed)

If you go through my instructions and they don't work the first time, try create a new env, re-configure it to subdir: osx-64, and try again. This is assuming that your conda environment is configured in to run in 'ARM mode'. You can verify this by by running: conda config --show. If you're in ARM mode, it'll display: subdir: osx-arm, if you're in x86 mode, it'll display: subdir: osx-64. You can change from subdir ARM to x68 at an environment level, with: conda config --env --set subdir osx-64

Tensorflow dependancies for apple silicon

Install latest tensorflow-deps (conda couldn't find them by default, so I had to manually install the tarballs directly from https://anaconda.org/apple/tensorflow-deps/files (2.10.0 at time of installation)): conda install package.tar.gz

Install latest tensorflow-macos (2.11.0 at time of installation): python -m pip install tensorflow-macos==2.X.X (adjust according to need)

Install latest tensorflow-metal (0.7.0 at time of installation): python -m pip install tensorflow-metal

Run: conda install -c apple llvmlite numba pandas (Honestly, I don't know why this step is necessary, but I followed Alex's instructions and it worked)

It may say that tensorflow-deps dependencies are causing an error - ignore and allow installation to proceed

Clone spleeter repo

cd <spleeter_env_location>

git clone https://github.com/Deezer/spleeter

Configure poetry file

pip install poetry

Edit pyproject.toml (located in cloned spleeter directory): Remove: tensorflow = "2.X.X" Remove: llvmlite (Alex's guide specified to remove numpy and pandas, but in my experience, they were not present) Add: tensorflow-macos = “<version_installed>”

Install the d*mn thing

python -m pip install ./spleeter

Finishing touches (for media encoding/export)

brew install libsndfile (if not already)

(Optional: sudo ln -s /opt/homebrew/lib/libsndfile.dylib /usr/local/lib/)

Epilogue

If this STILL doesn't work for you, find Alex's original comment, and try and adapt them on your own - they are much more general than my case, and maybe a different operation will suit you best.

Hope you get it up and running! 🙏

Thanks for the detailed solution! I've encountered one problem using the tensorflow-macos version 2.11.0. But after I upgraded to the latest version, everything works fine now.

@d13g0
Copy link

d13g0 commented Mar 24, 2024

I followed @junlan0050 procedure.

My setup:

  • I have a 2022 Apple MacBookPro M1
  • my default conda channel is conda-forge
  • I ran this on March 2024
    -I created a conda environment for python 3.10

After following the procedure I was getting an error:

AttributeError: module 'tensorflow' has no attribute 'estimator'

I checked the version of tensorflow: 2.16.1

I uninstalled tensorflow:

pip uninstall tensorflow tensorboard

Then I reinstalled with this version:

pip install tensorflow==2.13.0

Then spleeter worked for me. I hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests