Skip to content

Instantly share code, notes, and snippets.

@farmaker47
Created May 27, 2021 07:14
Show Gist options
  • Save farmaker47/0d4279ef154a6d9e976d0a373c5b9e8a to your computer and use it in GitHub Desktop.
Save farmaker47/0d4279ef154a6d9e976d0a373c5b9e8a to your computer and use it in GitHub Desktop.
if os.environ['COLAB_TPU_ADDR']:
cluster_resolver = tf.distribute.cluster_resolver.TPUClusterResolver(tpu='')
tf.config.experimental_connect_to_cluster(cluster_resolver)
tf.tpu.experimental.initialize_tpu_system(cluster_resolver)
strategy = tf.distribute.TPUStrategy(cluster_resolver)
print('Using TPU')
elif tf.test.is_gpu_available():
strategy = tf.distribute.MirroredStrategy()
print('Using GPU')
else:
raise ValueError('Running on CPU is not recommended.')
# View some info of the TPU in this colaboratory
from tensorflow.python.profiler import profiler_client
tpu_profile_service_address = os.environ['COLAB_TPU_ADDR'].replace('8470', '8466')
print(profiler_client.monitor(tpu_profile_service_address, 100, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment