Google ColaboratoryでTPUというものが使えるらしいので、使ってみました。
TPUとは
テンソル・プロセッシング・ユニット(Tensor processing unit、TPU)はGoogleが開発した機械学習に特化した特定用途向け集積回路(ASIC)です。
ja.wikipedia.org
Google Colaboratoryとは
Google Colaboratoryは教育や研究機関へ機械学習の普及を目的としたGoogleの研究プロジェクトの一つでです。
使い方
Google Colaboratoryを始めるには、以下のサイトにアクセスして、Googleアカウントでログインするだけです。
colab.research.google.com
ログインすると以下のような画面が表示されます。
Google ColabでTPUを使ってみる
ノートブックのメニューバーから「編集」>「ノートブックの設定」をクリックします。
次にTPUを選択します。
TPUが設定できたかどうか確認するには以下のコードを実行します。
import tensorflow as tf try: tpu = tf.distribute.cluster_resolver.TPUClusterResolver() # TPU detection print('Running on TPU ', tpu.cluster_spec().as_dict()['worker']) except ValueError: raise BaseException('ERROR: Not connected to a TPU runtime; please see the previous cell in this notebook for instructions!') tf.config.experimental_connect_to_cluster(tpu) tf.tpu.experimental.initialize_tpu_system(tpu) tpu_strategy = tf.distribute.TPUStrategy(tpu)
ちなみにGPUの場合
from tensorflow.python.client import device_lib device_lib.list_local_devices()