Local LLM Deployment: Hardware Requirements and Inference Optimization

    This article explains how to plan local LLM inference deployment around memory, concurrency, and cost. It covers weight and KV cache memory estimation, MoE deployment considerations, hardware selection steps, parallel strategy combinations, KV cache precision and block-size choices, and compute graph optimization. Readers can use these steps to validate hardware sizing and inference optimization decisions.

    Local LLM Deployment: Hardware Requirements and Inference Optimization

    LLM inference deployment is shifting from “can it run” to “can it run reliably and economically.” A complete deployment plan must answer three questions at the same time: whether the hardware can fit the model, whether the service can handle the target concurrency, and whether the cost is acceptable to the business. The following sections address these three questions.

    1. Where Deployment Requirements Come From

    Deploying a large model first requires meeting memory capacity conditions. Model weights occupy GPU memory, and the estimate is:

    Weight memory ≈ parameter count × bytes per parameter

    For a model with around 100 billion parameters, FP16 (2 bytes per parameter) requires about 200GB for weights, FP8 (1 byte per parameter) requires about 100GB, and 4-bit quantization (0.5 bytes per parameter) requires about 50GB. These figures cover weights only and do not include runtime overhead.

    During inference, each in-flight request also needs to store a key-value cache (KV cache). The longer the context and the higher the concurrency, the larger the KV cache footprint. For the same model, actual memory requirements can differ by several times under different concurrency levels and context lengths. Planning should therefore split memory into three parts—weights, KV cache, and activations plus framework reserves—and estimate each separately, while keeping 10% to 20% headroom.

    2. New Variables Introduced by Mixture-of-Experts Architectures

    Many newer large models use a Mixture of Experts (MoE) architecture. Each token activates only a small subset of expert networks, so total parameter count is large while per-step computation is related only to the active parameters. This design has two direct impacts on deployment.

    First, storage and computation are no longer symmetric. Total parameters determine the memory that must hold the model, while active parameters determine the approximate cost of each computation step. Looking only at active parameters underestimates memory requirements; looking only at total parameters overestimates compute requirements.

    Second, experts need to be distributed across cards. When experts are spread across multiple cards, each layer must dispatch tokens and aggregate results, which increases communication volume. Communication bandwidth and topology significantly affect throughput. Intra-machine interconnects between cards are usually faster than cross-machine communication, so partitioning should minimize cross-node expert calls.

    3. Hardware Selection Steps

    Hardware selection can follow this order:

    1. Determine the target model’s weight precision and total parameter count, and calculate the lower bound for weight memory.
    2. Estimate KV cache capacity based on target concurrency and the longest context.
    3. Select per-card memory, calculate the required number of cards, and consider constraints that parallelism places on card count.
    4. Check intra-node interconnect bandwidth to judge whether the setup is suitable for expert parallelism.
    5. Use small-scale stress tests to validate the estimates, then decide the scale to purchase or rent.

    Below is a simple estimation function for quick validation of the first and second steps:

    1. def estimate_memory_gb(params_b, bytes_per_param, kv_gb, overhead_ratio=0.15):
    2. """params_b: parameter count in billions; bytes_per_param: bytes per parameter; kv_gb: estimated KV cache in GB"""
    3. weights = params_b * bytes_per_param # billions of parameters × bytes = GB
    4. total = (weights + kv_gb) * (1 + overhead_ratio)
    5. return round(total, 1)
    6. # 100B parameters, FP8 weights, 40GB KV cache
    7. print(estimate_memory_gb(params_b=100, bytes_per_param=1, kv_gb=40)) # outputs 161.0

    This function provides only order-of-magnitude guidance. Actual memory usage is also affected by framework implementation, operator temporary buffers, and fragmentation, so measured results should be used.

    4. Combining Parallel Strategies

    Common parallelism methods include:

    • Tensor parallelism: splits matrix operations within a single layer across multiple cards, reducing per-card memory pressure but causing frequent intra-layer communication.
    • Pipeline parallelism: splits the model by layers, suitable for cross-node deployment, but introduces pipeline idle time.
    • Data parallelism: deploys multiple full replicas, with each replica handling requests independently, used to increase overall throughput.
    • Expert parallelism: for MoE structures, places different experts on different cards.

    The basic principle for combining them is: place communication-intensive parallelism within a high-bandwidth domain, while less communication-intensive parallelism can span longer distances. For inference services, a common approach is to use tensor parallelism or expert parallelism within a node, then scale horizontally across nodes with multiple replicas.

    5. KV Cache and Precision Choices

    KV cache is one of the main variables in inference memory. Reducing its storage precision from FP16 to FP8 approximately halves its footprint, but output quality must be validated.

    Block size determines the granularity of paged management. If blocks are too small, management overhead and memory fragmentation increase; if blocks are too large, short requests waste space. Block size should be chosen based on the actual request length distribution rather than simply using the default value.

    Some attention structures also maintain additional index caches. Using lower precision for these caches can further save memory, but precision loss must be evaluated separately and compared separately with the results for the main KV cache.

    6. Compute Graph Optimization

    A large amount of inference time is consumed by the launch overhead of small operators. Pre-capturing fixed-shape computation and replaying it can reduce scheduling overhead. Graph capture is sensitive to input shapes; dynamic batching scenarios usually pre-capture several shape buckets and route requests to the closest bucket for execution.

    Custom fused operators can reduce intermediate results.