Skip to content

feat: add target modules to bnb quantizers#333

Merged
gsprochette merged 12 commits intomainfrom
feat/add-target-modules-to-llm-int8
Sep 18, 2025
Merged

feat: add target modules to bnb quantizers#333
gsprochette merged 12 commits intomainfrom
feat/add-target-modules-to-llm-int8

Conversation

@gsprochette
Copy link
Copy Markdown
Collaborator

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Added new tests counting the number of quantized modules before and after, + notebook

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Additional Notes

cursor[bot]

This comment was marked as outdated.

@gsprochette gsprochette force-pushed the feat/add-target-modules-to-llm-int8 branch from c51ce04 to b4da5a1 Compare September 5, 2025 16:36
cursor[bot]

This comment was marked as outdated.

@gsprochette gsprochette force-pushed the feat/add-target-modules-to-llm-int8 branch from b4da5a1 to 8727d09 Compare September 5, 2025 17:06
Copy link
Copy Markdown
Member

@simlang simlang left a comment

Choose a reason for hiding this comment

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

Looks amazing! Mostly some naming comments, and a general discussion how we should handle defaults, let me know what you think!

Comment thread src/pruna/config/target_modules.py Outdated
Comment thread src/pruna/algorithms/quantization/huggingface_diffusers_int8.py Outdated
Comment thread src/pruna/algorithms/quantization/huggingface_diffusers_int8.py
Comment thread src/pruna/algorithms/quantization/huggingface_llm_int8.py
Comment thread src/pruna/algorithms/quantization/huggingface_diffusers_int8.py
Comment on lines +113 to +138
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"]}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

Comment thread src/pruna/algorithms/quantization/huggingface_diffusers_int8.py Outdated
Comment thread src/pruna/algorithms/quantization/huggingface_llm_int8.py Outdated
@gsprochette gsprochette requested a review from simlang September 8, 2025 16:21
cursor[bot]

This comment was marked as outdated.

Copy link
Copy Markdown
Member

@simlang simlang left a comment

Choose a reason for hiding this comment

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

Bugbot caught already a lot, just some renaming-issues.

Comment thread src/pruna/algorithms/quantization/huggingface_llm_int8.py Outdated
Comment thread src/pruna/algorithms/quantization/huggingface_llm_int8.py Outdated
@gsprochette gsprochette force-pushed the feat/add-target-modules-to-llm-int8 branch 3 times, most recently from 1c48603 to 9741c02 Compare September 9, 2025 08:01
cursor[bot]

This comment was marked as outdated.

@gsprochette gsprochette force-pushed the feat/add-target-modules-to-llm-int8 branch from 9741c02 to 0669e56 Compare September 9, 2025 08:05
cursor[bot]

This comment was marked as outdated.

@gsprochette gsprochette requested review from begumcig and simlang and removed request for johannaSommer September 9, 2025 08:56
Copy link
Copy Markdown
Member

@simlang simlang left a comment

Choose a reason for hiding this comment

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

Looks good! tysm!
LGTM! 🚀

@gsprochette gsprochette force-pushed the feat/add-target-modules-to-llm-int8 branch from 0669e56 to e093606 Compare September 16, 2025 14:07
Copy link
Copy Markdown
Member

@begumcig begumcig left a comment

Choose a reason for hiding this comment

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

Looks super good to me Gaspar!! Thank you so much for taking the time multiple times to explain everything 💜💜

@gsprochette gsprochette force-pushed the feat/add-target-modules-to-llm-int8 branch from faf29e1 to fd48beb Compare September 18, 2025 15:57
@gsprochette gsprochette merged commit 47d4657 into main Sep 18, 2025
7 checks passed
@gsprochette gsprochette deleted the feat/add-target-modules-to-llm-int8 branch September 18, 2025 16:09
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