def vjp_batched

bendtorch-core@0.1.0.0 · src/autograd/tensor_backward.bend:620

import bendtorch-core@0.1.0.0/src/autograd/tensor_backward.bend as TensorBackward
import Base
import bendtorch-core@0.1.0.0/src/shape/core.bend as Shape
import bendtorch-core@0.1.0.0/src/tensor/core.bend as Core
import bendtorch-core@0.1.0.0/src/tensor/batched_matmul.bend as Batched

620# d(a@b)/da and d(a@b)/db of torch.matmul: g @ b^T and a^T @ g over the
621# output's batch (Batched.left_gradient and Batched.right_gradient), each
622# then summed to its operand's shape with sum_to_size, which sums the batch
623# dimensions the operand was broadcast along and keeps a product that
624# already has the operand's shape. A 1-D operand's product already drops its
625# row or column.
626def vjp_batched(+a: Nat, +b: Nat, +left: Shape.Shape, +right: Shape.Shape, saved: Saved, g: Core.Dynamic) -> Pass:
627  match saved:
628    case Unsaved{}:
629      Pass{Unsaved{}, g, Fail{TensorError{Core.StorageLengthMismatch{}}}}
630    case Operands{x, y}:
631      batched_planned(a, b, left, right, x, y, g, Batched.plan(left, right))

Uses (10)

Used by (1)