Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/nightly_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ jobs:
- backend: "gguf"
test_location: "gguf"
additional_deps: ["peft", "kernels"]
- backend: "gemlite"
test_location: "gemlite"
additional_deps: []
- backend: "torchao"
test_location: "torchao"
additional_deps: []
Expand Down
2 changes: 2 additions & 0 deletions docs/source/en/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@
title: bitsandbytes
- local: quantization/gguf
title: gguf
- local: quantization/gemlite
title: GemLite
- local: quantization/nunchaku
title: Nunchaku Lite
- local: quantization/torchao
Expand Down
4 changes: 4 additions & 0 deletions docs/source/en/api/quantization.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Quantization techniques reduce memory and computational costs by representing we

[[autodoc]] quantizers.quantization_config.GGUFQuantizationConfig

## GemLiteConfig

[[autodoc]] quantizers.quantization_config.GemLiteConfig

## NunchakuLiteQuantizationConfig

[[autodoc]] quantizers.quantization_config.NunchakuLiteQuantizationConfig
Expand Down
57 changes: 57 additions & 0 deletions docs/source/en/quantization/gemlite.md
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"

Copy link
Copy Markdown
Contributor

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-testing repos, which are less likely to disappear or be renamed. Worth moving this under a stable org before merge.

Copy link
Copy Markdown
Author

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.


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`.
1 change: 1 addition & 0 deletions docs/source/en/quantization/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ The following backends support loading prequantized checkpoints out of the box.
|---|---|
| [bitsandbytes](./bitsandbytes) | Config is saved in `config.json`; no extra arguments needed. |
| [GGUF](./gguf) | Uses `from_single_file` with Model classes; pipeline-level loading is not supported. |
| [GemLite](./gemlite) | Loads prequantized checkpoints; requires the `gemlite` library. |
| [AutoRound](./autoround) | Only loading is supported; quantize first with the AutoRound CLI or Python API. |
| [Nunchaku Lite](./nunchaku) | Config is saved in `config.json`; requires the `kernels` package. |
| [ModelOpt](./modelopt) | Supports both quantizing on the fly and loading prequantized models. |
Expand Down
22 changes: 22 additions & 0 deletions src/diffusers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
is_accelerate_available,
is_auto_round_available,
is_bitsandbytes_available,
is_gemlite_available,
is_gguf_available,
is_librosa_available,
is_note_seq_available,
Expand Down Expand Up @@ -46,6 +47,7 @@
"schedulers": [],
"utils": [
"OptionalDependencyNotAvailable",
"is_gemlite_available",
"is_inflect_available",
"is_invisible_watermark_available",
"is_librosa_available",
Expand Down Expand Up @@ -85,6 +87,18 @@
else:
_import_structure["quantizers.quantization_config"].append("GGUFQuantizationConfig")

try:
if not is_torch_available() and not is_accelerate_available() and not is_gemlite_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils import dummy_gemlite_objects

_import_structure["utils.dummy_gemlite_objects"] = [
name for name in dir(dummy_gemlite_objects) if not name.startswith("_")
]
else:
_import_structure["quantizers.quantization_config"].append("GemLiteConfig")

try:
if not is_torch_available() and not is_accelerate_available() and not is_torchao_available():
raise OptionalDependencyNotAvailable()
Expand Down Expand Up @@ -947,6 +961,14 @@
else:
from .quantizers.quantization_config import GGUFQuantizationConfig

try:
if not is_gemlite_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils.dummy_gemlite_objects import *
else:
from .quantizers.quantization_config import GemLiteConfig

try:
if not is_torchao_available():
raise OptionalDependencyNotAvailable()
Expand Down
4 changes: 4 additions & 0 deletions src/diffusers/quantizers/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@

from .autoround import AutoRoundQuantizer
from .bitsandbytes import BnB4BitDiffusersQuantizer, BnB8BitDiffusersQuantizer
from .gemlite import GemLiteQuantizer
from .gguf import GGUFQuantizer
from .modelopt import NVIDIAModelOptQuantizer
from .nunchaku import NunchakuLiteQuantizer
from .quantization_config import (
AutoRoundConfig,
BitsAndBytesConfig,
GemLiteConfig,
GGUFQuantizationConfig,
NunchakuLiteQuantizationConfig,
NVIDIAModelOptConfig,
Expand All @@ -41,6 +43,7 @@
AUTO_QUANTIZER_MAPPING = {
"bitsandbytes_4bit": BnB4BitDiffusersQuantizer,
"bitsandbytes_8bit": BnB8BitDiffusersQuantizer,
"gemlite": GemLiteQuantizer,
"gguf": GGUFQuantizer,
"quanto": QuantoQuantizer,
"torchao": TorchAoHfQuantizer,
Expand All @@ -52,6 +55,7 @@
AUTO_QUANTIZATION_CONFIG_MAPPING = {
"bitsandbytes_4bit": BitsAndBytesConfig,
"bitsandbytes_8bit": BitsAndBytesConfig,
"gemlite": GemLiteConfig,
"gguf": GGUFQuantizationConfig,
"quanto": QuantoConfig,
"torchao": TorchAoConfig,
Expand Down
1 change: 1 addition & 0 deletions src/diffusers/quantizers/gemlite/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .gemlite_quantizer import GemLiteQuantizer
Loading
Loading