-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Fix meta tensor error with bitsandbytes quantization and device_map #12799
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -867,6 +867,26 @@ def load_sub_model( | |||||
| ) | ||||||
| if model_quant_config is not None: | ||||||
| loading_kwargs["quantization_config"] = model_quant_config | ||||||
|
|
||||||
| # When using bitsandbytes quantization with device_map on transformers models, | ||||||
| # we must disable low_cpu_mem_usage to avoid meta tensors. Meta tensors cannot | ||||||
| # be materialized properly when bitsandbytes tries to move quantization state | ||||||
| # (which includes tensors like code and absmax) to the target device. | ||||||
| # This issue occurs because quantization state is created during model loading | ||||||
| # and needs actual tensors, not meta placeholders. | ||||||
| # See: https://github.com/huggingface/diffusers/issues/12719 | ||||||
| if ( | ||||||
| is_transformers_model | ||||||
| and device_map is not None | ||||||
| and hasattr(model_quant_config, "quant_method") | ||||||
| ): | ||||||
| quant_method = getattr(model_quant_config.quant_method, "value", model_quant_config.quant_method) | ||||||
| if quant_method in ["llm_int8", "fp4", "nf4"]: # bitsandbytes quantization methods | ||||||
|
||||||
| if quant_method in ["llm_int8", "fp4", "nf4"]: # bitsandbytes quantization methods | |
| if quant_method == "bitsandbytes": # bitsandbytes quantization |
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.
Trailing whitespace detected. Please remove the trailing spaces on this line.