-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Add GemLite quantization backend support for pre-quantized checkpoints #14286
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
Draft
gabe-engineers
wants to merge
10
commits into
huggingface:main
Choose a base branch
from
gabe-engineers:add-gemlite-quantizer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f6e40fb
Add GemLite quantization backend support for pre-quantized checkpoints
gabe-engineers 77a21e2
Refactor GemLite pre-quantized loading
gabe-engineers 56d5d02
Remove redundant GemLite core import check
gabe-engineers b6dedd4
Remove GemLite CUDA device coercion
gabe-engineers 9b118c5
Finalize GemLite layers during loading
gabe-engineers db04c49
Fix GemLite documentation link
gabe-engineers fd7b31b
Validate GemLite compute dtypes
gabe-engineers abe8d1d
Clarify GemLite version requirement
gabe-engineers f3d69de
Test GemLite serialization round trip
gabe-engineers 5021969
Fix GemLite quantizer tests
gabe-engineers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <!--Copyright 2026 The HuggingFace Team. All rights reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations under the License. | ||
|
|
||
| --> | ||
|
|
||
| # GemLite | ||
|
|
||
| [GemLite](https://github.com/dropbox/gemlite) is a quantization backend for loading prequantized checkpoints in | ||
| Diffusers. It replaces supported `torch.nn.Linear` layers with GemLite layers, which run packed low-bit weights | ||
| directly with GemLite kernels. | ||
|
|
||
| ## Install GemLite | ||
|
|
||
| GemLite requires version 0.6.0 or later. | ||
|
|
||
| ```bash | ||
| pip install -U "gemlite>=0.6.0" | ||
| ``` | ||
|
|
||
| ## Load a quantized pipeline | ||
|
|
||
| GemLite only supports loading prequantized checkpoints. The quantization configuration is stored in the checkpoint's | ||
| `config.json` and read automatically by [`~DiffusionPipeline.from_pretrained`]. | ||
|
|
||
| ```python | ||
| import torch | ||
| from diffusers import DiffusionPipeline | ||
|
|
||
| model_id = "gabe-engineers/bonsai-image-ternary-4B-gemlite-2bit-unpacked-encoder" | ||
|
|
||
| pipe = DiffusionPipeline.from_pretrained( | ||
| model_id, | ||
| dtype=torch.float16, | ||
| device_map="cuda", | ||
| ) | ||
|
|
||
| image = pipe( | ||
| prompt="A bonsai tree in a quiet ceramic studio, soft morning light", | ||
| height=1024, | ||
| width=1024, | ||
| num_inference_steps=4, | ||
| guidance_scale=1.0, | ||
| ).images[0] | ||
| image.save("bonsai-gemlite.png") | ||
| ``` | ||
|
|
||
| > [!TIP] | ||
| > `dtype` must match the `compute_dtype` in the checkpoint's GemLite quantization configuration. This | ||
| > checkpoint uses `torch.float16`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .gemlite_quantizer import GemLiteQuantizer |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The only example checkpoint is under a personal namespace. Other quantization docs point at org-owned or
hf-internal-testingrepos, which are less likely to disappear or be renamed. Worth moving this under a stable org before merge.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.
I don't currently have a suitable org namespace to move this checkpoint into, so for now it would need to stay under my personal namespace. If the maintainers would prefer it under an HF-owned/testing namespace, I'm happy to move or copy it there if there's an appropriate destination.