xnn.gnn.fast.conv.ConvTensorProduct#
- class xnn.gnn.fast.conv.ConvTensorProduct(*args, **kwargs)[source]#
Bases:
TensorProduct,FastPathModuleuvutensor product with per-edge weights and a fused message pass.An
e3nn.o3.TensorProduct(same arguments, parameters andstate_dict) with one more method,conv(), which evaluates the whole message step. Called as a module it is the plain e3nn tensor product.The fast path applies when every instruction is
uvu, the second input has multiplicity one throughout (spherical harmonics) and the weights are per edge (shared_weights=False), which is the convolution of MACE and NequIP. It is exact up to the summation order.- weight_map(like, message_divisor=None)[source]#
The column map of the per-edge weights on the fast path.
The fused kernel takes the weights in its own column order and scale (and the message divisor folded in). Passed to the radial network (
RadialNet), the map is applied once to its last layer instead of every edge, andconv()is then called withweights_mapped=True.- Parameters:
like (torch.Tensor) – Any tensor on the device and in the dtype of the evaluation.
- Returns:
(index, scale)on the fast path;(None, None)on the reference path, where the weights are used as they are.- Return type:
tuple of (torch.Tensor or None, torch.Tensor or None)
- conv(node_feats, edge_attrs, edge_weights, edge_index, num_nodes, message_divisor=None, weights_mapped=False, weight_index=None)[source]#
Gather, tensor product and sum onto the receivers in one call.
- Parameters:
node_feats (torch.Tensor) – Node features,
(N, irreps_in1.dim).edge_attrs (torch.Tensor) – Edge attributes (spherical harmonics),
(E, irreps_in2.dim).edge_weights (torch.Tensor) – Per-edge path weights,
(E, weight_numel).edge_index (torch.Tensor) –
(2, E): row 0 the senders, row 1 the receivers.num_nodes (int) –
N.message_divisor (float, optional) – Divide the summed messages by this (NequIP’s
sqrt(avg_num_neighbors)); the reference divides the node sums, one pass over the nodes instead of the edges, and the fast path folds it into the weights.weights_mapped (bool, optional) –
edge_weightsalready carry the column map ofweight_map()(divisor included). DefaultFalse.weight_index (torch.Tensor, optional) –
(E,): edgeetakes the weights of rowweight_index[e](the two directions of a bond share theirs,edge_pairs()); by default rowe.
- Returns:
The summed messages,
(N, irreps_out.dim).- Return type:
- conv_blocks(node_feats, edge_attrs, edge_feats, edge_index, num_nodes, block, weights, weights_mapped=False, recompute=False)[source]#
conv()over blocks of edges, the per-edge weights made per block fromedge_feats.The weights of one block exist at a time. On the fast path the node features are brought to the kernel’s layout once and the blocks’ node sums are added in that layout, then brought back once, and the edge inputs are split once, so that a block costs work over its edges only, besides one sum over the nodes.
- Parameters:
edge_feats (torch.Tensor) – The per-edge input of
weights,(E, ...).block (int) – Edges per block.
weights (callable) –
weights(edge_feats[a:b])is the per-edge weights of edgesa:b.recompute (bool, optional) – Keep no block’s weights for the backward: each block runs again there.
- Returns:
The summed messages,
(N, irreps_out.dim), equal toconv()on all edges up to the order of the sums.- Return type: