Skip to main content
Home › Categories › Artificial Intelligence & Computing › What Is LLM Quantization and LoRA Fine-Tuning? Memory Math, FP16 vs INT4, and Practical Adaptation

What Is LLM Quantization and LoRA Fine-Tuning? Memory Math, FP16 vs INT4, and Practical Adaptation

Author: ZUVDEX Team 4 min read
llm quantization and lora fine tuning vram calculator llm formula fp16 bf16 fp8 int4 quantization lora vs qlora vs full fine tuning awq vs gptq vs gguf catastrophic forgetting fine tuning

Quantization and Low-Rank Adaptation (LoRA) are the two foundational memory-efficiency techniques that make large neural models practical on affordable hardware. Post-training quantization compresses model weights from 16-bit floating point down to 8-bit or 4-bit representations—cutting inference VRAM by 50% to 75% with minimal perplexity loss—while LoRA and QLoRA freeze the base model and train tiny rank-decomposed adapter matrices so teams can customize 8B to 70B models on a single GPU.

Key Highlights

  • Inference VRAM equals Model Weights + KV Cache + CUDA Activation Overhead; in BF16 (2 bytes/param), a 70B model needs ~140 GB for weights alone before a single user token is cached.
  • Hardware-native FP8 on Hopper/Blackwell GPUs preserves almost 100% of BF16 benchmark accuracy while doubling Tensor Core throughput.
  • 4-bit Activation-Aware Weight Quantization (AWQ) protects the 1% most salient weight channels affected by large activation magnitudes, outperforming naive round-to-nearest INT4.
  • LoRA trains pairs of small matrices A and B (ΔW = B·A) alongside frozen base weights—allowing dozens of tenant-specific adapters to hot-swap in milliseconds on a single shared base model.

1. Exact GPU VRAM Math for Inference vs Training

Running out of GPU memory (`CUDA out of memory`) happens when engineers count parameter weights but forget optimizer states, gradients, activations, and KV caches. For pure inference, weight memory in gigabytes is approximately `(Parameters in Billions × Bits per Weight) ÷ 8`, plus roughly 15–25% headroom for runtime buffers and concurrent user KV caches.

Full-parameter training in mixed precision is roughly 8× heavier than inference! Updating every weight of an 8B model with AdamW requires storing FP16 weights (16 GB), FP16 gradients (16 GB), and FP32 master weights plus two FP32 Adam momentum/variance states (96 GB)—exceeding 128 GB before batch activations are even allocated. That arithmetic explains why parameter-efficient LoRA transformed applied AI engineering.

Precision & Quantization Formats Compared for a 70B Parameter LLM
Format Bits / Weight 70B Weights VRAM Accuracy Retention Best Deployment Target
BF16 / FP16 16-bit ~140 GB 100% Reference Baseline Multi-GPU high-precision clusters
FP8 (E4M3) 8-bit float ~70 GB 99.5%+ (Near-lossless) H100 / H200 / B200 production serving
AWQ / GPTQ (INT4) 4-bit int ~38–42 GB 97–99% (Calibration-tuned) Single 48GB–80GB GPU high-speed vLLM
GGUF (Q4_K_M / Q5_K_M) 4.5–5.5 bit ~42–50 GB 98%+ Mixed block k-quants Apple Silicon unified RAM & CPU+GPU workstations
Extreme 2-Bit (IQ2) 2–2.5 bit ~20 GB Noticeable reasoning degradation Constrained edge experimentation only

2. How AWQ, GPTQ, and FP8 Avoid Destroying Model Reasoning

If you naively round every 16-bit neural weight to the nearest 4-bit integer between -8 and +7, outlier weights in attention and feed-forward layers stretch the quantization grid so wide that 99% of normal weights collapse toward zero—ruining coding and math accuracy.

Modern Post-Training Quantization (PTQ) solves outliers cleanly. GPTQ uses approximate second-order Hessian information from a small calibration dataset to adjust remaining weights as earlier columns are quantized, canceling rounding error. Activation-Aware Weight Quantization (AWQ) observes that less than 1% of weight channels multiply high-magnitude input activations; scaling those salient channels prior to 4-bit packing preserves sensitive reasoning circuits without mixed-precision hardware slowdowns.

3. Inside LoRA and QLoRA: Freezing Weights, Training Low-Rank Deltas

Introduced by Hu et al., Low-Rank Adaptation (LoRA) builds on an empirical discovery: when a massive pretrained LLM adapts to a downstream task, the weight update matrix ΔW has a very low ‘intrinsic rank.’ Instead of modifying a 4,096 × 4,096 weight matrix (16.7 million parameters), LoRA freezes W and injects two slim matrices—A (4,096 × 16) and B (16 × 4,096)—totaling just 131,072 trainable parameters (<0.8% of the original layer).

QLoRA pushes efficiency one step further by quantizing the frozen base model into 4-bit NormalFloat (NF4—an information-theoretically optimal data type for normally distributed neural weights), using double quantization on scaling constants, and paging optimizer spikes to CPU RAM. With QLoRA, a single 24 GB or 48 GB workstation GPU can fine-tune models that previously demanded an eight-GPU server rack.

  • Target all linear layers: Apply LoRA across q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, and down_proj—not just query and value matrices—to match full fine-tuning quality.
  • Data quality beats volume: 1,500 meticulously verified, deduplicated domain examples routinely outperform 100,000 noisy scraped rows.
  • Zero inference latency penalty: For single-model deployments, you can mathematically merge B·A straight back into W (`W_new = W + α/r · B·A`) before exporting.

FAQs

Should I quantize the KV cache as well as the model weights?

For long-context workloads (32K–128K tokens) or high concurrency, FP8 KV-cache quantization in vLLM or TensorRT-LLM cuts dynamic context memory in half with minimal accuracy impact—allowing twice as many simultaneous requests per GPU.

What is the difference between AWQ and GGUF?

AWQ is optimized for maximum parallel GPU throughput inside data-center engines like vLLM, whereas GGUF (created for the llama.cpp ecosystem) is designed for portable local execution across Apple Silicon unified memory, consumer GPUs, and x86/ARM CPUs.

How do I choose LoRA rank (r) and alpha (α)?

For stylistic formatting, classification, or SQL schema alignment, rank r = 16 with alpha = 32 is a reliable baseline. When teaching dense domain terminology or multi-step reasoning traces, r = 32 or r = 64 provides extra adapter capacity—provided your dataset is clean enough to avoid overfitting.

What causes 'catastrophic forgetting' during fine-tuning?

Training aggressively with a high learning rate on narrow single-format examples overwrites general instruction-following behavior. Mixing 10–15% general instruction replay data and using cosine learning-rate decay with LoRA keeps general reasoning intact.

References & Sources

  • Hu, E. J. et al. — LoRA: Low-Rank Adaptation of Large Language Models, International Conference on Learning Representations (ICLR).
  • Dettmers, T. et al. — QLoRA: Efficient Finetuning of Quantized LLMs, Advances in Neural Information Processing Systems (NeurIPS).
  • Lin, J. et al. — AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration, MLSys.
  • Frantar, E. et al. — GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers, ICLR.