Open-Weight LLM Deployment Guide: Compute Estimation and Inference Optimization
This guide explores the deployment of open-weight large language models, detailing essential steps including VRAM and KV cache estimation, quantization selection, inference service architecture, performance benchmarking, and cost analysis to help engineering teams navigate the transition from API calls to self-hosted infrastructure.
1. The Meaning and Value of Open Weights
Model weights are the set of parameters obtained after training, determining the model’s full inference capabilities. In the past, most large language models (LLMs) could only be accessed via remote APIs, preventing users from interacting with the model itself. With open weights, teams can download the model to run on their own machines or specified cloud environments, enabling subsequent quantization, fine-tuning, or service orchestration.
This approach brings three direct benefits. First, data can remain in the local environment, reducing the exposure of sensitive information. Second, inference latency and API costs can be self-regulated, eliminating total reliance on external service queuing and billing strategies. Third, model behavior can be adapted to specific business scenarios, such as constraining outputs for domain-specific terminology and formats.
However, weight availability does not equate to a low deployment barrier. Deployment requires sufficient compute, storage, networking, and operational capabilities. Additionally, license agreements may impose restrictions on commercial use, redistribution, or the release of derivative models. These terms must be verified clause by clause before going live.
2. Pre-Deployment Resource Estimation
2.1 VRAM Estimation
During inference, VRAM consumption primarily consists of three parts: model weights, the KV Cache, and runtime overhead. The weight portion can be roughly estimated using the following formula:
VRAM for Weights ≈ Parameter Count × Bytes per Parameter
The bytes per parameter for common precisions are as follows: 2 bytes for FP16 or BF16, 1 byte for INT8, and 0.5 bytes for INT4. For a 70B parameter model, the weights alone require approximately 140 GB in FP16 and 35 GB in INT4. This is a purely arithmetic result; actual usage must also account for the KV Cache and runtime overhead.
2.2 KV Cache and Concurrency Planning
The KV Cache stores intermediate results from attention calculations, and its footprint grows with context length and concurrent request volume. In long-context scenarios, the KV Cache can exceed the footprint of the weights themselves. Therefore, capacity planning must consider three parameters simultaneously: maximum context length, expected concurrency, and maximum single-output length.
It is recommended to provision for worst-case scenarios with a buffer, then gradually scale down based on monitoring data. Provisioning based solely on average load often leads to queuing timeouts during traffic peaks.
2.3 License and Compliance Review
Before launch, review the following:
- Whether the license permits commercial use, and if it restricts user scale or industry;
- Whether it allows using model-generated data to train other models;
- Whether there are explicit limits on the usage scope of model outputs;
- Whether different terms apply to internal use versus external service provision.
Review results should be documented and confirmed by legal or compliance personnel.
3. Quantization Selection
Quantization reduces VRAM usage and memory bandwidth pressure by lowering numerical precision, thereby increasing throughput or lowering hardware requirements. The trade-off is a potential degradation in output quality, which varies by task.
Consider the following when selecting a quantization strategy:
- Lower precision means smaller VRAM footprint, but higher quality risk;
- Tasks like code generation, mathematical reasoning, and structured output are typically more sensitive than general Q&A;
- Quantization effects must be validated on the target business evaluation dataset; theoretical compression ratios alone are insufficient.
The recommended approach is to establish a quality baseline with the unquantized version, then step down the precision incrementally. At each level, record quality metrics, time-to-first-token, throughput, and VRAM usage. Finally, select the lowest-cost solution that meets your quality threshold.
4. Inference Service Setup
4.1 Deployment Topologies
Based on hardware scale, common deployment topologies include:
- Single-node, single-GPU: Suitable for internal validation, low concurrency, or small models; simple to operate;
- Single-node, multi-GPU parallelism: Suitable for models that cannot fit on a single GPU; requires handling inter-GPU communication and load balancing;
- Multi-node deployment: Suitable for high concurrency or massive models; cross-node communication and fault isolation significantly increase complexity.
Most teams should start with a single node, expanding to multiple nodes only when stress testing proves a single node cannot meet demands.
4.2 General Architecture
A maintainable inference service typically includes the following components:
[Client]|[Gateway: Auth, Rate Limiting, Request Validation]|[Inference Cluster: Model Loading, Batch Scheduling]| |[Model Weight Storage] [Monitoring / Logging]
The gateway handles identity verification, rate limiting, and request size restrictions, preventing abnormal traffic from overwhelming inference nodes. The inference service manages model loading and request scheduling. Model weights should be stored in object storage for unified management, with versions and checksums recorded.
4.3 Interface Design
Inference interfaces should remain simple, with explicit timeouts and length limits. Below is a pseudo-code snippet illustrating the basic structure of a client call:
function call_inference(prompt, max_new_tokens, temperature):request = {prompt: prompt,max_new_tokens: max_new_tokens,temperature: temperature}for attempt in 1..MAX_RETRY:response = send_post(URL, request, timeout = TIMEOUT)if response.status == 200:return response.body.textif response.status == 429 or response.status >= 500:wait(backoff(attempt))continueraise error(response.status)raise error("retry exhausted")
Three key points here: timeouts must be explicitly set to prevent requests from hanging indefinitely; retries should only target rate limiting (429) and server errors (5xx), not client errors; and exponential backoff should be used between retries to reduce impact on an already overloaded service.
5. Performance Evaluation Methods
Performance metrics must cover both user experience and resource efficiency. Common metrics include:
- Time to First Token (TTFT): Time from request submission to the return of the first output token; directly impacts user perception;
- Output Speed: Tokens generated per second; determines completion time for long responses;
- Throughput: Number of completed requests or total output tokens per unit time; reflects resource utilization efficiency;
- Tail Latency: P95, P99 percentiles, used to identify sporadic slow requests;
- Error Rate: Proportion of timeouts, OOM (out of memory) errors, and service exceptions.
When load testing, note the following: request samples should originate from real business scenarios, covering short, medium, and long input lengths. Pre-warm the service before testing to avoid cold-start impacts. Concurrency should be increased incrementally, recording the latency curve at each level to find the inflection point. The test environment should match the production environment in hardware, network, and configuration; otherwise, results are not directly comparable.
6. Cost Accounting
The cost of a self-hosted service includes hardware procurement or rental, data center facilities and power, operations personnel, redundancy backups, and monitoring infrastructure. Conversely, the cost of external API calls is primarily driven by pay-as-you-go billing.
When comparing the two, use a unit cost metric:
Unit Output Cost = Monthly Total Cost / Monthly Valid Output Tokens
“Valid output” refers to outputs successfully returned to the user, excluding failed requests and discarded results.
Resource utilization is the critical factor in determining whether self-hosting is cost-effective. When hardware sits idle for extended periods, unit costs rise sharply. Assume a service has a monthly total cost of $15,000 and a valid output of 500 million tokens. The unit cost is approximately $3 per million tokens. If utilization drops by half while total costs remain unchanged, the unit cost doubles. This figure merely illustrates the calculation method; actual values must be derived from your team’s specific billing data.
7. Decision Framework: Self-Hosted vs. API
When choosing a deployment method, consider the following dimensions:
- Data Sensitivity: For scenarios involving personal information or internal secrets, local deployment takes priority;
- Load Characteristics: With stable and high request volumes, self-hosted unit costs are easier to amortize; for highly fluctuating or low volumes, on-demand API calls are usually more economical;
- Customization Needs: When modifying model behavior, integrating private knowledge, or conducting domain-specific fine-tuning, the value of open weights is more pronounced;
- Team Capability: Self-hosting requires continuous model operations, performance tuning, and security hardening; human resource investment cannot be ignored;
- Delivery Cycle: For temporary projects or validation phases, calling an API is usually faster.
In practice, many teams adopt a hybrid strategy. Core sensitive businesses are deployed locally, while peak overflow traffic or non-sensitive tasks utilize external APIs. A hybrid approach requires a unified gateway layer so that business code does not need to worry about the underlying source.
8. Pre-Launch Checklist
Before the official launch, verify the following items:
- License agreement review is complete, with written records on file;
- Input/output filtering rules are configured, with interception and auditing for sensitive content;
- Service access is secured via authentication and access control; API keys are stored in a key management service, not hardcoded in code or logs;
- Canary releases are adopted, allowing quick rollbacks to the previous version in case of anomalies;
- Monitoring covers latency, error rates, VRAM usage, and queue lengths, with alert thresholds set;
- Capacity plans clearly define scale-up conditions and responsible personnel;
- Model weight versions, quantization parameters, and configuration changes are all logged to facilitate issue reproduction.
These checklist items may seem trivial, but they save significant troubleshooting time when failures occur.
