spleeter icon indicating copy to clipboard operation
spleeter copied to clipboard

[Bug] Illegal hardware instruction

Open e16m opened this issue 5 years ago • 38 comments

  • [O ] I didn't find a similar issue already open.
  • [O] I read the documentation (README AND Wiki)
  • [O] I have installed FFMpeg
  • [O] My problem is related to Spleeter only, not a derivative product (such as Webapplication, or GUI provided by others)

Description

On a windows PC, I was able to successfully run a command using 'spleeter separator test.mp3'. However, on my mac which runs macOS Big Sur with Apple M1, I get the following error when running the same command: zsh: illegal hardware instruction

My question is, is spleeter incompatible with Big Sur or Apple M1? I found that this was the case for tensorflow, and I'm curious if there is any way around this to run spleeter on my mac. Thanks.

Step to reproduce

  1. Installed using pip with python 3.8
  2. Ran as 'spleeter separator test.mp3' on terminal
  3. Got 'illegal hardware instruction' error

Output

When I run the script I get the following error: zsh: illegal hardware instruction My expectation was that it would run the same as on my PC, with a success message.

Environment

OS macOS Big Sur Version 11.1
Installation type pip
RAM available 16 GB
Hardware spec -

Additional context

e16m avatar Apr 08 '21 17:04 e16m

Hi @rappercodes, we have not tested spleeter on Apple M1 yet, and it is very likely that the issue comes from an incompatibility issue. We have no M1 available at the moment to investigate on this issue, but if you find any hints about what could fix the issue, let us know.

romi1502 avatar Apr 15 '21 14:04 romi1502

Thanks @romi1502. It does seem like an incompatibility issue. If I do come across anything I will share here.

e16m avatar Apr 15 '21 14:04 e16m

I confirm that Tensorflow compatibility with Apple M1 chip is not available at the moment, you can find some workaround based on Rosetta 2 here.

Do not hesitate to tell us if you manage to make it work with Rosetta, otherwise we will just wait a TF release that is compatible with M1 :)

Faylixe avatar Apr 15 '21 15:04 Faylixe

For those of you who want to run Spleeter on a Mac with M1 chips, you may find a guide for installing TF here:

https://drive.google.com/drive/folders/1oSipZLnoeQB0Awz8U68KYeCPsULy_dQ7?usp=sharing

And a guide for building and installing Spleeter here:

https://drive.google.com/drive/folders/1ioRr6-xRNizoR7xqWxXUdgjoijFOd2SC?usp=sharing

Note that this is a temporary fix, until TF is updated to run on these new chips. Enjoy!

d-dawg78 avatar Apr 28 '21 10:04 d-dawg78

Any updates?

kode54 avatar Oct 04 '21 00:10 kode54

?

konglong87 avatar Oct 29 '21 08:10 konglong87

Anyone able to build a whl file for an M1 Pro running python 3.9? I can't seem to get it to build with bazel. Keeps erroring out. Super annoying. Not sure why this issue is closed. It should remain OPEN until there is an easier way to get this to run on M1...

Edit:

The error has to do with numpy (Executing genrule @local_config_python//:numpy_include failed (Exit 1)).

Trying some workarounds I saw but so far its been rough trying to get this to build through bazel.

kpatdev avatar Nov 14 '21 05:11 kpatdev

is it possible to use dockerized images to workaround M1 specific issue?

vumaasha avatar Dec 10 '21 06:12 vumaasha

FWIW, I found this guide for tensorflow: https://betterprogramming.pub/installing-tensorflow-on-apple-m1-with-new-metal-plugin-6d3cb9cb00ca

I'm going to still follow the workaround for spleeter, but if having a native M1 tensorflow install was a blocker, it may no longer be.

tartale avatar Dec 11 '21 02:12 tartale

Unfortunately, none of the suggested solutions have been working for me. Would really like this to work in my M1.

overdub60 avatar Jan 12 '22 22:01 overdub60

I am attempting to install Spleeter on a MBP with M1 Max.

Apple published details of how to install Tensorflow on Apple Silicon Macs with Tensorflow Pluggable Device support for Metal here:

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

That installed Tensorflow 2.7.0

Name: tensorflow-macos
Version: 2.7.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: [email protected]
License: Apache 2.0
Location: /Users/stevenslupsky/miniforge3/lib/python3.9/site-packages
Requires: absl-py, astunparse, flatbuffers, gast, google-pasta, grpcio, h5py, keras, keras-preprocessing, libclang, numpy, opt-einsum, protobuf, six, tensorboard, tensorflow-estimator, termcolor, typing-extensions, wheel, wrapt
Required-by: 

I installed ffmpeg and libsndfile successfully. When installing spleeter, I see an enormous number of error messages. At the end is the following:

ERROR: Cannot install spleeter==2.1.0 and spleeter==2.3.0 because these package versions have conflicting dependencies.

The conflict is caused by:
    spleeter 2.3.0 depends on tensorflow==2.5.0
    spleeter 2.1.0 depends on pandas==1.1.2

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies

sslupsky avatar Jan 23 '22 00:01 sslupsky

Hi all,

We, at Deezer, managed to use Spleeter on Mac M1 using Tensorflow Metal. Here are the instructions you must follow in order to complete the installation.

  1. Upgrade your mac OS to Monterey (12.0.0+).
  2. Switch to a Rosetta terminal.
  3. Install Python 3.8. For now, we have not managed to run Metal on Python 3.9+, and Metal does not work for versions pre-3.8.
  4. Download the .whl file that can be found here, and run the following command: python -m pip install --upgrade spleeter-2.3.0b0-cp38-cp38-macosx_11_0_x86_64.whl Note that python refers to your local python3 installation. We recommend uninstalling the packages you have installed locally to avoid potential conflicting dependencies. Run the following a few times:
python -m pip freeze > requirements.txt
python -m pip uninstall -r requirements.txt -y
  1. Test your new Spleeter installation using: python -m spleeter separate -p spleeter:2stems -o output audio_example.mp3 You can check your Activity Monitor to see the GPU being used.

We have also created branch for local development using Metal. Please run the following:

git clone https://github.com/Deezer/spleeter && cd spleeter
git fetch --all
git checkout tf_metal

You are free to edit and update the dependencies in pyproject.toml and build your own .whl files using poetry install and poetry build (poetry tutorial).

Finally, please send us your feedback in the comments below. A more substantial release may follow if this fix ends up working for you!

d-dawg78 avatar Jan 25 '22 22:01 d-dawg78

Finally, please send us your feedback in the comments below. A more substantial release may follow if this fix ends up working for you!

Worked great! thank you

tartale avatar Jan 26 '22 06:01 tartale

@d-dawg78 Thank you for the update. I followed the instructions @argsnd provided in issue #696 which I think installed the developer version of spleeter with the poetry dependency manager. I installed TensorFlow Metal according to the Apple Developer link I provided above. I successfully achieved my goal of installing and running spleeter and it appears to be running for me with python 3.9.7.

sslupsky avatar Jan 26 '22 15:01 sslupsky

@sslupsky that is awesome to hear! I have been trying to get Spleeter up and running on python 3.9.7 as well and I would love if you could give like a step by step (if I should follow #696 first or installing TensorFlow Metal from the Apple dev link because it seems that both #696 and the link download metal in their steps). I am still struggling on getting it to work together, and Im not sure if everything should be done with Rosetta etc. Thank you so much in advance! I really appreciate it

MasayukiNagase avatar Jan 26 '22 18:01 MasayukiNagase

@MasayukiNagase I installed TensorFlow Metal first using the Apple Developer instructions. After that I checked the version info for tensorflow-macos and confirmed I had version 2.7.0 installed.

I then followed #696 instructions 3, 5, 6

Then edited pyproject.toml and removed dependencies for tensorflow/numpy/scipy/llvmlite/librosa/pandas. As I recall, there doesn't appear to be a dependency for llvmlite in the pyproject.toml file I edited.

Then steps 8, 9 and 10.

After this, spleeter ran for me.

I have to source ~/miniforge3/bin/activate per the Apple Developer instructions to activate the correct python environment if I close the terminal or logout.

I took a screen shot of activity monitor and attached here.

https://user-images.githubusercontent.com/16888734/151265522-0b63731c-2d5c-4691-ad4e-7e80585960ee.mp4

sslupsky avatar Jan 26 '22 23:01 sslupsky

When I try to install python 3.8 I get:

% brew install [email protected]
Error: Cannot install under Rosetta 2 in ARM default prefix (/opt/homebrew)!
To rerun under ARM use:
    arch -arm64 brew install ...
To install under x86_64, install Homebrew into /usr/local.
ansolas@Marcs-Mac-mini Downloads %  

daslicht avatar May 16 '22 09:05 daslicht

For what it's worth, I've got spleeter working perfectly without Rosetta. I had to do a bit of massaging:

  1. In pyproject.toml, under [tool.poetry.dependencies]:
    • change llvmlite to ^0.37.0
    • add protobuf = ">3.19.0,<3.21.0"
  2. Create a new conda environment: conda create -n spleeter python=3.9. Activate it with conda activate spleeter.
  3. Run poetry update --lock
  4. Install some dependencies through conda-forge: conda install -c conda-forge numpy==1.19.5 numba==0.54.1 grpcio==1.46.3 cffi==1.15.0 typed-ast==1.4.3 h5py==3.1.0 librosa==0.8.0 (Note that I grabbed the version numbers from the poetry.lock file, so if you're using a newer version of spleeter you'd need to change them. Poetry doesn't currently have a way to install dependencies using conda, sadly.)
  5. Run poetry install
  6. Test the install with spleeter separate -p spleeter:2stems -o output audio_example.mp3

Running pytest, everything passes except:

  • test_evaluate[librosa]
  • test_separate_to_file[audio_example_mono.mp3-spleeter:5stems-librosa]
  • test_filename_conflict[audio_example.mp3-spleeter:5stems]

Not sure why those three specifically.

gormster avatar Jun 06 '22 03:06 gormster

Hi, I've been trying to follow all of the above guides, and none seem to work. I am running macOS Monterey 12.6, on a Macbook Pro 2021 Apple M1 Max. When trying to install the wheel (python -m pip install --upgrade spleeter-2.3.0b0-cp38-cp38-macosx_11_0_x86_64.whl) as mentioned in d_dawgs comment (with the arch -x86_64 prefix), I get error "arch: posix_spawnp: pip: Bad CPU type in executable". Without that command: it just says "ERROR: spleeter-2.3.0b0-cp38-cp38-macosx_10_9_x86_64.whl is not a supported wheel on this platform."

I am running this inside a rosetta terminal, and when I type arch, I get "i386". Is there something I'm doing wrong to get the wheel to work?

I've also tried installing tensor flow 2.6 and python3.8 separately then using poetry install but I keep getting all different poetry errors. Not really sure what approach at this point I should take to get this to work. Any guidance would be greatly appreciated.

acronomic avatar Sep 28 '22 18:09 acronomic

I tried as per instruction here, unfortunately getting this error in output:

> python3.8 -m spleeter separate -p spleeter:2stems -o spleeter ~/My.mp3

2022-11-23 11:55:30.302187: F tensorflow/c/experimental/stream_executor/stream_executor.cc:823] Non-OK-status: stream_executor::MultiPlatformManager::RegisterPlatform( std::move(cplatform)) status: Internal: platform is already registered with name: "METAL"
[1]    87357 abort      python3.8 -m spleeter separate -p spleeter:2stems -o spleeter

devcooch avatar Nov 23 '22 10:11 devcooch