Skip to content
class

ViewBackward

ViewBackward

Python wrappers

Public Python APIs implemented by this engine symbol.

Autograd node for reshape, squeeze, and unsqueeze.

Forward reinterprets the flat element buffer under a new shape. The backend dispatcher's reshape creates a new Storage alias over the same physical buffer; no data movement occurs. Backward reshapes the incoming gradient back to the original input shape recorded in input_shapes_[0]; because reshape is its own inverse on contiguous buffers (element ordering is unchanged), the backward pass is simply another reshape call.

Math

yk=xkfor k∈[0,numel(x)),y_k = x_k \quad \text{for } k \in [0, \mathrm{numel}(x)), where indices are taken in row-major flat ordering. The mapping between multi-dim indices changes, but the linear element ordering does not.

Shape

input_shapes_[0] — shape of the input tensor before the reshape. out_shape_ — shape after the reshape (inherited from FuncOp). Both must have identical element counts.

See Also

reshape_op, squeeze_op, unsqueeze_op, contiguous_op.

Parameters

grad_outStorage
Incoming gradient, shaped according to the forward output (out_shape_).

Attributes

schema_v1OpSchema
"view", AmpPolicy::KeepInput, requires_grad=true, is_view=true.

Notes

In graph mode apply_for_graph routes through reshape_op so the reshape itself becomes a tracked node and the upstream gradient flow participates in graph optimisation.

Methods

3
fn

apply

int apply(int grad_out)

Reshape grad_out from out_shape_ back to input_shapes_[0].

fn

apply_for_graph

int apply_for_graph(const int & grad_out)

Graph-mode: reshape via reshape_op so the result is tracked.

fnconst

node_name

int node_name()

Graph label — "reshape" — for debug printing and profiler traces. Overrides Node::node_name.