I'm on Ubuntu 20.04 LTS with CUDA 11.1 installed (and working, with PATH and LD_LIBRARY_PATH configured correctly), and I'm trying to define a reusable conda environment (i.e., in an environment.yml file) that successfully installs PyTorch with CUDA support.
However, when I use the environment file, I get a message that Torch wasn't compiled with CUDA support:
Python 3.8.10 | packaged by conda-forge | (default, May 11 2021, 07:01:05)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> device = torch.device("cuda:0")
>>> t = torch.tensor(device=device, data=[0,1,2,3])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jdr2160/anaconda3/envs/foo/lib/python3.8/site-packages/torch/cuda/__init__.py", line 166, in _lazy_init
raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled
My environment.yml is pretty bare-bones:
name: foo
channels:
- conda-forge
- nvidia
- pytorch
dependencies:
- cudatoolkit=11.1
- python=3.8
- pytorch
When I create an 'empty' python 3.8 environment and install the Conda packages from the command line instead of from an environment file, everything works fine:
$ conda env create --name bar python=3.8
...
$ conda activate bar
$ conda install pytorch cudatoolkit=11.1 -c pytorch -c nvidia
...
$ python
Python 3.8.10 | packaged by conda-forge | (default, May 11 2021, 07:01:05)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> device = torch.device("cuda:0")
>>> t = torch.tensor(device=device, data=[0,1,2,3])
>>>
Can anyone tell what's going on here? It seems that Conda doesn't see the cudatoolkit=11.1 dependency while installing PyTorch from the environment file, but I have no idea how to fix it.