Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exclude_modules to keep specific layers or other quirky components out of a target_modules selection #2044

Open
bghira opened this issue Aug 29, 2024 · 6 comments
Labels

Comments

@bghira
Copy link

bghira commented Aug 29, 2024

Feature request

The LoraConfig class should accept an optional exclude_modules list of regular expressions in an analogue to target_modules that then should be referenced when matching against entries from target_modules.

Motivation

Targeting proj_out and proj_mlp on some models greatly improves the results, but we find that the effect is more reliable and robust if the final proj_out and proj_mlp layers are excluded.

Your contribution

I can quickly integrate, test, and make use of this feature in bghira/simpletuner

I'm not sure I'll have time to submit a PR in the next two weeks, but after that perhaps I will be able to. Someone who grabs it before then will be much appreciated 💌

@BenjaminBossan
Copy link
Member

Thanks for opening this feature request. You're not the first one who would like to have this feature. If you or someone else wants to work on the PR, contributions are welcome.

That said, I just wanted to ask if you know that there are already ways to achieve this. One way is to use layers_pattern, which is used to match the string, and layers_to_transform, which is a list of indices of the layers you would like to match. More in the docs. It's a bit of an obscure feature but sounds like it is exactly what you require.

The most flexible way to tackle this type of problem is, however, to pass a string to target_modules. In this case a regex match is applied. This pretty much allows all kinds of fancy patterns, such as matching all proj_out except for layers.31.proj_out, just as an example.

@bghira
Copy link
Author

bghira commented Aug 29, 2024

oh, i see. so you are suggesting i programmatically search the keys and build a list of targets that match my exclude and target patterns! that is pretty good. maybe it's enough

@BenjaminBossan
Copy link
Member

What I meant is something like this: Say I have facebook/opt-125m. This model has 12 attention layers. Say I want to match fc1 but only layers 0-10, not 11. I can achieve this by passing:

config = LoraConfig(target_modules=r".*\.(?!11)\d+\.fc1$")

@JINO-ROHIT
Copy link
Contributor

Hi @BenjaminBossan just trying to understand and if possible would like to take this up and contribute.

The issue is to add an extra exclude params in the lora config to not use specific layers right? Is this needed since passing a 'fc' layers in target modules matches across all the layers?

@BenjaminBossan
Copy link
Member

Yes, I think you've got it.

If I understand the original request correctly, the use case is that we have N layers, each of which have proj_out and proj_mlp sub-modules. OP would like to target those, so they pass target_modules=["proj_out", "proj_mlp"] (+ probably some more targets). This matches the sub-modules of all N layers. Now they want to exclude the last layer, they want to pass the name of these specific layers to exclude_modules.

@JINO-ROHIT
Copy link
Contributor

alright @BenjaminBossan thanks, id like to take this up

BenjaminBossan pushed a commit that referenced this issue Oct 3, 2024
Allows to exclude target modules.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants