GGUF vs GPTQ vs AWQ vs EXL2: LLM Model Formats Explained (2026)
https://www.marktechpost.com/2026/09/18/gguf-vs-gptq-vs-awq-vs-exl2-llm-model-formats-explained-2026/📌 GGUF、GPTQ、AWQ、EXL2怎麼選?量化格式一次搞懂
TL;DR:容器格式與量化方法是兩層不同概念,搞懂這點才能對症選對LLM部署方案。
模型檔名裡的Q4_K_M、4.65bpw、AWQ這些後綴,常讓人一頭霧水。其實大部分的混淆,來自把兩層完全不同的東西混在一起看。
🤔 容器格式與量化方法,是兩回事
一個容器定義的是tensor如何存在磁碟上;一個量化方法定義的是權重如何被壓進更少的位元。權重記憶體用量約略等於「參數量 × 每權重位元數 ÷ 8」,這只是算術,不是廠商跑分,而且僅涵蓋權重本身,KV cache與執行期額外開銷還要另外疊加。
未量化模型通常以16位元權重形式發佈,存成pytorch_model.bin或model.safetensors。較舊的.bin/.pt檔案使用Python pickle格式,載入pickle檔案可能執行任意程式碼,對不受信任的checkpoint是安全風險。Hugging Face推出的safetensors則移除了這個風險:檔案只是一小段JSON標頭加上原始tensor緩衝區,內部沒有任何可執行內容,tensor可以被記憶體映射(mmap)並逐一載入,無需讀取整個檔案。值得注意的是,多數GPTQ、AWQ、EXL2、EXL3與MLX模型其實也都儲存在.safetensors檔案裡,量化資訊是放在tensor內容與設定檔中,而不是換了新容器。
🧩 GGUF:llama.cpp生態系的原生格式
GGUF由llama.cpp的創建者Georgi Gerganov提出,於2023年8月21日發布,取代舊有的GGML格式。舊格式(GGML、GGMF、GGJT)無法標示模型屬於哪個架構,新增一個超參數就會破壞所有既有檔案;GGUF改用具型別的鍵值(key-value)中繼資料,可以在不破壞舊檔案的前提下新增欄位。規格列出五個目標:單檔部署、可擴展性、mmap相容、易於載入、資訊完整內含於檔案中。與只存tensor的格式不同,GGUF可以在同一個檔案內連帶存放tokenizer、特殊token與Jinja聊天樣板。
檔名中的Q4_K_M之類後綴代表量化方案。以Q4_K為例:一個super-block容納256個權重,256×4bit=1024bit,再加上8組scale/minimum各12bit(共96bit),以及一個16bit的super-scale和16bit的super-minimum(共32bit),總計1152bit÷256=每權重4.5bit。而_S、_M、_L代表的是混合精度組合而非全新型態,例如llama.cpp文件說明Q4_K_M會對一半的attention.wv與feed_forward.w2張量使用Q6_K、其餘用Q4_K,這也是為什麼Q4_K_M實際檔案平均位元數會高於4.5bit。GGUF量化還可以使用校正資料:llama.cpp的llama-imatrix能從文字檔算出重要性矩陣,llama-quantize —imatrix再用它提升量化品質,對1bit、2bit的混合方案,若沒有提供imatrix,llama-quantize會提出警告。GGUF目前原生支援llama.cpp、LM Studio、GPT4All與Ollama等生態,vLLM雖然存在支援,但官方形容為「高度實驗性且未充分最佳化」,且現在需要額外的vllm-gguf-plugin。
🧩 GPTQ、AWQ、EXL2/EXL3、bitsandbytes、MLX 各有側重
GPTQ由IST Austria的Elias Frantar、ETH Zurich的Saleh Ashkboos與Torsten Hoefler,以及IST Austria/Neural Magic的Dan Alistarh共同提出,2022年10月31日發表於arXiv,後刊登於ICLR 2023。它是一種one-shot、訓練後(post-training)的權重量化方法,利用近似二階(Hessian)資訊決定如何捨入權重,某一欄的捨入誤差會透過調整尚未量化的權重來補償,需要少量校正資料集,但不需要重新訓練。原始的AutoGPTQ函式庫目前已不再維護。
AWQ(Activation-aware Weight Quantization)來自MIT Song Han團隊,2023年6月1日發表於arXiv,獲得MLSys 2024最佳論文獎。其核心觀察是並非所有權重都同等重要,保護約1%的「顯著」權重就能大幅降低量化誤差;巧妙之處在於AWQ透過觀察activation幅度、而非權重本身來找出這些顯著channel,且不將它們以更高精度另外儲存,而是透過數學上等價的變換將其縮放,維持統一、對硬體友善的格式。AWQ不使用反向傳播或重建,因此較不容易對校正資料集過擬合。
EXL2是turboderp開發的推理函式庫ExLlamaV2的原生格式,主打消費級GPU,採用與GPTQ相同的最佳化方法,支援2、3、4、5、6、8bit量化,因此檔名常標示如4.65bpw而非固定的「4-bit」。官方推薦的伺服器是提供OpenAI相容API的TabbyAPI。EXL2會重新命名部分tensor,讓每個模型在內部看起來都像Llama變體,這使得它較難被其他框架重用。
EXL3是後繼格式,建構於Cornell RelaxML提出、發表於NeurIPS 2024的QTIP之上,採用trellis編碼量化搭配incoherence processing,EXL3延續了QTIP的程序化codebook與trellis編碼方式,調整的是tensor的正規化與打包方式。ExLlamaV3在此基礎上新增2至8bit的KV cache量化、張量與專家並行推理、推測解碼、多模態支援,以及Transformers外掛,近期版本也加入了大型MoE模型的CPU卸載功能。硬體上,ExLlamaV3要求CUDA 12.4以上,其README中ROCm支援仍列為待辦事項。
bitsandbytes通常不是預先量化好下載,而是載入16bit模型後即時量化,其4bit模式源自QLoRA。MLX-LM則是Apple Machine Learning Research推出、用於在Apple Silicon上執行與微調LLM的Python套件,MLX模型是帶有MLX專屬量化權重的safetensors,可用mlx_lm.convert加上-q參數將Hugging Face模型量化並上傳至mlx-community組織。在Mac上,透過llama.cpp使用GGUF與使用MLX都是不錯的選擇。
⚠️ 數字僅供參考
文中引用Hugging Face針對Llama-2-7B級模型的量化位元/品質對照表僅為示意,數字來自2023年的7B模型,較新的模型在量化下的表現可能不同。
🎯 實務啟示
選格式前先分清楚自己要解決的是「容器」還是「量化」問題:若在llama.cpp/Ollama生態內部署,GGUF是預設選擇,且Q4_K_M搭配imatrix校正通常是品質與體積的均衡點;若鎖定消費級GPU且想要非整數位元的精細權衡,EXL2/EXL3更合適;若追求無需大量校正資料、對過擬合風險敏感的量化方案,AWQ值得考慮;若需要一次性、免重新訓練的post-training量化,GPTQ仍是成熟選項;在Apple Silicon上,GGUF與MLX都是可行路線。
🔗 來源
- 標題:GGUF vs GPTQ vs AWQ vs EXL2: LLM Model Formats Explained (2026)
- 作者/機構:Asif Razzaq/MarkTechPost
- 連結:https://www.marktechpost.com/2026/09/18/gguf-vs-gptq-vs-awq-vs-exl2-llm-model-formats-explained-2026/
#LLM #Quantization #GGUF #GPTQ #AWQ #EXL2 #LlamaCpp #ModelDeployment #MachineLearning #EdgeAI
原始資料 MarkTechPost · 收集於 2026-09-20
摘要原文
Most confusion comes from mixing 2 layers. A container defines how tensors are stored on disk. A quantization method defines how weights are squeezed into fewer bits. Weight memory ≈ parameters × bits-per-weight ÷ 8. This is arithmetic, not a vendor benchmark. It covers weights only. The KV cache and runtime overhead add more on top. Unquantized models usually ship as 16-bit weights, in either pytorch_model.bin or model.safetensors . The older .bin / .pt files use Python pickle. Loading a pickle file can execute arbitrary code, which makes untrusted checkpoints a security risk. Safetensors , created at Hugging Face, removes that risk. A file is a small JSON header plus raw tensor buffers, with nothing executable inside. Tensors can be memory-mapped and loaded one at a time without reading the whole file. Safetensors is now listed as a PyTorch Foundation project . Important nuance: most GPTQ, AWQ, EXL2, EXL3, and MLX models are also stored in .safetensors files. The quantization lives in the tensor contents and a config file, not in a new container. GGUF is a binary format for running models with GGML and GGML-based executors such as llama.cpp. It was created by Georgi Gerganov, who also leads llama.cpp ( Hugging Face docs ). It was introduced on August 21, 2023 as the replacement for the older GGML format. The older GGML, GGMF, and GGJT files could not say which architecture a model belonged to. Adding a new hyperparameter broke every existing file. GGUF switched to typed key-value metadata, so new fields can be added without breaking old files. The spec lists 5 goals: single-file deployment, extensibility, mmap compatibility, easy loading, and complete information inside the file. Unlike tensor-only formats, GGUF can carry the tokenizer, special tokens, and a Jinja chat template alongside the weights. The suffix in a name like Q4_K_M.gguf tells you the scheme. Figures below come from the Hugging Face GGUF docs . *Derived by hand, not listed in the HF table: 32 weights plus a 16-bit scale (and a 16-bit minimum for Q4_1). Checking the Q4_K math : A super-block holds 256 weights. 256 × 4 bits = 1,024 bits. Add 8 blocks × 12 bits of scales and minimums (96 bits). Add a 16-bit super-scale and 16-bit super-minimum (32 bits). Total: 1,152 ÷ 256 = 4.5 bits per weight. What _S , _M , _L mean : These are mixes, not new types. For example, llama.cpp describes Q4_K_M as using Q6_K for half of the attention.wv and feed_forward.w2 tensors and Q4_K elsewhere ( Unsloth docs ). That is why a Q4_K_M file averages above 4.5 bits per weight. Newer types : The HF table also lists TQ1_0 and TQ2_0 for ternary weights, plus MXFP4, a 4-bit microscaling floating-point type. A labeling quirk : Hugging Face files Q8_0 under “legacy” types. In practice, Q8_0 remains the standard near-lossless GGUF choice. Hugging Face’s reference table for a Llama-2-7B-class model shows the trade-off : Illustrative only. These numbers come from a 2023-era 7B model; newer models can react differently. GGUF quantization can use calibration data. llama.cpp’s llama-imatrix computes an importance matrix from a text file. llama-quantize --imatrix then uses it to improve quality. For 1-bit and 2-bit mixes, llama-quantize warns if no imatrix is supplied . The spec defines filenames as base name, size label, fine-tune, version, encoding, type, and shard. Shards use a 5-digit counter such as 00003-of-00009 . Optional mmproj- and mtp- prefixes mark vision projectors and multi-token-prediction draft modules. GGUF is native to llama.cpp and its ecosystem. Hugging Face documents use with llama.cpp, LM Studio, GPT4All, and Ollama . vLLM support exists but is limited. vLLM calls it highly experimental and under-optimized, and GGUF now needs the out-of-tree vllm-gguf-plugin . GPTQ was written by Elias Frantar (IST Austria), Saleh Ashkboos and Torsten Hoefler (ETH Zurich), and Dan Alistarh (IST Austria & Neural Magic). It first appeared on arXiv on October 31, 2022. It was published at ICLR 2023 . GPTQ is a one-shot, post-training weight quantization method. It uses approximate second-order (Hessian) information to decide how to round weights. Rounding error in one column is compensated by adjusting weights not yet quantized. It needs a small calibration dataset but no retraining. GPTQ repos often include GPTQ or tags like 4bit-128g in the name. The original AutoGPTQ library is no longer maintained . AWQ (Activation-aware Weight Quantization) comes from Song Han’s group at MIT. It first appeared on arXiv on June 1, 2023. It won the MLSys 2024 Best Paper Award . Not all weights matter equally. Protecting roughly 1% of ‘salient’ weights sharply reduces quantization error . The twist: AWQ finds those salient channels by looking at activation magnitudes, not the weights themselves. It does not store those channels at higher precision. Instead, it scales them up through a mathematically equivalent transformation, keeping a uniform, hardware-friendly format. AWQ uses no backpropagation or reconstruction, so it is less likely to overfit its calibration set. EXL2 is the native format of ExLlamaV2 , an inference library by turboderp for consumer GPUs. It uses the same optimization method as GPTQ and supports 2, 3, 4, 5, 6, and 8-bit quantization. That is why EXL2 files carry names like 4.65bpw instead of 4-bit . TabbyAPI is the official recommended server, providing an OpenAI-compatible API. EXL2 renames some tensors so every model looks like a Llama variant internally . That makes EXL2 hard to reuse in other frameworks. EXL3 is the successor format, built on QTIP from Cornell RelaxML. QTIP uses trellis-coded quantization with incoherence processing and was published at NeurIPS 2024. EXL3 keeps QTIP’s procedural codebook and trellis encoding. It changes how tensors are regularized and packed. ExLlamaV3 adds 2–8 bit KV-cache quantization, tensor- and expert-parallel inference, speculative decoding, multimodal support, and a Transformers plugin. Recent releases add CPU offloading for large MoE models . Hardware note: ExLlamaV3 requires CUDA 12.4 or later. Its README has listed ROCm support as a to-do item. bitsandbytes is usually not something you download pre-quantized. You load a 16-bit model and quantize it on the fly. Its 4-bit mode comes from QLoRA : MLX-LM is a Python package for running and fine-tuning LLMs on Apple Silicon with MLX. MLX comes from Apple Machine Learning Research . MLX models are safetensors with MLX-specific quantized weights. mlx_lm.convert with -q quantizes a Hugging Face model and can upload it to the mlx-community organization. On a Mac, both GGUF (via llama.cpp) and MLX are strong options. The post GGUF vs GPTQ vs AWQ vs EXL2: LLM Model Formats Explained (2026) appeared first on MarkTechPost .
由 claude-code/sonnet 自動生成