Switch off the GPU in a Python script
Here’s a simple piece of code which effectively directs a Python script to use the CPU rather than the GPU.
I develop Python code on a Windows Subsystem for Linux (WSL2) environment that has access to my machine’s GPU via CUDA. For one application, I needed to disable the GPU, but was having difficulty.
The following code, placed at the beginning of my script, ensured that the GPU was not used:
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
Forum posts suggest that this is a “messy” approach, but it gets the job done for my application.
Comments
No comments have yet been submitted. Be the first!