Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable GPU for Python program?

Tags:

python

cuda

gpu

I want to disable GPU from Python program.

I tried but the program is still using GPU. I am using Dlib face recognition.

os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"   # see issue #152
os.environ["CUDA_VISIBLE_DEVICES"] = ""
like image 260
John Bott Avatar asked Aug 30 '26 20:08

John Bott


1 Answers

Try this instead:

os.environ['CUDA_VISIBLE_DEVICES'] = '-1'

The docs recommend using an invalid index (-1) instead of trying to pass a blank value; setting this value to something blank is something that various people have come up with on their own but doesn't always seem to work. Source: https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars

like image 64
Michael Avatar answered Sep 01 '26 12:09

Michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!