To quantize a language model for local deployment, first choose the engine and its supported format, then prepare a quantized copy and validate it under real workload. Reducing the size of the weights does not guarantee either faster performance or that the model will fit into GPU memory with a long context window. For llama.cpp, one documented path is to convert the source model into high-precision GGUF, then create a Q4_K_M or Q8_0 variant from it.
Prepared by Vladimir Lomtev AI Studio on November 11, 2026 for developers and IT teams deploying an open LLM on their own hardware. This article breaks down a practical workflow for a text model and common reasons a launch fails. It is a supplement to the explanation of quantization principles, not a universal guide for every architecture, GPU, and multimodal model.
The commands were verified against the official llama.cpp instructions and Hugging Face documentation as of the preparation date. Build, conversion, and inference were not performed. Below are the documented sequence and suggested success criteria; compatibility of a specific model and environment must be confirmed separately.
Contents
- What Changes When You Quantize a Model
- Step 1. Choose the format for the engine, not by the file extension
- Step 2. Calculate the weights and separately budget memory for inference
- Step 3. Prepare the source model and llama.cpp tools
- Step 4. First create a high-precision GGUF
- Step 5. Create independent quantized variants
- Step 6. Test the model on the workload it was compressed for
- Why a quantized model still does not fit or runs slower
- Common Questions About Quantization
What Changes When You Quantize a Model
Quantization reduces the precision of number representation. Instead of storing each weight in 16-bit format, a more compact representation with scales and other metadata is used. The result is approximate values: details lost through rounding are not restored by simply converting the file back to FP16.
It is important to distinguish between three objects: weights — trained parameters; activations — intermediate computation values; KV cache — stored attention keys and values for tokens already processed. A method may compress only the weights or also affect other objects. The label “4-bit” without clarifying this composition is not enough to estimate resource usage. Quantization concepts in Transformers.
PTQ is post-training quantization of a finished model. Some methods use calibration texts to estimate the effects of rounding. QAT takes rounding into account during training. These are different processes; simply converting a finished GGUF to Q4_K_M does not make it QAT just because the file name changes.
Step 1. Choose the format for the engine, not by the file extension
First determine where the model will run: on CPU, on GPU, in a mixed setup, or on a server with parallel requests. Then verify support for the model architecture, quantization method, hardware, and the specific engine version. All of these conditions must be met at the same time.
| Option | What it means | What to check before choosing |
|---|---|---|
| GGUF with Q4_K_M, Q8_0, and other types | GGUF container and the selected tensor representation types, often for llama.cpp | Converter, architecture support, tensor types, and runtime backend |
| AWQ | A weight quantization method that takes activations into account | A ready checkpoint and a supported compute kernel |
| GPTQ | A layer-by-layer quantization method with error compensation | Checkpoint configuration, loading implementation, and kernel |
| bitsandbytes | A library for low-bit loading and computation | Backend, loading type, and computation precision |
| FP8 | A family of 8-bit floating-point formats | The specific weights/activations/cache scheme and hardware support |
GGUF is not a synonym for four bits. It can contain both high-precision and quantized tensors. AWQ and GPTQ are methods, while FP8 is a numeric representation that still has to be tied to an implementation. Treating these names as fully equivalent categories is not practical. Support overview in Transformers, vLLM compatibility matrix.
In this guide, the GGUF route is used from here on. It does not describe obtaining an AWQ or GPTQ checkpoint: renaming a finished GGUF does not replace the corresponding quantization process. For choosing the server itself, a separate comparison of vLLM, Ollama, llama.cpp, and SGLangis useful.
The outcome of this stage is a known engine and a format that it can actually run for the selected model. If compatibility has not been confirmed, it is too early to start a long conversion.
Step 2. Calculate the weights and separately budget memory for inference
For a rough lower-bound estimate of weight size, use the formula:
weight bytes ≈ number of parameters × bits per parameter / 8
For a hypothetical model with exactly 8 billion parameters, the following values result. This is a calculation of the useful weight data, not a file measurement and not the memory needs of a running server. GB here is decimal: 1 GB = 1 billion bytes.
| Storage precision | Theoretical weight size |
|---|---|
| 16 bits | 16 GB |
| 8 bits | 8 GB |
| 4 bits | 4 GB |
In a real file, there are group scales, metadata, and tensors with other precision levels. So Q4_K_M does not promise exactly four bits per parameter. For example, the llama.cpp developer table for Llama 3.1 8B lists an average bit rate of about 4.89 bits per weight for this variant. That is a characteristic of the specific example, not a universal value for all Q4 models. llama-quantize documentation.
At runtime, additional KV cache, work buffers, activations, and runtime memory are also required. Cache size depends, among other things, on the attention architecture, context length, the number of simultaneously served sequences, and the precision of the cache itself. Some architectures have limited attention windows, so the rule that “the entire cache always grows the same way” is also incorrect. KV cache strategies.
If the file is 5 GB, you cannot conclude that a 6 GB GPU will be enough. Preparing GGUF also requires RAM and disk space for the source file, the high-precision intermediate file, and the quantized result. Deleting the source just to free up space leaves you without a reliable basis for re-conversion.
The result of this stage is separate estimates for storage, preparation, and inference. There is no single spare-capacity percentage for every model here.
Step 3. Prepare the source model and llama.cpp tools
For this example, you need a directory source-model with the source files for a supported text model in Hugging Face format: weights, config, and tokenizer files. Place it next to the future llama.cppdirectory. This is the name of the local input directory, not the model name in the Hub.
Before you start, save the exact model revision and its usage terms. For a third-party quantized checkpoint, also find out which base it was derived from and with which settings. For your own quantization, prefer an available high-precision source rather than an already heavily compressed copy of unknown origin.
The next example is intended for a Linux terminal with Git, Python, CMake, and a compatible C/C++ compiler already installed. System dependencies and GPU build options are listed in the official build instructions.
git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp
git rev-parse HEAD > build-revision.txt
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
cmake -B build
cmake --build build --config Release --target llama-quantize
The file build-revision.txt records the commit you actually got. Cloning the main branch alone does not lock in a compatible set of versions for the future. Also save the Python version and installed packages; newer architectures may require an updated Transformers version. The converter documentation separately warns that model support depends on the version of this library. Do not update the environment between two variants you are comparing without recording the changes.
The readiness indicator is the built tool build/bin/llama-quantize and the ability to read the converter help:
python convert_hf_to_gguf.py --help
./build/bin/llama-quantize --help
This confirms that the tools are available, but it still does not confirm support for your checkpoint. Binary paths may differ on other operating systems and with a different build configuration.
Step 4. First create a high-precision GGUF
Inside the llama.cpp directory, run the documented conversion option for the local model:
python convert_hf_to_gguf.py ../source-model --outtype f16 --outfile ../model-f16.gguf
The converter should recognize the architecture and save the GGUF. If it reports an unsupported architecture or missing tensors, changing the file suffix will not fix the error. Check the completeness of the source and model support in the revision you are using. The purpose of the arguments is shown in the converter source.
f16 here is the selected intermediate format for the example, not a promise of optimality for any base model. If the source model uses BF16 or a more complex storage scheme, review the bf16 or autooption provided by the converter. Changes in the high-precision form should also be taken into account when comparing.
The result of this stage is the model-f16.gguf file and a saved conversion log without unexplained errors. Creating this file still does not mean the model has passed inference. For multimodal models, a language-only GGUF may not be enough: the project separately describes conversion of image and audio components. That route is not performed here and is not presented as universal.
Step 5. Create independent quantization variants
From the same high-precision file, you can prepare variants for comparison:
./build/bin/llama-quantize ../model-f16.gguf ../model-Q4_K_M.gguf Q4_K_M
./build/bin/llama-quantize ../model-f16.gguf ../model-Q8_0.gguf Q8_0
Both commands use the same high-precision source. Do not create Q8_0 from Q4_K_M in hopes of restoring lost accuracy. The llama.cpp documentation warns that requantizing already quantized tensors can significantly reduce quality compared with processing a 16-bit or 32-bit source. llama-quantize parameters and warnings.
This route uses basic quantization without an importance matrix. For some methods and variants, calibration matters: a small sample is passed through the model to help choose the representation. You cannot call a quantized copy “optimized for Russian” if the relevant procedure was not performed and its effect was not verified.
Save the resulting files with the base revision and settings noted. File size is a useful technical metric, but not the model’s final evaluation.
Step 6. Test the model in the workload it was compressed for
Run the resulting variants in a compatible engine with the same chat template, generation parameters, and input prompts. If the high-precision version does not fit on the same device, state that limitation clearly: timing comparisons on different configurations can no longer be explained by quantization alone.
For internal document search, use questions that are structurally realistic, long excerpts, and answers with exact numbers. For field extraction, check both value correctness and structure. Training example: from a message about a delivery delay, you need to extract the new date without confusing it with the original one. This is a proposed test scenario, not a completed experiment.
Compare the following characteristics:
- answer quality against a predefined reference, including refusals when data is insufficient;
- time to first token and the speed of subsequent generation—separately;
- peak memory usage at the required context length and concurrency;
- loading errors, out-of-memory conditions, and behavior under sustained load.
The Transformers documentation explains why reducing weights can speed up generation when memory bandwidth is the bottleneck, but it does not have to speed up every operation: unpacking and dequantization also require work. Processing long inputs and generating tokens step by step have different constraints. Weights, activations, and compute modes.
The result of this stage is the selected file with verified behavior in your task. This article does not include such results: we are describing exactly what to measure.
Why a Quantized Model Still Won’t Fit or Runs Slower
Insufficient memory with a long document. Weight compression did not automatically reduce the cache. Check the context limit, parallelism, and KV cache management features in your specific engine. Don’t change every setting at once; otherwise, you won’t be able to identify the cause.
The model loads, but part of the computation runs on the CPU. This may be a deliberate placement choice or a lack of GPU memory. Saving VRAM by moving data is not the same as speeding things up. Evaluate the actual layer placement and data transfer between devices.
The format is supported, but the required fast kernel is missing. Check the combination of method, GPU architecture, and server version. The format support table is a necessary condition, but it is not a benchmark for your specific workload.
The responses got worse, even though the speed is normal. Verify the model source, chat template, and generation settings, then compare with a less aggressive option. A template mistake can look like quality loss from quantization. Files based on different base models are not suitable for this conclusion.
Frequently Asked Questions About Quantization
Can I just download a ready-made GGUF?
Yes, if the source, license, base revision, and compatibility are confirmed. Converting it yourself is useful when you need a controlled source file or your own fine-tuned model. A ready-made file does not eliminate the need to test it on a real task.
Which should I choose: four-bit or eight-bit?
Compare the supported options within your memory budget and the quality you need. There is no universal winner: "eight-bit" does not guarantee error-free results, and "four-bit" does not guarantee a quality drop in your specific use case. Don’t confuse nominal bit width with the actual memory footprint of the service.
Does quantization replace LoRA or distillation?
No. Quantization changes how numbers are represented; LoRA trains additional parameters; distillation trains a student model. They can be combined, but each process has its own purpose. The separate topic of language model distillation is covered separately.
Can a fine-tuned model be quantized?
Yes, if the selected architecture and save format support it. First, determine what you have: a full checkpoint or an adapter with the base model. Merging the adapter, exporting, and then quantizing creates a new artifact that must be tested again; a successful adapter test does not automatically certify the final GGUF.
How Vladimir Lomtev’s AI Studio Helps Launch a Compact LLM
Vladimir Lomtev’s AI Studio can prepare the data and requirements for a local LLM, deploy and test the selected model, and integrate it with a corporate knowledge base or business system. The weight format is chosen together with the service architecture and hardware constraints; you cannot promise a specific speedup based on bit width alone.
The first step is to define one process: what requests come in, what the current response time is, which documents are used, and what criterion determines an acceptable result. Discuss the project.
Bottom Line: What Artifact Should Remain After Quantization
For a reproducible deployment, you need the model’s original revision, the tool version, the high-precision source, quantization settings, and the chosen output file. Practical readiness comes after quality and resource checks in the real working context, not after a small file appears.
Start with a compatible engine and independent variants from the same base model. If the model won’t fit, separate weight, cache, and execution memory. If quality drops, first rule out differences in the base model and template, then change the quantization level.



