Thrown by the autograd engine when a saved tensor is mutated between the forward and backward pass.
Each tensor carries a monotonically increasing version counter; the saved
snapshot records the version observed at save time. When the snapshot is
restored during backward, the engine compares the saved version against
the tensor's current version and raises VersionMismatch if they
differ — preventing silently incorrect gradients caused by in-place
mutation. Mapped to lucid._C.engine.VersionMismatch on the Python
side.
Parameters
expectedstd::int64_tgotstd::int64_tcontextstd::stringErrorBuilder (typically the saving op's name).Attributes
expected_std::int64_tgot_std::int64_tNotes
In-place ops on tensors that participate in autograd should either bump
the version counter on the underlying storage or be re-implemented as a
non-aliasing copy. Catching VersionMismatch and continuing is
strongly discouraged — the gradient is no longer well-defined.
Constructors
1VersionMismatch
void VersionMismatch(int expected, int got, int context)Construct a VersionMismatch with the version captured at forward time vs the version observed at backward time, plus the op-level context annotation the call site captured. Raised when a saved tensor was mutated in-place between forward and backward.
Methods
2Returns the version observed when the tensor was saved.
Returns
std::int64_tForward-pass version captured at save time.
Returns the version observed during the backward pass.
Returns
std::int64_tCurrent version of the tensor when the saved snapshot was restored.