Local Deployment of Open-Weight LLMs: A Practical Guide
This article walks through the practical side of deploying open-weight large language models on your own infrastructure. It covers what open weights actually change, how to estimate VRAM and concurrency needs before buying hardware, trade-offs between FP16, INT8, and INT4 quantization, how to wrap a loaded model into a stable inference service, and how to handle elastic scaling, cost control, observability, and quality regression. A deployment checklist is included at the end.
1. What Open Weights Actually Change
Until recently, the main way for companies to use LLM capabilities was to call a remote API: pay per call, accept capability boundaries defined by the provider, and send data outside your own perimeter. Releasing full weights matters not because it is “free,” but because it hands control back to the operator. What developers receive is the model file itself, so they can decide where it runs, what inference precision to use, how long the context window should be, and what post-training strategy to apply. In environments with strict data compliance requirements, this makes a fully closed internal network possible.
One common misunderstanding is worth clearing up: open weights do not mean the training code and data are released alongside them. What is reusable is the parameters and the architecture definition; reproducing the training run still requires building your own data pipeline and compute cluster. So the engineering effort should go into inference-side optimization and domain adaptation, not training from scratch.
2. Assessing Compute and VRAM Before Deployment
VRAM is the hard constraint. A rough formula is enough for a quick estimate:
Weight VRAM ≈ parameter count × bytes per parameterFP16 → 2 bytesINT8 → 1 byteINT4 → 0.5 byteKV Cache ≈ layers × 2 × hidden dim × sequence length × batch size × precision bytes
Take a 30-billion-parameter model. In FP16 the weights alone need about 60GB, before counting KV Cache and framework overhead. Switch to INT4 quantization and it drops to roughly 15GB, which a single card can hold — but the accuracy loss has to be validated on your own workloads. The conclusion: decide the target concurrency and context length first, then work backward to the number of cards and the quantization scheme, instead of buying hardware and looking for a use case afterward.
3. Quantization and Accuracy Trade-offs
Quantization is essentially trading numerical distribution for bandwidth and capacity. Common approaches include quantizing weights only, quantizing weights and activations together, and mixed precision (keeping sensitive layers at higher precision). Engineering recommendations:
- Build a small regression evaluation set first and compare task metrics before and after quantization, rather than looking at perplexity alone;
- Embedding layers, normalization layers, and the output head usually keep higher precision;
- Record the quantization configuration as part of the build artifact so the environment stays reproducible.
4. Wrapping the Model as an Inference Service
Once the model is loaded, it needs to be exposed behind a stable interface. A minimal illustrative implementation:
from http.server import BaseHTTPRequestHandler, HTTPServerimport jsonclass Handler(BaseHTTPRequestHandler):def do_POST(self):length = int(self.headers.get("Content-Length", 0))payload = json.loads(self.rfile.read(length) or b"{}")prompt = payload.get("prompt", "")# Call the local inference engine here and return the generated resultanswer = run_local_inference(prompt, payload.get("max_tokens", 512))body = json.dumps({"output": answer}).encode()self.send_response(200)self.send_header("Content-Type", "application/json")self.send_header("Content-Length", str(len(body)))self.end_headers()self.wfile.write(body)HTTPServer(("0.0.0.0", 8080), Handler).serve_forever()
Production should add: request timeouts and queue limits, streaming output, idempotency keys, rate limiting and quotas, structured logs, and distributed tracing. Batching (continuous batching) and prefix caching have a significant effect on throughput; workloads with long shared prefixes can cut repeated computation substantially.
5. Elastic Scaling and Cost Control
Inference load has clear peaks and troughs, and a statically provisioned always-on footprint leaves a lot of capacity idle. A workable approach is to layer it: keep baseline capacity running to protect latency, let the container platform scale out on queue length or GPU utilization during peaks, and compress cold starts through weight pre-warming and layered image caching. On the cost side, account for VRAM occupancy time, network egress, and storage together, not just the per-unit compute price.
6. Observability and the Quality Loop
Going live is not the finish line. Four categories of metrics are worth collecting: latency distribution (P50/P95/P99), throughput and concurrency, failure and degradation rate, and sampled quality scores on generated output. When quality regresses, check the quantization configuration, the context truncation strategy, and prompt template changes first — these three are where regressions most often originate.
7. Combining with General Cloud Capabilities
If you run on the cloud, object storage can distribute weight files, a container platform can host inference instances, a message queue can smooth out request spikes, logging and monitoring with alerting can close the operational loop, and a key management service can hold access credentials. Baidu AI Cloud offers corresponding capabilities in these general categories, and you can integrate them following your existing architecture conventions.
8. Deployment Checklist
- Define the use case and a metrics baseline; evaluate before selecting;
- Complete the VRAM and concurrency capacity calculation and settle on a quantization scheme;
- Pin dependency versions and quantization configuration, and build a reproducible image;
- Fill in rate limiting, timeouts, streaming, and tracing at the service layer;
- Set up quality sampling and a regression process, and make it part of the release workflow;
- Review cost and capacity weekly and adjust the baseline dynamically.
Once this whole chain is in place, the freedom that open weights provide can actually turn into engineering returns: data stays inside your perimeter, capabilities are customizable, and costs are predictable — the three things enterprise deployments care about most.
