How to set GPU count to 0 using os.environ['CUDA_VISIBLE_DEVICES'] =""?
So I have the following GPU configured in my system:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 461.33       Driver Version: 461.33       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name            TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  Tesla V100S-PCI...  TCC  | 00000000:3B:00.0 Off |                    0 |
| N/A   30C    P0    25W / 250W |      1MiB / 32642MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
|   1  Tesla V100S-PCI...  TCC  | 00000000:D8:00.0 Off |                    0 |
| N/A   31C    P0    25W / 250W |      1MiB / 32642MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

Now, via python, I have to set the environment, such that, GPU count = 0.
I have tried the following, after learning from various sources:
import os
os.environ[&quot;CUDA_VISIBLE_DEVICES&quot;]=&quot;&quot;
import torch
torch.device_count()

But, it still gives me the output as &quot;2&quot; as in for 2 GPUs in the system.
How to set the environment, such that it outputs &quot;0&quot; ?
Any other way, to set the count to &quot;0&quot; is also appreciated but it should be any ML-Library agnostic. (For example, I can't use device = torch.device(&quot;cpu&quot;) as this will work only for Pytorch and not for other libraries)

To prevent your GPU from being used, set os.environ[&quot;CUDA_VISIBLE_DEVICES&quot;] = &quot;-1&quot;
