Skip to content

Conversation

@JINO-ROHIT
Copy link
Contributor

This PR is aimed to address point 3 in #2155 to adjust the error message when layers transforms and layer patterns are specified.

Tbh, I dont quite understand the functionality of layern_patterns but assuming that we need layers_pattern when layers_transform is applied, ive added this simple check.

@BenjaminBossan
Copy link
Member

Thanks for working on this PR so quickly. Could you please propagate this check to the other config classes that support this too? Also, it would be great to add a test to tests/test_config.py for this. LMK if you have questions about this.

Apart from this fix, I think we can also improve the error reporting when users pass layers_pattern and layers_to_transform. Right now, we only check target_modules. In particular, I'm thinking about this message:

raise ValueError(
f"Target modules {peft_config.target_modules} not found in the base model. "
f"Please check the target modules and try again."
)

As the user reported, they got the error

*** ValueError: Target modules {'v_proj', 'q_proj'} not found in the base model. Please check the target modules and try again.

But the real reason was how they defined layers_pattern and layers_to_transform. Therefore, I think it would be nice if we check if those arguments were set and if yes, extend the error message accordingly. This could be in a separate PR though.

@JINO-ROHIT
Copy link
Contributor Author

Sure, i will work through this one

@JINO-ROHIT
Copy link
Contributor Author

ive added a test case and extended to other classes.

I noticed that one unrelated testcase was failing:

FAILED tests/test_config.py::TestPeftConfig::test_regex_with_layer_indexing_lora - AssertionError: Regex pattern did not match.

Should we try and fix this?

@JINO-ROHIT
Copy link
Contributor Author

As the user reported, they got the error

*** ValueError: Target modules {'v_proj', 'q_proj'} not found in the base model. Please check the target modules and try again.

But the real reason was how they defined layers_pattern and layers_to_transform. Therefore, I think it would be nice if we check if those arguments were set and if yes, extend the error message accordingly. This could be in a separate PR thoug

ouuu, il raise another PR to handle this second part

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@BenjaminBossan
Copy link
Member

Could you please run make style?

@JINO-ROHIT
Copy link
Contributor Author

Hi @BenjaminBossan done!

@BenjaminBossan
Copy link
Member

@JINO-ROHIT Oh I see there is an error there. It is actually possible to have layers_pattern being None, as we use a different regex in that case:

if layers_pattern is None or len(layers_pattern) == 0:
layer_index = re.match(r".*\.[^.]*\.(\d+)\.", key)

This is why a bunch of tests are failing. I didn't know that (or forgot), so this is my bad. I think we can still do the reverse though, i.e. if layers_to_transform is None, we should not have layers_pattern. WDYT?

@JINO-ROHIT
Copy link
Contributor Author

yeah missed this too, did you mean to do something like this?

@BenjaminBossan
Copy link
Member

Ah no, I don't think that's quite right. You added if layer_indexes is not None but above that, we already check if is_using_layer_indexes, so that's redundant.

What I mean is that the check

        if self.layers_to_transform is not None and self.layers_pattern is None:
            raise ValueError("When `layers_to_transform` is specified, `layers_pattern` must also be specified. ")

should be changed to

        if self.layers_pattern is not None and self.layers_to_transform is None:
            raise ValueError("When `layers_pattern` is specified, `layers_to_transform` must also be specified. ")

I also like to add some parentheses in these cases for readability:

if (self.layers_pattern is not None) and (self.layers_to_transform is None):

@JINO-ROHIT
Copy link
Contributor Author

yeah, now i get why the testcase werent passing after seeing the other test config files, ive made the reverse check and moved the check down so now i think all the testcases should pass

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you can see, some tests in the CI are failing. This is actually expected, as some of them just don't make sense anymore, like this one:

("foo.bar.7.baz", ["baz"], None, ["bar"], True),

While checking this, I also noticed some room for improvement in the checking logic, please take a look at my comment.

I think this needs to be changed and the tests adjusted a bit, like I mentioned. You can call pytest tests/test_tuners_utils.py locally to ensure that all relevant tests pass.

if isinstance(self.target_modules, str) and self.layers_pattern is not None:
raise ValueError("`layers_pattern` cannot be used when `target_modules` is a str.")
# check for layers_to_transform and layers_pattern
if (self.layers_pattern is not None) and (self.layers_to_transform is None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these checks should be adjusted like so:

Suggested change
if (self.layers_pattern is not None) and (self.layers_to_transform is None):
if self.layers_pattern and not self.layers_to_transform:

Why?

  1. If users pass layers_pattern=[], layers_to_transform=None, we should not raise.
  2. If users pass layers_pattern=["foo"], layers_to_transform=[], we should raise

Right now, we don't do that because of the strict None check.

@JINO-ROHIT
Copy link
Contributor Author

Sure, im away for a couple days on a conference, ill be back and fix this :)

@BenjaminBossan
Copy link
Member

Thanks @JINO-ROHIT. It's not urgent, so take your time, enjoy the conference.

@JINO-ROHIT
Copy link
Contributor Author

Thank you very much @BenjaminBossan , im back . the checks now are making a lot more sense, ive fixed them and run tests.

@JINO-ROHIT
Copy link
Contributor Author

Hi @BenjaminBossan any clue why this is failing?

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this check to the configs.

@BenjaminBossan BenjaminBossan merged commit 214345e into huggingface:main Oct 29, 2024
14 checks passed
yaswanth19 pushed a commit to yaswanth19/peft that referenced this pull request Oct 29, 2024
Guy-Bilitski pushed a commit to Guy-Bilitski/peft that referenced this pull request May 13, 2025
cyyever pushed a commit to cyyever/peft that referenced this pull request Sep 4, 2025
* base judge

* adding mixture of judges

* update doc

* update doc

* formatting

* fix small typo in doc

* fix randomcontraintjudge

* replace arxiv by hf papers

Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>

* formatting

Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>

* fix naming in __init__

* run precommi

* adding gold answers to judges

* cgpo llm judges

* fix init

* output type

* adjust booleans in test

* adapt moj doc

* renaming and removing factuality and safety judges

* fix typo in import

* fix small typo in naming

* formatting

* Update trl/trainer/judges.py

Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>

* update parameter name

* update tests

* update doc

* Update trl/trainer/judges.py

Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>

* Update doc

Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>

* fix alltruejudge type

* Refactor judge variable names and update test names

* Clarify judgment logic

* Fix invalid binary judgment check in AllTrueJudge class

* Fix invalid binary judgment check in AllTrueJudge class

---------

Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>
Co-authored-by: Quentin Gallouédec <quentin.gallouedec@huggingface.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants