LLM Inference Throughput Optimization on 8 Domestic AI Accelerators: A Practical Guide

    This article presents a practical methodology for improving large language model inference throughput on a multi-card domestic accelerator platform. It explains why a model that runs is not necessarily cost-efficient, how to turn deployment experience into reusable configuration records, and how to compare a baseline tensor-parallel setup against an optimized configuration that combines tensor, data, and expert parallelism. It also covers sequence parallelism, KV cache budgeting, graph mode and operator compilation, benchmark methodology with fixed SLO thresholds, common pitfalls, and a deployment checklist for teams that need reproducible results across hardware and software version changes.

    1. Background: Why “It Runs” Is Not the Same as “It Runs Efficiently”

    When deploying large-parameter inference services on domestic compute platforms, teams usually go through three stages: first get the model running, then meet the service level objectives (SLOs) for latency and stability, and finally push per-hardware throughput to its limit while staying inside those SLOs. Many teams get stuck between the second and third stages. The model produces output, but time-to-first-token (TTFT) fluctuates heavily, queuing becomes severe as concurrency rises, or the batch size has to be kept low to satisfy latency targets, leaving accelerator utilization persistently low.

    Throughput optimization is essentially a resource scheduling problem bounded by a hard latency constraint. The tighter the constraint, the smaller the room to maneuver. So the first step is not to tune parameters but to quantify the constraints: the upper bound on TTFT, the upper bound on end-to-end latency per request, the lower bound on output rate, and the acceptable queueing time. Only when these metrics are written down as explicit numbers do the parallelism strategy, batching strategy, and compiler options have a basis for evaluation.

    Note that this article is not tied to any specific hardware model or software stack. It discusses optimization methods for a general inference architecture built on multi-card accelerators with tensor parallelism, data parallelism, and expert parallelism. All performance figures here are illustrative of the methodology; actual gains must be measured on your own hardware and workload.

    2. Turning Deployment Experience into a Reusable Asset

    The largest hidden cost in domestic environments is that experience is not reusable. The same model, a different batch of cards, a different driver version, or a different inference engine version can invalidate every parameter you tuned before, leaving you to trial-and-error from scratch.

    The reusable approach is to break a deployment into a structured record containing at least six categories of information:

    • Model and quantization form: weight precision, quantization method, quantization granularity (per-tensor, per-channel, or per-group);
    • Hardware and topology: number of cards, inter-card interconnect bandwidth, ratio of intra-node to inter-node cards;
    • Runtime stack: inference engine version, image version, driver and compiler toolchain versions;
    • Resources and parallelism: TP/DP/EP values, per-card memory usage, KV cache budget;
    • Serving parameters: max batch size, batching window, sampling and decoding strategy, timeouts and retries;
    • Evaluation criteria: SLO definitions, concurrency gradients used in load tests, input and output length distributions, measurement duration.

    Make these fields into a searchable catalog indexed in both directions, by model dimension and by hardware dimension. When a new request comes in, the team can look up similar scenarios first instead of starting from zero. On the engineering side, the deployment backend can read configuration templates from the catalog and generate instances directly, avoiding the drift where the documentation says one thing and production runs another. If you use general capabilities such as Baidu AI Cloud’s container platform, object storage, and monitoring and alerting, configuration templates, images, and load test reports can live in a config repository, an image repository, and the observability system respectively, closing the loop.

    3. Case Setup: Baseline vs. Optimized on 8 Cards

    Assume a medium-scale sparse architecture model (referred to below as the “target model”) serves online traffic on a single node with 8 domestic accelerators, using quantized weights and a general domestic-card-adapted inference engine. The evaluation criteria are fixed: input length concentrated in the hundreds of tokens, output length on the order of hundreds of tokens, load tests run with increasing concurrency gradients, and SLOs defined as dual thresholds on TTFT and end-to-end latency.

    The baseline uses pure tensor parallelism: TP=8, DP=1. This configuration is simple to implement and distributes memory evenly, but its drawbacks surface quickly in online serving:

    1. A high tensor parallel degree amplifies per-layer forward communication, makes inter-card synchronization frequent, and leaves single-request latency sensitive to interconnect jitter;
    2. All concurrent requests share the same execution path, so batching can only happen within the same group, and head-of-line blocking is obvious;
    3. Expert routing in a sparse model is fragmented along the TP dimension, so uneven expert load results in “a few cards busy, most cards waiting.”

    The optimized configuration changes to TP=2, DP=4 and introduces expert parallelism (EP) for the sparse layers: tensor parallelism is confined to tighter card pairs within the node, data parallel replicas are expanded to 4 groups to raise concurrency capacity, and experts are distributed across cards to relieve routing hotspots. Two general optimizations are then layered on top. The first is sequence parallelism, which splits operators along the sequence dimension and merges communication, reducing activation memory and communication fragmentation for long sequences. The second is compute graph and operator compilation optimization (graph mode execution, operator fusion, constant folding, memory reuse), which cuts interpretation overhead and kernel launch costs.

    An illustrative configuration comparison (pseudocode, expressing structure only and not pointing to any specific product interface):

    1. baseline:
    2. tensor_parallel: 8
    3. data_parallel: 1
    4. expert_parallel: 1
    5. graph_mode: false
    6. seq_parallel: false
    7. optimized:
    8. tensor_parallel: 2
    9. data_parallel: 4
    10. expert_parallel: 4 # experts of sparse layers distributed across cards
    11. graph_mode: true # graph mode + operator fusion
    12. seq_parallel: true # sequence parallelism
    13. kv_cache_budget: 0.85 # memory budget, tune based on measurements
    14. max_batch: 32 # determined by load testing

    Under the same SLO, total machine throughput after optimization improves significantly over the baseline (an illustrative range of 30% to 55%, strongly correlated with the input/output length distribution, concurrency gradient, and interconnect bandwidth). The gains break down into four parts: lower communication volume improving single-request latency, data parallel replicas raising concurrency capacity, expert parallelism improving load balance, and compilation plus graph mode improving compute efficiency per unit of hardware.

    4. Parallelism Strategy: Making Multiple Cards Actually Serve Concurrency

    Parallelism strategy is not “the more cards, the finer the split.” It is about matching the ratio of communication to computation.

    • Tensor parallelism (TP): suited to scenarios with heavy per-layer computation where communication can be localized. Larger TP reduces per-card memory pressure but increases synchronization per layer. The practical rule is to keep TP within a single node’s high-bandwidth domain and avoid doing TP across nodes.
    • Data parallelism (DP): the most direct way to raise throughput, at the cost of memory redundancy from weight replicas. When memory is tight, a compromise of “smaller TP plus moderate DP” works.
    • Expert parallelism (EP): for sparse structures, distribute experts across cards and control hotspots with routing and a capacity factor. Too small a capacity factor drops tokens; too large wastes compute. Tune it against the load distribution.
    • Pipeline parallelism (PP): used when scaling across nodes. It lowers the frequency of inter-node communication but introduces bubbles, so it needs to be paired with micro-batch splitting.

    The recommended decision order: first set the TP upper bound based on memory, then determine the number of DP replicas from the latency target, and finally use EP/PP to handle sparse layers and inter-node scaling.

    5. Sequence Parallelism and Memory Budgeting

    In long-context scenarios, the main pressure comes from the KV cache and activations. The value of sequence parallelism is that it spreads the load along the sequence dimension and lowers peak per-card memory, which in turn allows a larger batch. Implementation points:

    1. Measure the memory curve under different concurrency levels first, set the KV cache budget ceiling, and leave headroom for fragmentation and temporary buffers;
    2. Sampling and decoding parameters affect how fast the cache grows, so align the maximum output length with the business side;
    3. Do not blindly enlarge the batching window. Beyond a certain point latency grows faster than throughput, so take the inflection point.

    6. Graph Mode and Operator Compilation Optimization

    In interpretation mode, every layer goes through scheduling, dispatch, and synchronization, an overhead that is especially visible in models dense with small operators. The general gains from graph mode and compilation optimization include operator fusion reducing intermediate tensors, constant folding reducing runtime computation, memory reuse reducing allocation jitter, and schedule merging reducing dispatch count. Caveats: dynamic shapes undermine graph optimization, so fix shapes or use bucketing where possible; custom operators need confirmed toolchain support; and after any runtime upgrade you must rerun accuracy and performance regression tests.

    7. Verification Method and Benchmark Criteria

    Optimization must be reproducible. Fix four things: the dataset and length distribution, the concurrency gradient, the SLO thresholds, and the measurement duration. Use an asynchronous client for load tests, separate TTFT from end-to-end latency, and record queueing time and error rate:

    1. # Pseudocode: benchmark loop with fixed criteria
    2. for concurrency in [8, 16, 32, 64, 128]:
    3. stats = run_benchmark(
    4. concurrency=concurrency,
    5. input_len_dist=fixed_dist,
    6. output_len_max=512,
    7. slo_ttft_ms=800,
    8. slo_e2e_ms=4000,
    9. duration_sec=300,
    10. )
    11. report(concurrency, stats.throughput, stats.p99_ttft, stats.p99_e2e)

    The criterion: a throughput gain counts as valid only if the P99 metrics stay within the thresholds. Also watch the error rate and retry rate to avoid a situation where throughput rises but the user experience collapses.

    8. Common Pitfalls

    • Looking only at average latency and ignoring the long tail; online services live or die by P99.
    • Filling the memory budget to the limit while ignoring fragmentation and burst concurrency, causing occasional failures.
    • Doing high TP across nodes, where communication becomes the bottleneck.
    • Accuracy drift when quantization and graph optimization are combined, with no regression set in place.
    • Load test data that differs greatly from real traffic distribution, making conclusions non-transferable.

    9. Implementation Checklist

    1. Quantify SLOs and the traffic profile;
    2. Build a structured deployment record catalog;
    3. Set parallelism in the order “TP ceiling, then DP replicas, then EP/PP as supplements”;
    4. Enable graph mode and compilation optimization, fixing shapes or using bucketing;
    5. Tune the KV cache budget and the batching inflection point;
    6. Run load tests with fixed criteria and record baseline vs. optimized comparisons;
    7. Bring configuration, images, and reports under unified management with monitoring and alerting, forming a rollback-capable release process.

    10. Conclusion

    On domestic compute, the deciding factor in inference optimization is not any single technique but the chain of “quantify constraints, match strategy, verify reproducibly, accumulate experience.” When parallelism strategy, sequence parallelism, compilation optimization, and benchmark criteria become standard practice, a team can quickly rebuild a baseline when hardware or versions change, turning throughput improvement from a lucky outcome into an expected one.