LLM Inference Optimization for Chinese-Developed AI Accelerators

    Optimizing Chinese-developed large language models for Chinese-developed AI accelerators requires more than hardware compatibility. This article explains how prefill and decoding workloads differ, why kernel fusion and memory layout matter, and how compiler optimization, bandwidth utilization, and scheduling affect performance. It also outlines a practical workflow for benchmarking, bottleneck analysis, numerical validation, and production load testing.

    1. From Running Successfully to Using Hardware Effectively

    As large language model inference moves into production, the focus shifts from whether a model can run on an AI accelerator to whether it can consistently approach the target hardware’s theoretical performance ceiling. This distinction is central to optimizing Chinese-developed models for Chinese-developed AI chips.

    The prefill phase is particularly important. It processes a potentially long input sequence in a single pass, with substantial computation and parallelism. This makes it a useful test of how well the accelerator’s compute units, compiler stack, operator libraries, and memory subsystem work together.

    Deep hardware optimization is not simply a model migration exercise. It involves reorganizing the computation graph, operator implementations, memory access patterns, and scheduling around the chip architecture. Its three main goals are:

    1. Reduce unnecessary memory traffic: Avoid repeatedly writing and reading intermediate tensors, easing bandwidth pressure.
    2. Improve compute-unit utilization: Keep core operations—including matrix multiplication, normalization, positional encoding, and attention—executing with minimal interruptions.
    3. Reduce scheduling overhead: Minimize the cost of kernel dispatch, synchronization, format conversion, and conditional execution.

    Only when these factors align can prefill compute throughput approach the hardware’s rated peak. In practice, the more useful measure is effective compute utilization: the computational throughput achieved under a real workload as a fraction of the relevant theoretical peak.

    2. Prefill and Decoding Require Different Optimization Strategies

    LLM inference typically has two phases:

    • Prefill: Processes the complete input prompt. It is generally compute-intensive and offers substantial parallelism.
    • Decoding: Generates tokens sequentially. It is generally more memory-intensive and depends heavily on bandwidth and cache efficiency.

    These differences rule out a single optimization strategy for both phases. Prefill optimization focuses on keeping compute resources busy, while decoding optimization focuses on supplying data fast enough.

    Looking only at generation speed can obscure time to first token. Conversely, focusing only on time to first token can come at the expense of overall throughput.

    A common mistake when adapting models to Chinese-developed accelerators is to replace low-level operators without restructuring data layouts. If tensors are repeatedly moved between normalization, positional encoding, attention, and type conversion, memory traffic can limit overall prefill performance even when individual matrix multiplications are highly efficient.

    3. Kernel Fusion Helps Approach Peak Performance

    A typical Transformer inference path contains many consecutive operations, including normalization, positional encoding, attention, type conversion, and residual connections. Executing each operation independently creates intermediate tensors and additional memory reads and writes.

    Hardware-specific optimization often uses kernel fusion to combine multiple steps into fewer execution units. Where the architecture and dependencies allow it, normalization, positional encoding, attention, and output type conversion can share an execution path, keeping more data in on-chip caches or registers rather than repeatedly accessing global memory.

    The main benefits are:

    1. Lower bandwidth consumption: Intermediate results need not be written to and read from global memory.
    2. More continuous execution: Fewer kernel launches and synchronization points reduce interruptions.
    3. Better cache locality: Coordinated access patterns improve opportunities for prefetching and cache reuse.

    The following schematic pseudocode illustrates the intent:

    1. function fused_prefill_kernel(input, weights, config):
    2. x = load_tile(input)
    3. x = normalize(x, weights.norm)
    4. x = apply_position_encoding(x, config.rope)
    5. q, k, v = project_qkv(x, weights.qkv)
    6. attn = scaled_dot_product_attention(q, k, v)
    7. out = cast_and_store(attn, config.output_dtype)
    8. return out

    This sketch expresses the idea of combining logical steps into an execution unit and exposing fewer intermediate tensors to the higher-level scheduler. It is not a complete Transformer implementation. Actual tiling and pipelining must account for the model’s operation dependencies and the accelerator’s cache capacity, compute-unit count, data widths, and memory hierarchy.

    4. Achievable Performance Depends on the Entire System

    Rated compute throughput is often the first number cited when evaluating an AI accelerator. Actual inference performance, however, depends on several interacting subsystems:

    • Compute-unit utilization: Whether matrix multiplication units remain active or experience idle gaps.
    • Memory bandwidth: Whether high-bandwidth memory can supply data continuously.
    • Cache hit rate: Whether frequently accessed data stays in fast storage.
    • Data conversion overhead: How often execution requires conversions between numerical formats.
    • Scheduling and synchronization: Whether execution stalls across cores, streams, or tasks.

    Approaching peak performance during prefill generally requires the following conditions:

    1. A sufficiently regular computation graph that the compiler can optimize effectively.
    2. Highly parallel core operators with data layouts matched to the hardware’s memory access patterns.
    3. Short-lived intermediate results that avoid unnecessary materialization in memory.
    4. Sustained memory bandwidth rather than brief bandwidth bursts.
    5. A software stack that limits dynamic branching and unpredictable scheduling.

    This explains why code-level optimization offers more performance value than framework compatibility alone. Compatibility establishes that interfaces work. Code-level optimization addresses the operators, memory behavior, and scheduling that determine how efficiently the model runs.

    5. How Memory and Interconnect Technologies Affect Inference

    LLM inference is sensitive to memory bandwidth. As models and sequence lengths grow, moving weights, activations, and attention intermediates becomes increasingly expensive. Without sufficient bandwidth, compute units cannot receive data continuously and may remain idle.

    Common hardware approaches to increasing bandwidth include:

    • Adding memory channels.
    • Increasing interface data width.
    • Using more advanced packaging and bonding technologies.
    • Shortening interconnect distances between compute chips and memory.
    • Improving interconnect efficiency across multiple chips.

    Hybrid bonding attracts attention because it can support more interconnect points over shorter distances, increasing bandwidth density and potentially reducing access latency. These designs also face engineering constraints, including yield control, stacking limits, per-device capacity limits, and the complexity of multi-chip interconnects.

    These considerations also apply to memory and interconnect development for Chinese-designed accelerators. However, higher hardware bandwidth does not automatically produce better application performance. The inference software must still:

    1. Keep frequently accessed weights as close to compute units as practical.
    2. Tile long-sequence attention to avoid loading excessively large tensors at once.
    3. Optimize KV cache layouts for reuse during decoding.
    4. Adjust batch sizes and concurrency strategies to match measured bandwidth behavior.

    6. A Practical Workflow: From Baselines to Sustained Performance

    A repeatable hardware optimization process should progress from measurement to targeted changes, followed by correctness validation and production-oriented testing.

    Step 1: Establish a Reproducible Baseline

    Run a reference model on the target hardware and record:

    • Time to first token.
    • Generated tokens per second.
    • Prefill throughput.
    • Device memory usage.
    • Compute-unit utilization.
    • Memory bandwidth utilization.

    The purpose is not merely to demonstrate that inference works. The baseline provides a consistent comparison point for subsequent optimizations.

    Step 2: Identify the Bottleneck Layer

    Performance bottlenecks typically fall into three categories:

    • Operator-level bottlenecks: Inefficient individual operators, excessive branching, or redundant computation.
    • Memory-level bottlenecks: Saturated bandwidth or poor cache hit rates.
    • Scheduling-level bottlenecks: Frequent dispatches or significant synchronization delays.

    Examine execution timelines rather than relying only on aggregate throughput.

    If compute utilization stays low while bandwidth is near its limit, data supply is likely the constraint. If bandwidth utilization is low and compute units repeatedly sit idle, scheduling or dependency management may be responsible.

    Step 3: Rework the Critical Operators

    Prioritize operators that account for the largest share of runtime or execute most frequently. Common prefill optimization targets include:

    • Normalization.
    • Positional encoding.
    • QKV projection.
    • Attention.
    • Output projection.
    • Type conversion.

    Possible changes include fusion, tiling, vectorization, branch reduction, and data layout adjustments. The appropriate choice depends on the measured bottleneck and target architecture.

    Step 4: Optimize the Compiled Graph

    Efficient operator implementations are only part of the solution. The compiler also needs visibility into a sufficiently complete computation graph.

    Common graph optimizations include:

    • Removing redundant nodes.
    • Consolidating static shape calculations.
    • Establishing predictable memory reuse strategies.
    • Reducing dynamic control flow.
    • Moving constant folding to compile time.

    Static or partially static graphs often help accelerator backends generate more efficient execution plans.

    Step 5: Validate Numerical Accuracy and Stability

    Performance improvements must not compromise output quality. After replacing or modifying an operator, validate:

    • Numerical agreement at the individual operator level.
    • End-to-end output consistency.
    • Stability during long-text generation.
    • Behavior on boundary inputs.
    • Regression results across different batch sizes.

    Automated numerical acceptance checks help prevent faster execution from introducing unacceptable output drift.

    Step 6: Run Load Tests and Plan Capacity

    Production testing should cover combinations of input length, concurrency, and output length. Key questions include:

    • Does prefill performance degrade with long inputs?
    • Does high concurrency create substantial queuing?
    • Does memory usage grow linearly with the number of active sessions?
    • Do tail latencies increase disproportionately?

    Performance measurements become useful for production planning only after testing across representative workload conditions.

    7. Evaluate More Than TFLOPS

    Engineering evaluations should use multiple metrics rather than a single compute-throughput figure.

    Metric Meaning Primary concern
    Prefill throughput Input tokens processed per unit of time Prompt processing and time to first token
    Decoding throughput Output tokens generated per unit of time Generation speed and user experience
    Effective compute utilization Achieved computational throughput relative to theoretical peak Depth of hardware optimization
    Bandwidth utilization Achieved memory transfer rate relative to peak bandwidth Memory bottlenecks
    Time to first token Time until the first output token is available Interactive responsiveness
    Energy efficiency Performance per watt Deployment cost

    Reporting only a percentage of peak hardware performance can hide important workload differences. A meaningful report should also specify the model architecture, input length, batch size, precision mode, concurrency strategy, and test environment.

    8. Models, Chips, and Software Must Evolve Together

    Deep optimization of Chinese-developed LLMs for Chinese-developed AI accelerators depends on coordinated progress across model architectures, chip designs, compilers, and operator libraries.

    An improvement in one component rarely creates a lasting advantage by itself. A feedback loop across the full stack is needed to turn theoretical hardware capability into sustained application throughput.

    That loop includes:

    1. Model development: Stable computation graphs that are amenable to optimization.
    2. Chip development: Compute capacity, memory bandwidth, and sufficient programmability.
    3. Software infrastructure: Compilation, scheduling, debugging, and performance analysis tools.
    4. Production workloads: Real usage feedback that guides continued iteration.

    When model teams contribute accelerator-specific operator implementations and publish performance measurements, this indicates a move beyond compatibility testing toward performance engineering. Such code-level evidence is more informative than promotional claims because it can be inspected, reproduced, and improved.

    9. Conclusion

    Optimizing LLM inference for Chinese-developed AI accelerators requires more than porting a model. It requires system-level work that accounts for the different characteristics of prefill and decoding.

    Kernel fusion, memory layout redesign, computation graph optimization, effective bandwidth use, and multidimensional evaluation can help teams move closer to the hardware’s theoretical performance ceiling.

    For developers, three questions should guide the process:

    • Is the workload limited by compute capacity or data supply?
    • Do the optimizations reach the operator and scheduling layers?
    • Have performance gains passed numerical accuracy and stability checks?

    Answering these questions with reproducible measurements is what gives model–hardware co-optimization practical engineering value.