xnn.trfnn.models.equiformer_v2#

EquiformerV2, the equivariant Transformer for higher-degree representations (Liao et al., ICLR 2024).

An implementation of

  • Y.-L. Liao, B. Wood, A. Das, T. Smidt, “EquiformerV2: Improved Equivariant Transformer for Scaling to Higher-Degree Representations”, ICLR 2024 (arXiv:2306.12059),

written from the paper and consistent with the conventions of the reference code (fairchem-core 1.x, models/equiformer_v2: feature layout, normalizations, initialization, parameter names) without copying it.

Every atom carries C channels of a full spherical-harmonic expansion, x_i of shape ((L + 1)^2, C). The equivariant graph attention of Equiformer is rebuilt on eSCN convolutions (section 3.1): the features of the two endpoints of an edge are concatenated and rotated into a frame whose y axis is the edge direction, where the tensor product with the edge harmonics reduces to an SO(2) linear map over the orders |m| <= m_max; the result is rotated back. On top of that (sections 3.2 to 3.4):

  • attention re-normalization: a layer norm on the scalars before the MLP attention;

  • separable S2 activation: SiLU on scalars, a SiLU on sphere samples for the higher degrees (also in the feed-forward networks, as a grid MLP);

  • separable layer norm: degree 0 and the degrees above 0 normalized separately.

The degree embedding rotates the m = 0 output of a radial function back from the edge frames and sums it over the neighbors (divided by avg_degree); the energy is a feed-forward network of the final features summed over the atoms and divided by avg_num_nodes. With direct_forces a final attention block predicts the forces from its degree-1 output (the OC20 S2EF models).

Conventions worth knowing:

  • The edge frames rotate r_j - r_i (center to neighbor), the negative of the xnn edge vector, onto the y axis (the e3nn polar axis). The reference picks a random roll about the edge for every evaluation; here the frame is the minimal rotation, deterministic and differentiable. The model depends on the roll only through the sampling of the sphere in the S2 activation.

  • The reference detaches the rotation matrices from the positions, which leaves the gradient of the energy incomplete; here the energy is differentiated through them, so forces and stress from autograd are the exact derivatives.

  • smooth_cutoff=True makes the energy continuous at the cutoff (not part of the paper), as in Equiformer. The reference’s truncation to the nearest max_neighbors atoms is not supported (it makes the energy discontinuous); use the radius instead.

Functions

edge_rotation(vec)

The minimal rotation taking each edge direction onto the y axis, (E, 3, 3).

grid_resolution(lmax, mmax, resolution)

Samples in latitude and longitude: resolution for both, or the reference's minimum.

m_primary_order(lmax, mmax)

The reduced coefficients reordered by order: m = 0 for every degree, then +m and -m.

make_norm(kind, lmax, channels)

"layer_norm_sh" (separable, the paper's), "layer_norm" (per degree) or "rms_norm_sh".

reduced_index(lmax, mmax)

Positions of the coefficients with |m| <= mmax in the full (lmax + 1)^2 layout.

Classes

DegreeLayerNorm(lmax, channels[, eps])

Equivariant layer norm of Equiformer on (N, (L + 1)^2, C): each degree normalized on its own.

EdgeDegreeEmbedding(channels, lmax, mmax, ...)

The degree embedding: radial m = 0 coefficients rotated back from the edge frames and summed.

EdgeFrames(lmax)

Wigner-D blocks of the edge rotations, degree by degree, from Clebsch-Gordan recursion.

EquiformerV2([n_features, n_interactions, ...])

EquiformerV2: equivariant graph attention on eSCN convolutions.

FeedForwardNetwork(channels, ...)

The feed-forward network (Figure 1d): SO(3) linear, separable S2 activation, SO(3) linear.

GateActivation(lmax, mmax, channels)

SiLU on degree 0, the sigmoid of extra scalars (one per channel and degree) on the others.

RMSLayerNorm(lmax, channels[, eps])

RMS norm over all degrees (degree-balanced), with degree 0 centered and given a bias.

S2Grid(lmax, mmax[, resolution])

Projection of (B, n, C) coefficients onto sphere samples (P, B, C) and back.

SO2Convolution(in_channels, out_channels, ...)

eSCN convolution in the edge frame: one linear map per order m, mixing +m and -m.

SO2GraphAttention(channels, hidden_channels, ...)

Equivariant graph attention on eSCN convolutions (section 3.5, Figure 1b).

SO3Linear(in_features, out_features, lmax)

Linear map per degree of (N, (L + 1)^2, C_in) features, with a bias on degree 0.

SeparableLayerNorm(lmax, channels[, eps])

Separable layer norm (section 3.4): a layer norm on degree 0, one RMS over all degrees above 0.

SeparableS2Activation(grid)

SiLU on separate degree-0 scalars, S2 activation (SiLU on the sphere) for the higher degrees.

TransformerBlockV2(channels, ...)

Pre-norm block: norm, SO(2) graph attention, residual; norm, feed-forward, residual.