问题描述
我正在尝试在 TPU 上运行一个简单的程序:
import tensorflow as tf
tpu = tf.distribute.cluster_resolver.TPUClusterResolver()
print("Device:",tpu.master())
tf.config.experimental_connect_to_cluster(tpu)
tf.tpu.experimental.initialize_tpu_system(tpu)
strategy = tf.distribute.experimental.TPUStrategy(tpu)
a = tf.constant([[1.0,2.0,3.0],[4.0,5.0,6.0]])
b = tf.constant([[1.0,2.0],[3.0,4.0],[5.0,6.0]])
with strategy.scope():
c = tf.matmul(a,b)
print("c device: ",c.device)
with tf.Session(config=tf.ConfigProto(log_device_placement=True)) as sess:
print(c.eval())
当我运行它时,看起来像是找到了 TPU。但是,所有记录的设备的名称中都没有“TPU”——它们都在 cpu 上。
我做错了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)