Created
May 27, 2021 07:14
-
-
Save farmaker47/0d4279ef154a6d9e976d0a373c5b9e8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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