运行pytorch / xla时缺少XLA配置

问题描述

我正在尝试使用Pytorch / XLA运行GCP TPU,我正在使用带有debian-9-torch-xla-v20200818映像的VM,我启动了TPU并使用ctpu状态检查它是否正在运行,这表明两个cpu和TPU正在运行,然后我激活了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似乎与问题有关。也许您没有设置XRT_TPU_CONFIG:(vm)$ export XRT_TPU_CONFIG =“ tpu_worker; 0; $ TPU_IP_ADDRESS:8470”请按照here的说明进行操作,

,

如果看到XRT_TPU_CONFIG设置正确的另一种可能性是忘记了使用适当的scopes启动实例:

gcloud compute instances create ... --scopes=https://www.googleapis.com/auth/cloud-platform