Deploying Open-Weight LLMs Locally: Key Technical Decisions

    This article covers the technical decisions involved in running open-weight large language models on your own infrastructure. It compares API access with self-hosting, explains how to estimate GPU memory for model weights and the KV cache, and outlines key design choices for inference services, including quantization, parallelism, batching, and service wrapping.

    1. What Open Weights Mean

    Most teams have only been able to use large language models through APIs. The model runs on the provider’s infrastructure, and the user is responsible only for building requests and handling responses. When model weights are open, users get the model files themselves. They can deploy the model on their own or rented compute, and they can adjust the inference pipeline, prompt templates, and quantization method. This brings three changes:

    • Data can stay within the internal network, which suits businesses with strict privacy or compliance requirements.
    • The cost structure shifts from per-call billing to resource-based costs. When the workload is stable, unit cost is easier to predict.
    • The model can be fine-tuned or trimmed for specific tasks, but the team takes on the work of training, evaluation, and maintenance.

    Every open-weight model comes with a license that sets specific terms for commercial use, redistribution, usage scale, and other conditions. Before launch, legal or compliance staff should review the license clause by clause and archive their conclusions.

    2. API Access vs. Self-Hosted Deployment

    Dimension API Access Self-Hosted Deployment
    Upfront investment Low, ready once integrated High, requires compute, storage, and operations staff
    Unit cost Grows linearly with call volume Depends on resource utilization; unit cost is lower at high load
    Data boundary Request data must be sent to the provider Data can remain in the internal environment
    Customizability Limited by API capabilities Inference parameters, quantization, and fine-tuning strategies can be adjusted
    Operational responsibility Mainly borne by the provider Fully borne by the user

    Consider the following when choosing. Self-hosting makes more sense when daily request volume is stable and high, data sensitivity is high, and deep customization is needed. API access is the safer option when request volume fluctuates widely, the team is small, or you need to validate business assumptions quickly. Many teams first use an API to confirm requirements and the upper bound of output quality, then move well-defined, high-frequency scenarios to local deployment.

    3. Resource Estimation: Calculate GPU Memory First, Then Choose Hardware

    GPU memory is the first barrier to deployment. You can roughly estimate the memory used by model weights with the following formula:

    Weight memory (GB) ≈ parameter count (billions) × bytes per parameter

    At common precisions, each parameter takes the following number of bytes. FP16 and BF16 use 2 bytes, INT8 uses 1 byte, and INT4 uses about 0.5 bytes. For a 70-billion-parameter model, FP16 weights need about 140 GB, INT8 weights about 70 GB, and INT4 weights about 35 GB. This figure covers only the weights. At runtime, you also need memory for the KV cache, activations, and runtime overhead. Typically, reserve an additional 20% to 40%, depending on context length and concurrency.

    KV cache memory scales with the number of concurrent requests and the context length. In long-context scenarios, the KV cache can take up more memory than the weights, so choosing hardware based only on model size is not enough.

    The code below provides the basic estimation functions. The parameters are illustrative values and do not correspond to any specific model’s specifications.

    1. def estimate_weight_memory_gb(params_billion: float, bytes_per_param: float) -> float:
    2. """Estimate the GPU memory used by model weights in GB, excluding KV cache and runtime overhead."""
    3. return params_billion * bytes_per_param
    4. def estimate_kv_cache_gb(
    5. num_layers: int,
    6. num_kv_heads: int,
    7. head_dim: int,
    8. context_len: int,
    9. concurrent_requests: int,
    10. bytes_per_elem: int = 2,
    11. ) -> float:
    12. """Estimate KV cache memory in GB, counting both the K and V caches."""
    13. per_token_bytes = 2 * num_layers * num_kv_heads * head_dim * bytes_per_elem
    14. total_bytes = per_token_bytes * context_len * concurrent_requests
    15. return total_bytes / (1024 ** 3)
    16. def plan_gpu_count(weight_gb: float, kv_gb: float, overhead_ratio: float, per_gpu_mem_gb: float) -> int:
    17. """Calculate the number of accelerators needed based on weights, KV cache, and overhead ratio, rounded up."""
    18. total = (weight_gb + kv_gb) * (1 + overhead_ratio)
    19. return int(-(-total // per_gpu_mem_gb))
    20. weights = estimate_weight_memory_gb(70, 0.5) # INT4 weights, about 35 GB
    21. kv = estimate_kv_cache_gb(80, 8, 128, 8192, 16) # 8K context, 16 concurrent requests
    22. print(plan_gpu_count(weights, kv, 0.3, 80)) # Estimated GPU count with 80 GB per card

    Use these estimates as the initial basis for procurement or resource requests. Before launch, run load tests with real workloads to correct any estimation errors.

    4. Key Design Considerations for Inference Services

    4.1 Quantization and Precision Trade-offs

    Quantization reduces memory usage and increases throughput, but it introduces some accuracy loss. Choose a quantization scheme based on results from your own evaluation dataset, not only on theoretical compression ratios. For structured tasks such as classification and extraction, low-bit quantization usually has a smaller impact. For tasks like long-chain reasoning or code generation, validation needs to be more thorough.

    4.2 Parallelism Strategy

    When a model exceeds the memory of a single GPU, split it across multiple GPUs or machines. Tensor parallelism suits single-node, multi-GPU setups, where communication overhead concentrates on the inter-GPU interconnect. Pipeline parallelism suits cross-node deployments, but it introduces pipeline bubbles that lower utilization. Cross-node communication bandwidth often becomes the performance bottleneck, so evaluate the network topology before deployment.

    4.3 Batching and Latency

    Dynamic batching combines requests that arrive at different times into one computation, which can substantially improve throughput. Larger batches raise the computational efficiency per request, but each request may wait longer. Set the maximum batch size and maximum wait time based on the latency requirements of your application.

    4.4 Service Wrapping

    An inference service typically needs the following capabilities:

    • Rate limiting and queuing, to keep traffic spikes from overwhelming GPU memory.
    • Timeouts and retries, to prevent requests from hanging for long periods.
    • Streaming responses, to shorten the time to first token that users perceive.