Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify pytorch / cuda version in pipenv

Tags:

pytorch

pipenv

I am trying to install a specific version of pytorch that is compatible with a specific cuda driver version with pipenv. The pytorch website shows how to to this with pip:

pip3 install torch==1.3.1+cu92 torchvision==0.4.2+cu92 -f https://download.pytorch.org/whl/torch_stable.html

I tried to convert this into an entry in my Pipfile like this:

[[source]]
name = "pytorch"
url = "https://download.pytorch.org/whl/torch_stable.html"
verify_ssl = false

pytorch = {version="==1.3.1+cu92", index="pytorch"}
torchvision = {version="==0.4.2+cu92", index="pytorch"}

However, this does not work. The dependency with this version can not be resolved. I am not sure if the url that is listed with the -f parameter in the pip3 command is even a valid source for pipenv.

I could install both libraries by just passing the command through to pip like this:

pipenv run pip install torch==1.3.1+cu92 torchvision==0.4.2+cu92 -f https://download.pytorch.org/whl/torch_stable.html

but I am not really satisfied with that solution since the dependencies are not in the Pipfile and I have to manually document the usage of this command.

like image 309
moe Avatar asked Jan 15 '20 13:01

moe


People also ask

Which version of CUDA should I install for PyTorch?

NVIDIA CUDA Toolkit It is a development environment that creates GPU-accelerated applications. It includes libraries that work with GPU, debugging, optimization tools, and many other features. In order to install CUDA, you need to install the CUDA Toolkit 10.2, a version compatible with Pytorch 1.7.

Does PyTorch support CUDA 11?

Can PyTorch work with CUDA 11.6 or 11.7? Thanks. Yes, you could install the binaries with the CUDA 11.6 runtime by swapping the version from the provided install commands and you can of course build from source using both CUDA versions.

Do I need to install CUDA to use PyTorch?

No CUDA. To install PyTorch via pip, and do not have a CUDA-capable or ROCm-capable system or do not require CUDA/ROCm (i.e. GPU support), in the above selector, choose OS: Linux, Package: Pip, Language: Python and Compute Platform: CPU. Then, run the command that is presented to you.


1 Answers

The problem with the approach above lies in the structure of https://download.pytorch.org/whl/torch_stable.html. Pipenv can only find torch versions 0.1 to 0.4.1 because all others have the cuda (or cpu) version as a prefix e.g. cu92/torch-0.4.1-cp27-cp27m-linux_x86_64.whl.

But the cuda version is a subdirectory. So if you change the url of the source to the cuda version and only specify the torch version in the dependencies it works.

[[source]]
name = "pytorch"
url = "https://download.pytorch.org/whl/cu92"
verify_ssl = false

[packages]
torch = {index = "pytorch",version = "==1.4.0"}

The only problem I encountered is that numpy is not recognized as a dependency of pytoch 1.4.0. But this seems to be a problem of the specific pytorch wheel. With version 1.3.1 or 1.5.1 and a recent pipenv version it works.

So if after the installation with pipenv install, the command pipenv run python -c "import torch" throws an error, numpy must be added manually.

like image 198
moe Avatar answered Oct 22 '22 06:10

moe