【问题标题】:Colab TPU error InvalidArgumentError: Cannot assign a device for operationColab TPU 错误 InvalidArgumentError:无法分配设备进行操作
【发布时间】:2020-02-22 17:57:00
【问题描述】:

在 google colab 中使用 TPU 时出现以下错误

InvalidArgumentError:无法为操作 Adam/iterations/IsInitialized/VarIsInitializedOp 分配设备:{{node Adam/iterations/IsInitialized/VarIsInitializedOp}} 已明确分配给 /job:worker/replica:0/task:0/device: TPU:0 但可用设备是 [ /job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0 ]。确保设备规范引用了有效的设备。 [[亚当/迭代/IsInitialized/VarIsInitializedOp]]

TPU_WORKER = 'grpc://' + os.environ['COLAB_TPU_ADDR']
        resolver = tf.contrib.cluster_resolver.TPUClusterResolver(TPU_WORKER)
        tf.contrib.distribute.initialize_tpu_system(resolver)
        strategy = tf.contrib.distribute.TPUStrategy(resolver)
        with strategy.scope():
            # Setup the model inputs / outputs
            model = Model(inputs=[inputs_img, inputs_mask], outputs=outputs)
            # Compile the model
            model.compile(
                optimizer = Adam(lr=lr),
                loss=self.loss_total(inputs_mask)
            )

【问题讨论】:

    标签: tensorflow keras google-colaboratory tpu google-cloud-tpu


    【解决方案1】:

    keras.modelskeras.layers 移动到tf.keras.modelstf.keras.layers 为我解决了这个问题。 还要确保您没有使用本地存储。请改用 GCS 存储桶。

    【讨论】:

    • 嗨!当我尝试这样做时,我得到一个“ModuleNotFoundError”。我怎样才能解决这个问题?我也在研究 colab 笔记本。谢谢!
    【解决方案2】:

    这是一个参考 TPU colab,请确保将加速器更改为 TPU: 运行时 -> 更改运行时间 -> TPU

    https://colab.research.google.com/notebooks/tpu.ipynb

    【讨论】:

      猜你喜欢
      • 2020-10-09
      • 1970-01-01
      • 2019-07-29
      • 2021-03-30
      • 2011-04-26
      • 1970-01-01
      • 1970-01-01
      • 2017-02-13
      • 2022-01-19
      相关资源
      最近更新 更多