AssertionError: Torch not compiled with CUDA enabled 11.4

username: akslduk
cooked: <p>Hello, I’m trying to run styleGAN3 and keep facing this problem<br>
AssertionError: Torch not compiled with CUDA enabled</p>
<p>How to fix it?</p>
<pre><code class="lang-auto">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 &lt;module&gt;
    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
</code></pre>

username: ptrblck
cooked: <p>Check the CUDA runtime used in your PyTorch install via <code>torch.version.cuda</code> and <code>torch.cuda.is_available()</code>, as you might have installed the CPU-only version.</p>

username: Maryam_Darei
cooked: <p>Hi</p>
<p>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.</p>

username: ptrblck
cooked: <p>I don’t think CUDA is supported on Mac so you might need to install the MPS binaries.</p>

username: Maryam_Darei
cooked: <p>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:</p>
<pre><code class="lang-auto">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)}")
</code></pre>

username: marksaroufim
cooked: <p>In your case you’d need to do something like <code>torch.device("mps" if torch.backends.mps.is_available() else "cpu")</code> CUDA is not a supported device on Macs</p>
<p><a href="https://pytorch.org/docs/stable/notes/mps.html" class="onebox" target="_blank" rel="noopener nofollow ugc">https://pytorch.org/docs/stable/notes/mps.html</a></p>