Single-Machine Open-Source LLM Deployment: Evaluation, Quantization, and Serving Guide
This guide explains how to deploy open-source large language models on a single machine, covering how to build a small evaluation set, estimate VRAM and choose quantization levels, measure TTFT and generation speed, compare dense and MoE models, and set up serving with vLLM or llama.cpp. It also includes health checks, an API call example, and a streaming benchmark script for practical validation.
1. Build Your Own Evaluation Set
Public leaderboard scores can be used for initial screening, but they should not be the only basis for model selection. Benchmark questions may differ significantly from your business distribution, prompt templates and scoring rules vary across evaluations, and models may have been optimized for common benchmarks. When using leaderboard results, record the source, update time, and applicable tasks before deciding whether to enter the next round of testing.
A more reliable basis comes from a small evaluation set containing at least three types of samples:
- Business samples: real problems the team encounters daily, such as a code modification request for a specific module.
- Boundary samples: long-context inputs, or tasks that require strict adherence to an output format, such as returning only JSON.
- High-risk samples: content where failure is costly, such as code involving data cleaning or permission decisions.
Each sample should be recorded using the table below, and the fields must remain consistent across all candidate models:
| Field | Description | Example |
|---|---|---|
| Sample ID | Unique identifier for review | S-016 |
| Task type | Code modification, question answering, formatted output, etc. | Code modification |
| Prompt | Full prompt, unchanged during testing | See prompts/v1.txt item 3 |
| Decoding parameters | temperature, top_p, max output length | temperature=0, top_p=1, max_tokens=1024 |
| Pass criteria | Unit tests or human judgment rules | All unit tests pass |
| Revision rounds | Number of interactions before a usable result | 2 |
| Manual intervention time | Time in minutes for human correction, from the start of human reading to confirmation that the result is usable | 6 |
| Judgment | Pass, partial pass, fail | Pass |
During execution, fix temperature=0 and top_p=1, use the same prompts for all candidate models, and judge results with test cases or human review. During aggregation, calculate the pass rate for each sample category as the number of passed samples divided by the total number of samples in that category. Compare pass rate, average revision rounds, and average manual intervention time together; looking at any single metric alone can lead to misjudgment.
Conclusion first: fix the decoding parameters, score business samples, boundary samples, and high-risk samples separately, and then compare the three pass rates.
2. Estimate VRAM and Quantization Levels
Estimate VRAM before deployment to avoid downloading a model that is tens of GB in size only to find that it cannot be loaded. The basic formula for weight VRAM is:
Weight VRAM (bytes) ≈ parameter count × bits per parameter ÷ 8
The parameter count should use the actual number of parameters; for example, 14B means 14 billion, or 14 × 10^9. To convert bytes to GB, divide by 10^9.
For a 14B model:
- FP16 or BF16 (16-bit): 14 × 10^9 × 16 ÷ 8 ≈ 28 GB
- INT8 (8-bit): about 14 GB
- INT4 (4-bit): about 7 GB. Actual K-quant formats such as GGUF Q4_K_M have an average bits per parameter slightly above 4, so measure by file size.
Runtime total VRAM also includes KV cache and framework overhead. The KV cache estimation formula is:
KV cache (bytes) ≈ 2 × layers × KV heads × head dimension × context length × concurrent requests × bytes per element
The bytes per element is 2 for FP16. Layers, KV heads, and head dimension can be found in the model directory’s config.json; the field names are usually num_hidden_layers, num_key_value_heads, and head_dim.
Example: 40 layers, 8 KV heads, head dimension 128, context length 8192, concurrency 1. Under FP16, KV cache is approximately 2 × 40 × 8 × 128 × 8192 × 1 × 2 ≈ 1.34 GB.
Total VRAM can be roughly written as: weight VRAM + KV cache + framework overhead. Framework overhead depends on the inference engine and CUDA version and usually needs to be measured. Estimation results are only for screening; after startup, use nvidia-smi to observe actual VRAM usage as the final reference.
Quantization levels can be broadly divided into three tiers from high to low precision:
- 16-bit: closest to the original model, highest VRAM usage, suitable for a quality baseline when VRAM is sufficient.
- 8-bit: about half the VRAM, quality usually close to the original model, suitable for scenarios that need to balance quality and speed.
- 4-bit: lowest VRAM usage, most noticeable quality loss, and the evaluation set should be used to confirm whether high-risk samples still pass.
Quantization formats must match the inference engine. AWQ and GPTQ are commonly used with GPU serving frameworks such as vLLM; GGUF is commonly used with llama.cpp and Ollama. Loading the wrong format will fail directly, so check the engine’s supported format list before switching engines.
3. TTFT, Generation Speed, and Dense vs. MoE Tradeoffs
TTFT (time to first token) refers to the time from sending a request to receiving the first output token. It is mainly affected by input length and prefill computation. Generation speed refers to the number of output tokens per second after the first token; it is mainly affected by memory bandwidth and computation in the decoding stage. The two cannot substitute for each other: customer-service applications care more about TTFT, while long-form generation cares more about generation speed.
The total latency of a single request can be approximated as:
Total latency ≈ TTFT + output tokens ÷ generation speed
When measuring, fix the following settings; otherwise, different tests cannot be compared:
- Input length and output length: fix each separately, for example 512 input tokens and 256 output tokens.
- Concurrency: fix at 1 for single-user use; for multi-user serving, test 2, 4, and other concurrency levels separately.
- Warm-up: run at least 3 requests and discard the results before formal timing to exclude the effects of first model loading and CUDA initialization.
- Sample count: measure at least 100 times per setting, and report p50 (median) and p95, not only the mean.
Dense models activate all parameters every time they generate a token, so VRAM usage and computation grow with parameter count. MoE (mixture-of-experts) models divide parameters among multiple experts, and each token activates only a subset of them, so per-token computation is lower. However, all expert weights of an MoE model must remain resident in VRAM, so memory demand is still high, and routing and multi-GPU communication add overhead.
Use the following rules for model selection:
- Limited single-card VRAM and a need for stable low latency: prefer a quantized dense model.
- Single-machine multi-GPU with high concurrency: an MoE model may have an advantage in throughput, but it must be measured under the same settings.
- Only a single card with tight VRAM: MoE is usually unsuitable because the weights themselves may not fit.
4. Serving Setup
Confirm the environment before deployment:
- Operating system and driver: use
nvidia-smito check the driver version and the maximum supported CUDA version. - Python version: create a virtual environment according to the selected engine’s documentation; do not install into the system Python.
- PyTorch and CUDA: check with
python -c "import torch; print(torch.version.cuda, torch.cuda.is_available())"; the two must match. - Dependency versions: record the exact versions of all pip packages in
requirements.txt.
For vLLM, an example startup command is:
python -m venv ~/llm-envsource ~/llm-env/bin/activatepip install vllm==<version selected from official documentation>vllm serve <model path or repo name> \--host 127.0.0.1 \--port 8000 \--gpu-memory-utilization 0.90 \--max-model-len 8192
If the model uses AWQ or GPTQ quantization, add --quantization awq or the corresponding parameter, and keep it consistent with the model format.
To load a GGUF model with llama.cpp, use:
llama-server -m ./models/model-Q4_K_M.gguf -c 8192 -ngl 99 --host 127.0.0.1 --port 8080
Here, -ngl specifies the number of layers placed on the GPU. A larger value means placing as many layers as possible on the GPU; reduce it if VRAM is insufficient.
Health checks have two steps. First, confirm that the service has loaded the model. Second, confirm that generation works:
curl -s http://127.0.0.1:8000/v1/modelscurl -s http://127.0.0.1:8000/v1/chat/completions \-H "Content-Type: application/json" \-d '{"model":"<model name>","messages":[{"role":"user","content":"Introduce yourself in one sentence"}],"temperature":0,"max_tokens":64}'
The model name must match the id returned by /v1/models.
Example call code (install the openai library; use the version specified in the official documentation):
from openai import OpenAIclient = OpenAI(base_url="http://127.0.0.1:8000/v1", api_key="local")resp = client.chat.completions.create(model="<model name>",messages=[{"role": "user", "content": "Write a function to determine whether a number is prime"}],temperature=0,max_tokens=512,)print(resp.choices[0].message.content)
The script below measures TTFT and generation speed. It approximates token count by the number of streaming chunks; the result is an estimate and should be cross-checked with the engine’s built-in statistics endpoint:
import timefrom openai import OpenAIclient = OpenAI(base_url="http://127.0.0.1:8000/v1", api_key="local")messages = [{"role": "user", "content": "Explain hash tables in detail"}]start = time.perf_counter()first = Nonechunks = 0stream = client.chat.completions.create(model="<model name>", messages=messages,temperature=0, max_tokens=256, stream=True,)for chunk in stream:if chunk.choices and chunk.choices[0].delta.content:if first is None:first = time.perf_counter()chunks += 1end = time.perf_counter()ttft = first - startgeneration_speed = chunks / (end - first)print(f"TTFT: {ttft:.4f}s")print(f"Generation speed (approx. chunks/s): {generation_speed:.2f}")
