Skip to content

Commit e1997b8

Browse files
committed
ENH Improve err msg for target modules (#2169)
1 parent 6f82003 commit e1997b8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/peft/tuners/tuners_utils.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,17 +509,27 @@ def inject_adapter(
509509
)
510510
elif not excluded_modules and unmatched_modules:
511511
# None of the targeted modules matched
512-
raise ValueError(
512+
error_msg = (
513513
f"Target modules {peft_config.target_modules} not found in the base model. "
514514
f"Please check the target modules and try again."
515515
)
516+
if peft_config.layers_to_transform is not None:
517+
error_msg += f" Note: You specified 'layers_to_transform': {peft_config.layers_to_transform}."
518+
if peft_config.layers_pattern is not None:
519+
error_msg += f" You also specified 'layers_pattern': {peft_config.layers_pattern}."
520+
raise ValueError(error_msg)
516521
else:
517522
# Some modules did not match and some matched but were excluded
518-
raise ValueError(
523+
error_msg = (
519524
"No modules were targeted for adaptation. "
520525
"This might be caused by a combination of mismatched target modules and excluded modules. "
521526
"Please check your `target_modules` and `exclude_modules` configuration."
522527
)
528+
if peft_config.layers_to_transform is not None:
529+
error_msg += f" Note: You specified 'layers_to_transform': {peft_config.layers_to_transform}."
530+
if peft_config.layers_pattern is not None:
531+
error_msg += f" You also specified 'layers_pattern': {peft_config.layers_pattern}."
532+
raise ValueError(error_msg)
523533

524534
elif hasattr(peft_config, "exclude_modules") and peft_config.exclude_modules and not excluded_modules:
525535
# exclude_modules was passed but was not used

0 commit comments

Comments
 (0)