Last active
June 23, 2020 18:01
-
-
Save MITsVision/0366b719a85475003e007c969fae45dd 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
import tensorflow as tf | |
#Detect TPUs, GPUs | |
# Detect hardware, return appropriate distribution strategy | |
try: | |
# TPU detection. No parameters necessary if TPU_NAME environment variable is | |
# set: this is always the case on Kaggle. | |
tpu = tf.distribute.cluster_resolver.TPUClusterResolver() | |
print('Running on TPU ', tpu.master()) | |
except ValueError: | |
tpu = None | |
if tpu: | |
tf.config.experimental_connect_to_cluster(tpu) | |
tf.tpu.experimental.initialize_tpu_system(tpu) | |
strategy = tf.distribute.experimental.TPUStrategy(tpu) | |
else: | |
# Default distribution strategy in Tensorflow. Works on CPU and single GPU. | |
strategy = tf.distribute.get_strategy() | |
print("REPLICAS: ", strategy.num_replicas_in_sync) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment