Table of Contents

Method ApplyLoraAdapter

Namespace
LMKit.Model
Assembly
LM-Kit.NET.dll

ApplyLoraAdapter(string, float)

Preloads a Low-Rank Adaptation (LoRA) adapter from the specified file into the model, preparing it for dynamic application at inference time. Upon preload, a new entry appears in the model’s Adapters collection. The adapter will only take effect when its scale is greater than zero.

public void ApplyLoraAdapter(string path, float scale = 1)

Parameters

path string

The file system path to the LoRA adapter source file. Must not be null, empty, or whitespace.

scale float

The initial scale factor for the LoRA adapter. Must be zero or positive. A value of zero registers the adapter but keeps it inactive until the scale is raised, at which point it will be applied during inference.

Exceptions

ArgumentNullException

Thrown if the path parameter is null, empty, or whitespace.

ArgumentOutOfRangeException

Thrown if the scale parameter is less than zero.

FileNotFoundException

Thrown if no file exists at the specified path.

InvalidDataException

Thrown if the file’s header is not a valid LoRA adapter format.

RuntimeException

Thrown if the adapter fails to preload correctly, for example due to native backend errors.

ApplyLoraAdapter(LoraAdapterSource)

Preloads a Low-Rank Adaptation (LoRA) adapter into the model using parameters from a LoraAdapterSource instance. Upon preload, the adapter is registered in the model’s Adapters collection and will only be applied at inference time when its Scale is greater than zero.

public void ApplyLoraAdapter(LoraAdapterSource loraAdapterSource)

Parameters

loraAdapterSource LoraAdapterSource

An instance of LoraAdapterSource containing the path to the LoRA parameters and the desired scale factor.

Remarks

Supports dynamic adapter loading: adapters are registered here and only take effect during subsequent inference if their scale is set above 0. A scale of 0 means the adapter remains inactive until the scale is raised and the model is re-evaluated.

Exceptions

ArgumentNullException

Thrown if the loraAdapterSource parameter is null.

RuntimeException

Thrown if the adapter fails to preload correctly, for example due to I/O errors, invalid file format, or native backend failures when preparing the adapter for later inference.