xnn.common.models.ops#

Tensor operations shared across model families (gnn / cnn / dnn).

Kept here, at the models level, because they are common to more than one architecture type. Per-family helpers live under the family package instead (e.g. models/gnn/base.py), and graph-level reductions that every model needs live on InteratomicPotential (aggregate_energy).

Module Attributes

WEIGHT_INITS

Weight initializations by name (init_linear_()); "torch" keeps PyTorch's default.

FUSED_SLOPE_MIN_ELEMENTS

From this many elements a training activation (SiLU, GELU) keeps its fused derivative under autograd; below it torch's own function, whose fewer Python calls win where the step is bound by launches.

ATOMIC_MASSES

Standard atomic weights (u) by atomic number, Z = 0 to 99 (the ASE table), for center_of_mass().

Functions

build_triplets(edge_index, num_nodes)

Enumerate neighbour pairs (j, k) sharing a centre i.

cell_volume(cell)

Volume of row-vector cells (..., 3, 3) as the scalar triple product.

center_of_mass(pos, atomic_numbers, batch, ...)

Center of mass of every structure of a batch.

exact_softplus(x)

Evaluate log(1 + exp(x)) exactly to round-off, with exact derivatives.

gather_rows(src, index)

Rows src[index] (dim 0), with the faster kernels of the device.

glorot_orthogonal_(weight[, scale])

Initialize a weight matrix as a (semi-)orthogonal matrix with Glorot variance.

he_orthogonal_(weight)

He-scaled orthogonal initialization with exact standardization (GemNet, section 6).

init_linear_(linear[, weight])

Initialize a dense layer by name: its weight by weight, its bias to zero.

init_linears_(module[, weight])

Apply init_linear_() to every dense layer inside module.

make_activation(activation)

Return a fresh activation module from a name or a module instance.

refresh_ghosts(x)

Per-atom rows with the ghost atoms' rows replaced by their owners' values.

scatter_sum(src, index, dim_size)

Sum rows of src into dim_size buckets given by index (dim 0).

segment_softmax(logits, index, num_segments)

Softmax of row logits over the rows that share a segment.

segment_sum(x, lengths)

Sum of consecutive segments of x along dim 0; lengths (int64) sum to len(x).

shifted_softplus(x)

Shifted softplus ssp(x) = ln(0.5 e^x + 0.5) with ssp(0) = 0.

small_gather_elements()

Element count below which gather_rows() and scatter_sum() use index_select and index_add_ on CUDA as well.

softplus_inverse(x)

Return y such that softplus(y) = x (x > 0, float or array).

structure_sum(src, index, dim_size)

Sum per-atom values into per-structure totals, accumulated in float64.

structure_sums(src, index, dim_size)

structure_sum() of several per-atom rows at once: src (T, N) to float64 totals (T, dim_size) in one scatter (one cast, one zero fill and one index add for every row instead of three launches per row).

whole_structure_sum(src, index, dim_size)

scatter_sum() of per-atom rows into per-structure totals over every atom of a structure, also when the structure is split over several processes.

Classes

GELU([approximate])

torch.nn.GELU (exact form) whose derivative stays the fused kernel under autograd.

GaussianActivation(*args, **kwargs)

Gaussian activation exp(-x^2) (the original ANI-1 hidden activation).

ScaledTanh(*args, **kwargs)

1.59223 tanh(x), the scaled hyperbolic tangent of the RuNNer networks.

ShiftedSoftplus(*args, **kwargs)

Module form of shifted_softplus(), for use inside nn.Sequential.

SiLU([inplace])

torch.nn.SiLU whose derivative stays the fused kernel under autograd.

Softplus(*args, **kwargs)

Softplus log(1 + e^x) evaluated exactly at every x (module form of exact_softplus()).

Square(*args, **kwargs)

x^2.