web-dev-qa-db-ja.com

Google ColabでTPUを使用する方法

Google colabは、Runtime AcceleratorにTPUをもたらします。 Official Tensorflow github でTPUの使用方法の例を見つけました。しかし、この例はgoogle-colaboratoryでは機​​能しませんでした。次の行で止まりました:

tf.contrib.tpu.keras_to_tpu_model(model, strategy=strategy)

I 利用可能なデバイスを印刷する colabで[] TPUアクセラレータ用。誰もがコラボでTPUを使用する方法を知っていますか?

enter image description here

11
Amir

Colab固有のTPUの例を次に示します。 https://colab.research.google.com/github/tensorflow/tpu/blob/master/tools/colab/shakespeare_with_tpu_and_keras.ipynb

キーラインは、TPU自体に接続するためのものです。

# This address identifies the TPU we'll use when configuring TensorFlow.
TPU_WORKER = 'grpc://' + os.environ['COLAB_TPU_ADDR']

...

tpu_model = tf.contrib.tpu.keras_to_tpu_model(
training_model,
strategy=tf.contrib.tpu.TPUDistributionStrategy(
    tf.contrib.cluster_resolver.TPUClusterResolver(TPU_WORKER)))

(GPUとは異なり、TPUを使用するにはTPUワーカーへの明示的な接続が必要です。そのため、高速化を観察するには、トレーニングと推論の定義を微調整する必要があります。)

13
Bob Smith