xnn.hybnn.fast.mlp_kernels#

Triton kernels and autograd functions of SpookyNet’s fused residual MLPs (see xnn.hybnn.fast.spookynet).

A residual MLP of SpookyNet is a stack of residual blocks h + L_B(L_A(h)), optionally followed by an output layer, where every layer is L(h) = swish(h) W + b with the learned activation swish(h) = alpha h sigmoid(beta h) (per-feature alpha, beta). Here G such MLPs of one structure run at once on one input (the grouped evaluation; G = 1 for a single one), and each of the three passes a force loss needs is one autograd function for the whole MLP:

  • the forward;

  • the backward: the layers in reverse, each a product, the activation’s backward and, when the pass needs them, the weight gradients. The force derivative needs no weight gradients and computes none, as autograd does for its own operations;

  • the backward of the backward (second derivatives): the incoming gradient’s tangent pushed forward through the MLP, then one reverse sweep of the adjoints of the values and of the tangents.

The activation’s elementwise work is one Triton kernel per layer and pass; the sums over rows for alpha and beta are partial sums per program, added in a fixed order afterwards (deterministic). The products run on cuBLAS. Third derivatives, and second derivatives through the weight gradients, are not supported. Imported only when the fast path runs, so that triton is needed only there.

Module Attributes

TILE

Elements per program (rows times padded features).

Functions

residual_mlps(x, n_residual, output, params)

G residual MLPs of one structure on x, fused.

Classes

MLPFunction(*args, **kwargs)

G residual MLPs on one input x (N, F): outputs (G, N, F').

MLPGradFunction(*args, **kwargs)

The backward of MLPFunction (the gradients of x and of the parameters the pass needs, for the incoming gradient gout), differentiable once more with respect to x, gout and the parameters through the gradient of x.