xnn.hybnn.fast.spookynet#

Fast paths of SpookyNet: a compiled block for evaluation, fused MLPs for training.

Evaluation: the interaction modules, the nonlocal attention included, run as one block compiled with torch.compile() (see xnn.common.models.compiled). The sizes of the attention’s padding (the structures and the largest structure) enter as the shape of an input, so a new batch does not compile the block again. The compiled code fuses the elementwise work of all modules, which is what a SpookyNet evaluation spends its launches on.

Training: every residual MLP (the grouped ones of the local and nonlocal interactions, the single ones and the residual blocks) runs as one fused function per pass, its second derivatives included (xnn.hybnn.fast.mlp_kernels). They run a quarter fewer kernels than the reference, which counts in captured steps; in ordinary steps on small systems their orchestration on the host costs as much.

Module Attributes

NEVER

the reference.

AUTO_POLICY

below an edge count, since it saves kernel launches.

AUTO_POLICY_TRAINING

Edge counts above which use_fast="auto" takes the fused MLPs in an ordinary training step (a force loss, second derivatives included), per GPU model and precision.

AUTO_POLICY_CAPTURED

The same for a captured training step (a padded batch with an index plan, replayed as a CUDA graph), where only the GPU's work counts: the fused MLPs run fewer kernels at every size (not in float64 on an L40S or a T4).

Functions

fused_supported(device, dtype)

The fused MLP layers (xnn.hybnn.fast.mlp_kernels): a CUDA device with Triton, float32 or float64.

residual_block(x, block)

x + W2 swish(W1 swish(x)) of one residual block (both layers with biases or none), fused.

residual_mlps(x, mlps)

[m(x) for m in mlps] for residual MLPs of one structure (plain linear layers and Swish activations, all with biases or none), one fused evaluation for all of them.

supported(device, dtype)

torch.compile on a CUDA device in float32 or float64.