Skip to content
fn

forward_time_input

→std::shared_ptr<TensorImpl>
int forward_time_input(const int & live, const int & values, const int & shape, const Edge & edge, int op_name, int input_idx)

The tensor a node was handed at forward time, rebuilt — or nullptr when live still is that tensor.

live stopped being it when an in-place op that records a graph wrote into it: the op gives it a grad_fn of its own. The write moves its version too, so this is reached past check_version_match only when that check is waived (is_mutation_on_saved_allowed), or when something gave live a grad_fn without writing into it — a custom Function that returns its input (see Node::restore_saved_for_graph). The rebuilt tensor holds the values the node saved by value and sits where live sat when the node was recorded — on edge, the edge the node recorded for it — so graph-mode backward computes what eager backward computes, and its own derivative flows to what produced those values rather than to the write.

Parameters

liveconst std::shared_ptr<TensorImpl>&
The tensor the node holds for graph-mode backward.
valuesconst Storage&
What the node saved by value for the same input. Empty when the node's formula does not read the input's values.
shapeconst Shape&
The input's shape at forward time.
edgeconst Edge&
The edge the node recorded for the input.
op_namestd::string_view
Name of the op, for the error message.
input_idxstd::size_t
Zero-based index of the input within op_name.

Returns

std::shared_ptr<TensorImpl>

The rebuilt tensor; nullptr when live is still the tensor the node was handed, or when the node saved no values — its formula then reads live for its shape alone.

Raises

LucidError
values is not the whole input in one dtype, so there is nothing to rebuild it from.