feat: add target modules to bnb quantizers#333
Conversation
c51ce04 to
b4da5a1
Compare
b4da5a1 to
8727d09
Compare
simlang
left a comment
There was a problem hiding this comment.
Looks amazing! Mostly some naming comments, and a general discussion how we should handle defaults, let me know what you think!
| def get_unconstrained_hyperparameter_defaults( | ||
| self, model: Any, smash_config: SmashConfig | SmashConfigPrefixWrapper | ||
| ) -> TARGET_MODULES_TYPE: | ||
| """ | ||
| Get default values for the target_modules based on the model and configuration. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| model : Any | ||
| The model to get the default hyperparameters from. | ||
| smash_config : SmashConfig | ||
| The SmashConfig object. | ||
|
|
||
| Returns | ||
| ------- | ||
| TARGET_MODULES_TYPE | ||
| The default target_modules for the algorithm. | ||
| """ | ||
| prefix: str | ||
| if hasattr(model, "transformer"): | ||
| prefix = "transformer." | ||
| elif hasattr(model, "unet"): | ||
| prefix = "unet." | ||
| else: | ||
| prefix = "" | ||
| return {"include": [prefix + "*"], "exclude": [prefix + "lm_head"]} |
There was a problem hiding this comment.
maybe a more general discussion on the defaults - the defaults here contain some key configuration so the model doesn't break from quantization, which we hide from the user. a user might decide to exclude some specific module for their use case but doesn't know about those defaults are necessary for the model to work and wonder why the model breaks.
Should we join the defaults with the user config instead of overwriting them?
There was a problem hiding this comment.
One option I saw is a add_to_default flag, if it's true then you the target modules is dict(include = user_defined_include + include_default, exclude = user_defined_exclude + exclude_default). I have that in mind it's coming in a future PR
simlang
left a comment
There was a problem hiding this comment.
Bugbot caught already a lot, just some renaming-issues.
1c48603 to
9741c02
Compare
9741c02 to
0669e56
Compare
0669e56 to
e093606
Compare
begumcig
left a comment
There was a problem hiding this comment.
Looks super good to me Gaspar!! Thank you so much for taking the time multiple times to explain everything 💜💜
faf29e1 to
fd48beb
Compare
Description
Add Target Modules to BnB quantizers. To do so, I also introduced a routine to get the ignored modules, and restrict any target modules to only leaf modules (Linear, Conv1d, but not SelfAttention for example). These new functionalities are usefull to apply target modules to HF based quantizers.
Related Issue
Fixes #(issue number)
Type of Change
How Has This Been Tested?
Added new tests counting the number of quantized modules before and after, + notebook
Checklist
Additional Notes