Skip to content

[quantization] quantize on the fly through a "quantize" load operation - #50240

Closed
ArthurZucker wants to merge 34 commits into
mainfrom
quantize-load-operation
Closed

ArthurZucker wants to merge 34 commits into
mainfrom
quantize-load-operation

Conversation

@ArthurZucker

@ArthurZucker ArthurZucker commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

🤗 Transformers CI

Replaces WeightTransform.quantization_operation with a "quantize" entry in get_load_operations, as asked in the #50238 review.

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

Pages changed in this PR:

@IlyasMoutawwakil IlyasMoutawwakil left a comment

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.

thanks ! much cleaner ! i'm not very knowledgeable about most of these quantizers specifics but tests should catch if anything is not right.

i have two questions one about making dequantization not require kernels (i later saw many quantizers also use third party functions so maybe we can give up on that 🥲). and one about the dropped tests.

on a side note, now that everything passes by conversion ops, should we also make it clear what gets reversed and what not during saving, mostly to protect reloading and for users to know what to expect. for me it's smth like:

  • quantize/dequantize: never reversed because the user already has the original on disk, if they do on-the-fly quant/dequant, it's generally bcz they want that to be saved.
  • serialize/deserialize: should be reversed (swizzle, etc) bcz otherwise they will be applied a second time at reload.
  • model weight conversions: should probably be reversed ? (renames, packed experts, etc) following the bf16 path.

@SunMarc

## Dequantizing bitsandbytes models

Once quantized, you can [`~PreTrainedModel.dequantize`] a model to the original precision but this may result in some quality loss. Make sure you have enough GPU memory to fit the dequantized model.
Pass `dequantize=True` to load a pre-quantized bitsandbytes checkpoint back in its original precision. This may result in some quality loss, and requires enough memory to fit the dense model.

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.

did we ever confirm this ? that dequantization can result in quality loss

Comment thread src/transformers/integrations/eetq.py Outdated
from .hub_kernels import get_kernel

self.hf_quantizer = hf_quantizer
self.kernel = get_kernel("kernels-community/quantization-eetq", version=1)

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.

dequantization shouldn't require a kernel (per @SunMarc suggestion), because a user might specifically want to dequantize because they don't have the right hardware for the kernels.

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.

yes let's add the torch ops as a fallback if possible.

Comment thread tests/quantization/bnb/test_4bit.py Resolved
…ad op, uncompressed checkpoints no longer force it
… the checkpoint format; drop no-op after-load hook
…hts load decompressed, compressed-tensors only sets up activation / kv cache quantization
Replaces WeightTransform.quantization_operation: the op is appended last to each param's converter.
…converters of modules keeping their packed tensors
…buffer kept; serialize visits every module; gptq/awq/auto_round/quark dequantize moved to a follow-up
…vfp4 loads pre-quantized checkpoints with dequantize=True
@ArthurZucker
ArthurZucker force-pushed the quantize-load-operation branch from a3a741f to 4f11091 Compare November 4, 2026 08:40
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: bitnet_integration, bnb, compressed_tensors_integration, fbgemm_fp8, finegrained_fp8, higgs, hqq, metal, mxfp4, nvfp4, sinq

@ArthurZucker
ArthurZucker removed this pull request from stack #50244 November 5, 2026 02:08
# Conflicts:
#	src/transformers/quantizers/quantizer_eetq.py
Base automatically changed from compressed-tensors-dequantize-on-load to main November 5, 2026 02:51
ArthurZucker added a commit that referenced this pull request Nov 5, 2026
… set per param by the plan; no quantization code left in core
@ArthurZucker

Copy link
Copy Markdown
Collaborator Author

Merged into #50245: quantize is a load operation there too, set per param by the quantization plan, so core has no quantization code left.

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.

4 participants