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

Add scale map to apply_max_norm_regularization #1873

Draft
wants to merge 2 commits into
base: sd3
Choose a base branch
from

Conversation

rockerBOO
Copy link
Contributor

@rockerBOO rockerBOO commented Jan 11, 2025

Allows setting the scale_weight_norms via

toml

scale_weight_norms = 2.5
scale_weight_norms_map = { "*ff_net_*_proj*" = 5.0 }

CLI (formats it as a string and we convert it into a dict)

--scale_weight_norms 2.5
--scale_weight_norms_map "{ '*ff_net_*_proj*' = 5.0 }"

Set --scale_weight_norms 5.0 to some value for the other values and the map would set those values for matching module keys.

This is is just an idea to allow us to scale the weight norms differently for different modules. The implementation details are up in the air because I'm not sure what would be best here.

Could be that we want to use regex for the module name matching. Or make the map work exclusively to scale_weight_norms.

See https://github.com/rockerBOO/sd-ext/blob/main/scale_norms.py which emulates the same behavior but on the static weights. You can try different strategies with the map.

@recris
Copy link

recris commented Jan 12, 2025

This is something I wanted to implement for some time.

Maybe match the names using fnmatch style patterns? Slightly simpler than regex.

@rockerBOO
Copy link
Contributor Author

Yeah fnmatch seems to be a good fit. I will give it a try.

@rockerBOO
Copy link
Contributor Author

rockerBOO commented Jan 23, 2025

Added fnmatch. It is only fnmatch so will need the * where you want it to be matching. Note it will be including .lora_down in the name so if it's at the end of the base name you'll want to add the * at the end.

toml

scale_weight_norms = 2.5
scale_weight_norms_map = { "*ff_net_*_proj*" = 5.0 }

CLI (formats it as a string and we convert it into a dict)

--scale_weight_norms 2.5
--scale_weight_norms_map "{ '*ff_net_*_proj*' = 5.0 }"

Also only supports vanilla LoRA. I am wanting to add more logging/reporting to better get what keys are being scaled and to what, and what ratio. Lots of metrics to help showcase what it's doing as it is a little buggy with reporting for some reason.

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.

2 participants