xnn.common.train.graphed#

Training steps replayed as one CUDA graph (trainer.cuda_graph).

A training step on small molecules is bound by kernel launches: the model, the force derivative and the parameter gradients of a force loss take thousands of small kernels, each launched from the host. A captured step replays all of them as one graph. Capture needs fixed shapes and no host synchronization inside the step:

  • every batch is padded to fixed counts of atoms, edges and model indices by one inert structure (PaddedCollate): its labels are masked out, so it adds exactly nothing to the loss and the gradients;

  • the index work whose sizes depend on the data (the triplets of DimeNet, the embedding edges, triplets and quadruplets of GemNet) runs before the step, in the data-loader workers, through the model’s index_planner(), and the batch carries the result as index_plan;

  • the loss runs without reading values back (weighted_loss(sync=False)), the optimizer is capturable, and the logged values are read after the replay.

The first batches run as ordinary steps (they warm up the libraries’ workspaces), the next is captured and every later one replayed.

Module Attributes

PADDING_Z

The atomic number of the padding atoms.

PADDING_SPACING

The spacing of the padding atoms along x (neighbors on the line, which carry the padding edges, sit within every cutoff; no edge links them to a real atom).

WARMUP_STEPS

Ordinary steps before the capture.

Functions

capacity(planner, dataset, batch_size)

Counts that fit every batch of batch_size structures of dataset.

combine(planner, graphs)

The index plan of a batch from the plans of its structures (index_plan of each).

index_planner(model)

The index planner of the first submodule of model that has one, or None.

padding_structure(n_atoms, n_edges, like)

The inert structure that fills a batch: n_atoms >= 2 atoms on a line, n_edges edges between neighbors on the line (each with its reverse: n_edges is even), spread over the pairs in turn so that no atom collects many of them (sums onto one atom would serialize), no labels.

strip_padding(batch)

The real structures of a padded batch (PaddedCollate), without the padding structure and the index plan: what an ordinary step takes.

Classes

Capacity(atoms, edges, plan)

The fixed counts of a padded batch.

FixedShapePlanner([check])

The planner of a model whose shapes the batch fixes by itself and which takes no padding structure (a model bound to one system, ByteFF): a captured evaluation replays the batch as it comes and is recorded again when its counts change.

GraphedStep(body, device[, warmup])

A training step on padded batches, captured once and replayed.

NoIndexPlanner([check])

The planner of a model whose step needs no index work beyond its edges (PhysNet): the padded batch fixes the atom and edge counts only.

PaddedCollate(planner, cap)

Collate structures into a batch of fixed counts with its index plan.

PlannedDataset(dataset, planner)

A dataset whose structures carry their index plans, built once.