How LLM Inference Frameworks Maximize Domestic AI Accelerator Utilization

    This article explains why LLM inference bottlenecks usually come from data movement, kernel launch overhead, and cross-device communication rather than peak FLOPS, and presents a four-layer optimization framework covering operator fusion, paged KV cache management, continuous batching with preemption, and topology-aware parallelism. It also covers quantization trade-offs, observability metrics for capacity planning, and a staged rollout path for delivering low-latency, high-throughput inference on domestic accelerators.

    1. The Real Bottleneck Is Not Peak Compute

    When teams port large models to domestic accelerators, the first instinct is that the hardware is not fast enough. Production load tests usually point to a different conclusion: peak floating-point utilization is not the limiting factor. Throughput is constrained by data movement, kernel launch overhead, and cross-device communication.

    The reason is straightforward. During autoregressive decoding, each step processes only one token, so matrix multiplications collapse into tall, skinny shapes with very low arithmetic intensity. The hardware spends most of its time waiting on memory.

    The optimization goal for an inference framework should therefore shift from raising peak compute to eliminating wasted movement and stalls. This determines the priority of every later engineering decision: remove memory-access and scheduling waste first, then discuss precision and parallelism strategies.

    2. A Four-Layer Co-Optimization Framework

    2.1 Operator Layer: Favor Fusion, Avoid Materializing Intermediate Tensors

    In an unoptimized implementation, a single attention computation may involve separate reshape, scale, mask, softmax, and dropout operators. Each one writes its intermediate result back to device memory and reads it out again. The core benefit of fusion is removing those round trips.

    1. # Pseudocode: naive pre-fusion implementation (multiple memory round trips)
    2. scores = q @ k.transpose(-1, -2) * scale
    3. scores = scores + mask
    4. probs = softmax(scores, dim=-1)
    5. out = probs @ v
    6. # Fusion approach: scoring, masking, normalization, and weighting in one kernel
    7. out = fused_attention(q, k, v, mask, scale) # intermediates stay in on-chip cache

    Automatic operator tuning also matters in practice. The optimal tiling and parallel split for the same operator vary widely across tensor shapes, so the framework should cache tuning results per shape instead of re-running the search on every request.

    2.2 Memory Layer: KV Cache Management Is the Throughput Dividing Line

    In online serving, memory fragmentation often becomes a bottleneck before capacity does. Paged cache management is the common approach: split the cache into fixed-size blocks and map logical sequences to physical blocks through a block table, which enables dynamic growth, sharing, and fast reclamation.

    1. class BlockPool:
    2. def __init__(self, block_size, num_blocks):
    3. self.block_size = block_size
    4. self.free = list(range(num_blocks))
    5. self.table = {} # seq_id -> [block_id]
    6. def append(self, seq_id, token_ids):
    7. need = (len(token_ids) + self.block_size - 1) // self.block_size
    8. blocks = [self.free.pop() for _ in range(need)]
    9. self.table.setdefault(seq_id, []).extend(blocks)
    10. def release(self, seq_id):
    11. self.free.extend(self.table.pop(seq_id, []))

    Combined with prefix sharing (a single cached copy for identical system prompts) and copy-on-write, memory usage in long-prompt scenarios can drop substantially.

    2.3 Scheduling Layer: Continuous Batching and Preemption

    Static batching requires all requests to start and finish together, so short requests wait for long ones to complete generation, which wastes a great deal of capacity. Continuous batching schedules at iteration granularity: batches are reassembled after every generated step, finished requests leave immediately, and waiting requests fill the gap. To keep a few very long sequences from wrecking overall latency, preemption with recomputation or swapping is needed, temporarily suspending low-priority sequences when memory is tight.

    The scheduler should also distinguish two workload types. Prefill is compute-intensive while decoding is memory-intensive. Mixing them in one batch causes interference, so disaggregated execution can deploy each with a different parallelism degree and batching policy.

    2.4 Communication Layer: Match Parallel Splits to the Interconnect Topology

    Tensor parallelism requires a reduction at every layer and communicates frequently, so it should stay within a single node’s high-speed interconnect. Pipeline parallelism moves little data but introduces bubbles, which calls for a sensible number of stages plus micro-batch scheduling. Expert parallelism requires balanced routing; otherwise load skew appears. A practical rule: measure actual interconnect bandwidth and latency first, then choose split dimensions, rather than copying a reference configuration.

    3. Quantization and Precision: Trading Bandwidth for Throughput

    Weight quantization directly reduces the bytes loaded per step, which pays off most in the decoding phase. Activation quantization is harder, requiring per-channel scaling, outlier handling, and higher precision retained in sensitive layers. Before launch, teams must establish an evaluation loop: compare perplexity, task accuracy, and long-context consistency before and after quantization on real business corpora, and set an acceptable regression threshold instead of relying on a single benchmark run.

    4. Observability and Capacity Planning

    A production-grade framework depends on measurement. At minimum, collect per-request time to first token, per-token latency, average sequence length within a batch, cache hit rate, preemption count, per-device memory watermarks, and interconnect utilization. Load-test modeling based on these metrics is what lets you estimate maximum concurrency under a given latency constraint and reserve elastic containers and queue buffers for traffic peaks. Logs and metrics should feed into a unified logging service and monitoring/alerting system, with automatic scale-out or degradation on anomalies.

    1. First establish a precision-alignment baseline with a fixed evaluation set and random seed.
    2. Then apply operator fusion and paged caching, watching how memory-access and memory-usage curves change.
    3. Next introduce continuous batching and disaggregated execution, tuning batch size and preemption thresholds.
    4. Finally layer on quantization and parallelism strategies, rolling out item by item with a fast rollback switch available.

    When model vendors participate deeply in building the compute ecosystem, they feed the real characteristics of business workloads back into the hardware and firmware layers, forming a positive loop of workload, framework, and chip. For engineering teams, mastering these general optimization methods is what makes it possible to deliver stable, low-latency, high-throughput inference services under constrained hardware, and that is also the key support for the continued maturation of the domestic compute ecosystem.