teddykoker / torchsort

Fast, differentiable sorting and ranking in PyTorch
https://pypi.org/project/torchsort/
Apache License 2.0
765 stars 33 forks source link

installation issue with cuda #62

Closed franchesoni closed 1 year ago

franchesoni commented 1 year ago

Hello, I'm sorry to open such a wide issue but this has already taken more than 15 hours of my life.

I have run the following commands:

rm -rf env_borgen
python -m venv env_borgen
source env_borgen/bin/activate
pip install --upgrade pip
pip install --force-reinstall torch --extra-index-url https://download.pytorch.org/whl/cu116  #gpu install
pip install --no-cache-dir --upgrade torchsort 
python check_install.py

where check_install.py is simply:

import torch
from torchsort import soft_rank

aaa = torch.rand(1, 3)
soft_rank(aaa.cpu())
soft_rank(aaa.cuda())
print('everything works!')

but I get

raceback (most recent call last):
  File "/home/franchesoni/projects/current/borgen2/setup/check_install.py", line 7, in <module>
    soft_rank(aaa.cuda())
  File "/home/franchesoni/projects/current/borgen2/env_borgen/lib/python3.9/site-packages/torchsort/ops.py", line 48, in soft_rank
    return SoftRank.apply(values, regularization, regularization_strength)
  File "/home/franchesoni/projects/current/borgen2/env_borgen/lib/python3.9/site-packages/torchsort/ops.py", line 103, in forward
    dual_sol = isotonic_l2[s.device.type](s - w)
  File "/home/franchesoni/projects/current/borgen2/env_borgen/lib/python3.9/site-packages/torchsort/ops.py", line 31, in _error
    raise ImportError(
ImportError: You are trying to use the torchsort CUDA extension, but it looks like it is not available. Make sure you have the CUDA toolchain installed, and reinstall torchsort with `pip install --force-reinstall --no-cache-dir torchsort` to rebuild the extension.

by the way, /usr/local/cuda/bin/nvcc --version returns:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Tue_Mar__8_18:18:20_PST_2022
Cuda compilation tools, release 11.6, V11.6.124
Build cuda_11.6.r11.6/compiler.31057947_0

and I don't have sudo access.

could I please get help in this regard? I don't know how to proceed and I really want to use the tool on GPU

teddykoker commented 1 year ago

Hi @franchesoni, thank you for your patience! I'm assuming the installation didn't produce any error messages, which means if the cuda driver was not compiled, the compilation was never run. setup.py will only attempt to compile the cuda code if nvcc is in your path, which can be verified with which nvcc. If it is not in the path you can add it by running:

PATH=$PATH:/usr/local/cuda/bin/nvcc

This should at least attempt to compile the cuda code upon installation, and you should get some error messages if it does not work successfully.

Please let me know if you are still having issues!

teddykoker commented 1 year ago

Closing due to lack of activity, assuming fixed