Autograd node for the bilinear (rank-3-weight) layer.
Implements the bilinear form
over arbitrary leading batch dimensions, equivalent to the contraction
y = einsum("...p,opq,...q->...o", x1, W, x2) + b. Both inputs and the
weight are saved so that the backward can compute
The bias gradient is simply grad_out reduced over all batch axes.
Math
Attributes
schema_v1OpSchema"bilinear_layer", AmpPolicy::Promote.orig_x1_shape_ShapeSaved
x1 shape for backward reconstruction.orig_x2_shape_ShapeSaved
x2 shape for backward reconstruction.Notes
All leading "batch" dimensions of x1 and x2 must match exactly.
The bias is detected as absent (no bias term) when the saved bias shape
recorded in input_shapes_[3] is empty.
Static methods
1static
forward
→TensorImplPtrint forward(const int & x1, const int & x2, const int & weight, const int & bias)Compute the bilinear layer with autograd wiring.
Parameters
x1TensorImplPtrTensor whose last dimension equals .
x2TensorImplPtrTensor whose last dimension equals and whose leading shape matches that of
x1.weightTensorImplPtrWeight tensor of shape
(D_out, D_1, D_2).biasTensorImplPtrOptional bias vector of shape
(D_out,). Pass nullptr to disable the additive bias.Returns
TensorImplPtrOutput tensor of shape (*, D_out) where * denotes the shared leading shape of x1 / x2.