运行 pytorch/xla 时缺少 XLA 配置

Missing XLA configuration when running pytorch/xla

我正在尝试 运行 GCP TPU Pytorch/XLA,我正在使用带有 debian-9-torch-xla-v20200818 映像的虚拟机,我启动 TPU 并检查它是 运行ning 使用 ctpu status 显示 CPU 和 TPU 都是 运行ning,然后我激活 torch-xla-nightly 环境,但是当我尝试调用这个简单的代码时:

import torch
import torch_xla
import torch_xla.core.xla_model as xm

dev = xm.xla_device()
t1 = torch.ones(3, 3, device = dev)
print(t1)

出现此错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/anaconda3/envs/torch-xla-nightly/lib/python3.6/site-packages/torch_xla/core/xla_model.py", line 231, in xla_device
devkind=devkind if devkind is not None else None)
File "/anaconda3/envs/torch-xla-nightly/lib/python3.6/site-packages/torch_xla/core/xla_model.py", line 136, in get_xla_supported_devices
 xla_devices = _DEVICES.value
File "/anaconda3/envs/torch-xla-nightly/lib/python3.6/site-packages/torch_xla/utils/utils.py", line 32, in value
self._value = self._gen_fn()
File "/anaconda3/envs/torch-xla-nightly/lib/python3.6/site-packages/torch_xla/core/xla_model.py", line 18, in <lambda>
_DEVICES = xu.LazyProperty(lambda: torch_xla._XLAC._xla_get_devices())
RuntimeError: tensorflow/compiler/xla/xla_client/computation_client.cc:274 : Missing XLA configuration

我尝试了所有方法,但似乎没有任何效果。

看看this link as it seems to pertain to the issue. Maybe you didn't setup the XRT_TPU_CONFIG: (vm)$ export XRT_TPU_CONFIG="tpu_worker;0;$TPU_IP_ADDRESS:8470" Follow the instructions here,你应该没问题。

如果您看到 XRT_TPU_CONFIG 设置正确,另一种可能是您忘记使用适当的 scopes:

启动您的实例
gcloud compute instances create ... --scopes=https://www.googleapis.com/auth/cloud-platform