Lmxyy commited on
Commit
df765bc
·
verified ·
1 Parent(s): ed50de1

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +102 -0
README.md ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: flux-1-dev-non-commercial-license
4
+ tags:
5
+ - image-to-image
6
+ - SVDQuant
7
+ - FLUX.1-dev
8
+ - INT4
9
+ - FLUX.1
10
+ - Diffusion
11
+ - Quantization
12
+ - ControlNet
13
+ - depth-to-image
14
+ language:
15
+ - en
16
+ base_model:
17
+ - black-forest-labs/FLUX.1-Depth-dev
18
+ base_model_relation: quantized
19
+ pipeline_tag: image-to-image
20
+ datasets:
21
+ - mit-han-lab/svdquant-datasets
22
+ library_name: diffusers
23
+ ---
24
+
25
+ <p align="center" style="border-radius: 10px">
26
+ <img src="https://github.com/mit-han-lab/nunchaku/raw/refs/heads/main/assets/logo.svg" width="50%" alt="logo"/>
27
+ </p>
28
+ <h4 style="display: flex; justify-content: center; align-items: center; text-align: center;">Quantization Library:&nbsp;<a href='https://github.com/mit-han-lab/deepcompressor'>DeepCompressor</a> &ensp; Inference Engine:&nbsp;<a href='https://github.com/mit-han-lab/nunchaku'>Nunchaku</a>
29
+ </h4>
30
+
31
+
32
+ <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
33
+ <a href="https://arxiv.org/abs/2411.05007">[Paper]</a>&ensp;
34
+ <a href='https://github.com/mit-han-lab/nunchaku'>[Code]</a>&ensp;
35
+ <a href='https://hanlab.mit.edu/projects/svdquant'>[Website]</a>&ensp;
36
+ <a href='https://hanlab.mit.edu/blog/svdquant'>[Blog]</a>
37
+ </div>
38
+
39
+ ![teaser](https://github.com/mit-han-lab/nunchaku/raw/refs/heads/main/assets/teaser.jpg)
40
+ SVDQuant is a post-training quantization technique for 4-bit weights and activations that well maintains visual fidelity. On 12B FLUX.1-dev, it achieves 3.6× memory reduction compared to the BF16 model. By eliminating CPU offloading, it offers 8.7× speedup over the 16-bit model when on a 16GB laptop 4090 GPU, 3× faster than the NF4 W4A16 baseline. On PixArt-∑, it demonstrates significantly superior visual quality over other W4A4 or even W4A8 baselines. "E2E" means the end-to-end latency including the text encoder and VAE decoder.
41
+
42
+ ## Method
43
+ #### Quantization Method -- SVDQuant
44
+
45
+ ![intuition](https://github.com/mit-han-lab/nunchaku/raw/refs/heads/main/assets/intuition.gif)
46
+ 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.
47
+
48
+ #### Nunchaku Engine Design
49
+
50
+ ![engine](https://github.com/mit-han-lab/nunchaku/raw/refs/heads/main/assets/engine.jpg) (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.
51
+
52
+ ## Model Description
53
+
54
+ - **Developed by:** MIT, NVIDIA, CMU, Princeton, UC Berkeley, SJTU and Pika Labs
55
+ - **Model type:** INT W4A4 model
56
+ - **Model size:** 6.64GB
57
+ - **Model resolution:** The number of pixels need to be a multiple of 65,536.
58
+ - **License:** Apache-2.0
59
+
60
+ ## Usage
61
+
62
+ ### Diffusers
63
+
64
+ Please follow the instructions in [mit-han-lab/nunchaku](https://github.com/mit-han-lab/nunchaku) to set up the environment. Then you can run the model with
65
+
66
+ ```python
67
+ import torch
68
+ from diffusers import FluxPipeline
69
+
70
+ from nunchaku.models.transformer_flux import NunchakuFluxTransformer2dModel
71
+
72
+ transformer = NunchakuFluxTransformer2dModel.from_pretrained("mit-han-lab/svdq-int4-flux.1-dev")
73
+ pipeline = FluxPipeline.from_pretrained(
74
+ "black-forest-labs/FLUX.1-dev", transformer=transformer, torch_dtype=torch.bfloat16
75
+ ).to("cuda")
76
+ image = pipeline("A cat holding a sign that says hello world", num_inference_steps=50, guidance_scale=3.5).images[0]
77
+ image.save("example.png")
78
+ ```
79
+
80
+ ### Comfy UI
81
+
82
+ ![comfyui](https://github.com/mit-han-lab/nunchaku/blob/main/assets/comfyui.jpg?raw=true)
83
+ Please check [comfyui/README.md](comfyui/README.md) for the usage.
84
+
85
+ ## Limitations
86
+
87
+ - 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.
88
+ - You may observe some slight differences from the BF16 models in details.
89
+
90
+ ### Citation
91
+
92
+ If you find this model useful or relevant to your research, please cite
93
+
94
+ ```bibtex
95
+ @inproceedings{
96
+ li2024svdquant,
97
+ title={SVDQuant: Absorbing Outliers by Low-Rank Components for 4-Bit Diffusion Models},
98
+ 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},
99
+ booktitle={The Thirteenth International Conference on Learning Representations},
100
+ year={2025}
101
+ }
102
+ ```