Why Quantization Matters
마지막 수정:
Quantization은 단순히 “작은 dtype을 쓴다”가 아니다.
LLM inference에서 quantization은 token 하나를 만들 때 움직여야 하는 byte 수를 줄이는 방법이다. 현대 GPU에서 많은 decode workload는 FLOPs가 부족해서 느린 것이 아니라, weight와 KV cache를 계속 HBM에서 읽어야 해서 느리다.
핵심 병목
LLM이 다음 token을 만들 때 반복해서 읽는 것은 크게 세 가지다.
model weights
KV cache
activations / temporary buffers
작은 batch의 decode에서는 weight를 매 token마다 다시 읽는 비용이 크다. context가 길어지면 KV cache도 함께 커진다. 그래서 quantization의 1차 효과는 다음처럼 봐야 한다.
FP16 weights -> INT8 / INT4 weights
same model behavior target
fewer bytes moved
more room for KV cache
more batching or longer context
이 관점에서는 bit precision이 정확도 문제이기 전에 memory traffic과 energy 문제다.
FP16 baseline
1.76x concurrency- Weights
- 27.5 GiB
- KV cache
- 11.00 GiB
- Cache tokens
- 72,064
4-bit AWQ weights
4.66x concurrency- Weights
- 9.4 GiB
- KV cache
- 29.15 GiB
- Cache tokens
- 191,056
왜 모델이 바로 망가지지 않나
양자화는 값을 낮은 bit grid에 맞추기 때문에 error를 만든다.
하지만 trained neural network의 weight는 물리 시뮬레이션의 상수처럼 “정확한 숫자 하나”를 요구하는 경우가 적다. 많은 weight는 방향, 상대적 영향, feature 조합을 분산해서 표현한다. 그래서 적당한 bit-width와 좋은 scale 선택에서는 작은 perturbation을 흡수할 수 있다.
그렇다고 공짜는 아니다. 다음 조건에서는 품질 손실이 커질 수 있다.
too few bits
bad calibration data
activation outliers
wrong granularity
unsupported runtime kernel
long-context KV cache error accumulation
줄어든 메모리가 어디에 쓰이나
weight-only quantization은 특히 serving에서 중요한 효과를 만든다. weight가 작아지면 같은 GPU 안에서 남는 memory가 생긴다. 그 memory는 보통 다음으로 간다.
larger KV cache
higher concurrency
longer context
larger batch window
그래서 weight-only INT4가 항상 matmul 자체를 빠르게 만드는 것은 아니어도, 실제 serving throughput을 올릴 수 있다. 모델 weight가 차지하던 공간을 KV cache와 scheduler 여유로 바꾸기 때문이다.
Path에서 볼 질문
이 path는 quantization을 다음 질문들의 연결로 본다.
무엇을 quantize할까? weights / activations / KV cache
언제 quantize할까? PTQ / QAT / training-time low precision
어떻게 나눌까? per-tensor / per-channel / per-token / group / block
어떻게 실행할까? dequant / fused dequant GEMM / native low precision kernel
무엇을 측정할까? memory / latency / throughput / perplexity / task quality
이 질문들을 잡으면 GPTQ, AWQ, SmoothQuant, FP8, KV cache quantization이 서로 다른 이름의 기술이 아니라 같은 trade-off 공간 안에 있다는 것이 보인다.
확인
- LLM inference에서 quantization이 memory traffic을 줄인다는 말은 구체적으로 어떤 byte를 줄인다는 뜻인가?
- weight-only quantization이 matmul compute를 크게 줄이지 않아도 serving throughput을 올릴 수 있는 이유는 무엇인가?
- quantization error가 작아도 실제 task quality를 따로 검증해야 하는 이유는 무엇인가?