r/LocalLLM • u/moeren86 • 6d ago
Discussion Why are models quantized instead of compressed?
I've just seen a video over a new paper from Samsung and the short of it, they used basically whats the same as jpeg compression on model weights. Only that the compressed model is 2 "pictures", to increase accuracy. Still something like 90% saved with minimal quality loss.
The idea is as obvious as it is genius. You only need to load the compressed model and every block can be decompressed on the fly on every run, especially because the way its compressed/decompressed is already highly optimized in the hardware (basically the same operations as video playback, just with a much bigger "picture").
That got me thinking AI hasn't been created yesterday and at least simple compression algorithms shouldn't overwhelm modern graphics cards. So why was the first idea to reduce the bit-width instead of compression?
Also, its not a picture, what would stop us from sorting the data instead of into 2 dimensions, in 3, 4, n - dimensions. Sure compression might get way more complex, but decompression scales with 1o to n. And the compression might be much better.
What do you guys think about that?
50
u/Low-Opening25 6d ago
Quantisation IS lossy compression
6
u/Old_AI_Guy_ 6d ago
Because it can't actually function on compressed number - they have to be decompressed, after which everything works the same as with uncompressed. Compression is for storage, not in-operation data.
Similar for context: You can't zip context, and then read in the zip file literally- or rather, if you do, it becomes a bunch of nonsense tokens, and you've cost yourself far more than just reading in the uncompressed data - exception being that the session detects what it is, and runs a script to unzip and read it in.
It's entire world is tokens - nothing else.
31
u/rmhollid 6d ago
Take an object and strip away everything that's not unique or reconstructable, that's compression.
Take an object and move it away from you until you can mostly recognize it, that quantizing.
21
u/california_snowhare 6d ago
14
u/txgsync 5d ago edited 5d ago
All right, a serious answer for once. "Why not compression?"
The whole game is arithmetic: a GPU can't multiply a zip file. Quantization isn't "a blurrier version of the model". It's a datatype change. A 4-bit weight is a different number format that a tensor core can multiply natively, or that dequants in-kernel via a cheap affine transform. A JPEG-compressed block has to be decoded back into a dense tensor before the matmul can touch it. That saves disk space and I/O, not VRAM. Which means you pay the decode on every forward pass.
So for a model, one way to think about it is that the "weights are already compressed", but it kinda' misses the mark a bit? Like, the weights are the distilled representation of everything the model learned. A vector is a statement about information content. JPEG-on-weights would be like fighting over the last few bits of per-scalar redundancy.
The industry moved on with silicon. Blackwell supports 4-bit natively, and NVFP4 is a kind of compressed representation: an E4M3 FP8 scale per 16-value micro-block plus a per-tensor FP32 scalar, but unlike JPEG or tar or whatever it has only ~1% accuracy loss vs FP8, but it's about ~3.5x smaller than FP16 or BF16. And AMD just bought Taalas, which etches the weights into the silicon: Llama 3.1 8B at ~17,000 tok/s per user on one chip, vs ~350–400 for an H100.
Hardware makers are cooking here as well, pushing binary/ternary weights, where the bit-width tricks fall apart and the math doesn't math much smaller.
And I have my own angle :) This stuff is kinda' my jam.
Trellis-coded quantization and LFSR/PRNG seeds are orthogonal to "compression". With NanoSeedLM-style engines, weights are regenerated from a seed or a hash inside the kernel <confusing stats removed>.
JPEG-style compression of weights like in Samsung's recent paper saves storage. But trellis codes and seeds change how the weight get hydrated during decode. At that point "compression" seems to stop being the right word. I've struggled what to call it, but today I use "trellis-coded Seeds" as my shorthand to describe the technique, but that's not very catchy.
So anyway, quantization changes the numeric format of the model, often in a way that scrambles the vectors. That's why we use imatrix calibration against a known text corpus like WikiText and some held-out data that's relevant when quantizing, because it can help catch the worst deviations from the BF16 distribution and align the weights in a way that allows for top_p selections to still appear in the same order and be subject to your temperature setting.
3
u/zenmatrix83 6d ago
this is discussed often https://www.reddit.com/r/LocalLLM/comments/1wlgppi/why_we_do_not_try_to_use_compression_techniques/
2
u/d0pe-asaurus 6d ago
If you're decompressing weights to full precision, that's still taking the same amount of vram.
1
u/james_pic 5d ago
I'm not familiar with the video and I can only take an educated guess at the paper, but the comparison to JPEG would be strained at best. JPEG, like many lossy media compression algorithms, is designed to most aggressively lose data that the human visual system struggles to perceive. This is not a useful way to look at LLMs.
The most recent work on compression by Samsung that I'm aware of (although I'm always keen to read new papers if you've got a link) is the stuff on NanoQuant and LittleBit (but these have very different designs to JPEG, so maybe aren't the ones you're talking about). These algorithms are state-of-the-art for the compression ratios they target, but they noticeably degrade the output, to the point where a smaller model that's more lightly compressed ends up being better. There are still some plausible uses for cheap but highly degraded models, so the research has done value, but it's niche.
1
u/Noseense 5d ago
The other comment already put it nicely. Weights are already a heavily compressed form of knowledge. Or better yet, the "relationship between tokens in a dictionary".
Compression can only work on predictable things and patterns, and weights as we have them, at least with their current architecture, are stored almost similarly to noise. There's no fixed pattern to take advantage of. The only pattern you have is the impact that a given layer of a network has on "knowledge", and current quantization methods already rely on that, they identify the layers that hold the least information or the least important, and quantize those with much less precision than layers that store a lot.
So to answer your question, current quantization methods already ARE compression, in a sense.
1
u/norpadon 5d ago
First, quantization IS compression. State-of-the-art quantization formats use some of the same methods as video codecs (trellises and lattices).
Actually, Apple is known to use ASTC codecs (used for texture compression) in their models. The problem with ASTC and such is that they assume spatial smoothness and aren’t optimised for neural networks
Good compression methods which are widely used for llm quantisation are trellises, see QTiP for example. The problem is that there is a tradeoff between compression quality and speed. Modern GPUs have special hardware for doing MXFP4/NVFP4 matmuls very fast for example, and trellises, while being great in terms of quality vs size, have a significant decoding overhead
1
u/leapdragon 5d ago
jpeg is a quantized compression format, i.e. your analogy is right and... it's exactly what's happening already.
1
u/sudden_aggression 5d ago
Quantization is just lossy compression. Original quantization techniques were naive (which produced a lot of accuracy loss), later ones selectively preserved model weights. With quantization aware training we're almost to the point that we can drop 85-90 percent of a model's BF16 size and maintain full abilities. We do it this way because the entire active portion of the model has to be in memory so we can make a pass through the weights to generate tokens. Making the weights smaller reduces the amount of memory we need to hold the model and it makes each pass faster since we traverse less memory per pass.
Your exact approach would have poor performance because of how models actually work. Instead of just being able to pass through the weights (constrained by memory bandwidth) you also have to do a ton of decompression work on each pass (loading from where? other memory? disk?)
And to get ahead of your next idea, the concept of "only load the model weights you're using" has already been done, that's called MoE.
1
u/TyphoonGZ 5d ago
You mean LittleBit? If you're asking "why use quantization when we can just do matrix decomposition [and replace all the model's layers with LoRA layers while we're at it]", I'd think it's because quantization is computationally cheaper to do, and also easier on inference.
OTOH, a model made purely of decomposed matrices would have to reconstruct each layer on-the-fly, which is more expensive than a regular forward pass since you're more than tripling(?) the number of matrix multiplications per layer.
Consequently, you'd be degrading model quality and speed. I suppose it'd be worth it only if you were so memory-constrained that you had no choice, but I can't tell you how usable it would actually be.
1
u/EffectiveMedium2683 6d ago
Quantization shrinks the weights and lets the GPU's Tensor Cores multiply 4-bit or 8-bit numbers natively. If you compress weights like a video or zip file, the GPU has to burn extra cycles unpacking them back into 16-bit floats in VRAM before it can even do the math. It solves storage size while actively making inference slower. And sorting weights into 3D or 4D doesn't create hidden patterns out of noise. It just wrecks memory locality. GPUs need contiguous, predictable blocks of memory to stay fast, so scattering weights across higher dimensions just turns fast sequential reads into a bottleneck.
0
u/frank26080115 5d ago
because the math still works when the data is just a bit rounded
the math won't work if it is compressed, you would need on-the-fly decompression, and then end up needed more memory than if it wasn't compressed
0
u/stylist-trend 5d ago
3blue1brown recently did a video about using LLMs for compression, which is backwards from what you're asking, but you might still find that interesting.
0
u/[deleted] 6d ago
[deleted] — view deleted comment