Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Choose a method","local":"choose-a-method","sections":[{"title":"Start from your goal","local":"start-from-your-goal","sections":[],"depth":2},{"title":"Check memory with the quantization picker","local":"check-memory-with-the-quantization-picker","sections":[],"depth":2},{"title":"Benchmarks","local":"benchmarks","sections":[],"depth":2}],"depth":1}"/> | |
| <link href="/docs/transformers/pr_45649/en/_app/immutable/entry/start.Cf6g_lQr.js" rel="modulepreload"> | |
| <link href="/docs/transformers/pr_45649/en/_app/immutable/chunks/bcIanF0A.js" rel="modulepreload"> | |
| <link href="/docs/transformers/pr_45649/en/_app/immutable/chunks/CBySwR1V.js" rel="modulepreload"> | |
| <link href="/docs/transformers/pr_45649/en/_app/immutable/entry/app.Ckn5M_jH.js" rel="modulepreload"> | |
| <link href="/docs/transformers/pr_45649/en/_app/immutable/chunks/Cdb1BouH.js" rel="modulepreload"> | |
| <link href="/docs/transformers/pr_45649/en/_app/immutable/chunks/dUGfULTE.js" rel="modulepreload"> | |
| <link href="/docs/transformers/pr_45649/en/_app/immutable/chunks/D5-p1Lz5.js" rel="modulepreload"> | |
| <link href="/docs/transformers/pr_45649/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload"> | |
| <link href="/docs/transformers/pr_45649/en/_app/immutable/nodes/0.92KZZ6l3.js" rel="modulepreload"> | |
| <link href="/docs/transformers/pr_45649/en/_app/immutable/chunks/Conj1S5Z.js" rel="modulepreload"> | |
| <link href="/docs/transformers/pr_45649/en/_app/immutable/nodes/716.2MTmLrY1.js" rel="modulepreload"> | |
| <link href="/docs/transformers/pr_45649/en/_app/immutable/chunks/DoQ7MZQh.js" rel="modulepreload"> | |
| <!--9risur--><meta name="hf:doc:metadata" content="{"title":"Choose a method","local":"choose-a-method","sections":[{"title":"Start from your goal","local":"start-from-your-goal","sections":[],"depth":2},{"title":"Check memory with the quantization picker","local":"check-memory-with-the-quantization-picker","sections":[],"depth":2},{"title":"Benchmarks","local":"benchmarks","sections":[],"depth":2}],"depth":1}"/><!----> | |
| <link href="/docs/transformers/pr_45649/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"><div dir="ltr" class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----></span> <span dir="auto">Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg><!----></button></div> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="choose-a-method" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#choose-a-method"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Choose a method<!----></span></h1><!--]--><!----> <p>If your checkpoint is already quantized, the checkpoint decides the method. Load it as shown in <a href="./overview#load-a-pre-quantized-checkpoint">Load a pre-quantized checkpoint</a>. Otherwise, pick a method based on your hardware and what you need to do with the model after loading it.</p> <!--[1--><h2 class="relative group"><a id="start-from-your-goal" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#start-from-your-goal"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Start from your goal<!----></span></h2><!--]--><!----> <p>Each row recommends a first method to try. Check the full comparison table before you commit to one.</p> <table><thead><tr><th>Goal</th><th>Start with</th><th>Why</th></tr></thead><tbody><tr><td>Fit a model in less memory with the least setup</td><td><a href="./bitsandbytes">bitsandbytes</a></td><td>Quantizes to 4 or 8 bits while loading without calibration, runs on CUDA, XPU, HPU, and CPU, and supports saving and fine-tuning.</td></tr><tr><td>Fine-tune with QLoRA</td><td><a href="./bitsandbytes#qlora">bitsandbytes</a></td><td>Supports 4-bit NF4 with PEFT. <a href="./hqq">HQQ</a>, <a href="./eetq">EETQ</a>, <a href="./gptq">GPTQ</a>, <a href="./sinq">SINQ</a>, and <a href="./quanto">Quanto</a> also support fine-tuning.</td></tr><tr><td>Speed up inference with <code>torch.compile</code></td><td><a href="./torchao">torchao</a></td><td><code>generate</code> compiles torchao models automatically with a static cache, and torchao has int4, int8, and FP8 schemes for CUDA, XPU, and CPU.</td></tr><tr><td>Get the best 4-bit accuracy</td><td><a href="./gptq">GPTQ</a></td><td>Calibrates on a dataset while loading. To use <a href="./awq">AWQ</a> or <a href="./auto_round">AutoRound</a> instead, quantize with their libraries and load the checkpoint.</td></tr><tr><td>Run FP8 on Ada, Hopper, or Intel XPU</td><td><a href="./finegrained_fp8">Fine-grained FP8</a></td><td>Needs CUDA compute capability 8.9 or higher, or an XPU. <a href="./fbgemm_fp8">FBGEMM FP8</a> needs compute capability 9.0 or higher, or an XPU.</td></tr><tr><td>Run FP4 on Blackwell</td><td><a href="./nvfp4">NVFP4</a></td><td>Quantizes to NVIDIA’s 4-bit float format while loading. <a href="./mxfp4">MXFP4</a> runs on compute capability 7.5 or higher, XPU, and CPU.</td></tr><tr><td>Run on Apple silicon</td><td><a href="./metal">Metal</a></td><td>Quantizes to 2, 4, or 8 bits on MPS while loading. <a href="./gguf">GGUF</a> files also load on MPS.</td></tr><tr><td>Load checkpoints made with llm-compressor</td><td><a href="./compressed_tensors">compressed-tensors</a></td><td>Loads FP8, int4, and int8 checkpoints in the compressed-tensors format.</td></tr><tr><td>Compress below 4 bits</td><td><a href="./hqq">HQQ</a> or <a href="./sinq">SINQ</a></td><td>Quantize to 2 or 3 bits while loading without calibration. <a href="./aqlm">AQLM</a>, <a href="./vptq">VPTQ</a>, and <a href="./spqr">SpQR</a> checkpoints go lower but must be quantized with their own libraries.</td></tr></tbody></table> <details><summary>Show the full comparison table</summary> <table><thead><tr><th>Method</th><th><code>quant_method</code></th><th>Workflow</th><th>Bits</th><th>Hardware</th><th>Save</th><th>Fine-tune</th><th>Auto-compile</th></tr></thead><tbody><tr><td><a href="./aqlm">AQLM</a></td><td><code>aqlm</code></td><td>Pre-quantized only</td><td>1–2</td><td>CUDA, CPU</td><td>✅</td><td>✅ with <code>aqlm>=1.0.2</code></td><td>❌</td></tr><tr><td><a href="./auto_round">AutoRound</a></td><td><code>auto-round</code></td><td>Pre-quantized only</td><td>2–8</td><td>CUDA, XPU, CPU</td><td>✅</td><td>❌</td><td>❌</td></tr><tr><td><a href="./awq">AWQ</a></td><td><code>awq</code></td><td>Pre-quantized only</td><td>4</td><td>CUDA, ROCm, XPU, CPU</td><td>✅ except ExLlama backends</td><td>✅ with <code>gptqmodel>=5.0.0</code></td><td>❌</td></tr><tr><td><a href="./bitnet">BitNet</a></td><td><code>bitnet</code></td><td>Pre-quantized only</td><td>1.58</td><td>CUDA</td><td>✅</td><td>Only <code>autobitlinear</code> in <code>online</code> mode</td><td>❌</td></tr><tr><td><a href="./bitsandbytes">bitsandbytes</a></td><td><code>bitsandbytes</code></td><td>While loading</td><td>4, 8</td><td>CUDA, XPU, HPU, CPU</td><td>✅</td><td>✅</td><td>❌</td></tr><tr><td><a href="./compressed_tensors">compressed-tensors</a></td><td><code>compressed-tensors</code></td><td>Pre-quantized only</td><td>Set by checkpoint</td><td>CUDA, XPU, MPS, CPU</td><td>✅</td><td>✅ except with FP8 kernels</td><td>✅</td></tr><tr><td><a href="./eetq">EETQ</a></td><td><code>eetq</code></td><td>While loading</td><td>8</td><td>CUDA</td><td>✅</td><td>✅</td><td>❌</td></tr><tr><td><a href="./fbgemm_fp8">FBGEMM FP8</a></td><td><code>fbgemm_fp8</code></td><td>While loading</td><td>8</td><td>CUDA (compute capability 9.0+), XPU</td><td>✅</td><td>❌</td><td>❌</td></tr><tr><td><a href="./finegrained_fp8">Fine-grained FP8</a></td><td><code>fp8</code>, <code>mxfp8</code></td><td>While loading</td><td>8</td><td>CUDA (compute capability 8.9+), XPU</td><td>✅</td><td>❌</td><td>✅</td></tr><tr><td><a href="./fouroversix">Four Over Six</a></td><td><code>fouroversix</code></td><td>While loading</td><td>4</td><td>CUDA (fastest on Blackwell), CPU</td><td>✅</td><td>Only with <code>keep_master_weights=True</code></td><td>❌</td></tr><tr><td><a href="./fp_quant">FP-Quant</a></td><td><code>fp_quant</code></td><td>While loading</td><td>4</td><td>CUDA, XPU</td><td>✅</td><td>Only with <code>store_master_weights=True</code></td><td>❌</td></tr><tr><td><a href="./gguf">GGUF</a></td><td><code>gguf</code></td><td>Pre-quantized only</td><td>1–8</td><td>CUDA, MPS, XPU, CPU</td><td>❌</td><td>❌</td><td>✅</td></tr><tr><td><a href="./gptq">GPTQ</a></td><td><code>gptq</code></td><td>While loading, with calibration</td><td>2, 3, 4, 8</td><td>CUDA, ROCm, XPU, CPU</td><td>✅</td><td>✅</td><td>❌</td></tr><tr><td><a href="./higgs">HIGGS</a></td><td><code>higgs</code></td><td>While loading</td><td>2, 3, 4</td><td>CUDA</td><td>✅</td><td>❌</td><td>❌</td></tr><tr><td><a href="./hqq">HQQ</a></td><td><code>hqq</code></td><td>While loading</td><td>1, 2, 3, 4, 8</td><td>CUDA, XPU</td><td>✅</td><td>✅</td><td>❌</td></tr><tr><td><a href="./metal">Metal</a></td><td><code>metal</code></td><td>While loading</td><td>2, 4, 8</td><td>MPS</td><td>✅</td><td>❌</td><td>❌</td></tr><tr><td><a href="./mxfp4">MXFP4</a></td><td><code>mxfp4</code></td><td>While loading</td><td>4</td><td>CUDA (compute capability 7.5+), XPU, CPU</td><td>✅</td><td>❌</td><td>❌</td></tr><tr><td><a href="./nvfp4">NVFP4</a></td><td><code>nvfp4</code></td><td>While loading</td><td>4</td><td>One Blackwell GPU</td><td>❌</td><td>❌</td><td>✅</td></tr><tr><td><a href="./quanto">Quanto</a></td><td><code>quanto</code></td><td>While loading</td><td>2, 4, 8</td><td>CUDA, MPS, XPU, CPU</td><td>❌</td><td>✅</td><td>❌</td></tr><tr><td><a href="./quark">Quark</a></td><td><code>quark</code></td><td>Pre-quantized only</td><td>Set by checkpoint</td><td>CUDA, ROCm, CPU</td><td>❌</td><td>❌</td><td>❌</td></tr><tr><td><a href="./sinq">SINQ</a></td><td><code>sinq</code></td><td>While loading</td><td>2, 3, 4, 6, 8</td><td>One CUDA GPU, CPU</td><td>✅</td><td>✅</td><td>❌</td></tr><tr><td><a href="./spqr">SpQR</a></td><td><code>spqr</code></td><td>Pre-quantized only</td><td>3</td><td>CUDA</td><td>✅</td><td>❌</td><td>❌</td></tr><tr><td><a href="./torchao">torchao</a></td><td><code>torchao</code></td><td>While loading</td><td>4, 8</td><td>CUDA, XPU, CPU</td><td>✅</td><td>Only 8-bit schemes</td><td>✅</td></tr><tr><td><a href="./vptq">VPTQ</a></td><td><code>vptq</code></td><td>Pre-quantized only</td><td>1–8</td><td>CUDA</td><td>✅</td><td>❌</td><td>❌</td></tr></tbody></table></details> <!--[1--><h2 class="relative group"><a id="check-memory-with-the-quantization-picker" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#check-memory-with-the-quantization-picker"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Check memory with the quantization picker<!----></span></h2><!--]--><!----> <p>The <a href="https://huggingface.co/spaces/stevhliu/quantization-picker" rel="nofollow">quantization picker</a> estimates whether a model fits on your hardware at each precision, including the KV cache. Pick a model, your hardware, and what you need the method to do, and the <strong>Compare</strong> view lists the methods that match.</p> <iframe src="https://stevhliu-quantization-picker.hf.space" frameborder="0" width="100%" height="420"></iframe> <!--[1--><h2 class="relative group"><a id="benchmarks" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#benchmarks"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->Benchmarks<!----></span></h2><!--]--><!----> <p>The benchmarks below compare several methods on Llama 3.1 8B and 70B. They report accuracy, throughput in tokens per second, peak memory in GB, and quantization time.</p> <p>Llama 3.1 70B in bf16 ran on 2 NVIDIA A100 80GB GPUs. FP8 methods ran on 1 NVIDIA H100 80GB GPU, and all other methods ran on 1 NVIDIA A100 80GB GPU. Throughput was measured at batch size 1, generating 64 tokens. Results include <code>torch.compile</code> and Marlin kernels where a method supports them.</p> <iframe src="https://huggingface.co/datasets/derekl35/quantization-benchmarks/embed/viewer/default/train" frameborder="0" width="100%" height="560px" title="benchmarking results dataset"></iframe> <p>The results group into three bit ranges.</p> <table><thead><tr><th>Bits</th><th>Methods benchmarked</th><th>Memory vs. bf16</th><th>Accuracy</th></tr></thead><tbody><tr><td>8</td><td>bitsandbytes int8, HQQ, Quanto, torchao, FP8</td><td>About 2x smaller</td><td>Very close to bf16</td></tr><tr><td>4</td><td>AWQ, GPTQ, HQQ, bitsandbytes NF4, SINQ</td><td>About 4x smaller</td><td>High. AWQ and GPTQ often lead but need calibration.</td></tr><tr><td>Below 4</td><td>VPTQ, AQLM, 2-bit GPTQ</td><td>More than 4x smaller</td><td>Noticeable drop, especially at 2 bits. AQLM and VPTQ take a long time to quantize.</td></tr></tbody></table> <blockquote class="tip"><p>Benchmark accuracy and speed on your own task and hardware before you pick a method for production.</p></blockquote> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/transformers/blob/main/docs/source/en/quantization/selecting.md" target="_blank"><svg class="mr-1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg><!----> <span><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]--> | |
| <script> | |
| { | |
| __sveltekit_j5svul = { | |
| base: "/docs/transformers/pr_45649/en", | |
| assets: "/docs/transformers/pr_45649/en" | |
| }; | |
| const element = document.currentScript.parentElement; | |
| Promise.all([ | |
| import("/docs/transformers/pr_45649/en/_app/immutable/entry/start.Cf6g_lQr.js"), | |
| import("/docs/transformers/pr_45649/en/_app/immutable/entry/app.Ckn5M_jH.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 716], | |
| data: [null,null], | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 20 kB
- Xet hash:
- 2e5edab36b078873bf19640fd9a1c1c360dbd694d375bdce0a328fb52dfbb4e0
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.