xnn.gnn.fast.conv.ConvTensorProduct#

class xnn.gnn.fast.conv.ConvTensorProduct(*args, **kwargs)[source]#

Bases: TensorProduct, FastPathModule

uvu tensor product with per-edge weights and a fused message pass.

An e3nn.o3.TensorProduct (same arguments, parameters and state_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.

fast_supported(device, dtype)[source]#

Whether the fast path can run for inputs on device in dtype.

Parameters:
Return type:

bool

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, and conv() is then called with weights_mapped=True.

Parameters:
  • like (torch.Tensor) – Any tensor on the device and in the dtype of the evaluation.

  • message_divisor (float, optional) – As in conv().

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_weights already carry the column map of weight_map() (divisor included). Default False.

  • weight_index (torch.Tensor, optional) – (E,): edge e takes the weights of row weight_index[e] (the two directions of a bond share theirs, edge_pairs()); by default row e.

Returns:

The summed messages, (N, irreps_out.dim).

Return type:

torch.Tensor

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 from edge_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:
  • node_feats (Tensor) – As in conv().

  • edge_attrs (Tensor) – As in conv().

  • edge_index (Tensor) – As in conv().

  • num_nodes (int) – As in conv().

  • 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 edges a:b.

  • weights_mapped (bool, optional) – As in conv().

  • 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 to conv() on all edges up to the order of the sums.

Return type:

torch.Tensor

indexes_weights(like)[source]#

Whether conv() reads weight_index inside the fast kernel; otherwise it gathers the weights per edge first.

Parameters:

like (Tensor)

Return type:

bool