xnn.gnn.fast.cgcnn#
Fast path of CGCNN: the network from the positions to the pooled atom features as one compiled stage.
The stage forms the bond vectors and lengths from the positions and the cell, their Gaussian
expansion, the element rows and their dense layer, every convolution and the mean over each
crystal. In a convolution the reference concatenates [v_i, v_j, u_ij] for every bond before
the first dense layer. That layer is linear, so here its weight is split into the three blocks of
the concatenation: the parts of the atom and of its neighbor are multiplied once per atom (the
neighbor’s then gathered to the bonds), and only the Gaussian bond features are multiplied per
bond. The batch normalizations, the gate, the neighbor sum, the residual and the softplus follow.
The results are the same to rounding, with a quarter of the first layer’s work on the bonds and
one compiled call in place of some fifty operations.
The stage serves graphs in which every atom keeps the same number of neighbors, grouped by atom
(the neighbor table of the authors’ layout, as the selection of the model and
structure_to_graph() with max_neighbors produce); other graphs take the
reference. In training mode the stage normalizes with the statistics of the batch and returns
them, and the running statistics are updated outside it, as torch.nn.BatchNorm1d updates
them. The dense layers after the pooling stay outside the stage (their dropout draws random masks).
On a GPU the stage is compiled by torch.compile(); when a gradient is needed its compiled
backward gives the first derivatives and a backward that is itself differentiated gives the second
(compile_differentiable()). On a CPU it runs as written.
Module Attributes
Edge counts above which |
|
The same for training mode (a step with a property loss). |
Functions
|
Give the compiler the representative sizes of the size class of a graph, on the first dimension of every edge-sized and every atom-sized input of the stage: it tunes the reductions of a stage for these sizes (and keeps the versions of the classes apart in its cache), not for those of its first call, so that a stage first called on a few hundred bonds still reduces hundreds of thousands quickly. |
|
The network up to the pooling as one function of its tensors. |
|
The size class of a graph: 0 below 2^13 edges, 1 below 2^16, 2 above. |
|
The network stage of |
|
Update the running statistics of |