xnn.common.config.schema.OptimConfig#

class xnn.common.config.schema.OptimConfig(lr=0.001, weight_decay=0.0, epochs=100, energy_weight=1.0, force_weight=10.0, stress_weight=0.0, dipole_weight=0.0, polarizability_weight=0.0, charge_weight=0.0, les_dipole_weight=0.0, les_charge_weight=0.0, property_weight=0.0, reaction_weight=0.0, reaction_batch_size=16, scheduler='plateau', huber_delta=0.0, huber_delta_energy=None, huber_delta_forces=None, huber_delta_stress=None, huber_delta_reactions=None, optimizer='adam', clip_grad=0.0, ema_decay=0.0, head_weights=None, freeze=<factory>, train_only=<factory>, prior_weight=0.0, prior_weights=None, loss_weighting='fixed')[source]#

Bases: object

Optimizer, schedule, and loss-weighting settings.

Variables:
  • lr (float) – Learning rate. Defaults to 1e-3.

  • weight_decay (float) – L2 weight-decay coefficient. Defaults to 0.0.

  • epochs (int) – Number of training epochs. MACE max_num_epochs. Defaults to 100.

  • energy_weight (float) – Weight of the energy term in the loss. MACE energy_weight. Defaults to 1.0.

  • force_weight (float) – Weight of the force term in the loss. Defaults to 10.0.

  • stress_weight (float) – Weight of the stress term; values > 0 enable stress training for periodic systems. Defaults to 0.0.

  • dipole_weight (float) – Weight of the dipole-moment term, for models with a dipole output (PaiNN, PhysNet, AIMNet2) on data with dipole labels. Defaults to 0.0.

  • polarizability_weight (float) – Weight of the polarizability-tensor term (PaiNN). Defaults to 0.0.

  • charge_weight (float) – Weight of the per-atom partial-charge term, for models with a charges output (the 3G / 4G HDNNP charge networks, PhysNet, AIMNet2) on data with charges labels. Defaults to 0.0.

  • les_dipole_weight (float) – Weight of the LES dipole term: the les_dipole of a model wrapped in LatentEwald against the dipole labels. Defaults to 0.0.

  • les_charge_weight (float) – Weight of the LES charge term: les_charges against the charges labels. Defaults to 0.0.

  • property_weight (float) – Weight of the property term: the properties output of a property model (MEGNet) against the properties labels, without division by the atom count. Defaults to 0.0.

  • reaction_weight (float) – Weight of the reaction-energy term: the errors of reaction energies (differences of the energies of several structures, a ReactionSet given to the trainer), in eV squared. Defaults to 0.0.

  • reaction_batch_size (int) – Reactions per training step of that term. Defaults to 16.

  • scheduler (str) – Learning-rate scheduler (none / cosine / plateau). MACE uses ReduceLROnPlateau. Defaults to "plateau".

  • huber_delta (float) – Crossover from quadratic to linear in the loss, which caps the pull of a few large residuals. 0.0 (the default) is plain squared error. Note xnn scales the Huber function to agree with the squared error below delta, so the loss weights keep their meaning when it is switched on; MACE uses the textbook half-square form.

  • huber_delta_energy (float, optional) – Per-term override of huber_delta for the energy term. None (default) falls back to it. Energies (eV per atom) and forces (eV/A) differ in scale by an order of magnitude, so one delta rarely suits both.

  • huber_delta_forces (float, optional) – Per-term override of huber_delta for the force term.

  • huber_delta_stress (float, optional) – Per-term override of huber_delta for the stress term.

  • huber_delta_reactions (float, optional) – Per-term override of huber_delta for the reaction-energy term.

  • optimizer (str) – "adam" (default; weight_decay is an L2 penalty), "amsgrad" (Adam with the AMSGrad maximum of the second moment, whose steps shrink as training settles; the DimeNet papers’ choice) or "adamw" (decoupled weight decay, the fine-tuning protocols’ choice).

  • clip_grad (float) – Maximum gradient norm per step (torch.nn.utils.clip_grad_norm_); 0.0 (default) disables clipping.

  • ema_decay (float) – Decay of an exponential moving average of the weights, updated after every optimizer step and used for validation, testing and the saved checkpoints (0.99-0.9999 in the fine-tuning protocols). 0.0 (default) trains and saves the raw weights.

  • head_weights (dict, optional) – Per-head loss weights of a multi-head model, e.g. {"pt_head": {"energy_weight": 1.0, "force_weight": 10.0}}; a head not listed uses the global weights. Each head’s terms are averaged over its own structures and the heads are summed.

  • freeze (list of str) – fnmatch patterns of parameter names to freeze (layer-freezing fine-tuning), e.g. ["model.node_embedding*", "model.interactions.0.*"].

  • train_only (list of str) – Patterns of the only parameters to train; everything else is frozen (["*readouts*", "*atom_ref*"] trains the readout alone).

  • prior_weight (float) – Weight of a quadratic pull of every trainable parameter toward its value at the start of the run, prior_weight * sum((p - p0)^2) in the parameter’s own units, added to the training loss and logged as prior. It keeps an ill-conditioned refit (a few dozen force-field parameters against a short scan) from drifting along the directions the data does not fix. Defaults to 0.0.

  • prior_weights (dict, optional) – Per-parameter pulls: fnmatch patterns of parameter names mapped to weights, e.g. {"*dihedral_v": 0.1, "*charge": 10.0}. The first pattern that matches a parameter sets its weight; the others take prior_weight.

  • loss_weighting (str) – "fixed" (the default) sums the terms with their weights. "uncertainty" also learns a scale sigma_k per term: the training steps minimize sum_k L_k / (2 sigma_k^2) + log sigma_k (Kendall et al., CVPR 2018), where L_k is the term times its weight. The logged loss stays the fixed-weight sum, and sigma_<term> gives each scale. Single-head training without trainer.cuda_graph.

Parameters: