spotify / basic-pitch

A lightweight yet powerful audio-to-MIDI converter with pitch bend detection
https://basicpitch.io
Apache License 2.0
3.45k stars 272 forks source link

Mac M1 illegal hardware instruction #52

Closed briansorahan closed 6 months ago

briansorahan commented 1 year ago

I'm on Mac OS Monterey version 12.6 Just pip installed this tool and tried to run it against a wav file and got this error

basic-pitch ~/basic-pitch-output kay_laughing.wav

✨✨✨✨✨✨✨✨✨
✨ Basic Pitch  ✨
✨✨✨✨✨✨✨✨✨

Importing Tensorflow (this may take a few seconds)...
[1]    41863 illegal hardware instruction  basic-pitch ~/basic-pitch-output kay_laughing.wav

I tried adding the --debug-file option to the above command to see if I could get any more info to share but the file was never even created.

Pls let me know what other info would be useful!

Here is the output of pip show

pip show basic-pitch
Name: basic-pitch
Version: 0.2.0
Summary: Basic Pitch, a lightweight yet powerful audio-to-MIDI converter with pitch bend detection.
Home-page: https://github.com/spotify/basic-pitch
Author: Spotify
Author-email: basic-pitch@spotify.com
License: Apache 2.0
Location: /Users/brian.soraham/miniconda3/lib/python3.9/site-packages
Requires: librosa, resampy, typing-extensions, mir-eval, tensorflow, pretty-midi, scipy
Required-by:

and I'm on python 3.9.7

zhouyijian commented 1 year ago

x86_64 tensorflow has this bug, you can use arm64 tensorflow

jonch070 commented 1 year ago

Also having trouble with this!

dohertyguirand commented 1 year ago

Hi @briansorahan, thank you for flagging this! Are you able to upgrade to python 3.10? We are currently unable to support M1 hardware using older versions of python. Let me know if you run into issues with python 3.10.

You can also use a virtual machine for Windows or Mac with Intel hardware. I am working on documentation on how to do that now.

dohertyguirand commented 1 year ago

Hi @jonch070, which version of python are you using? If you using a version less than 3.10 and have M1 hardware, try upgrading to python 3.10. We are currently unable to support M1 hardware using older versions of python.

briansorahan commented 1 year ago

I'll give 3.10 a try today

burcellf commented 1 year ago

Hello, I'm also having the same 'illegal hardware instruction' error. I'm using: Macbook Pro M1 MacOS 13.1 created a venv with Python 3.10

I also tried switching between the x86_64 and the arm64, but haven't been able to get this to run. Let me know what I can do to help.

Thank you in advance for your help as I'm really looking forward to trying out this package!

dohertyguirand commented 1 year ago

Hey @burcellf, thanks for your message. What command did you run to install basic-pitch? Also which version of basic-pitch do you have?

burcellf commented 1 year ago

Hey @dohertyguirand, thank you for your prompt reply.

I installed basic-pitch using the following command:

conda create -c conda-forge  -n basic_pitch python=3.10

the .__version__ command says I'm running version: 0.2.4

dohertyguirand commented 1 year ago

@burcellf Try installing with pip as we haven't made a proper conda installation.

briansorahan commented 1 year ago

Here are the changes in my environment

python

python --version
Python 3.10.11

basic-pitch

Name: basic-pitch
Version: 0.2.4
Summary: Basic Pitch, a lightweight yet powerful audio-to-MIDI converter with pitch bend detection.
Home-page: https://github.com/spotify/basic-pitch
Author: Spotify
Author-email: basic-pitch@spotify.com
License: Apache 2.0
Location: /Users/brian.soraham/miniconda3/lib/python3.10/site-packages
Requires: librosa, mir-eval, numpy, pretty-midi, resampy, scipy, tensorflow, typing-extensions
Required-by:

tensorflow (don't think I shared this before, but including it here since maybe it's relevant)

pip show tensorflow
Name: tensorflow
Version: 2.11.1
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: packages@tensorflow.org
License: Apache 2.0
Location: /Users/brian.soraham/miniconda3/lib/python3.10/site-packages
Requires: absl-py, astunparse, flatbuffers, gast, google-pasta, grpcio, h5py, keras, libclang, numpy, opt-einsum, packaging, protobuf, setuptools, six, tensorboard, tensorflow-estimator, tensorflow-io-gcs-filesystem, termcolor, typing-extensions, wrapt
Required-by: basic-pitch

Still getting the illegal hardware instruction error.

FWIW, I also tried the same command in a miniconda3:4.12.0 container and got this

✨✨✨✨✨✨✨✨✨
✨ Basic Pitch  ✨
✨✨✨✨✨✨✨✨✨

Importing Tensorflow (this may take a few seconds)...
The TensorFlow library was compiled to use AVX instructions, but these aren't available on your machine.
qemu: uncaught target signal 6 (Aborted) - core dumped
Aborted

This was with python 3.10.11 too. I guess it's prob an issue with the virtual CPU in the VM that is running the container

dohertyguirand commented 1 year ago

@briansorahan what command did you use to install basic-pitch? M1 hardware should be using tensorflow-macos instead of tensorflow. Let me know what you used and I will try to replicate.

briansorahan commented 1 year ago

I used pip install basic-pitch but I am running my terminal (and tmux, which actually spawns my shell) with rosetta. I've had too many build failures with arm64, e.g. grpcio I should revisit this at some point though...

dohertyguirand commented 1 year ago

@briansorahan Oh I see. We currently do not support rosetta. I've tried it myself in the past with basic-pitch and haven't gotten the entire installation workflow to succeed. I would recommend using arm64 architecture.

briansorahan commented 1 year ago

@dohertyguirand Thanks! I'll give that a shot and circle back here with the results

briansorahan commented 1 year ago

I forked the repo and added a dockerfile locally since docker is oftentimes my goto solution when I have trouble installing/running things on my macbook

FROM tensorflow/tensorflow:2.13.0
RUN  pip install basic-pitch
ENTRYPOINT ["basic-pitch"]

I built the image with

docker build -t basic-pitch .

I no longer see the illegal hardware instruction error, but the command takes a really long time (I've never actually seen it complete). I'm trying to get a MIDI file output from one of the audio files in this repo

mkdir output
docker run --rm -v $(pwd):/cwd -w /cwd basic-pitch output tests/resources/vocadito_10.wav
drubinstein commented 1 year ago

How long are you experiencing? Tensorflow can take 5-10 seconds to import when running Python so it could be the overhead of the import.

briansorahan commented 1 year ago

I let it run for at least 30 minutes just to see if it would ever complete, figuring maybe the audio file I used was weird somehow and triggered an edge case

drubinstein commented 1 year ago

vocadito should be fine to work with. I'm wondering if it's a docker issue (are you using an x86 image instead of an ARM one). Regardless, I've been able to install basic-pitch on my M1 laptop and run audio through it without a problem. With tensorflow 2.13, basic-pitch 0.2.6 ran in < 10 seconds for vocadito_10.wav.

time basic-pitch /tmp  ~/git/basic-pitch/tests/resources/vocadito_10.wav
...
basic-pitch /tmp ~/git/basic-pitch/tests/resources/vocadito_10.wav  8.37s user 3.72s system 43% cpu 27.620 total

I'm curious what would happen if you tried to import tensorflow in a vanilla python shell on your machine. Otherwise, it could be helpful if you could try to pinpoint when the illegal instruction error is raised. You could try print-debugging, or the faulthandler / prepending PYTHONFAULTHANDLER=1 to your command.

rabitt commented 6 months ago

Closing due to inactivity - feel free to reopen if this issue is still persisting.