File size: 5,597 Bytes
df765bc ba6eac7 4f4c8d5 fbf0bb4 df765bc ef2ed40 df765bc 6ba653b ba6eac7 df765bc e5cad8a df765bc b7ae6b5 df765bc b7ae6b5 df765bc b7ae6b5 df765bc b7ae6b5 df765bc e5cad8a df765bc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
---
license: other
license_name: flux-1-dev-non-commercial-license
tags:
- image-to-image
- SVDQuant
- INT4
- FLUX.1
- Diffusion
- Quantization
- ControlNet
- depth-to-image
- image-generation
- text-to-image
- FLUX.1-Depth-dev
- ICLR2025
language:
- en
base_model:
- black-forest-labs/FLUX.1-Depth-dev
base_model_relation: quantized
pipeline_tag: image-to-image
datasets:
- mit-han-lab/svdquant-datasets
library_name: diffusers
---
<p align="center" style="border-radius: 10px">
<img src="https://github.com/mit-han-lab/nunchaku/raw/refs/heads/main/assets/logo.svg" width="50%" alt="logo"/>
</p>
<h4 style="display: flex; justify-content: center; align-items: center; text-align: center;">Quantization Library: <a href='https://github.com/mit-han-lab/deepcompressor'>DeepCompressor</a>   Inference Engine: <a href='https://github.com/mit-han-lab/nunchaku'>Nunchaku</a>
</h4>
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
<a href="https://arxiv.org/abs/2411.05007">[Paper]</a> 
<a href='https://github.com/mit-han-lab/nunchaku'>[Code]</a> 
<a href='https://svdquant.mit.edu'>[Demo]</a> 
<a href='https://hanlab.mit.edu/projects/svdquant'>[Website]</a> 
<a href='https://hanlab.mit.edu/blog/svdquant'>[Blog]</a>
</div>

`svdq-int4-flux.1-depth-dev` is an INT4-quantized version of [`FLUX.1-Depth-dev`](https://huggingface.co/black-forest-labs/FLUX.1-Depth-dev), which can generate an image based on a text description while following the structure of a given input image. It offers approximately 4× memory savings while also running 2–3× faster than the original BF16 model.
## Method
#### Quantization Method -- SVDQuant

Overview of SVDQuant. Stage1: Originally, both the activation ***X*** and weights ***W*** contain outliers, making 4-bit quantization challenging. Stage 2: We migrate the outliers from activations to weights, resulting in the updated activation and weight. While the activation becomes easier to quantize, the weight now becomes more difficult. Stage 3: SVDQuant further decomposes the weight into a low-rank component and a residual with SVD. Thus, the quantization difficulty is alleviated by the low-rank branch, which runs at 16-bit precision.
#### Nunchaku Engine Design
 (a) Naïvely running low-rank branch with rank 32 will introduce 57% latency overhead due to extra read of 16-bit inputs in *Down Projection* and extra write of 16-bit outputs in *Up Projection*. Nunchaku optimizes this overhead with kernel fusion. (b) *Down Projection* and *Quantize* kernels use the same input, while *Up Projection* and *4-Bit Compute* kernels share the same output. To reduce data movement overhead, we fuse the first two and the latter two kernels together.
## Model Description
- **Developed by:** MIT, NVIDIA, CMU, Princeton, UC Berkeley, SJTU and Pika Labs
- **Model type:** INT W4A4 model
- **Model size:** 6.64GB
- **Model resolution:** The number of pixels need to be a multiple of 65,536.
- **License:** Apache-2.0
## Usage
### Diffusers
Please follow the instructions in [mit-han-lab/nunchaku](https://github.com/mit-han-lab/nunchaku) to set up the environment. Also, install some ControlNet dependencies:
```shell
pip install git+https://github.com/asomoza/image_gen_aux.git
pip install controlnet_aux mediapipe
```
Then you can run the model with
```python
import torch
from diffusers import FluxControlPipeline
from diffusers.utils import load_image
from image_gen_aux import DepthPreprocessor
from nunchaku.models.transformer_flux import NunchakuFluxTransformer2dModel
transformer = NunchakuFluxTransformer2dModel.from_pretrained("mit-han-lab/svdq-int4-flux.1-depth-dev")
pipe = FluxControlPipeline.from_pretrained(
"black-forest-labs/FLUX.1-Depth-dev",
transformer=transformer,
torch_dtype=torch.bfloat16,
).to("cuda")
prompt = "A robot made of exotic candies and chocolates of different kinds. The background is filled with confetti and celebratory gifts."
control_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/robot.png")
processor = DepthPreprocessor.from_pretrained("LiheYoung/depth-anything-large-hf")
control_image = processor(control_image)[0].convert("RGB")
image = pipe(
prompt=prompt, control_image=control_image, height=1024, width=1024, num_inference_steps=30, guidance_scale=10.0
).images[0]
image.save("flux.1-depth-dev.png")
```
### Comfy UI
Work in progress. Stay tuned!
## Limitations
- The model is only runnable on NVIDIA GPUs with architectures sm_86 (Ampere: RTX 3090, A6000), sm_89 (Ada: RTX 4090), and sm_80 (A100). See this [issue](https://github.com/mit-han-lab/nunchaku/issues/1) for more details.
- You may observe some slight differences from the BF16 models in detail.
### Citation
If you find this model useful or relevant to your research, please cite
```bibtex
@inproceedings{
li2024svdquant,
title={SVDQuant: Absorbing Outliers by Low-Rank Components for 4-Bit Diffusion Models},
author={Li*, Muyang and Lin*, Yujun and Zhang*, Zhekai and Cai, Tianle and Li, Xiuyu and Guo, Junxian and Xie, Enze and Meng, Chenlin and Zhu, Jun-Yan and Han, Song},
booktitle={The Thirteenth International Conference on Learning Representations},
year={2025}
}
``` |