fn
check_version_match
void check_version_match(const int & live, int saved_version, int op_name, int input_idx)Verify that a saved tensor's version counter has not advanced.
Compares the current version() of the tensor referenced by live
against saved_version. When they differ the saved data has been
mutated in place since it was stashed for backward, which would silently
corrupt the gradient — so a VersionMismatch is raised naming
the op and input that owns the broken contract.
Parameters
liveconst std::weak_ptr<TensorImpl>&Weak reference to the still-live tensor. When the referent has been destroyed the check is skipped (no harm if it cannot be mutated after the fact).
saved_versionstd::int64_tVersion counter value captured when the tensor was saved.
op_namestd::string_viewName of the op for diagnostic messages (e.g.
"matmul").input_idxstd::size_tZero-based index of the offending input within
op_name.Raises
VersionMismatchThe live counter differs from
saved_version and the safety override (is_mutation_on_saved_allowed) is false.