Skip to content

Instantly share code, notes, and snippets.

@AIAnytime
Created February 23, 2021 09:03
Show Gist options
  • Save AIAnytime/c8ebad5a94664f83c91189d00c7a4a5c to your computer and use it in GitHub Desktop.
Save AIAnytime/c8ebad5a94664f83c91189d00c7a4a5c to your computer and use it in GitHub Desktop.
How to disable GPU with TensorFlow?
try:
# Disable all GPUS
tf.config.set_visible_devices([], 'GPU')
visible_devices = tf.config.get_visible_devices()
for device in visible_devices:
assert device.device_type != 'GPU'
except:
# Invalid device or cannot modify virtual devices once initialized.
pass
#2nd method
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment