bioimage-io / core-bioimage-io-python

Python libraries for loading, running and packaging bioimage.io models
https://bioimage-io.github.io/core-bioimage-io-python/
MIT License
27 stars 21 forks source link

zsh: illegal hardware instruction #125

Open esgomezm opened 2 years ago

esgomezm commented 2 years ago

Hi!

I'm trying to test a model that pass the validation test but I get the following message, both with test-model and predict-image:

(bio-core-dev) esti@estimacbookair BioImageIO % bioimageio validate models/arabidopsis_03JUN2021.bioimage.io.model/model.yaml
No validation errors for models/arabidopsis_03JUN2021.bioimage.io.model/model.yaml

(bio-core-dev) esti@estimacbookair BioImageIO % bioimageio test-model models/arabidopsis_03JUN2021.bioimage.io.model/model.yaml 
zsh: illegal hardware instruction  bioimageio test-model 

(bio-core-dev) esti@estimacbookair BioImageIO % bioimageio predict-image models/arabidopsis_03JUN2021.bioimage.io.model/model.yaml --inputs models/arabidopsis_03JUN2021.bioimage.io.model/exampleImage.npy --outputs models/arabidopsis_03JUN2021.bioimage.io.model/resultImage.npy
zsh: illegal hardware instruction  bioimageio predict-image  --inputs  --outputs 

I'm testing it in macOS

constantinpape commented 2 years ago

This is a weird one... I tried this on linux and the commands work as expected (there are some test errors, but that's unrelated).

@esgomezm Could you try running this with bash instead of zshell?

Could someone with access to a mac also test this? @k-dominik or @akreshuk? Maybe we should also add Mac to the CI. @esgomezm is trying with this model: https://bioimage.io/#/?id=10.5072%2Fzenodo.849110

oeway commented 2 years ago

I think I saw this error before for some ImJoy plugins, I guess it's tensorflow-1 model right? Some tensorflow precompiled binary used instructions that are not supported by some old mac. There is little we can do about it except black list some tensorflow-1 versions for MacOS.

constantinpape commented 2 years ago

@esgomezm which mac version are you using?

oeway commented 2 years ago

@constantinpape As I understand, it's more about the CPU itself doesn't support those instructions, so we should also know whether it's an old mac hardware or not. @esgomezm Is it a new or old mac computer?

constantinpape commented 2 years ago

(Yes, I was thinking this might be BigSur / M1 related)

esgomezm commented 2 years ago

It's a new one with M1 processor

oeway commented 2 years ago

It's a new one with M1 processor

Oh, so @constantinpape you are right, then we need to perhaps to somehow detect that and use a tensorflow version compiled for that?

k-dominik commented 2 years ago

Did you install tesorflow via conda @esgomezm ?

constantinpape commented 2 years ago

Oh, so @constantinpape you are right, then we need to perhaps to somehow detect that and use a tensorflow version compiled for that?

I am not really sure how we could autodetect that, but we can maybe offer an environment file for BigSur. It seems like there are pip packages available: https://stackoverflow.com/questions/65521255/installing-tensorflow-on-mac-os-big-sur-with-pip (But note that it's very unlikely there will be anything for tf1, which might be needed for this model)

oeway commented 2 years ago

I am thinking about print a warning or error in the setup.py if it's M1. Here is some code made by others:

import platform
import subprocess

def isMac():
    return platform.system() == "Darwin"

def getProcessorMac():
    return subprocess.check_output(['sysctl','-n','machdep.cpu.brand_string']).decode('utf-8')

def isM1():
    return getProcessorMac() == "Apple M1\n"

if(isMac()):
    print(isM1())

Ref: https://www.youtube.com/watch?v=_uzZ5vD4uNw https://pastebin.com/B7d71D5G

constantinpape commented 2 years ago

I am thinking about print a warning or error in the setup.py if it's M1. Here is some code made by others:

Yes, that's a good solution for the setup.py. But it will still be tough to put together working envs for BigSur. I think for now we should add this and also add a warning to the README.

esgomezm commented 2 years ago

Did you install tesorflow via conda @esgomezm ?

Not sure. I followed your instructions which create a new conda environment and pip for the dependencies:

conda env create -f dev/environment-base.yaml
conda activate bio-core-dev
pip install -e . --no-deps
constantinpape commented 2 years ago

Yes, that is installing tf via conda, see https://github.com/bioimage-io/core-bioimage-io-python/blob/main/dev/environment-base.yaml#L17.