-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
pass module to Params4bit.from_prequantized to ensure quant_state #32524
pass module to Params4bit.from_prequantized to ensure quant_state #32524
Conversation
cc @SunMarc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the work ! Left a comment !
@@ -212,6 +212,7 @@ def create_quantized_param( | |||
quantized_stats=quantized_stats, | |||
requires_grad=False, | |||
device=target_device, | |||
module=module, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just do what was done in the reverted PR ?
param_kwargs = {}
sig = inspect.signature(bnb.nn.Params4bit.from_prequantized)
if "module" in sig.parameters:
param_kwargs["module"] = module
or we could perform the version check here to device if we pass module or not !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice ! Thanks for fixing @winglian ! I left a minor question !
param_kwargs = {} | ||
sig = inspect.signature(bnb.nn.Params4bit.from_prequantized) | ||
if "module" in sig.parameters: | ||
param_kwargs["module"] = module | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick question about inspect.signature
, does this make the quantization slower ? I'm a bit concerned since create_quantized_param
is called for each param cc @muellerzr as I remember that you prefer not to use inspect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SunMarc also happy to do it as
@cached_property
def is_bnb_gte_0_43_3(self) -> bool:
if self._is_bnb_gte_0_43_3 is not None:
return self._is_bnb_gte_0_43_3
self._is_bnb_gte_0_43_3 = version.parse(importlib.metadata.version("bitsandbytes")) >= version.parse("0.43.3")
return self._is_bnb_gte_0_43_3
and then we can use self. is_bnb_gte_0_43_3()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version parsing is far more preferred!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though generally this would exist in import_utils
as a min_version
to is_bnb_available()
. (We should then cache the bnb_version if we don't already, similar to _torch_version
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit: I think if there's a variable or function named for this that the name should be more meaningful than is_bnb_gte_0_43_3
. It should describe what that version check is about, e.g. 'bnb_can_load_from_float_storage`.
That said, I like the suggestion to model it the way I see is_accelerate_available(min_version)
in import_utils
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we do the version parsing? 🤗
4ae9391
to
7a8c1f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool thanks
…ggingface#32524) * pass module to Params4bit.from_prequantized to ensure quant_state * make sure to check bnb version * revert min bnb version and use inspect on method instead * use version instead of inspect to prevent performance hit * make the property name readable
What does this PR do?
see #32477 #32477
Let's start with making sure pre-quantized models can be loaded properly for FSDP. This at least unlocks pre-quant models with qlora+fsdp where CPU RAM isn't a blocker.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.