xnn.gnn.fast.megnet#
Fast path of MEGNet: the encoders, the blocks and the Set2Set readouts as compiled stages.
The reference block concatenates [v_i, v_j, e_k, u] for every bond before the first
dense layer of the bond update. That layer is linear, so here its weight is split into
the four blocks of the concatenation: the atom and state parts are multiplied once per
atom and per structure and gathered to the bonds, and only the bond part is multiplied
per bond. The atom update is split the same way (its state part once per structure).
The results are the same to rounding, without the bond-sized concatenation and with a
quarter of the first layer’s work on the bonds.
The Set2Set readouts write the LSTM cell out (the gate equations of
torch.nn.LSTM), so that all their steps are one stage. On a GPU every stage is
compiled by torch.compile(), which fuses the activations, gathers and means into
few kernels. When a gradient is needed the stages are compiled with their first and
second derivatives (compile_twice_differentiable()); on a
CPU they run as written.
Module Attributes
every size, since on an A100 the compiled stages and on a CPU the split layers (as written) were faster than the reference from one 20-atom cell to one of 16384 atoms, in both precisions. |
|
every size, on an A100 with a third to two thirds of the reference's memory. |
Functions
|
|
|
|
|
The (weight, bias) of every layer of the given MLPs, in order. |
|
Whether every layer of |
|
|
|
The stage |