Local LLM Deployment in Practice: From Hardware Sizing to Production Serving

    This practical guide explains how to deploy large language models on local infrastructure, from estimating GPU memory for weights, KV cache, and runtime overhead to choosing quantization, selecting inference server features, verifying weights, configuring serving, load testing, troubleshooting, and completing pre-launch checks. It focuses on building a stable, verifiable, and tunable inference service rather than simply loading a model.

    1. Why Local LLM Deployment Is More Complex Than It Seems

    Large language models range from tens of billions to trillions of parameters. The deployment challenge is usually not whether the model can be loaded, but whether it can serve requests stably and efficiently. During deployment, GPU memory capacity, memory bandwidth, communication overhead, and request scheduling constrain one another. Any weak point can slow overall performance.

    Inference can be divided into two phases. In the first phase, prefill, the model reads all input tokens at once and computes the initial cache. This phase is compute-intensive and suitable for parallelism. In the second phase, decode, the model generates output tokens one by one. Each step must read all weights and the historical cache, making this phase more sensitive to memory bandwidth. Because the two phases have different bottlenecks, resource planning should consider them separately.

    Models released in recent years have also introduced architectural changes. Mixture-of-Experts (MoE) architectures activate only part of the parameters for each token, reducing computation, but the total parameters still need to fit in GPU memory, and expert weight access patterns are more scattered than those of dense layers. Long-context models use methods such as sparse attention and hierarchical compression to slow cache growth. These designs improve theoretical efficiency, but they place higher demands on cache management and scheduling in the inference server.

    2. Resource Assessment Before Deployment

    Before deployment, estimate GPU memory requirements to avoid discovering capacity shortages after launch. GPU memory is mainly consumed by three parts: model weights, KV cache, and runtime overhead.

    2.1 Weight Memory

    The formula for estimating weight memory is:

    1. Weight memory ≈ number of parameters × bytes per parameter

    Common precisions and their bytes per parameter are shown below:

    Precision Bytes per parameter Approximate weight footprint for a 70B dense model
    BF16 / FP16 2 about 140 GB
    FP8 1 about 70 GB
    FP4 / 4-bit integer 0.5 about 35 GB

    These numbers are purely arithmetic results. Actual usage also includes index structures, quantization scale factors, and layers that are not quantized, such as some embedding layers and normalization layers. When estimating, reserve an additional 5% to 10% of headroom.

    For MoE models, the total parameter count determines weight memory, while the active parameter count determines per-token computation. During deployment, estimate memory based on total parameters, and estimate the throughput ceiling based on active parameters.

    2.2 KV Cache Memory

    KV cache is the main overhead that grows linearly with context length and concurrency. The general estimation formula is:

    1. KV cache ≈ 2 × layers × KV heads × head dimension × context length × concurrent requests × bytes per element

    The factor 2 represents the Key and Value caches. In models using grouped-query attention, the number of KV heads is usually much smaller than the number of attention heads, so the cache is smaller.

    If context length increases from 8K to 128K, the KV cache for a single request grows by 16 times. If 32 concurrent requests are supported at the same time, total cache demand can quickly exceed the weights themselves. Therefore, context length and concurrency should be planned together, rather than looking only at the maximum length supported by the model.

    2.3 Runtime Overhead

    The inference framework itself requires GPU memory, communication buffers, CUDA graphs or equivalent execution graph caches, and sampling and logging modules, all of which consume GPU memory. With multi-GPU tensor parallelism, each GPU also stores temporary tensors for communication. In practice, set the GPU memory utilization target to 85% to 90% to leave room for bursty load and fragmentation.

    3. Quantization and Precision Selection

    Quantization is a primary way to reduce GPU memory usage and improve memory access efficiency, but it introduces precision loss. When choosing precision, trade off GPU memory usage, inference speed, and output quality.

    • BF16 or FP16: Closest to the training-time setting, suitable as a quality baseline and for scenarios with sufficient GPU memory.
    • FP8: Well supported by hardware on many modern data center GPUs, and can usually halve weight memory with a small precision loss.
    • FP4 or 4-bit integer quantization: Lowest GPU memory usage, but more sensitive to the quantization method, group size, and calibration data, requiring dedicated validation.

    Quantization approaches generally fall into two categories. One is post-training quantization, which converts existing weights directly without retraining. The other is quantization-aware training, which simulates low-precision computation during training. It usually achieves better precision but costs more. Deployers generally can only use quantized versions released by the model provider or use generic tools for post-training quantization.

    After selecting a precision, regression testing is mandatory. Prepare an evaluation set covering common tasks, including factual question answering, code generation, mathematical reasoning, and long-document summarization, and compare score differences across precisions. If degradation on a task type exceeds what the business can accept, change the precision or adjust the quantization configuration.

    4. Feature Selection for Inference Serving

    Inference serving features directly affect post-deployment performance. Use the following checklist during selection:

    1. Continuous batching: Dynamically merges decode steps from different requests, significantly improving GPU utilization. This is a basic requirement for high-concurrency scenarios.
    2. Prefix caching: Reuses KV cache for identical system prompts or document prefixes, reducing repeated prefill computation. The benefit is clear in multi-turn chat and document question answering.
    3. Speculative decoding: Uses a smaller model or an additional prediction head to generate candidate tokens first, which are then verified in batches by the main model. The benefit depends on the acceptance rate of candidates and is more effective for tasks with simple output distributions.
    4. Tensor parallelism and pipeline parallelism: Splitting methods for multi-GPU deployment. Tensor parallelism has lower latency but requires high inter-GPU communication bandwidth; pipeline parallelism has lower bandwidth requirements but increases time to first token.
    5. Long-context support: Confirm whether the inference server supports the model’s full context window and whether the cache allocation strategy remains stable with long sequences.
    6. Compatible interface: If the upstream application already depends on a certain chat interface format, prioritize a server compatible with that format to reduce migration cost.

    For new models with special attention structures, the inference server needs to maintain different cache pools for different layers and ensure cache consistency across prefill, decode, and speculative decoding execution paths. Traditional prefix caching assumes that every layer has the same cache structure, and it may fail or produce false hits with heterogeneous caches. Before launch, confirm that the selected server has been adapted for the architecture and has passed correctness tests.

    5. Deployment Steps

    The following steps apply to single-machine, multi-GPU scenarios. For specific commands and parameter names, refer to the official documentation of the inference server you use.

    5.1 Prepare the Runtime Environment

    1. Confirm that the GPU driver version and runtime library version match the requirements of the inference server.
    2. Create an isolated runtime environment for the server, preferably using containers or virtual environments to isolate dependencies.
    3. Confirm that disk space is sufficient for weight files, and reserve space for logs and cache directories.
    4. Check host memory, inter-GPU interconnect, and network bandwidth to ensure that multi-GPU communication does not become a bottleneck.

    5.2 Obtain and Verify Weights

    After downloading the weights, verify file checksums first to confirm that the files are complete and consistent with the released version. Corrupted or replaced weights can cause abnormal output and are difficult to detect from logs.

    1. 1. Download all shard files and configuration files from the model release page
    2. 2. Compute a checksum for each file and compare it with the checksum published on the release page
    3. 3. Confirm that the tokenizer, chat template, and quantization parameters in the configuration match the weight version

    5.3 Write the Startup Configuration

    Below is an illustrative configuration. The field names are only used to explain the logic; refer to the documentation of the server you use for actual fields.

    1. model:
    2. path: /data/models/example-model
    3. precision: fp8
    4. verify_checksum: true
    5. parallel:
    6. devices: 8
    7. tensor_parallel_size: 8
    8. serving:
    9. max_context_length: 65536
    10. max_concurrent_requests: 32
    11. gpu_memory_ratio: 0.90
    12. enable_prefix_cache: true
    13. enable_speculative_decoding: false
    14. log_level: info

    Pay attention to the following points when configuring:

    • max_context_length does not need to be set to the maximum value supported by the model. If the business only needs 32K, setting a smaller value can free a large amount of KV cache space to increase concurrency.
    • If gpu_memory_ratio is too high, the risk of GPU memory overflow increases; if it is too low, hardware is wasted. Start at 0.85 and adjust based on load test results.
    • Speculative decoding is disabled by default. Enable it only when load testing proves a positive benefit and output quality does not degrade.

    5.4 Start and Health Check

    After the server starts, first check the logs for weight loading, GPU memory allocation, and cache pool initialization, and confirm that there are no warnings or errors. Then send a fixed test request and check whether the returned text is reasonable.

    1. Request URL: http://127.0.0.1:<port>/<chat endpoint path>
    2. Request body: a fixed test prompt, with temperature set to 0 for comparison
    3. Checks: returned status code, time to first token, generated length, and whether output matches the baseline

    Health checks should be integrated into automation. Send a probe request at fixed intervals and record the latency distribution. A live server process does not mean the inference results are correct, so the probe should include a simple validation of the output.

    6. Load Testing and Tuning

    Before launch, perform load testing to determine the real capacity of the service. Load testing should simulate the actual request distribution, including input length, output length, concurrency, and request arrival rate.

    6.1 Key Metrics

    • Time to first token (TTFT): Reflects prefill efficiency and has the greatest impact on interactive experience.
    • Time per output token (TPOT): Reflects decode efficiency and determines output smoothness.
    • Throughput: Total tokens processed per unit time, which determines cost per unit.
    • Peak GPU memory: Determines whether the service can withstand bursty long requests.

    These metrics involve trade-offs. Increasing concurrency usually improves throughput but lengthens per-request latency. Choose an operating point based on business priorities rather than pursuing maximum throughput alone.

    6.2 Tuning Order

    1. First fix the context length and precision, adjust concurrency, and find the maximum concurrency that meets the latency target.
    2. Then adjust the tensor parallelism degree. More GPUs can reduce per-GPU memory pressure but increase communication overhead, so compare through actual testing.
    3. Enable prefix caching and observe the hit rate. A low hit rate usually means there are fewer common prefixes in business requests, so the benefit is limited.
    4. Finally, evaluate speculative decoding. If the acceptance rate is lower than expected, disable it to avoid extra computation.

    Change only one parameter at a time and record the results to make cause and effect easier to determine.

    7. Troubleshooting Common Issues

    Out of memory (OOM)

    • First check whether there are unusually long requests. Reducing the maximum context length or limiting per-request input length usually provides immediate relief.
    • Reduce concurrency or lower the GPU memory utilization target to leave room for fragmentation.
    • If memory is still insufficient, consider lower-precision weights or more GPUs.

    Throughput lower than expected

    • Check whether continuous batching is effective. If requests are processed almost serially, confirm whether the client is sending requests concurrently.
    • Check inter-GPU communication. In multi-GPU scenarios, insufficient communication bandwidth can lead to low GPU utilization.
    • Check whether CPU-side tokenization and post-processing are becoming bottlenecks, especially under high concurrency.

    Output quality degradation

    • Compare output with the baseline precision. If differences are concentrated in a certain task type, re-evaluate the quantization scheme.
    • Check whether the chat template matches the model version. Template mismatch is a common cause and looks very much like model capability degradation.
    • Confirm that prefix caching and speculative decoding are not introducing errors. Disable these features and retest to quickly locate the issue.

    Time to first token too high

    • Long input significantly increases prefill time. Consider truncating, segmenting, or summarizing overly long input as preprocessing.
    • If prefix cache misses occur, prewarm frequently used system prompts.

    8. Pre-Launch Checklist

    • Weight file checksums verified, and configuration files match the weight version
    • Peak GPU memory still has headroom at target concurrency and maximum context
    • Output quality on the baseline test set meets business requirements
    • Load test results meet latency and throughput targets, and operating point parameters are recorded
    • Health checks, log collection, and alert rules configured
    • A clear rollback plan exists to quickly switch to the previous version or a standby service
    • Access control and request rate limiting enabled; secrets injected through environment variables or a secret management service, not written into configuration files

    The core of local deployment is to connect resource estimation, precision selection, and serving tuning into a verifiable chain. Every step should be supported by metrics, and every change should be reversible. Following the process in this article can help you obtain a stable and predictable inference service in a relatively short time.