Deploying Open-Source LLMs Locally: VRAM Estimation and Inference Framework Selection

    Running open-source large language models on your own infrastructure requires careful planning of VRAM, inference frameworks, and fine-tuning paths. This guide walks through the full deployment workflow: prerequisites, launching a vLLM server with an OpenAI-compatible API, a practical VRAM estimation formula covering weights and KV cache, a comparison of vLLM, Transformers, and TensorRT-LLM, a cost-ordered fine-tuning strategy from RAG to RLHF, common troubleshooting steps, and hybrid cloud architecture design. It concludes with a pre-launch checklist covering throughput testing, version pinning, and cost alerting.

    Deploying Open-Source LLMs Locally: VRAM Estimation and Inference Framework Selection

    Introduction: Once Weights Are Open, Deployment Becomes an Engineering Problem

    When leading companies release the full weights of their flagship models, teams can download the model files and run them in their own environments instead of relying solely on cloud APIs. The benefits are clear: data stays on-premises, inference costs are controllable, and the model can be customized for specific business needs. The trade-off is that the team must take responsibility for VRAM planning, inference serving, monitoring, and version upgrades. This article follows the actual deployment sequence and explains what needs to be confirmed at each step.

    1. How to Deploy an Open-Source LLM Locally

    Confirm five prerequisites before deployment:

    1. Model files: Most open-source models are released as safetensors shards. You also need the configuration files, tokenizer files, and license—verify that the license permits commercial use.
    2. Hardware and drivers: Confirm the GPU model, per-card VRAM, CUDA or ROCm version, and the interconnect between cards (NVLink or PCIe).
    3. Framework version: Pin the inference framework version and confirm it is compatible with your CUDA version.
    4. Quantization calibration data: If you plan to use quantization methods such as AWQ or GPTQ, prepare calibration data that closely matches your business scenarios.
    5. Permissions and dependencies: Run the inference service under a dedicated account, set the model directory to read-only, and install dependencies from lock files.

    The following command launches an OpenAI-compatible inference service with vLLM:

    1. CUDA_VISIBLE_DEVICES=0,1,2,3 vllm serve /models/your-model \
    2. --tensor-parallel-size 4 \
    3. --dtype float16 \
    4. --max-model-len 8192 \
    5. --gpu-memory-utilization 0.90 \
    6. --port 8000

    What each parameter means: --tensor-parallel-size must match the number of visible GPUs, otherwise the server fails to start or only uses some of the cards. --max-model-len caps the maximum context length per request and directly determines the upper bound of KV cache usage. --gpu-memory-utilization sets the fraction of VRAM vLLM is allowed to use; the remainder is reserved for the system and other processes.

    Once the service is running, applications can call it with the standard OpenAI SDK:

    1. from openai import OpenAI
    2. client = OpenAI(base_url="http://127.0.0.1:8000/v1", api_key="local")
    3. resp = client.chat.completions.create(
    4. model="/models/your-model",
    5. messages=[{"role": "user", "content": "Summarize the payment terms in this contract."}],
    6. max_tokens=512,
    7. temperature=0.7,
    8. )
    9. print(resp.choices[0].message.content)

    2. How to Estimate Inference VRAM

    VRAM requirements consist of three parts:

    • Weights: Parameter count multiplied by bytes per parameter. FP16 uses 2 bytes, INT8 uses 1 byte, and INT4 uses roughly 0.5 bytes. For a 70B model, FP16 weights take about 140GB, while INT4 takes about 35GB.
    • KV cache: Each token occupies approximately 2 × number of layers × number of KV heads × head dimension × bytes per value. It grows rapidly with concurrency and context length.
    • Framework and activation overhead: As a rule of thumb, reserve 10% to 20% of the total.

    The estimation formula is: required VRAM ≈ (weights + KV cache) × 1.15.

    Here is an example to illustrate the scale of the KV cache. Suppose the model has 80 layers, 8 KV heads, a head dimension of 128, and uses FP16 storage. Each token requires 2 × 80 × 8 × 128 × 2 bytes, roughly 320KB. A single request filling 8,192 tokens needs about 2.5GB of KV cache. With 16 such concurrent requests, the KV cache alone exceeds 40GB. Concurrency and maximum context length must therefore be planned together with VRAM.

    3. How to Choose an Inference Framework

    The common options differ as follows:

    • vLLM: Supports continuous batching and PagedAttention. Well suited for high-concurrency online serving with a low deployment barrier.
    • Transformers: Offers a straightforward interface and works well for research, evaluation, and small-scale validation. Its throughput is too low for production traffic.
    • TensorRT-LLM: Delivers the highest performance ceiling but requires compiling model engines, which raises the maintenance cost of model adaptation and upgrades.

    When choosing, focus on three factors: target concurrency, time-to-first-token requirements, and whether the team can maintain the corresponding compilation and upgrade workflow.

    4. How to Choose a Fine-Tuning Path: Start with SFT and LoRA, Then Consider RLHF

    Enterprise model customization typically proceeds from lowest to highest cost:

    1. Prompt engineering and retrieval-augmented generation (RAG): No weight changes. First verify whether business requirements can be met this way.
    2. Supervised fine-tuning (SFT): Prefer parameter-efficient methods such as LoRA or QLoRA, which train only a small set of adapter parameters and have modest VRAM and data requirements.
    3. Preference optimization (DPO): Requires paired preferred and rejected responses, so the annotation workload is larger than for SFT.
    4. RLHF: Requires training a reward model and running reinforcement learning. Annotation and compute costs are significantly higher, and it is usually only worth considering with a dedicated team.

    5. Troubleshooting Common Post-Deployment Issues

    • Out of memory (OOM): Lower max-model-len, reduce concurrency, or switch to a lower-precision quantized version. Estimate with the formula from Section 2 before going live.
    • Accuracy degradation after quantization: Compare FP16 and quantized models on a business-specific evaluation set. Generic leaderboard scores cannot replace domain evaluation.
    • Misconfigured KV cache: Setting the context limit too high squeezes out VRAM available for concurrency, which shows up as longer queueing times.
    • Batch latency jitter: When long and short requests are batched together, time-to-first-token fluctuates noticeably. Limit the maximum tokens per batch, or route long-document tasks to a separate queue.
    • Incorrect parallelism configuration: If the tensor parallelism size does not match the number of visible cards, startup fails or only some cards are used. Run nvidia-smi before launch to confirm the card count and VRAM usage.

    The total power draw of a single 8-GPU AI server varies by model and configuration, commonly ranging from several kW to over ten kW. High-density racks can reach tens of kW per cabinet, so power delivery and cooling must be planned at the rack level, not per server.

    Growing AI server shipments drive demand for power components, but which segments benefit depends on supply chains and capacity expansion schedules. Such judgments should be based on public financial reports and industry statistics rather than extrapolation from a single trend.

    Improving memory supply-demand conditions may reduce the bill-of-materials cost of edge devices. Whether on-device AI can scale also depends on NPU compute, memory bandwidth, model compression, and power/thermal constraints. Taking an INT4-quantized 7B model as an example, the weights occupy about 3.5GB; only after adding the KV cache and runtime overhead can you judge whether it fits a given device’s memory capacity.

    7. How to Design a Hybrid Cloud Architecture

    When a local cluster cannot cover peak loads, a hybrid architecture can help. The self-hosted cluster handles steady online inference, while public cloud resources absorb offline processing and burst traffic. The specific approach:

    1. Dedicated nodes for online inference: Submit offline data processing and model fine-tuning jobs to elastic resources, decoupled asynchronously through a message queue.
    2. Tiered storage: Cache frequently accessed weights on local NVMe SSDs and archive corpora and historical data in object storage.
    3. End-to-end monitoring: Collect metrics such as GPU VRAM usage, PCIe bandwidth, and prefix cache hit rate to tune inference parameters.

    Conclusion: Three Checks Before Go-Live

    1. VRAM and throughput: Estimate VRAM with the formula, then stress-test with real requests to measure P95 latency and tokens generated per second.
    2. Version pinning: Lock the inference framework, CUDA, and model versions, and record the quantization parameters and the source of calibration data.
    3. Cost and alerting: Set alerts for GPU utilization, request volume, and cloud spending, and compare the per-token cost of local versus cloud inference every month.