179 points · by lmxyy · 2y ago · 65 comments
It is important to keep in mind that modifying a model changes the performance of the resulting model, where performance is "correctness" or "quality" of output.
Just because the base model is very performant does not mean the smaller model is.
This means that another model that is the same size as the new quantized model may outperform the quantized model.
Suppose there are equal sized big models A and B with their smaller quantized variants a and b. A being a more performant model than B does not guarantee a being more performant than b.
Unlike traditional model compression work that simply applies existing techniques, SVDQuant synthesizes several ideas in a comprehensive new approach to model quantization:
- Developing a novel outlier absorption mechanism using low-rank decomposition — this aspect alone seems quite novel, although the math is admittedly way beyond my level
- Combining SVD with smoothing in a way that specifically addresses the unique challenges of diffusion models
- Creating an innovative kernel fusion technique (they call it “Nunchaku”) that makes the theoretical benefits practically realizable, because without this, the extra computation required to implement the above steps would simply slow the model back down to baseline
This isn't just incremental improvement - the paper achieves several breakthrough results:
- First successful 4-bit quantization of both weights AND activations for diffusion models
- 3.5x memory reduction for 12B parameter models while maintaining image quality
- 3.0x speedup over existing 4-bit weight-only quantization approaches
- Enables running 12B parameter models on consumer GPUs that previously couldn't handle them
And, I’ll add, as someone who has been following the diffusion space quite actively for the last two years, the amount of creativity that can be unleashed when models are accessible to people with consumer GPUs is nothing short of astonishing.
The authors took pains to validate their approach by testing it against three models (Flux, PixArt-Sigma, and SDXL) and along several quality-comparison axes (FID score, Image Reward, LPIPS, and PSNR). They also did a proper ablation study to see the contribution of each component in their approach to image quality.
What particularly excites me about this paper is not the ability to run a model that eats 22GB of VRAM in just 7GB. The exciting thing is the prospect of running a 60GB model in 20GB of VRAM. I’m not sure whether anyone has or is planning to train such a monster, but I suspect that Midjourney, OpenAI, and Google all have significantly larger models running in their infrastructure than what can be run on consumer hardware. The more dimensions you can throw at image and video generation, the better things get.
I am trying to call attention to the models used for evaluation comparison. There are 3 factors: inference speed/latency, model size in total loaded VRAM, and model performance in terms of output.
Comparisons should address all of these considerations, otherwise it's easy to hide deficiencies.
https://cdn.prod.website-files.com/64f4e81394e25710d22d042e/...
By showing their work side-by-side with other quantization schemes, you can also see a great example of the flavor of different results you can get with these slight tweaks (e.g., ViDiT INT8) and that their quantization does a much better job in reproducing the "original" (Figure 15).
In this application, it's not strictly true that you care to have the same results, but this work does a pretty good job of it.
Once a model has been trained, I believe the main metrics people care about are
1. inference speed
2. memory requirements
3. quality of output.
There are usually tradeoffs here. Generally you get a lower memory requirement (a good thing), sometimes faster inference (a good thing), but usually a lower quality of output.
I don't think reproduction of original output is the typical goal.
E.g. compare quantized LLaMA 70B to unquantized LLaMA 8B.
Even better if the test model has a smaller version with similar byte size to the quantized larger one.
Take a look, it's good stuff! Basically a LoRA to reconstruct outliers lost by quantization, helping keep the performance of the original model.
Its basically H100 speeds with 4090, 4.80it/s. 1.1 sec for flux schenll(4 steps) and 5.5 seconds for flux dev(25 steps). Compared to normal speeds(comfyui fp8 with "--fast" optimization") which is 3 seconds for schnell and 11.5 seconds for dev
Its why fal, replicate, pretty much all big diffusion api providers use h100
tldr; 4090 is max 3.51 it/s even with all the current optimizations. h100 is 11.5it/s with all optimizations, and even without its 6.1 it/s
Paper discussing here is using 4 bit compute, which is 4x on 4090 in comparison with bf16 compute, while h100 doesn't have this at all (i.e. best you can get is 2x compute with fp8). So this paper will even out difference between those two to some extent. If to judge by theoretical numbers - H100 has 1979 TFLOPs fp8 compute, and 4090 has 1321 TOPS. Which puts it around ~65% of performance. Given the price of it ~$2K compared to H100s ~$30K this seems like a very good deal.
But again, no 4090 in DCs.
I had to int4 a llama model to get it to properly run on my 3060.
I'm curious, how much resolution / significant digits do we actually need for most genAI work? If you can draw a circle with 3.14, maybe it's good enough for fast and ubiquitous usage.
Which is rather unfortunate as it means that the difference between what you can train locally and what you can run locally is growing ever larger.
Necessary precision depends on, unsurprisingly, what you're truncating. Flux drops off around q6. Text generation around q4.
The llms apple are putting in iphones are q4 3b models.
Diffusion models, however, are computationally bound, even for single batches, so quantizing weights alone yields limited gains.This means that the only saving you're getting in speed for a diffusion model is being able to do more effective flops since the floats are smaller, e.g. instead of doing one 32bit multiplication, you're doing 8 4bit ones.
By comparison for transformers you not only gain the flop increase, but also the improvement in memory shuffling that they do, e.g. it also takes you 8 times less time to load the memory into working memory from vram.
The above is a vast over simplification and in practice will have more asterisks than you can shake a stick at.
Quantizing in general helps with the memory bottleneck but does not help in reducing computational costs, so it’s not as useful for improving performance of diffusion models, that’s what it’s saying.
> To achieve measured speedups, both weights and activations must be quantized to the same bit width; otherwise, the lower precision is upcast during computation, negating any performance benefits.
tries to explain that.
What it means though is that if you only store the inputs in lower precision, but still upcast to say bf16 or fp32 to perform the operation, you're not getting any computational speedup. In fact, you're paying for upconverting and then downconverting afterwards.
You won't however have access to usual sampler, latent image, Lora nodes to do anything beyond basic t2i
This is the whole magic, the rest of the workflow doesn't need to unload and flush memory, causing big delays for jobs.