Skip to content
fn

assignable_grad

int assignable_grad(const TensorImpl & self, const TensorImpl & g)

The buffer self.grad = g installs.

The gradient slot is a bare Storage, read as self's dtype, device and shape; g must have all three — checked in that order, as the reference does — and may not be self. A hook's returned gradient passes the same checks against the gradient it replaces.

Raises

DtypeMismatch, DeviceMismatch, ShapeMismatch
g is of another kind.
LucidError
g is self, or a Metal strided view with no buffer of its own.