AssertionError: Torch not compiled with CUDA enabled 11.4

Hello, I’m trying to run styleGAN3 and keep facing this problem
AssertionError: Torch not compiled with CUDA enabled

How to fix it?

ray@gamepc:~/stylegan3-main$ conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

ray@gamepc:~/stylegan3-main$  conda init stylegan3


(stylegan3) ray@gamepc:~/stylegan3-main$ python3 gen_images.py --outdir=out --trunc=1 --seeds=2 --network=https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-r-afhqv2-512x512.pkl
Loading networks from "https://api.ngc.nvidia.com/v2/models/nvidia/research/stylegan3/versions/1/files/stylegan3-r-afhqv2-512x512.pkl"...
No CUDA runtime is found, using CUDA_HOME='/usr'
Traceback (most recent call last):
  File "/home/ray/stylegan3-main/gen_images.py", line 143, in <module>
    generate_images() # pylint: disable=no-value-for-parameter
  File "/home/ray/anaconda3/envs/stylegan3/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/ray/anaconda3/envs/stylegan3/lib/python3.9/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/ray/anaconda3/envs/stylegan3/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ray/anaconda3/envs/stylegan3/lib/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/ray/stylegan3-main/gen_images.py", line 108, in generate_images
    G = legacy.load_network_pkl(f)['G_ema'].to(device) # type: ignore
  File "/home/ray/anaconda3/envs/stylegan3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 852, in to
    return self._apply(convert)
  File "/home/ray/anaconda3/envs/stylegan3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 530, in _apply
    module._apply(fn)
  File "/home/ray/anaconda3/envs/stylegan3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 530, in _apply
    module._apply(fn)
  File "/home/ray/anaconda3/envs/stylegan3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 530, in _apply
    module._apply(fn)
  File "/home/ray/anaconda3/envs/stylegan3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 552, in _apply
    param_applied = fn(param)
  File "/home/ray/anaconda3/envs/stylegan3/lib/python3.9/site-packages/torch/nn/modules/module.py", line 850, in convert
    return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)
  File "/home/ray/anaconda3/envs/stylegan3/lib/python3.9/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

(stylegan3) ray@gamepc:~/stylegan3-main$ nvidia-smi
Wed Jan 19 22:51:34 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.86       Driver Version: 470.86       CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:01:00.0 Off |                  N/A |
|  0%   60C    P2   385W / 420W |   9419MiB / 24251MiB |    100%      Default |
|                               |                      |                  N/A |
-------------------------------+----------------------+----------------------+

(stylegan3) ray@gamepc:~/stylegan3-main$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

Check the CUDA runtime used in your PyTorch install via torch.version.cuda and torch.cuda.is_available(), as you might have installed the CPU-only version.

Hi

I have same problem and the torch.version.cuda is none and torch.cuda.is_available() is false. What is the solution. I use my MacBook Pro with GPU.

I don’t think CUDA is supported on Mac so you might need to install the MPS binaries.

Thank you for your response. Does it need to change my code, I mean when I want to device determine to run on GPU, like:

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
if device.type == "cuda":
   deviceid = torch.cuda.current_device()
   log.info(f"Gpu device {torch.cuda.get_device_name(deviceid)}")

In your case you’d need to do something like torch.device("mps" if torch.backends.mps.is_available() else "cpu") CUDA is not a supported device on Macs

https://pytorch.org/docs/stable/notes/mps.html