nvalchemi.training.losses.reductions.per_graph_mean#

nvalchemi.training.losses.reductions.per_graph_mean(values, batch_idx, num_graphs=None)[source]#

Mean of per-node values across each graph.

This divides each graph’s sum by that graph’s node count and returns one value per graph. It does not choose how those graph values are weighted in a later scalar reduction. For per-graph values \(x_i\), the graph-balanced scalar is \(B^{-1} \sum_i x_i\); the atom-weighted scalar is \((\sum_i N_i x_i) / (\sum_i N_i)\).

Empty graphs (zero nodes) are safe: their sum is zero and their count is clamped to 1 before the division, so they yield zero. See the module docstring for shared parameter / error semantics.

Returns:

Per-graph means.

Return type:

Float[torch.Tensor, “B …”]

Parameters:
  • values (Float[torch.Tensor, 'V ...'])

  • batch_idx (BatchIndices)

  • num_graphs (int | None)