Skip to content

Commit

Permalink
ENH Improve err msg for target modules (#2169)
Browse files Browse the repository at this point in the history
  • Loading branch information
JINO-ROHIT authored Oct 22, 2024
1 parent 095e86c commit 0d58942
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/peft/tuners/tuners_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,17 +509,27 @@ def inject_adapter(
)
elif not excluded_modules and unmatched_modules:
# None of the targeted modules matched
raise ValueError(
error_msg = (
f"Target modules {peft_config.target_modules} not found in the base model. "
f"Please check the target modules and try again."
)
if peft_config.layers_to_transform is not None:
error_msg += f" Note: You specified 'layers_to_transform': {peft_config.layers_to_transform}."
if peft_config.layers_pattern is not None:
error_msg += f" You also specified 'layers_pattern': {peft_config.layers_pattern}."
raise ValueError(error_msg)
else:
# Some modules did not match and some matched but were excluded
raise ValueError(
error_msg = (
"No modules were targeted for adaptation. "
"This might be caused by a combination of mismatched target modules and excluded modules. "
"Please check your `target_modules` and `exclude_modules` configuration."
)
if peft_config.layers_to_transform is not None:
error_msg += f" Note: You specified 'layers_to_transform': {peft_config.layers_to_transform}."
if peft_config.layers_pattern is not None:
error_msg += f" You also specified 'layers_pattern': {peft_config.layers_pattern}."
raise ValueError(error_msg)

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

0 comments on commit 0d58942

Please sign in to comment.