Skip to content
class

VersionMismatch

extendsLucidError
VersionMismatch

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_t
Version that was captured during the forward pass.
gotstd::int64_t
Version observed during the backward pass.
contextstd::string
Annotation produced by ErrorBuilder (typically the saving op's name).

Attributes

expected_std::int64_t
Stored snapshot version.
got_std::int64_t
Stored current version.

Notes

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

1
ctor

VersionMismatch

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

2
fnconst

expected_version

→std::int64_t
int expected_version()

Returns the version observed when the tensor was saved.

Returns

std::int64_t

Forward-pass version captured at save time.

fnconst

got_version

→std::int64_t
int got_version()

Returns the version observed during the backward pass.

Returns

std::int64_t

Current version of the tensor when the saved snapshot was restored.