Skip to content
class

SolveBackward

SolveBackward

Python wrappers

Public Python APIs implemented by this engine symbol.

Autograd node for the general linear solve AX=BAX = B.

Wired on the operands after the shape contract aligned them — (batch, N, N) and (batch, N, K) — so it never sees a vector or a broadcast. The forward saves AA as saved_inputs_[0] (required to build A⊤A^\top for the adjoint solve) and the solution XX as saved_output_ (required for the outer-product step that yields ∂L/∂A\partial L / \partial A).

Math

Given upstream gradient G=∂L/∂XG = \partial L / \partial X:

∂L∂B=solve(A⊤,G),∂L∂A=− ∂L∂B X⊤ \frac{\partial L}{\partial B} = \text{solve}(A^\top, G), \qquad \frac{\partial L}{\partial A} = -\,\frac{\partial L}{\partial B}\, X^\top

Both expressions compose existing differentiable ops ([[solve_op]] / [[matmul_op]] / [[neg_op]] / [[mT_op]]) so that second-order gradients flow automatically.

References

Giles, "Collected Matrix Derivative Results for Forward and Reverse Mode Algorithmic Differentiation" (Oxford, 2008), §2.4.

Attributes

schema_v1OpSchema
"solve", one saved-input slot, AmpPolicy::KeepInput — prevents a lossy autocast promotion before the LAPACK call.

Instance methods

2
fn

apply

→std::vector<Storage>
int apply(int grad_out)

Compute input gradients for the forward solve AX=BAX = B.

Parameters

grad_outStorage
Upstream gradient G=∂L/∂XG = \partial L / \partial X, shaped like the forward output XX.

Returns

std::vector<Storage>

Two-element vector {dA, dB} matching the input ordering [A=0, B=1] that NaryKernel expects, where dB = solve(Aᵀ, G) and dA = -dB @ Xᵀ.

Notes

The transpose solve solve(Aᵀ, G) performs a fresh LU factorisation of A⊤A^\top — the forward factors are not cached.

fn

apply_for_graph

int apply_for_graph(const int & grad_out)

The same adjoint solve, recorded, with X recomputed from A and B.