Jingkang50 / OpenOOD

Benchmarking Generalized Out-of-Distribution Detection
MIT License
871 stars 113 forks source link

faiss installation issues in conda env #254

Open felixsh opened 3 months ago

felixsh commented 3 months ago

I'm trying to install OpenOOD in a conda environment per yaml file, like so:

name: env
channels:
  - pytorch
  - nvidia
  - defaults
dependencies:
  - python=3.12
  - numpy
  - matplotlib
  - scikit-learn
  - scipy
  - tqdm
  - pytorch:pytorch
  - pytorch:torchvision
  - nvidia:pytorch-cuda=12.1
  - pytorch::faiss-gpu
  - cython
  - pip
  - pip:
    - git+https://github.com/Jingkang50/OpenOOD

Building with conda env create --file=env.yaml throws an error saying faiss-gpu>=1.7.2 can not be satisfied. Changing this to faiss>=1.7.2 in setup.py resolves the issue.

The problem is probably somewhere between pip and conda. On inspection conda list | grep faiss --> faiss-gpu, but pip list | grep faiss --> faiss and pip can not find the faiss-gpu package.

Not sure if this needs fixing or is a packaging issue with conda, either way the trinity of faiss, faiss-cpu, faiss-gpu is confusing. Maybe this helps somebody else trying to install OpenOOD in a conda env.

zjysteven commented 3 months ago

Thanks for sharing this. Just curious, what about removing pytorch::faiss-gpu in conda dependencies and just let pip alone to handle faiss installation?

felixsh commented 3 months ago

Letting pip handle the dependencies results in an error:

ERROR: Could not find a version that satisfies the requirement faiss-gpu>=1.7.2 (from openood) (from versions: none)
ERROR: No matching distribution found for faiss-gpu>=1.7.2

Installing with pip in python3.11 (no conda) produces a similar error. I guess the installation via pip is not intended, to quote the faiss-installation guide: "The supported way to install Faiss is through conda."

zjysteven commented 3 months ago

Right, turned out that the pypi package expects python >=3.7, <3.11. With as late as python 3.10 the pip installation still works but not with 3.11.

image
felixsh commented 3 months ago

Thanks for the clarification! So, I just missed the correct version.

I will stick with python 3.12 and the solution above for now, that seems to work just fine. From my side this can be closed, only suggestion I have to maybe add this as a note under the installation section.

Tankiit commented 12 hours ago

This was also bugging me and the above solution works in MPS now. So anyone struggling in Mac just remove the fails-gpu to cpu and hopefully this should go through.