How to convert a meta tensor to normal tensor?

If we simply try to cast a meta tensor to another device, it doesn’t work

>>> import torch
>>> a=torch.empty([10,10],device="meta")
>>> a.to("cpu")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NotImplementedError: Cannot copy out of meta tensor; no data!

What is the recommended way to convert a meta tensor to normal tensor?

The issue with converting a meta tensor to a cpu tensor is that… the meta tensor doesn’t have any data! What data do you want your tensor to contain once you “move” into cpu?

One option would be to just construct a fresh tensor on the cpu device, using the metadata from your meta tensor.

Cpu_tensor = torch.empty_like(meta_t, device=“cpu”)