xnn.common.finetune.heads.MultiHead#
- class xnn.common.finetune.heads.MultiHead(model, heads)[source]#
Bases:
InteratomicPotentialA potential with several readout heads over one shared trunk.
Head 0 is the wrapped model’s own readout (and reference energies); the other heads are copies of the modules the model names in its
head_modules. Every head sees the same trunk, so a forward pass on a batch mixing heads runs the trunk once per head present (on that head’s structures) with the head’s parameters substituted, and nothing is computed twice.- Parameters:
model (InteratomicPotential) – The potential to give several heads. Its current readout becomes head 0.
heads (sequence of str) – The head names, in index order (
["pt_head", "Default"]for the MACE replay convention: the pretrained readout serves the replay data, the copy adapts to the target data).
- Variables:
model (InteratomicPotential) – The trunk, carrying head 0.
extra_heads (torch.nn.ModuleList) – One
_HeadCopyper head after the first.cutoff (float) – The trunk’s radial cutoff.
- Raises:
TypeError – If the model declares no
head_modules.ValueError – For an empty or repeated head list.
- property species#
The trunk’s supported atomic numbers, if it lists them.
- forward(data)[source]#
Evaluate every structure with the head it is labelled with.
- Parameters:
data (AtomicGraph) – The batch;
data.headholds the head index per structure (Nonemeans head 0 throughout).- Returns:
The trunk’s outputs (
node_energy,energy,node_features, …) in the batch’s order.- Return type:
dict of str to torch.Tensor
- using(head)[source]#
Make the trunk carry the modules of
headfor the duration of a block.Lets any single-head routine (reference-energy estimation, pseudolabelling, a deployment export) act on one head through
model; the trunk’s own head is restored afterwards.
- select(head)[source]#
A standalone single-head potential: the trunk with one head’s modules.
- Parameters:
- Returns:
A deep copy of the trunk carrying that head; the same class as the wrapped model, so every deployment path (TorchScript export, ASE calculator, MDI) applies unchanged.
- Return type:
- label(structures, head)[source]#
Tag structures with one of this model’s heads (see
label_head()).
- set_use_fast(use_fast)[source]#
Forward the fast-path setting to the trunk (see
xnn.common.models.fast.set_use_fast()).- Return type:
- classmethod from_config(cfg)[source]#
Build through
build_model()(extra["heads"]).- Return type: