Running Large Language Models Locally: Model Selection, Memory Planning, and Deployment Steps
This guide explains how to run 9B–14B quantized language models on a personal computer. It covers model selection, memory and VRAM estimates, unified memory limitations, and step-by-step deployment with llama.cpp, including model verification, GPU offloading, and local server setup.
1. Why Run a Model Locally?
Many people use large language models at work to summarize meeting notes, extract key points from reports, and analyze spreadsheet data. Cloud services may become slow or unavailable during peak periods. Uploading internal documents to a third-party service may also violate company confidentiality or compliance requirements.
Running a model locally reduces dependence on the network and keeps files on the computer.
Local deployment also has trade-offs. Models require suitable hardware, downloading and maintaining them takes some technical work, and local models are generally less capable than the most advanced cloud models. The practical approach is to first determine whether your computer can handle the model, then decide whether deployment is worthwhile.
2. Scope: 9B to 14B Quantized Models
2.1 Parameter Count Determines the Hardware Requirements
Larger models are generally more capable, but they also require more memory. Leading open-source models can have total parameter counts in the trillion range, with hundreds of billions of parameters activated during inference. Such models require server-grade hardware and are not suitable for ordinary computers.
This article focuses on 9B to 14B quantized models. They are suitable for summarization, rewriting, basic programming, and common mathematics problems. They still lag behind cloud-based large models in complex reasoning and long-context comprehension.
If your computer has limited memory, a 7B-class model can be used as an alternative. The estimation methods and deployment steps in this article also apply to that class of model.
2.2 The Value and Limitations of Distilled Models
Distillation uses a more capable teacher model to generate training data, which is then used to train a smaller student model. The student learns the teacher’s output patterns for particular tasks, but cannot fully reproduce all of the teacher’s capabilities.
For example, a 9B distilled model may perform well on programming and mathematics tasks, while typically having narrower knowledge coverage and weaker long-chain reasoning than its teacher model.
When selecting a model, first review the evaluation results and intended-use descriptions published by the model provider. Then test the model with your own real-world tasks.
2.3 Choosing a Quantization Format
Quantization compresses model weights from 16-bit floating-point values to a lower bit width. With 4-bit quantization, for example, the weights theoretically occupy one quarter of the space required by FP16.
Q4_K_S is a common 4-bit format in the llama.cpp ecosystem. It produces smaller files, but the loss in output quality is also greater. Q4_K_M usually provides a better balance between file size and quality and is a good format to try first.
For tasks such as document summarization, Q4 quantization generally provides usable quality. If you have sufficient memory, you can try Q5 or Q6 for more stable output, although these formats require more memory.
3. Hardware Estimation: RAM, VRAM, and Unified Memory
3.1 Memory Has Three Main Components
When running a model locally, memory is primarily used for:
- Model weights
- The KV cache, which stores attention states for the context
- Runtime buffers
A rough estimate for the weight size is:
Weight size ≈ parameter count × bits per parameter ÷ 8
A 9B model in Q4_K_S format uses approximately 4.6 bits per parameter, resulting in roughly 5 GB of weights. Using the same method, a 14B model requires approximately 8 GB.
KV cache usage increases linearly with the context length. For an 8B-class architecture with 32 layers, 8 KV heads, and a head dimension of 128, each token uses approximately 128 KB at FP16 precision. An 8,192-token context therefore uses about 1 GB. Doubling the context length also doubles the cache usage.
Different models have different numbers of layers and KV heads. Recalculate the estimate using the values in the model’s configuration file.
The following table provides rough estimates based on the method above. Actual testing is recommended.
| Configuration (8K context) | Weights | KV cache | Buffers | Total | Recommended headroom | Recommended system RAM |
|---|---|---|---|---|---|---|
| 9B, Q4_K_S | Approx. 5 GB | Approx. 1 GB | Approx. 1 GB | Approx. 7 GB | 10 GB | 16 GB |
| 14B, Q4_K_S | Approx. 8 GB | Approx. 1.2 GB, estimated with 40 layers and 8 KV heads | Approx. 1 GB | Approx. 10 GB | 12 GB | 32 GB |
The operating system and other applications also consume memory, so system RAM should not be allocated based only on the model size.
A computer with 16 GB of RAM is recommended only for 9B models. A 14B model is better suited to a system with 32 GB of RAM. If you plan to process documents containing tens of thousands of Chinese characters, or run multiple tasks at the same time, recalculate the requirements using the actual context length.
3.2 Dedicated GPU VRAM
Dedicated graphics cards commonly have between 8 GB and 12 GB of VRAM. Loading a 9B model into 8 GB of VRAM can be challenging, and an 8K context may use most or all of the available memory.
In this situation, you can offload only some of the model layers to the GPU and run the remaining layers on the CPU. The relevant parameter is described in Section 4.
3.3 The Speed Limit of Unified Memory
Some newer AI laptops use a unified memory architecture in which the CPU and integrated GPU share the same memory. This allows the GPU to access a larger memory pool, making it easier to load a 14B model and use a longer context.
Unified memory also has a cost. Its bandwidth is determined by the system memory architecture and is generally lower than the memory bandwidth of a dedicated GPU. During text generation, most of the model weights must be read for every generated token, so generation speed is largely limited by memory bandwidth.
The theoretical upper bound can be estimated as follows:
Maximum generation speed (tokens/second)≈ memory bandwidth (GB/second) ÷ model file size (GB)
For example, if a 9B Q4 model is approximately 5 GB and the device provides 100 GB/s of memory bandwidth, the theoretical upper limit is about 20 tokens per second. Actual performance will be lower.
The test conditions for the 64 GB unified-memory device mentioned in the original source were not disclosed, so no speed figure is provided here. Measure performance on your own hardware as described in Section 5.
4. Deploying with llama.cpp
4.1 Prepare the Build Environment
On Windows, install Visual Studio Build Tools with Desktop development with C++ selected, along with CMake.
On macOS, install the Xcode Command Line Tools by running:
xcode-select --install
Then install CMake.
On Linux, install build-essential, CMake, and Git.
If you are using an NVIDIA GPU, also install the corresponding version of the CUDA Toolkit. macOS uses Metal acceleration by default and does not require additional configuration.
4.2 Download the Source Code and Build
Run the following commands in a terminal:
git clone https://github.com/ggml-org/llama.cppcd llama.cppcmake -B buildcmake --build build --config Release -j
For NVIDIA GPU support, change the first CMake command to:
cmake -B build -DGGML_CUDA=ON
After compilation, the executables are placed in the build/bin directory. On Windows, they are located under:
build\bin\Release
4.3 Download and Verify the Model
Download a GGUF file from the model publisher’s official page or a trusted Hugging Face repository. The filename usually indicates the quantization format, such as Q4_K_S.
Before downloading, confirm that the model’s license permits internal business use.
After downloading, verify the file’s SHA-256 hash against the value published by the model provider.
On macOS and Linux:
shasum -a 256 models/model-file-name.gguf
On Windows:
certutil -hashfile models\model-file-name.gguf SHA256
If the publisher does not provide a hash, at minimum confirm that the file comes from the official account. Do not use repackaged files from unknown sources.
4.4 Start Interactive Mode
Run:
./build/bin/llama-cli -m models/model-file-name.gguf -c 8192 -ngl 99
The parameters are:
-m: Specifies the model file path.-c: Sets the context length. This determines how much text the model can process and directly affects memory usage.-ngl: Specifies the number of layers to offload to the GPU. A value of99attempts to place as many layers as possible on the GPU.
If you run out of VRAM, reduce the value, for example to 20 or 30. The remaining layers will run on the CPU.
On Windows, use backslashes in file paths where appropriate.
4.5 Start a Local Server
If you want to call the model from office software or a browser, start the local server with:
./build/bin/llama-server -m models/model-file-name.gguf -c 8192 -ngl 99 --host 127.0.0.1 --port 8080
The address is set to 127.0.0.1, which allows access only from the local computer. Do not change it to 0.0.0.0 without understanding the network exposure implications.
