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.

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.

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.

FineTuningSummaryHook

Cache fine-tuning parameter counts after registration hooks run.

BaseFingerprintHook

Cache model fingerprints before PEFT hooks mutate models.

ModulePatchHook

Field

Type

Description

patches

dict[str, BaseSpec | Module]

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

register_parameters

bool

If True, register the patched module parameters as both trainable and managed under the fixed ‘patch’ source. Registered patch parameters are included in the final trainable allow-list by default and are protected from being overridden by other sources modifying the model.

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. When supplied without freeze_patterns, they define the full trainable set, along with the trainable parameters registered by earlier hooks, e.g., ModulePatchHook. Everything else is frozen.

freeze_mode

Literal['requires_grad', 'optimizer_only']

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

FineTuningSummaryHook

This class has no configurable fields.

BaseFingerprintHook

This class has no configurable fields.

LoRAHook

LoRAHook

Apply LoRA adapters to models.

Field

Type

Description

lora_config

LoRAConfig

LoRA PEFT configuration describing adapter targets, rank, scaling, dropout, MLP wrapping, and custom wrapper registrations.

register_parameters

bool

If True, register LoRA adapter parameters as trainable and managed on the workflow. Set to False for standalone model loading where no training workflow registry exists. Defaults to True.

PEFT helpers#

Configuration and utility APIs for parameter-efficient fine-tuning workflows. LoRA is the only PEFT method currently supported. Pass peft_config=LoRAConfig(...) to FineTuningStrategy to train LoRA adapters and use load_peft_checkpoint_into_model(...) to load a trainable-state PEFT checkpoint into a compatible base model.

PeftMethodRegistration

Operations and configuration type associated with one PEFT method.

register_peft_method

Register all behavior required to use one PEFT method.

available_peft_methods

Return registered and built-in PEFT method names.

load_peft_checkpoint_into_model

Load PEFT weights from a native checkpoint into a compatible base model.

LoRAConfig

ALCHEMI LoRA configuration for FineTuningStrategy.

available_lora_wrappers

Return registered (layer, LoRA-wrapper) pairs.