xnn.common.models.multilinear#

Multilinear blocks: autograd functions that keep only their operands.

A block f(op_0, ..., op_k) linear in each operand (a sum of terms, each linear in the operands it contains) is evaluated without recording, and its derivatives come in closed form from the block itself:

  • the adjoint bar f_i(g) of each operand (the gradient for the incoming gradient g), and

  • their own derivatives (the second backward of force training). For each term, <c_i, bar f_i(g)> = <g, f(op_i <- c_i)>, so the derivatives of the adjoints are values and adjoints of the same block with one operand replaced by its cotangent, over the terms that contain it.

Nothing but the operands (and, in a second backward, the incoming gradient) is kept. The blocks can be pair sums written as fused kernels, whose adjoints are kernels of the same form. Third derivatives are not supported. Eager only: custom autograd functions do not script.

Functions

add_optional(a, b)

a + b, or b when a is None.

multilinear(block, *ops)

block.value(ops), with first and second derivatives from the block.

Classes

MultilinearBlock()

Interface of a block for multilinear().