Performance Optimization Strategies for Adapting LLMs to Specialized Accelerators

    This article explores performance optimization methods for adapting large language models (LLMs) to specialized accelerators. It details the shift from theoretical compute power to hardware-software co-design efficiency, examining the distinct characteristics of Prefill and Decoding phases. Key topics include the implementation of fused operators, specialized execution instances, and a structured path for deep adaptation from basic compatibility to service-level optimization. The article also outlines best practices for establishing reproducible performance baselines and the broader impact on the AI compute ecosystem.

    In recent years, the competition in LLM inference systems has gradually shifted from simply comparing theoretical chip compute power to hardware-software co-design efficiency. For a given accelerator, theoretical peak performance does not equal actual usable performance. Model architecture, operator implementation, memory access patterns, compiler optimizations, and computational characteristics during the inference phase all significantly impact the final results.

    Public code changes reveal that some mainstream LLMs are undergoing deeper adaptations for specialized accelerators. These optimizations are not merely about adding device support; they involve redesigning fused operators and execution strategies tailored to specific model versions, tensor shapes, and attention computation paths. Public data indicates that, under specific testing conditions, the measured performance during the Prefill phase can reach a high proportion of the hardware’s theoretical peak, approaching 98.5%. This phenomenon demonstrates that the relationship between domestic models and domestic compute power is transitioning from “able to run” to “running efficiently.”

    1. Why the Prefill Phase Better Reflects System Optimization Capabilities

    LLM inference is typically divided into two phases: Prefill and Decoding.

    Prefill handles the user’s complete input context. Since the input sequence is usually long, the system can perform large-scale matrix computations with high computational density, making it suitable for leveraging the accelerator’s parallel computing capabilities. Decoding generates subsequent tokens one by one; each step has a relatively small computational load but requires frequent reads from the historical KV Cache, making it more susceptible to memory bandwidth, scheduling overhead, and communication latency.

    Therefore, Prefill performance is usually closer to the chip’s theoretical computing power, while Decoding performance better reflects the system’s overall proficiency in memory bandwidth, cache management, and low-latency scheduling.

    When evaluating an LLM inference solution, one cannot look at a single metric alone. At least the following should be considered simultaneously:

    1. Prefill throughput;
    2. Decoding throughput;
    3. Time to first token (TTFT);
    4. Time per output token (TPOT);
    5. Memory footprint;
    6. Performance degradation under long contexts;
    7. Throughput stability during multi-user concurrency;
    8. Scaling efficiency across different batch sizes.

    Publishing only the peak results of one phase can easily mislead readers about the system’s overall capability. A more rigorous approach is to fully specify the test environment, input length, output length, batch size, precision mode, and whether operator fusion is enabled.

    2. Fused Operators Are Key to Improving Utilization

    In traditional implementations, a single attention computation might sequentially execute multiple steps: normalization, positional encoding, matrix multiplication, scaling, and type conversion. Each step may produce intermediate tensors and incur additional memory read/write overhead.

    The basic idea behind operator fusion is to merge multiple continuous, data-dependent computations into a single device kernel. This reduces:

    • Write-backs of intermediate tensors;
    • Scheduling overhead between different operators;
    • Global memory access count;
    • Tensor layout transformation costs;
    • Unnecessary data type conversions.

    In attention computation scenarios, fusing normalization, positional encoding, attention computation, and type conversion allows data to remain in on-chip caches or registers as much as possible, reducing memory access pressure. For long-sequence Prefill tasks, this optimization is particularly pronounced because the input scale is large, and any extra data movement is amplified.

    However, fusion does not mean “the more operators, the better.” Over-fusion can lead to complex kernel code, increased register usage, decreased thread occupancy, and even excessively long compilation times. Therefore, engineering implementations must strike a balance between computational density, register pressure, parallelism, and maintainability.

    3. Specialized Instances and Model Architecture Adaptation

    While general-purpose operators offer better compatibility, they usually cannot achieve extreme optimization for the actual structure of a specific model version. LLMs differ in hidden dimensions, number of heads, head dimensions, KV layout, and positional encoding methods. These differences directly affect thread mapping and memory access patterns.

    A common optimization approach is to provide dedicated execution instances for specific model architectures. The core is not simply hardcoding parameters, but generating hardware-friendlier execution paths based on actual tensor shapes. For example:

    • Selecting a more reasonable thread block size for a fixed head dimension;
    • Switching tiling strategies based on sequence length;
    • Adopting different memory access layouts for Query and KV tensors;
    • Providing specialized parallel configurations for common batch sizes;
    • Designing independent computation paths for different precision modes.

    This approach reduces runtime branching and allows the compiler to more fully perform constant propagation, loop unrolling, and instruction scheduling. However, it also incurs maintenance costs: if the model architecture changes, the original specialized paths may fail; if input shapes are too diverse, the number of specialized instances can quickly bloat.

    Therefore, actual systems typically adopt a combination of “general paths + high-frequency specialized paths.” Common shapes use highly optimized specialized kernels, while low-frequency or anomalous shapes fall back to general implementations, thus balancing performance and compatibility.

    4. How to Interpret 98.5% Peak Utilization

    Hardware peak utilization is not equivalent to actual business throughput, nor should it be understood as achieving the same results across all scenarios.

    Approaching hardware peaks usually means comparing measured floating-point compute throughput against the device’s theoretical peak under clearly defined test conditions. This ratio is influenced by multiple factors, including:

    • Data types used;
    • Compute scale;
    • Input sequence length;
    • Batch size;
    • Whether specific fused kernels are used;
    • Presence of communication or synchronization overhead;
    • Whether the test only measures core computation time.

    If the test only covers the compute-intensive Prefill phase, the result may be very close to the theoretical peak. But in real online services, overheads such as request queuing, data preprocessing, KV Cache allocation, network communication, and result returning must also be considered.

    Therefore, 98.5% is more appropriate as an efficiency metric for a specific class of core operators under specific conditions, rather than a comprehensive performance conclusion for the entire inference service. Technical articles and performance reports should avoid conflating the two.

    5. The Adaptation Path from “Able to Run” to “Running Efficiently”

    Deep adaptation between domestic LLMs and specialized accelerators typically involves several stages.

    Stage 1: Basic Compatibility. The focus is on completing operator mapping, precision conversion, model loading, and the basic inference process to ensure the model runs stably.

    Stage 2: Operator Replacement. Targeting performance bottlenecks, general implementations are replaced with device-specific kernels, focusing on optimizing matrix multiplication, normalization, attention, and KV Cache access.

    Stage 3: Graph-Level Optimization. Through operator fusion, constant folding, memory reuse, and execution graph rearrangement, intermediate result write-backs and unnecessary synchronizations are reduced.

    Stage 4: Model-Level Optimization. Based on the model architecture, parallel strategies, tensor layouts, and cache management methods are adjusted to make the software execution logic better match the hardware architecture.

    Stage 5: Service-Level Optimization. The focus shifts from individual operators to batch processing, request merging, dynamic scheduling, fault recovery, and multi-instance resource isolation.

    Only by completing these layers of synergy can a stable inference system be truly formed, rather than stopping at the “model can start” stage.

    6. Performance Verification Requires a Reproducible Baseline

    To prevent peak data distortion, performance testing should establish a clear, reproducible baseline. It is recommended to at least record the following information:

    1. Device type:
    2. Software stack version:
    3. Model architecture:
    4. Input length:
    5. Output length:
    6. Batch size:
    7. Data precision:
    8. Operator fusion enabled:
    9. Test rounds:
    10. Warm-up excluded:
    11. Metrics recorded:

    During testing, sufficient warm-up should be performed first to prevent initial compilation, memory allocation, and cache building from affecting results. Statistics should not only record the best score but also provide the average, P50, P95, and the fluctuation range.

    For Prefill, focus on throughput variations across different input lengths; for Decoding, focus on single-token latency, KV Cache footprint, and the performance curve as concurrency increases.

    Furthermore, operator-level profiling should be combined with end-to-end stress testing. Operator-level data helps locate compute or memory access bottlenecks, while end-to-end data reflects scheduling and communication overheads in real services. Both are indispensable.

    7. Practical Significance for the Compute Ecosystem

    When the model side begins to provide deep optimization for specialized accelerators, it signals a shift in the industry chain relationship. Hardware vendors no longer just provide chips and basic drivers, and model developers no longer focus solely on algorithmic efficacy. Both parties must collaboratively address operator libraries, compilers, runtimes, and service frameworks.

    This synergy offers three main values:

    First, it improves the actual utilization efficiency of domestic hardware, narrowing the gap between theoretical capability and business performance.

    Second, it drives the maturation of the software stack. Only through repeated validation under real LLM workloads can compilers, schedulers, memory management, and monitoring tools uncover more issues.

    Third, it helps form a sustainable ecosystem loop. Model architecture changes will push hardware optimizations backward, and hardware features will influence model deployment. Long-term synergy between the two reduces dependence on a single technological path.

    It should be noted that a single code commit or benchmark result only proves progress along a specific technical path and does not directly represent the maturation of the entire ecosystem. Subsequent observation is still needed regarding stability under more models, more input scales, and more concurrent scenarios, as well as the completeness of the toolchain and operations system.

    Overall, the core of deep adaptation lies not in adding a device option, but in systematically reconstructing around the model’s computation graph, the hardware’s execution units, and real business workloads. Only by combining fused operators, memory access, compiler optimization, runtime scheduling, and service engineering can theoretical peaks be translated into stable, reproducible, and scalable actual performance.