xnn.gnn.models.mace#
MACE (Batatia et al. 2022): higher body-order equivariant message passing.
A faithful, self-contained MACE built on the xnn equivariant-GNN abstractions:
it subclasses EquivariantGNN (species bookkeeping,
per-element reference energy atom_ref, and the
SphericalHarmonicEdgeEmbedding edge featurizer) and
adds the genuinely MACE-specific pieces – the real
RealAgnostic(Residual)InteractionBlock and a learned symmetric contraction
over Clebsch-Gordan paths (correlation order).
The CG U basis (U_matrix_real()) is bit-identical to mace-torch and
the symmetric contraction reproduces it to ~1e-16 given the same weights
(see tests/common/test_gnn.py). Only e3nn is required – no mace-torch,
cuequivariance or opt_einsum_fx.
The model is TorchScript-deployable: the tensor-only MACE.node_energy()
core compiles under torch.jit.script (used by the LAMMPS/TorchScript
exporters in xnn.common.deploy) and reproduces the eager model to
machine precision (see tests/gnn/test_mace.py).
Difference from upstream MACE: num_interactions (the number of message-passing
layers T) is fully flexible – T = 0 (a pure atom_ref/pair-repulsion
baseline) through any T = N – rather than being fixed to 2. All architecture
options are read from ModelConfig.extra (see MACE.from_config());
upstream MACE-CLI spellings (r_max, atomic_numbers, E0s, …) are
translated to the xnn names at config-load time by the key-translation registry
in xnn.common.config.translate.
The CG coupling and the symmetric contraction are independent implementations
(plain torch.einsum, built on e3nn’s o3.wigner_3j; no codegen/cueq
deps), verified bit-identical against ACEsuit/mace (MIT licence). All
conventions – CG normalization, coupling-path ordering, parameter and buffer
names – follow upstream so trained mace-torch weights transplant directly.
Module Attributes
Headroom over the memory of the unblocked message passes from an interaction on (per edge, the weights and radial layers each keeps for the backward, and the largest weight gradient): the "auto" pass runs unblocked when all edges, times this, fit in the free GPU memory. |
|
Otherwise the pass of one interaction still runs unblocked when its per-edge weights of all edges, times this, fit in the free memory (the weights, their gradient and the radial layers). |
|
the free memory is partly cached fragments, and the backward of a block needs more than its weights. |
|
Edges from which MACE's eager evaluation makes the radial weights once per bond (the two directions of a bond share them), below which the pairing costs more than it saves. |
|
Numbers per edge and weight kept free on top of the one-pass need before the edges read their weights by bond (the bonds' weight gradient and the kernel's indexed backward). |
|
Bytes per edge kept free on the device outside PyTorch's memory pool, where the fast kernel allocates the index buffers of weights read by bond. |
|
The smallest block, in edges. |
Functions
|
Symmetric coupling basis of |
|
Choose how the MACE interactions of |
Classes
|
Faithful MACE with a flexible number of interaction layers (T = 0..N). |
Non-residual interaction with learned density normalization. |
|
Residual interaction with learned density normalization. |
|
Non-residual interaction: the skip connection is applied to the message. |
|
Residual interaction: self-connection computed from the input features. |
|
|
Per-element symmetric contraction over all output irreps (the MACE product basis). |