Skip to content

Commit 2bf7bc2

Browse files
FIX Transformers weight conversion regression (#3197)
After a change in huggingface/transformers#45448, weight conversion tests started failing. Transformers provided a fix in huggingface/transformers#45622 but it needs to be ported to PEFT too. This PR, together with the Transformers fix, resolves the issue.
1 parent 8c6943c commit 2bf7bc2

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/peft/utils/transformers_weight_conversion.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,10 @@ def build_peft_weight_mapping(
206206
return []
207207

208208
# strip "base_model.model" and add adapter name
209-
new_weight_conversions = [WeightRenaming("base_model.model.model.", "model.")]
209+
new_weight_conversions = [
210+
WeightRenaming("base_model.model.model.", "model."),
211+
WeightRenaming("base_model.model.", ""),
212+
]
210213

211214
prefixes = set()
212215
from peft.mapping import PEFT_TYPE_TO_PREFIX_MAPPING
@@ -268,10 +271,10 @@ def build_peft_weight_mapping(
268271
new_conversion = orig_conversion.__class__(
269272
source_patterns=new_source_patterns,
270273
target_patterns=new_target_patterns,
271-
distributed_operation=orig_conversion.distributed_operation,
272-
quantization_operation=orig_conversion.quantization_operation,
273274
operations=peft_weight_operations,
274275
)
276+
new_conversion.distributed_operation = orig_conversion.distributed_operation
277+
new_conversion.quantization_operation = orig_conversion.quantization_operation
275278
new_weight_conversions.append(new_conversion)
276279

277280
elif len(orig_conversion.target_patterns) == 1 and orig_conversion.target_patterns[0].endswith("down_proj"):
@@ -310,10 +313,10 @@ def build_peft_weight_mapping(
310313
new_conversion = orig_conversion.__class__(
311314
source_patterns=new_source_patterns,
312315
target_patterns=new_target_patterns,
313-
distributed_operation=orig_conversion.distributed_operation,
314-
quantization_operation=orig_conversion.quantization_operation,
315316
operations=peft_weight_operations,
316317
)
318+
new_conversion.distributed_operation = orig_conversion.distributed_operation
319+
new_conversion.quantization_operation = orig_conversion.quantization_operation
317320
new_weight_conversions.append(new_conversion)
318321

319322
return new_weight_conversions

0 commit comments

Comments
 (0)