xnn.trfnn.models.equiformer#
Equiformer, the equivariant graph attention transformer (Liao & Smidt, ICLR 2023).
An implementation of
Y.-L. Liao, T. Smidt, “Equiformer: Equivariant Graph Attention Transformer for 3D Atomistic Graphs”, ICLR 2023 (arXiv:2206.11990),
written from the paper on e3nn irreps features and the xnn abstractions, and consistent with the conventions of the authors’ code (atomicarchitects/equiformer: feature layouts, normalizations, initialization) without copying it.
Every atom carries an irreps feature x_i (C_L type-L vectors per degree).
A Transformer block is pre-norm: equivariant layer norm, equivariant graph
attention, residual; layer norm, feed-forward network, residual. The graph
attention (section 4.2) mixes the two endpoints of an edge,
x_ij = Linear_dst(x_i) + Linear_src(x_j), takes a depth-wise tensor product
(DTP) with the spherical harmonics of the edge weighted by a radial function,
f_ij = Linear(x_ij (x)_DTP SH(r_ij)), and derives
MLP attention:
a_ij = softmax_j(w^T LeakyReLU(f_ij^(0)))from the scalars;non-linear values:
v_ij = Linear(Gate(f_ij) (x)_DTP SH(r_ij))(or the linear messagev_ij = f_ij);
summed as sum_j a_ij v_ij over h heads and projected. The dot-product
attention of the ablation (appendix C.3) is the alternative attention="dot_product".
The embedding adds a degree embedding (a DTP of a constant feature summed over
the neighbors and divided by sqrt(avg_degree)) to the atom embedding; the
energy is a two-layer readout of the final scalars summed over the atoms and
divided by sqrt(avg_num_nodes).
Conventions worth knowing:
The spherical harmonics are evaluated on
r_j - r_i(center to neighbor), the negative of the xnn edge vector.The SE(3) models of the paper label every irrep even (
1e,2e), so tensor-product paths ignore parity; E(3) irreps (1o, …) give the E(3)-Equiformer of appendix C.4.smooth_cutoff=Truemakes the energy continuous at the cutoff (not part of the paper): the degree-embedding messages are multiplied by a polynomial envelope and the attention becomes the envelope-weighted softmax ofsegment_softmax().
Functions
|
The depth-wise tensor product: one weight per channel and path ( |
|
The radial basis of the Equiformer models. |
|
The irreps of the paper's architectures, optionally rescaled. |
Classes
|
The degree embedding of section 4.3: a DTP of a constant feature summed over the neighbors. |
|
Equiformer, the equivariant graph attention transformer. |
|
Equivariant layer norm of an irreps feature (section 4.1). |
|
Linear, gate, linear (the feed-forward network of section 4.3). |
|
The gate activation (section 4.1): SiLU on the scalars, sigmoid gates on the other irreps. |
|
Equivariant graph attention (section 4.2), or the dot-product attention of appendix C.3. |
|
Equivariant linear map: one weight matrix per pair of equal irreps, a bias on the even scalars. |
|
Pre-norm block: norm, graph attention, residual; norm, feed-forward, residual. |