Autograd node for broadcasting a tensor to a larger shape.
Forward replicates a along all broadcast dimensions so that its shape
matches the requested output shape, following NumPy broadcasting rules
(left-pad with size-1 dims, then allow size-1 dims to broadcast). Backward
inverts that replication by summing the incoming gradient over every axis
that was broadcast — either a newly prepended axis or a size-1 dimension
that was expanded — via Dispatcher::reduce_broadcast.
Math
Forward expands each size-1 broadcast axis by replication: Backward reduces over those axes:
= \sum_{i_k} \frac{\partial L}{\partial y_{[\ldots, i_k, \ldots]}}. $$ **Shape** Output rank == `output_shape_.size()`. For each axis from the right, either `input_shape_[d] == output_shape_[d]` or `input_shape_[d] == 1` (broadcast). Newly prepended axes are implicitly summed in backward. **See Also** `broadcast_to_op`, `expand_op`.Parameters
input_shape_ShapeThe original tensor shape before broadcasting.
output_shape_ShapeThe fully broadcast target shape.
Attributes
schema_v1OpSchema"broadcast_to", AmpPolicy::KeepInput, requires_grad=true.