npx skills add ...
npx skills add nvidia/nvalchemi-toolkit --skill nvalchemi-fine-tuning
How to fine-tune nvalchemi-compatible models with FineTuningStrategy, pretrained checkpoint initialization, module patches, trainable-parameter filters, conservative optimizer defaults, validation, restart checkpoints, and model-agnostic MACE, AIMNet2, custom BaseModelMixin, or PyTorch inputs. Use when adapting a pretrained MLIP (e.g. MACE-MP) to new reference data, freezing or patching submodules during training, or resuming an interrupted fine-tune from a checkpoint.
npx skills add nvidia/nvalchemi-toolkit --skill nvalchemi-fine-tuning
Use FineTuningStrategy when adapting pretrained weights to a new dataset,
objective, trainable parameter set, or model head. Link users to
docs/userguide/finetuning.md, docs/userguide/training.md,
docs/userguide/models.md, and docs/userguide/losses.md for full details.
Use nvalchemi-training finetune when the user wants quick experimentation:
an offline JSON spec, a scaffold for a supported source model, a Rich intent
report, or direct CLI execution without needing full API knowledge. Use a
Python script with FineTuningStrategy when the user needs arbitrary code,
custom model construction, dynamic data routing, dynamic losses, or non-standard
orchestration. Use nvalchemi-training train init for training-from-scratch
specs. The main groups are train, finetune, schema (dump, template),
and spec (report, run). Fine-tuning sources live under finetune init:
checkpoint, mace, aimnet2, and custom.
Common flow:
Use --loss-dtype-policy on finetune init or train init when the CLI
scaffold should serialize dtype alignment in strategy.loss_fn_spec. spec report renders the selected policy before execution.
Repeat --dataset to record a MultiDataset workflow. Use torchrun ... -m nvalchemi.training.cli spec run SPEC --distributed for DDP; the CLI initializes
DistributedManager, prepends DDPHook, builds the dataset(s), constructs the
strategy, and calls run(...).
Runtime hooks belong in source.hooks. Each entry contains a spec object
that is the serialized BaseSpec itself: cls_path, timestamp, and the
constructor keyword fields for the hook. The CLI builds the hook during spec
validation and rejects entries that are not Hook or CheckpointableHook
instances. The optional stages list uses TrainingStage names to override
where the hook fires, and spec report lists hook firing order chronologically.
For model-input transforms such as neighbor lists, use BEFORE_FORWARD; this
stage is reused by training and strategy-owned validation. Do not add a
validation-only callback for this.
Expect spec report to include warnings for common mistakes such as high
fine-tuning learning rates, missing validation data, unsafe checkpoint output
paths, or MACE compile settings.
FineTuningStrategy(models=...) when the user already loaded or built a
trainable model.FineTuningStrategy.from_pretrained_checkpoint(...) to start a fresh
fine-tuning run from model weights in a native nvalchemi checkpoint.FineTuningStrategy.load_checkpoint(...) only to resume an interrupted
fine-tuning run with optimizer/scheduler/counters/hook state.from_pretrained_checkpoint loads the complete checkpoint model set. A
single-model checkpoint becomes a single model input; multi-model checkpoints
preserve their named mapping. Source optimizer state, hooks, validation
settings, counters, and num_epochs/num_steps do not carry over. If the user
omits loss_fn or optimizer_configs, they may opt into source metadata with
use_original_loss=True or use_original_opt_class=True. Reused optimizer
configs get optimizer_lr=1e-5 by default; pass optimizer_lr=None to keep the
checkpoint LR.
Use low learning rates for full-model fine-tuning. Prefer trainable_patterns
for head-only or adapter-style workflows; patterns match fully qualified names
such as "main.model.readout.weight".
Use this when a previous nvalchemi run produced a restartable checkpoint but the new task should get fresh fine-tuning counters and optional source loss/optimizer metadata.
For multi-model checkpoints, write training_fn(models, batch) and pass
optimizer_configs keyed by the model(s) to update. Models omitted from
optimizer_configs are frozen/eval during training but can be used as teachers
or references. use_original_loss and use_original_opt_class require native
strategy metadata; they do not work with component-only checkpoints.
Prefer native wrapper constructors for supported pretrained models, for example
MACEWrapper.from_checkpoint(..., compile_model=False), because they preserve
reconstruction metadata for later strategy checkpoints. compile_model=True is
inference-only for MACE and freezes parameters.
For arbitrary PyTorch checkpoints:
create_model_spec(wrapper_cls_or_factory, ...) for reproducible rebuilds.state_dict; use strict=False only for intentional head or
adapter changes and inspect missing/unexpected keys.training_fn that returns the
mapping expected by the loss.FineTuningStrategy checkpoint before relying on resume behavior.Use module_patches to replace or add child modules before optimizer
construction. Use create_model_spec(...) for patches that must serialize;
direct module instances are runtime-only.
trainable_patterns alone is an allow-list. freeze_patterns excludes broad
regions first, then trainable_patterns re-includes exceptions. Use
freeze_mode="optimizer_only" only when frozen parameters should still receive
gradients for diagnostics or custom hooks.
Typical strategies to fine-tune without catastrophic forgetting include adding different readout/output heads or a new atom embedding table. Users will likely need a way to route based on dataset. If the user does not specify a strategy, discuss options tailored to the model and fine-tuning dataset. Note that equivariant models like MACE will need specialized read-out layers as to preserve equivariance.
dtype_policy: use
"prediction_to_target" to cast outputs to labels or "target_to_prediction"
to cast labels to outputs. Set it on a leaf loss, on ComposedLossFunction(...),
or as loss_fn.dtype_policy = ... after operator-sugar construction.FineTuningStrategy.load_checkpoint, not
from_pretrained_checkpoint.