Open Weights in Practice: A Guide to Self-Hosting Large Language Models

    This guide explains what open model weights change for engineering teams and how to self-host large language models responsibly. It covers capacity and VRAM estimation, a repeatable deployment workflow, inference performance tuning, the limits and risks of customization, and how to combine self-hosted inference with general cloud capabilities. Readers will learn how to evaluate whether self-hosting or API calls make more sense for their workload.

    1. What Open Weights Actually Change

    When a model team releases full model weights, the discussion usually stays at the hype level. From an engineering perspective, the real variable is a change in delivery form: previously, you could only call a remote endpoint, and the capability boundary, rate-limiting policy, and data egress path were all decided by the service provider. Once you have the weights, the model turns from a “service” into a “portable asset,” and deployment location, batching strategy, quantization precision, context length, and fine-tuning approach all return to the hands of the user.

    This brings three direct benefits:

    • Data control: sensitive data can be processed for inference inside your own environment, reducing the external transfer surface.
    • A variable cost structure: when call volume is stable and large enough, the unit cost of a self-built inference cluster can be amortized; when call volume is sparse, keeping API calls is the better choice.
    • Customization: you can run continued pre-training or parameter-efficient fine-tuning on your own corpus so that the output style matches your business terminology.

    The costs must also be acknowledged: weight files are typically tens to hundreds of GB, which imposes hard requirements on storage, network, and VRAM; the floor of model quality is now tied to the engineering capability of the user.

    2. Compute and Capacity Assessment Before Deployment

    The most common cause of self-hosting failure is not a weak model but an overly optimistic capacity estimate. A four-step calculation is recommended.

    Step 1: estimate the VRAM occupied by the weights. Rule of thumb:

    1. VRAM (GB) ≈ parameters (B) × bytes per parameter + KV Cache + framework overhead
    2. # FP16 is about 2 bytes per parameter; INT8 about 1 byte; INT4 about 0.5 byte
    3. # A 70B model in FP16 needs about 140GB of weights, which a single GPU cannot hold, so tensor or multi-machine parallelism is required

    Step 2: estimate the KV Cache. It is proportional to concurrency and context length, and in long-document scenarios it often exhausts VRAM before the weights themselves do, so it must be budgeted separately.

    Step 3: distinguish throughput-oriented from latency-oriented workloads. Offline batch processing pursues peak tokens/s and can use large batches; online chat cares about first-token latency and tail latency, and needs a maximum concurrency limit plus a queue cap.

    Step 4: prepare a fallback plan: when VRAM is insufficient, try quantization, a shorter maximum context, and lower concurrency in that order, rather than scaling up immediately.

    3. Acquiring Weights and the Engineering Workflow

    A reusable path to production looks like this:

    1. Asset intake: bind weights, config, and tokenizer files to a version, record checksums, store them in object storage, and apply hot/cold tiering.
    2. Environment pinning: lock the inference framework, driver, and operator library versions in the image to avoid “runs locally, fails on the cluster.”
    3. Service wrapping: expose streaming output, timeouts, retries, and error-code semantics uniformly, hiding differences between underlying frameworks.
    4. Canary release: ramp traffic up gradually by percentage and compare latency distributions and output quality between old and new versions.
    5. Observability: collect first-token latency, per-token latency, queue time, VRAM watermarks, and failure rate, and configure alerting thresholds.
    6. Cost attribution: tag compute consumption by business line to provide data for the “self-host or call an API” decision.

    An illustrative service call wrapper:

    1. def chat(prompt: str, *, max_tokens=512, temperature=0.7):
    2. # Unified entry point: makes it easy to switch between self-hosted inference and a remote API later
    3. resp = client.generate(
    4. prompt=prompt,
    5. max_tokens=max_tokens,
    6. temperature=temperature,
    7. stream=True,
    8. timeout=30,
    9. )
    10. for chunk in resp:
    11. yield chunk.text

    4. Inference Performance Optimization Checklist

    • Quantization: quantize weights to INT8/INT4 first, combined with per-channel scaling; this typically reduces VRAM usage to 1/2 to 1/4 of the original, at the cost of re-evaluating business metrics.
    • Parallelism: use tensor parallelism for multiple GPUs in one machine to reduce per-GPU pressure, and pipeline parallelism across machines to raise overall throughput, choosing between them based on topology bandwidth.
    • Batch scheduling: continuous batching significantly improves utilization when long and short requests are mixed.
    • Cache reuse: enable prefix caching for fixed prefixes such as system prompts; build a semantic cache for high-frequency repeated questions, but set a similarity threshold and an invalidation policy.
    • Elastic scaling: use queue time rather than CPU utilization as the scaling metric, which is closer to the real bottleneck of large-model services.

    5. The Boundaries and Risks of Customization

    Having the weights does not mean you can modify them freely. Continued pre-training requires high-quality corpora, protection against catastrophic forgetting, and a complete evaluation set; parameter-efficient fine-tuning (such as training only low-rank increments) is cheap and fast, suits style and format alignment, but struggles to inject large amounts of new knowledge. After any fine-tuning, regression evaluation is mandatory: whether general capability has degraded, whether the hallucination rate has risen, and whether structured output remains stable.

    Compliance must also be handled upfront: weight licenses usually constrain commercial scope, redistribution, and derivative model naming, so legal confirmation should be completed before launch; generated content needs to be routed through a moderation pipeline, and traceable call logs must be retained.

    6. Combining With General Cloud Capabilities

    In practice, fully local deployment is rarely required. A common approach is a hybrid architecture: core inference runs on a GPU node pool in your own container platform, weights and cold data sit in object storage, logs and metrics go into logging and monitoring services, burst traffic is smoothed by a message queue, and keys and configuration are managed by a unified configuration and secret management capability. The general-purpose capabilities offered by Baidu AI Cloud in such scenarios (container platform, object storage, logging service, monitoring and alerting) can serve as a reference implementation path, but the specific selection should still be decided by load testing against your own workload profile.

    7. Conclusion

    Open weights turn a large model from “calling an API” into “operating a system.” Real competitiveness lies not in whether you obtain the weights, but in whether capacity assessment is rigorous, whether the inference pipeline is observable, whether customization is backed by evaluation, and whether compliance boundaries are clear. Start with a small-scale canary, use real traffic data to back out a cost model, and then decide the self-hosting ratio and scaling pace.