Skip to content
class

PhantomStorage

PhantomStorage

The storage of a phantom tensor: the bytes it would take, its dtype, and no buffer.

A phantom tensor has a shape, a dtype, a device and autograd state like any other, and no values. The engine makes one in place of every result while PhantomMode is on, so a model can be built — every parameter shaped, every op's output shape inferred by the op itself — without allocating a byte. Reading its values raises (refuse_phantom_read).

Attributes

nbytesstd::size_t
The bytes the tensor's elements would take. 0 until a tensor adopts it: the phantom backend does not know the shape of what it returns, the TensorImpl that adopts the storage does.
dtypeDtype
Element type. Default Dtype::F32.
deviceDevice
The device the phantom stands in for. Every other storage says its device by its kind; a phantom has none, and a bare gradient Storage handed to a hook, a custom Function or a seed is wrapped on the device storage_device reads off it.

Notes

No VersionCounter: the siblings' storage counters are read by nothing autograd compares (see the file header), and a phantom's writes move only TensorImpl::version. Without one, a phantom costs no heap allocation at all.