Skip to content
fn

holds_saved_values

bool holds_saved_values(const int & s)

Whether a node kept an input's values for backward in the slot s.

The one rule that decides both which inputs a node's version check guards (AutogradNode::validate_versions) and which ones graph-mode backward can rebuild (forward_time_input). A backward that reads an input's values saves them, by value, in that input's slot; an empty slot means the formula reads the input's shape at most, so a write into the input after forward cannot change the gradient and is not refused — the reference's rule for add, sum or a view. Checking every input instead refused y[:, 1] = y[:, 0] + 5 on the CPU, where the slice is a view whose version the write moves. A zero-element input saves no bytes and is not guarded either: no write can change what it holds.