LoRAAdapterMerger
Helpers & Utilities · AiDotNet.LoRA
Bakes LoRA adapter layers into plain layers across a whole network, producing a model that serves the fine-tuned behavior with no per-layer LoRA overhead — the standard way to deploy a LoRA-fine-tuned model as its own servable variant.
For Beginners
after fine-tuning a model with LoRA you have “original weights + small changes”. Merging bakes the changes into the weights so you can serve one clean model — like accepting all tracked changes in a document.
How It Works
Each ILoRAAdapter layer in the model is replaced by the result of
MergeToOriginalLayer (W' = W + scaling · B·A), which preserves the
adapted behavior exactly while collapsing “base + adapter” into a single layer. Adapters whose type does
not support merging are left in place (they still compute correctly, just without the speed/simplicity
win). The network’s forward iterates its Layers list directly, so the
in-place replacement takes effect immediately.
Methods
| Method | Summary |
|---|---|
bool HasAdapters(NeuralNetworkBase<T> model) |
Gets a value indicating whether model still contains any LoRA adapter layers. |
int MergeInPlace(NeuralNetworkBase<T> model) |
Merges every mergeable LoRA adapter layer in model into a plain layer, in place. |