|
| 1 | +<!--Copyright 2026 The HuggingFace Team. All rights reserved. |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 4 | +the License. You may obtain a copy of the License at |
| 5 | +
|
| 6 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +
|
| 8 | +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 9 | +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 10 | +specific language governing permissions and limitations under the License. |
| 11 | +
|
| 12 | +--> |
| 13 | + |
| 14 | +# GemLite |
| 15 | + |
| 16 | +[GemLite](https://github.com/mobiusml/gemlite) is a quantization backend for loading prequantized checkpoints in |
| 17 | +Diffusers. It replaces supported `torch.nn.Linear` layers with GemLite layers, which run packed low-bit weights |
| 18 | +directly with GemLite kernels. |
| 19 | + |
| 20 | +## Install GemLite |
| 21 | + |
| 22 | +GemLite requires version 0.6.0 or later. |
| 23 | + |
| 24 | +```bash |
| 25 | +pip install -U "gemlite>=0.6.0" |
| 26 | +``` |
| 27 | + |
| 28 | +## Load a quantized pipeline |
| 29 | + |
| 30 | +GemLite only supports loading prequantized checkpoints. The quantization configuration is stored in the checkpoint's |
| 31 | +`config.json` and read automatically by [`~DiffusionPipeline.from_pretrained`]. |
| 32 | + |
| 33 | +```python |
| 34 | +import torch |
| 35 | +from diffusers import DiffusionPipeline |
| 36 | + |
| 37 | +model_id = "gabe-engineers/bonsai-image-ternary-4B-gemlite-2bit-unpacked-encoder" |
| 38 | + |
| 39 | +pipe = DiffusionPipeline.from_pretrained( |
| 40 | + model_id, |
| 41 | + dtype=torch.float16, |
| 42 | + device_map="cuda", |
| 43 | +) |
| 44 | + |
| 45 | +image = pipe( |
| 46 | + prompt="A bonsai tree in a quiet ceramic studio, soft morning light", |
| 47 | + height=1024, |
| 48 | + width=1024, |
| 49 | + num_inference_steps=4, |
| 50 | + guidance_scale=1.0, |
| 51 | +).images[0] |
| 52 | +image.save("bonsai-gemlite.png") |
| 53 | +``` |
| 54 | + |
| 55 | +> [!TIP] |
| 56 | +> `dtype` must match the `compute_dtype` in the checkpoint's GemLite quantization configuration. This |
| 57 | +> checkpoint uses `torch.float16`. |
0 commit comments