File tree Expand file tree Collapse file tree 3 files changed +15
-6
lines changed Expand file tree Collapse file tree 3 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,17 @@ class PEFTAttributeConfig(ModeloptBaseConfig):
72
72
description = "Custom initialization function for LoRA B matrix. Default to zero initialization." ,
73
73
)
74
74
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
+
75
86
@field_validator ("rank" )
76
87
@classmethod
77
88
def validate_rank (cls , v ):
Original file line number Diff line number Diff line change @@ -62,7 +62,8 @@ def update_model(
62
62
Returns:
63
63
The updated model with LoRA adapters
64
64
"""
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." )
66
67
67
68
# Check if model is already in PEFT mode by looking for LoRA modules
68
69
if not is_peft_model (model ):
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ def _register_adapter(
72
72
73
73
# Store in adapter dictionary with explicit rank
74
74
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 ." )
76
76
self ._lora_adapters [adapter_name ] = {
77
77
"lora_a" : lora_a ,
78
78
"lora_b" : lora_b ,
@@ -94,10 +94,7 @@ def update_layer_lora(
94
94
95
95
Args:
96
96
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
101
98
"""
102
99
raise NotImplementedError ("Subclasses must implement update_layer_lora" )
103
100
You can’t perform that action at this time.
0 commit comments