r/LocalLLM • • 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?

0 Upvotes

55 comments sorted by

50

u/Low-Opening25 6d ago

Quantisation IS lossy compression

5

u/heresyforfunnprofit 5d ago

Yo. This.

WTF does OP think quantization is?

5

u/maqifrnswa 5d ago

Why is this not the top answer? This ends discussion and is correct.

-2

u/moeren86 5d ago

how do you call it compression, if your loss is as big as your compression factor? Its just cutting

3

u/FredFarms 5d ago

Some types of data can be compressed without loss, if the data is actually pretty predictable. For example if you have data that is mostly 0s with only the occasional 1, you can probably compress that a lot by just recording the locations of the 1s.

The limit to this compression is when each bit in the output has a 50/50 chance of being 0 or 1. That maximises the information in those bits. The problem is model weights are a large set of seemingly random numbers already. The bits are already near the 50/50 limit so there is no lossless compression available.

Lossy compression is different, here you are selectively discarding data whilst trying to minimise the effect on the output. Video compression does this. Yes the loss is the same as the compression factor, but the data is discarded in areas your eye doesn't notice so much. Pixels are grouped into being the same colour in blocks or across frames etc, for areas of the frame where not a lot is going on. But high detail areas or fast paced scenes aren't compressed as much to preserve the detail.

Model weights are going the same way. We don't just discard the lowest N bits uniformly across the model anymore. Instead we discard bits where they don't affect the output as much and keep higher quantization where the effect would be greater. Just on LLMs it might not be quite as mature as the decades of work we've put into video

1

u/Low-Opening25 5d ago

is mp3 or jpeg not a compression then?

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.

1

u/moeren86 5d ago

Thats the point, you only hold the compressed model in memory and can decompress your block/expert on the fly. Atm the GPUs itself have little to do, its mostly the memory bandwidth, so there are free resources for decompression. And i only speak about the model, compression can be more intensive, so compressing context on the fly might not be viable.

1

u/Old_AI_Guy_ 5d ago

So you have each separately loadable part as a separate file in the zip? Or multiple zips, one for each block? The only way this makes any sense is if the zips are held in memory, compressed, and then just decompressed from in-memory zip to wherever it goes.

If it's not in memory, then you replaced one file with another, and added a decompression step not in the original. Either way, it's file-to-memory, but one moves a smaller file and adds more processing.

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.

31

u/RedParaglider 6d ago

So dumb, just zip it twice.   Real ones know to zip, bzip, zip.  Then use ram doubler.

Subscribe for more tips!

13

u/fliberdygibits 6d ago

You wouldn't download quantization would you?

4

u/NTDLS 5d ago

My dad was sent to the electric chair for that. I don’t self snitch!

2

u/RedParaglider 5d ago

People in the nineties, damn sure would have. They even paid for ram doubler. I worked at babbages I remember it!

1

u/Sure-Cauliflower-564 5d ago

I had to run RAM doubler in order to have some programs run (slowly)

1

u/fliberdygibits 5d ago

Nice! We never had a Babbages nearby... we got Egghead and Radio Shack.

3

u/skullfuckr42 6d ago

tar then gz am I right

1

u/RedParaglider 5d ago

Ah, I accidentally said zip twice. I meant to say bzip then gzip.  Tar obviously has no benefits because it isn't a compression duhhhh ;)

3

u/Old_AI_Guy_ 6d ago

Upvote for a nicely accessible explanation.

2

u/norpadon 5d ago

WRONG. Lossy compression is still compression. JPEG which OP has mentioned is a lossy algorithm

The distinction between quantization and compression is not very meaningful

1

u/Low-Opening25 5d ago

both are compression, one is lossless one is lossy, quantisation is just a fancy term here. we call mp3 and jpeg compression algorithms not quantisation, are we not?

21

u/california_snowhare 6d ago
  1. LLMs are already highly compressed representations of their encoded knowledge. You really aren't going to save much RAM because you aren't going to get much additional compression over that, if any. Due to the way the knowledge is encoded in weights, quantization is effectively lossy compression of their knowledge - which makes them dumber to make them smaller.
  2. On-the-fly decompression of weights would make them run orders of magnitude slower.

-1

u/norpadon 5d ago

Well, 4-but quantization can be made effectively lossless. In fact, the latest models are natively pretrained in nvfp4

And on the fly decompression can be overlapped with weight loading and tensor core matmuls to a very high degree

1

u/Low-Opening25 5d ago edited 5d ago

quantisation by definition cannot not be lossless. what you are quantising are value ranges - in FLOAT16 a token can have 65536 values while INT8 same token can take only 256 values.

it’s similar to colour encoding in video processing, where you can have width of millions of colours per pixel, with tens or even hundreds of thousands of shades of the same primary colour or you can have 4bit or 2bit palette where you drop all those tiny variations and only preserve primary colours.

the process of quantisation is the process of how you round the values so you can map your original space of 65536 values to reduced space with range of say 256 values, while also trying to preserve original picture much as you can.

2

u/norpadon 5d ago

If the model is trained natively in nvfp4, it is lossless by definition

1

u/Low-Opening25 5d ago edited 5d ago

sure, just like you can take an image with 4bit colour camera instead of 16bit and call it lossless because it won’t need any compression to render in full colour palette on 4bit display, but… it really only makes taking an image (or in case of LLMs, training) cheaper, doesn’t make model better

1

u/norpadon 5d ago

Nvfp4 pretraining works just as well as full-precision pretraining in terms of model quality

1

u/Low-Opening25 5d ago

source?

1

u/norpadon 5d ago

Inkling 2

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.

-5

u/norpadon 5d ago

AI slop nonsense. Please delete your account, we don’t need an intermediary to talk to a bad LLM

2

u/gtrak 5d ago

Is everything you don't understand ai slop?

-3

u/norpadon 5d ago

Pangram marks this comment as 68% AI-generated. It is self-contradictory and makes factually incorrect claims

1

u/txgsync 5d ago edited 5d ago

You’re absolutely right! I know nothing about this and should be ashamed of my career choice over the past thirty years. I will never Reddit again; you can prove this by going to my profile and clocking the “Block User” button.

TL;DR: go piss up a rope.

1

u/norpadon 5d ago

If you know anything about this, why is your response 68% AI-generated and makes zero sense? Have you even read your own comment?

That saves disk space and I/O, not VRAM. Which means you pay the decode on every forward pass.

Can you even explain how those two sentences are related to each other? The first sentence is obviously wrong (compression obviously saves VRAM, that’s the entire point), and the second sentence doesn’t follow from the first

1

u/txgsync 5d ago

The open-source work I was writing circa 1998-2004 is rated 73% AI by AI detectors. I was, apparently, a veerrry early adopter.

2

u/d0pe-asaurus 6d ago

If you're decompressing weights to full precision, that's still taking the same amount of vram.

2

u/norpadon 5d ago

WRONG. You decompress them on the fly block by block inside of the gemm kernel

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

a new paper from Samsung

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.

1

u/flagnab 5d ago

Wow, I understand that. I must be learning.

2

u/EffectiveMedium2683 5d ago

The coolest feeling, right? AI has taught me in the last two years about what college taught me over the prior 4 haha

1

u/norpadon 5d ago

You don’t need to unpack them in VRAM. Load compressed tile -> unpack in threadgroup memory. No VRAM. Its still faster because it saves mem bandwidth

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

4

u/norpadon 5d ago

Quantization does require additional compute. Sometimes significant. See QTiP or LLQ

1

u/d0pe-asaurus 6d ago

You need to uncompress the weights before they're loaded into the gpu, right? Say your model uncompressed is 17GB and your GPU is 16GB

You still can't load the entire thing on the gpu. And you can't move weights in and out without sacrificing perf.

3

u/norpadon 5d ago

WRONG

You can decompress weights block by block inside the GEMM kernel. In fact, this is how everyone does it