Local Deployment of Open-Weight LLMs: A Practical Guide

    This article walks through the practical side of running open-weight large language models on your own infrastructure. It explains what changes when you receive full model weights instead of API access, how to estimate GPU memory for weights and KV cache, a minimal four-layer serving architecture, and the role of quantization, fine-tuning, and regression evaluation. It also covers stability and cost controls such as autoscaling, caching, model tiering, and capacity drills, plus how hybrid deployments can rely on general-purpose cloud capabilities. The goal is to help teams decide whether self-hosting makes sense and roll it out with measurable metrics.

    1. What Open Weights Actually Change

    So far, most enterprises consumed LLMs through API calls: the model stayed on the provider’s side, and the enterprise only got an input/output channel. Delivering full weights changes the delivery model itself — from “renting inference capacity” to “obtaining an auditable, portable asset that can be fine-tuned.” That unlocks three new capabilities:

    1. Controlled data boundary: sensitive data never leaves the internal network, which satisfies compliance and audit requirements.
    2. A trimmable inference path: you can swap the tokenizer strategy, rewrite sampling parameters, and drop irrelevant pre- and post-processing.
    3. Real deep customization: domain-specific continued pre-training, instruction tuning, preference alignment, and distillation all become possible.

    The costs are equally clear: the enterprise now owns compute procurement, service stability, model upgrades, and safety alignment. So “should we self-host” is fundamentally a long-term comparison between asset depreciation and per-call fees, not a matter of technical preference.

    2. Sizing Compute and GPU Memory Before Deployment

    GPU memory is the hardest constraint. These rules of thumb are enough for a first pass:

    1. weight memory ≈ parameters × bytes per parameter
    2. inference peak ≈ weight memory + KV cache + activations and framework overhead
    3. KV cache ≈ 2 × layers × KV heads × head dim × sequence length × batch × bytes

    For a 7B model, FP16 needs roughly 14GB for weights alone; INT8 about 7GB; INT4 about 3.5–4GB. In long-context scenarios the KV cache grows linearly with sequence length and often becomes the real bottleneck, so you need mitigations such as paged cache and prefix reuse.

    Selection guidance: prefer tensor parallelism plus continuous batching when throughput matters; lower the batch size and fix a maximum sequence length when latency matters; prefer quantization when memory is tight, but verify the accuracy regression on an evaluation set.

    3. A Minimal Viable Architecture for Inference Serving

    Split the service into four layers so each can scale independently and fail in isolation:

    • Access layer: authentication, rate limiting, canary routing.
    • Scheduling layer: queues and priorities, with long and short requests in separate pools.
    • Inference layer: a pool of model instances supporting hot loading and rolling upgrades.
    • Observability layer: logging service plus monitoring/alerting plus distributed tracing.

    Illustrative configuration (pseudocode, structure only):

    1. serving:
    2. model: local-weights
    3. precision: int8
    4. parallel: {tp: 2}
    5. engine:
    6. max_batch_tokens: 8192
    7. max_seq_len: 32768
    8. kv_cache: paged
    9. autoscale: {min: 2, max: 16, target_gpu_util: 0.75}
    10. gateway: {rate_limit_qps: 200, timeout_ms: 30000}

    4. Quantization, Fine-Tuning, and Quality Regression

    Going live is rarely “just run the original weights.” It is usually three steps: quantize first to cut cost, then run instruction tuning on domain corpora to fill capability gaps, then apply preference alignment to improve response style. The key discipline is a regression evaluation set: every quantized or fine-tuned version runs the same metrics before release, so you avoid “cost went down, quality collapsed.”

    Operationally, version training artifacts, quantized artifacts, and evaluation reports together, keeping weights and configs traceable as one unit so rollback is straightforward.

    5. Stability and Cost Control

    • Autoscaling: scale on two signals — queue wait time and GPU memory utilization — not QPS alone.
    • Cache reuse: cache results for high-frequency prefixes and repeated questions to cut redundant compute significantly.
    • Model tiering: route simple requests to small models and complex requests to large ones.
    • Capacity drills: run load tests and fault injection regularly to confirm the degraded path works.

    6. Combining With General-Purpose Cloud Capabilities

    For a hybrid deployment, general-purpose capability categories can fill the gaps: object storage for weights and datasets, a container platform for orchestrating inference instances, a message queue for peak shaving, logging and monitoring for observability, and a key management service for credentials. Baidu AI Cloud offers these same general-purpose capability categories in such scenarios, and enterprises can choose either full self-hosting or a hybrid form based on their own compliance requirements.

    7. Conclusion

    Open weights hand the choice back to the enterprise, but the real bar shifts from “can we call it” to “can we operate it reliably.” Start small: quantize first, load-test second, customize last, and let measurable metrics drive each decision — that is how you balance cost, performance, and compliance.