Fine-tuning API#

Registration-time helpers for adapting pretrained models before optimizer construction.

See also

Strategy#

FineTuningStrategy

Training strategy for patching modules and selecting trainable parameters.

FineTuningStrategy.from_pretrained_checkpoint

Start a new fine-tuning run from checkpointed model weights.

FineTuningStrategy.load_checkpoint

Load a restartable strategy checkpoint.

Use FineTuningStrategy.load_checkpoint(...) to resume an interrupted run with saved optimizer state, scheduler state, counters, and serialized fine-tuning configuration. Use FineTuningStrategy.from_pretrained_checkpoint(...) to start a new fine-tuning run whose model weights are initialized from an existing checkpoint; optimizer state, hooks, and counters do not carry over. See Fine-Tuning Pretrained Models for patterns and examples.

Hooks#

Registration-time hooks that adapt the model tree and optimizer parameter set before training starts. They do not own backward() or optimizer-step behavior; use Training update hooks for batch-update policies.

ModulePatchHook

Patch model submodules at registration time.

TrainableParameterHook

Select which parameters stay trainable during fine-tuning.

ModulePatchHook

Field

Type

Description

patches

dict[str, nvalchemi.training._spec.BaseSpec | torch.nn.modules.module.Module]

Ordered mapping of target paths to replacement modules or specs that build modules.

TrainableParameterHook

Field

Type

Description

freeze_patterns

tuple[str, ...]

Glob patterns for parameters to freeze. Overridden by trainable_patterns — a parameter matching both stays trainable.

trainable_patterns

tuple[str, ...]

Glob patterns for parameters to keep trainable. On their own they define the full trainable set (everything else is frozen).

freeze_mode

typing.Literal['requires_grad', 'optimizer_only']

Whether excluded parameters are temporarily frozen via requires_grad=False or only excluded from optimizer construction.