lora
lora
¶
LoRA adaptation helpers for HuggingFace modules.
LoRAAdaptation
dataclass
¶
LoRAAdaptation(enabled=False, rank=8, alpha=16, dropout=0.0, target_modules=value, exclude_modules=None, bias='none', init_lora_weights=DEFAULT_LORA_INIT_WEIGHTS)
Runtime configuration for Low-Rank Adaptation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enabled
|
bool
|
Whether to wrap the model with LoRA adapters. Disabled configurations leave the original module unchanged. |
False
|
rank
|
int
|
Adapter rank |
8
|
alpha
|
int
|
Adapter scaling factor. PEFT applies the learned update with
scale |
16
|
dropout
|
float
|
Dropout probability on the adapter path. Larger values add regularization before the low-rank update. |
0.0
|
target_modules
|
str
|
PEFT target-module preset. |
value
|
exclude_modules
|
list[str] | None
|
Optional module names to leave unwrapped even if they match the selected target preset. |
None
|
bias
|
str
|
PEFT bias handling mode. |
'none'
|
init_lora_weights
|
str
|
PEFT adapter weight initialization strategy passed to
|
DEFAULT_LORA_INIT_WEIGHTS
|
__post_init__
¶
Validate LoRA hyperparameters.
Source code in src/versatil/models/adaptation/lora.py
is_lora_enabled
¶
to_peft_lora_config
¶
Convert a VersatIL LoRA config to PEFT's LoRA configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lora_config
|
LoRAAdaptation
|
VersatIL LoRA configuration. |
required |
Returns:
| Type | Description |
|---|---|
LoraConfig
|
PEFT LoRA configuration. |
Source code in src/versatil/models/adaptation/lora.py
apply_lora_config
¶
Wrap a HuggingFace module with LoRA adapters when configured.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
HuggingFace module to adapt. |
required |
lora_config
|
LoRAAdaptation | None
|
Optional LoRA configuration. |
required |
frozen
|
bool
|
Whether the owning wrapper requests a fully frozen model. |
required |
Returns:
| Type | Description |
|---|---|
Module
|
The original model when LoRA is disabled, otherwise a PEFT-wrapped model. |