Skip to content

Commit 1bb3985

Browse files
committed
Some minor updates
Signed-off-by: Jingyu Xin <[email protected]>
1 parent 6df1954 commit 1bb3985

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

modelopt/torch/peft/config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ class PEFTAttributeConfig(ModeloptBaseConfig):
7272
description="Custom initialization function for LoRA B matrix. Default to zero initialization.",
7373
)
7474

75+
@field_validator("lora_a_init", "lora_b_init")
76+
@classmethod
77+
def validate_init_method(cls, v):
78+
"""Validate initialization method is supported."""
79+
valid_methods = {"kaiming_init", "zero_init"}
80+
if v not in valid_methods:
81+
raise ValueError(
82+
f"Invalid initialization method: {v}. Supported methods: {', '.join(valid_methods)}"
83+
)
84+
return v
85+
7586
@field_validator("rank")
7687
@classmethod
7788
def validate_rank(cls, v):

modelopt/torch/peft/convert.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def update_model(
6262
Returns:
6363
The updated model with LoRA adapters
6464
"""
65-
assert is_megatron_core_model(model), "We only support mcore format for the PEFT mode"
65+
if not is_megatron_core_model(model):
66+
raise ValueError("PEFT mode currently supports Megatron-Core models only.")
6667

6768
# Check if model is already in PEFT mode by looking for LoRA modules
6869
if not is_peft_model(model):

modelopt/torch/peft/lora/layer.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def _register_adapter(
7272

7373
# Store in adapter dictionary with explicit rank
7474
if adapter_name in self._lora_adapters:
75-
raise ValueError(f"adapter_name: {adapter_name} is already exist..")
75+
raise ValueError(f"Adapter '{adapter_name}' already exists.")
7676
self._lora_adapters[adapter_name] = {
7777
"lora_a": lora_a,
7878
"lora_b": lora_b,
@@ -94,10 +94,7 @@ def update_layer_lora(
9494
9595
Args:
9696
adapter_name: Name for the new adapter
97-
rank: Rank of the LoRA decomposition (default: 64)
98-
scale: Scale factor for the LoRA output (default: 1.0)
99-
lora_a_init: Optional initialization function for LoRA A matrix
100-
lora_b_init: Optional initialization function for LoRA B matrix
97+
attr_config: PEFTAttributeConfig containing rank, scale, and initialization settings
10198
"""
10299
raise NotImplementedError("Subclasses must implement update_layer_lora")
103100

0 commit comments

Comments
 (0)