Local Deployment of Open-Source LLMs on 22GB VRAM: Tuning and Benchmark Results

    This article answers three common questions about running 27B-class open-source models on a ~22GB VRAM budget, explains how to estimate memory for weights, KV Cache, runtime buffers, and multimodal modules, and walks through a full deployment using llama.cpp. It covers model selection (total vs. active parameters), a three-layer evaluation of capability, efficiency, and cost, hardware and reliability risks of unofficial memory-expanded GPUs, step-by-step installation, download, checksum verification, GGUF conversion, and Q4_K_M/Q3 quantization, plus llama.cpp and vLLM launch commands. It also provides two reference benchmark setups, sampling-parameter tuning, troubleshooting order for OOM and other common failures, a compliance checklist, and a practical action plan with time estimates.

    Local Deployment of Open-Source LLMs on 22GB VRAM: Tuning and Benchmark Results

    1. Three Frequently Asked Questions

    Can 22GB of VRAM run a 27B model?

    Yes, with conditions. If your goal is a model that is usable, can answer questions, summarize, and write code, then a dense open-source model in the 27B class will generally fit within a 22GB VRAM budget when using Q4 quantization and a relatively short context. Here, “22GB budget” should not be read as an unofficially memory-expanded card, but rather as roughly 22GB of usable VRAM. Deployment success rates are high if the context is only 8K to 32K, concurrency is 1, and image understanding is not forced on. If you simultaneously enable long context, image input, high concurrency, or tool calling, VRAM pressure rises quickly.

    A safer choice is an official 24GB GPU or a professional-grade card. Unofficially expanded, modified, or re-soldered memory cards may carry risks around stability, power delivery, thermals, warranty, and driver compatibility, and are not suitable for production.

    Q4_K_M vs. Q3 — which should I choose?

    Q4_K_M is usually the balance point between quality and VRAM. At Q4_K_M, a 27B-class model’s weights are typically much smaller than FP16, and output quality is more stable than Q3, making it suitable for everyday Q&A, summarization, code assistance, and document understanding.

    Q3 suits cases where VRAM is tighter, where speed is the priority, or where you need to reserve space for the KV Cache. However, Q3 is more prone to repeated generation, degraded instruction-following, and unstable formatting. For code, JSON output, or tool calling, prefer Q4 first; if you must use Q3, add sampling constraints, schema validation, and retry-on-failure.

    How do I estimate VRAM for local deployment?

    You can use a simplified formula:

    Weights VRAM ≈ parameter count × bytes per parameter.

    For a 27B model at roughly 4-bit quantization, weights typically land in the 15GB to 18GB range, depending on the quantization format, the framework implementation, and whether extra modules are included. On top of that, add:

    • KV Cache: grows roughly linearly with context length.
    • Runtime buffers: batch caches, the CUDA context, and the inference framework’s own overhead.
    • Multimodal modules: image understanding consumes additional VRAM.
    • Concurrent requests: the higher the concurrency, the greater the VRAM and latency pressure.

    So don’t just ask “can the model load?” — ask “can it run stably at the target context length?”


    2. Before Choosing a Model: Total Parameters, Active Parameters, and KV Cache

    New-generation open-source models commonly show two traits: sparsity and size tiering.

    A sparse model may have a very large total parameter count, yet only a small number of parameters are activated per token. So the weights still occupy VRAM, but the per-token compute is small and generation may be faster. A dense model runs every token through all parameters, so compute scales more directly with model size.

    A rough mental model:

    Dimension Total params Active params VRAM usage Generation speed Typical use case
    Dense model Medium or large Equal to total params Mainly determined by weights and KV Cache Affected by VRAM bandwidth and compute Single GPU, single user, low-latency interaction
    Sparse model Larger Far smaller than total params Weights still occupy VRAM May be faster when few params are active Ample VRAM, throughput-focused, long context

    The key point: don’t look at total parameters alone. Total parameters determine weight size, active parameters determine compute speed, the quantization format determines compression ratio, and KV Cache plus context length determine the extra VRAM pressure.


    3. A Three-Layer Evaluation: Capability, Efficiency, and Cost

    For local deployment, don’t rely solely on public benchmark scores — build a regression set from your own business samples. Cover at least three task types: Q&A, code, and structured output. If you have image input, test image understanding separately.

    Scenario Metrics Suggested sample size Pass criteria
    Knowledge Q&A Accuracy, human rating 100 questions Meets the business minimum
    Code generation Compile pass rate, unit test pass rate 50 questions Not below the threshold
    Instruction-following JSON validity rate, field completeness rate 100 items Validity rate not below 95%
    Image understanding Table recognition, screenshot Q&A accuracy 50 images Meets an acceptable line
    Agent tasks Multi-step completion rate, tool-call success rate 20 tasks Can complete the end-to-end flow

    Efficiency testing shouldn’t report a single token/s number. Record at least:

    • Time to first token: with long inputs, mainly affected by compute and parallelism.
    • Decode speed: tokens generated per second, which affects conversation fluidity.
    • Concurrent throughput: measure single-stream speed and concurrent throughput separately.
    • Peak VRAM: context, concurrency, and KV Cache quantization all affect it.
    • Input/output lengths: always note the input length, generation length, and whether image is enabled.

    Cost includes the GPU, electricity, and tuning time. Local deployment isn’t “zero cost” — it converts a one-time cloud expense into fixed hardware and operations costs.


    4. Hardware and Risk: Don’t Use Unofficially Expanded Cards in Production

    If your target is a 22GB VRAM budget, prefer an official 24GB GPU or a professional card. Unofficially expanded or modified cards may have the following problems:

    • Memory chips of unknown origin, with uncontrollable stability.
    • Possibly insufficient power design, prone to driver crashes under sustained high load.
    • Possibly mismatched cooling; excessive temperatures trigger throttling.
    • Difficult warranty, with higher risk for second-hand or modified cards.
    • Possibly poor driver compatibility, especially affecting CUDA, Vulkan, or specific inference frameworks.

    If you must use a non-standard card: first check power and temperature, then run a long stress test; don’t put it straight into production; and prepare a fallback plan.


    5. Deploying from Scratch: Install, Download, Verify, Quantize, and Launch

    Below is a reproducible path centered on llama.cpp. If you use vLLM, prepare an AWQ or GPTQ format that vLLM supports — don’t feed GGUF directly into vLLM.

    1. Environment and dependencies

    Example environment:

    • Ubuntu 22.04 or a similar Linux distribution
    • NVIDIA driver 570.xx or newer
    • CUDA 12.6 or a compatible version
    • Python 3.10
    • More than 22GB of usable VRAM; an official 24GB GPU is recommended

    Install the base dependencies:

    1. sudo apt update
    2. sudo apt install -y build-essential cmake libcurl4-openssl-dev git python3-pip

    2. Build llama.cpp

    1. git clone https://github.com/ggerganov/llama.cpp
    2. cd llama.cpp
    3. mkdir build && cd build
    4. cmake .. -DGGML_CUDA=ON
    5. cmake --build . --config Release -j $(nproc)

    Parameter names may differ slightly between versions of llama.cpp. Before running, use --help to check the parameters supported by your current build.

    3. Download the model and verify it

    Replace <org>/<27b-dense-model> with the model name from the official repository:

    1. huggingface-cli download <org>/<27b-dense-model> \
    2. --local-dir ./models/27b-dense \
    3. --include "*.safetensors" "*.json" "*.txt"

    Verify after downloading:

    1. cd ./models/27b-dense
    2. sha256sum * | tee sha256.txt

    Compare the result with the hash on the official release page, repository notes, or model card. If the official source provides no hash, at least confirm the repository origin, license, and file integrity.

    4. Convert to GGUF and quantize

    Convert:

    1. python convert_hf_to_gguf.py ./models/27b-dense \
    2. --outfile ./models/27b-dense-f16.gguf \
    3. --outtype f16

    Quantize to Q4_K_M:

    1. ./llama-quantize ./models/27b-dense-f16.gguf \
    2. ./models/27b-dense-q4_k_m.gguf q4_k_m

    Quantize to Q3:

    1. ./llama-quantize ./models/27b-dense-f16.gguf \
    2. ./models/27b-dense-q3_k_m.gguf q3_k_m

    5. Start inference

    Text chat example:

    1. ./llama-cli \
    2. -m ./models/27b-dense-q4_k_m.gguf \
    3. -ngl 99 \
    4. -c 8192 \
    5. -b 2048 \
    6. -t 8 \
    7. --temp 0.7 \
    8. --top-p 0.9 \
    9. -ctk q8_0 \
    10. -ctv q8_0

    Parameter notes:

    • -ngl 99: offload as many model layers to the GPU as possible. If VRAM is insufficient, lower it to 60, 40, or 20.
    • -c 8192: context length. Start at 8192 or 16384, then increase gradually.
    • -b 2048: batch size. Reduce it when VRAM is tight.
    • -t 8: number of CPU threads; adjust to your machine.
    • -ctk q8_0 and -ctv q8_0: KV Cache quantization. In long-context scenarios this can significantly reduce extra VRAM.

    Start the server:

    1. ./llama-server \
    2. -m ./models/27b-dense-q4_k_m.gguf \
    3. -ngl 99 \
    4. -c 8192 \
    5. -b 2048 \
    6. -t 8 \
    7. -ctk q8_0 \
    8. -ctv q8_0 \
    9. --host 127.0.0.1 \
    10. --port 8080

    If the model supports image understanding, you need to additionally load the matching mmproj file:

    1. ./llama-server \
    2. -m ./models/27b-dense-q4_k_m.gguf \
    3. --mmproj ./models/mmproj-xxx.gguf \
    4. -ngl 99 \
    5. -c 8192 \
    6. -b 2048

    If no mmproj is loaded, or the model itself doesn’t support images, disable image input first to avoid misdiagnosing it as a model capability problem.

    6. vLLM comparison test

    vLLM usually doesn’t load GGUF directly. To use vLLM, prepare AWQ or GPTQ weights:

    1. pip install vllm

    Launch an AWQ model:

    1. python -m vllm.entrypoints.openai.api_server \
    2. --model ./models/27b-dense-awq \
    3. --quantization awq \
    4. --max-model-len 8192 \
    5. --gpu-memory-utilization 0.90 \
    6. --dtype float16

    If the weights are GPTQ, replace awq with gptq. After launch, use the OpenAI-compatible API to test time to first token, generation speed, and peak VRAM.


    6. Two Reference Benchmark Configurations and Interpretation

    The tables below give example test conditions. Different hardware, drivers, quantization versions, and context lengths all affect the results, so base your actual deployment on your own machine.

    Configuration Test conditions Example generation speed Modality Key parameters and notes
    27B-class dense model, Q4_K_M, Q8 KV Cache ~1024 input tokens, 512 generated tokens, concurrency 1 ~20 to 25 token/s Text-first; image needs extra mmproj -ngl 99, -c 8192, -ctk q8_0, -ctv q8_0; record power and temperature with nvidia-smi
    Sparse model with active params far below total params, Q3, Q8 KV Cache ~2048 input tokens, 512 generated tokens, concurrency 1 ~80 to 100 token/s Text-first; image needs separate validation Q3 boosts speed but may reduce stability; check for repeated generation and instruction-following

    Recommended monitoring:

    1. nvidia-smi --query-gpu=memory.used,power.draw,temperature.gpu --format=csv -l 1

    Interpretation:

    • 20 to 25 token/s is close to normal reading speed, suitable for everyday Q&A, code assistance, and document summarization.
    • A 32K context can hold a fair amount of material, but the KV Cache grows noticeably.
    • A sparse model with small active parameters is usually faster than a dense model at the same VRAM budget, when quality is acceptable.
    • Image input significantly increases time to first token and VRAM usage; if it’s not needed, disable it first.

    7. Tuning: Sampling Parameters, Over-Long Reasoning, and Long Context

    1. General sampling configuration

    Chat, creative writing, and general summarization can start from the following configuration:

    1. {
    2. "temperature": 0.7,
    3. "top_p": 0.9,
    4. "min_p": 0.05,
    5. "repetition_penalty": 1.1,
    6. "presence_penalty": 0.1,
    7. "max_tokens": 4096
    8. }

    Parameter notes:

    • temperature: controls randomness. Higher is more divergent, lower is more stable.
    • top_p: controls the candidate word range.
    • min_p: filters low-probability tokens, suited to stable output.
    • repetition_penalty: suppresses repetition; setting it too high makes sentences unnatural.
    • presence_penalty: encourages introducing new content.
    • max_tokens: caps the maximum generation length to prevent runaway output.

    Fallback strategy: tasks such as code generation, JSON output, and tool calling should reduce randomness. For example:

    1. {
    2. "temperature": 0.2,
    3. "top_p": 0.9,
    4. "repetition_penalty": 1.05,
    5. "max_tokens": 2048
    6. }

    If necessary, disable min_p and add schema validation and retry-on-failure.

    2. Over-long reasoning

    Some models may generate very long chains of reasoning on complex problems, even looping in repeated self-confirmation. If your workload is mainly Q&A, summarization, and code completion, you can disable deep reasoning by default or cap the maximum reasoning length. If you must enable it, set an upper limit on reasoning length and log token consumption.

    3. Very long context

    Some implementations or versions claim to support long context, but actual capability depends on VRAM, the context window, the inference framework, and the KV Cache strategy. Don’t just look at “how long is supported” — look at “whether it’s stably usable.” Test progressively through 8K, 16K, and 32K; for long-document scenarios, combine with retrieval augmentation to avoid stuffing too much content in at once.


    8. Common Errors and Troubleshooting Order

    1. Out of memory (OOM)

    Symptoms: loading fails, inference is interrupted, VRAM is fully occupied by the system or framework.

    Check in this order:

    1. Lower the context length, e.g., from 32768 to 8192.
    2. Lower -ngl, e.g., from 99 to 60, 40, or 20.
    3. Disable image input or mmproj.
    4. Lower the batch size.
    5. Fall back from Q4_K_M to Q3_K_M or Q3_K_S.
    6. Keep the KV Cache at Q8; if it’s still unstable, test Q4 KV Cache, but verify quality.

    2. Time to first token too high

    Symptoms: a long wait before the first token appears.

    Check in this order:

    1. Shorten the input length.
    2. Disable image prefill.
    3. Lower concurrency.
    4. Check whether too many layers are running on the CPU.
    5. Check that the driver, CUDA, or backend is working normally.
    6. Compare different frameworks and quantization formats.

    3. Image input failure

    Symptoms: the image has no effect, errors appear, or the answer is off-topic.

    Check in this order:

    1. Confirm whether the model supports images.
    2. Confirm the matching mmproj is loaded.
    3. Confirm the image size and encoding format.
    4. Close other high-VRAM tasks.
    5. Verify the basic pipeline with a text-only model first.

    4. Q3 repetition degradation

    Symptoms: repeated phrases, broken formatting, ignored instructions.

    Handling:

    • Raise repetition_penalty to around 1.1.
    • Lower temperature to between 0.2 and 0.5.
    • Use top_p around 0.9.
    • Add JSON schema validation for structured output.
    • If quality requirements are high, fall back to Q4_K_M.

    5. Unstable KV Cache quantization

    Symptoms: quality drops with long context, abnormal output.

    Handling:

    • Prefer Q8 KV Cache.
    • If quality is abnormal, fall back to unquantized KV Cache.
    • Lower the context length.
    • Check whether the framework version supports the corresponding quantization format.

    9. Cloud-Edge-Device Collaboration and a Compliance Checklist

    Local deployment diverts part of the cloud inference demand but won’t fully replace cloud services. A more sensible structure is cloud-edge-device collaboration: handle privacy-sensitive, low-latency, high-concurrency everyday tasks locally, and handle complex reasoning, ultra-large models, and elastic scaling in the cloud.

    Before rolling out, work through this checklist:

    • Confirm whether the model license permits local deployment, commercial use, redistribution, or distillation.
    • Download weights only from official repositories or trusted mirrors.
    • Verify the SHA256, signature, or repository version after downloading.
    • Redact phone numbers, ID numbers, internal code, and customer information from prompts and documents.
    • Disable raw prompt logging by default, keeping only necessary audit information.
    • In RAG scenarios, filter documents by user permission to prevent high-privilege material from entering low-privilege sessions.
    • Record the model version, quantization format, inference framework version, and hardware environment.
    • For high-concurrency scenarios, prepare rate limiting, timeouts, retries, and fallback strategies.

    10. Action Checklist and Time Estimates

    Recommended rollout path:

    1. Prepare an official 24GB GPU or more than 22GB of usable VRAM.
    2. Download a 27B-class dense open-source model, preferring Q4_K_M.
    3. Complete installation, quantization, launch, and a single-turn Q&A with an 8192 context.
    4. Test Q&A, code, JSON output, and tool calling with your own samples.
    5. If VRAM allows, then test long context, image understanding, and sparse models.
    6. If VRAM is insufficient, fall back in this order: official 24GB, Q4_K_M, shorter context, disable image, lower concurrency, Q3, Q8 KV Cache.
    7. Complete the license, weight-source, data-redaction, logging, and permission-isolation checks.

    If the network is stable and the GPU is compatible, a first deployment can usually be up and running within 1 to 3 hours; if you run into quantization, driver, or VRAM problems, reserve half a day to a full day for troubleshooting.