bmvandoren / Nighthawk

Nighthawk is a machine learning model for acoustic monitoring of nocturnal bird migration.
Other
21 stars 4 forks source link

Installation yields wrong version of TensorFlow on M1 Macs. #5

Open HaroldMills opened 1 year ago

HaroldMills commented 1 year ago

On Kevin Tolan's M1 MacBook Pro, Nighthawk 0.1.0 gets installed with the regular tensorflow package instead of with Apple's tensorflow-macos package, and this causes nighthawk to fail because of an illegal machine instruction when it runs.

Nighthawk's pyproject.toml file aims to install TensorFlow in the form of the tensorflow-macos package on Apple silicon (i.e. M1 and M2) Macs and the regular tensorflow package everywhere else. It tries to do this with conditional dependencies that look at the platform_system and platform_machine environment markers, assuming that they will be "Darwin" and "arm64" if and only if the platform is an Apple silicon one. That works for my M2 Mac mini, but not for Kevin's M1 MacBook Pro. The marker values there are "Darwin" and "x86_64", which unfortunately are the same as for Intel Macs (or at least my 2019 MacBook Pro).

I do not see other markers in PEP 508 that seem like they would be useful for identifying Apple silicon Macs, and Google searches have not turned up a solution. A workaround that seemed to work in Kevin's case was to install the wrong TensorFlow package with Nighthawk and then do:

pip uninstall tensorflow
pip install tensorflow-mac

to replace it with the correct one.

ses4j commented 1 year ago

@HaroldMills That is surprising behavior, since M1 is arm64. What does Kevin's box return when he runs this on commandline?

python -c "import platform; print(platform.machine())"

? It should be 'arm64'.

HaroldMills commented 1 year ago

@ses4j The following script:

import platform

print(f'machine: {platform.machine()}')
print(f'processor: {platform.processor()}')
print(f'system: {platform.system()}')

yielded:

machine: x86_64
processor: i386
system: Darwin

when we ran it yesterday on Kevin's computer. I think this might be because he's using an x86_64 Python via Rosetta, and hope to get some more Zoom time with him to look into that.

Do you have an M1 Mac?

ses4j commented 1 year ago

I don't, but I was doublechecking with a coworker who does. His gives arm64. And yeah, I think your guess about his Python interpreter must be right (or he doesn't have the computer he thinks he does ;) ) Try the command line arch and see what that gives. It doesn't use the python interpreter...