LLM Inference Optimization on Chinese NPU Platforms: Architecture and Engineering Trade-Offs
This article examines an open-source LLM inference implementation optimized for a Chinese NPU platform. It explains how custom operators, kernel fusion, 1 GiB huge-page allocation for the KV cache, and UDMA-based expert weight redistribution improve execution efficiency. It also analyzes remaining challenges in MoE prefill synchronization, batched KV cache copies, and Engram CPU offloading, highlighting why software stack maturity matters when evaluating inference infrastructure.
As large language models grow in parameter count, inference places increasing demands on the underlying compute infrastructure. Chinese heterogeneous computing platforms are evolving their software stacks to support high-standard LLM inference services.
A leading AI team recently open-sourced production-grade inference code optimized for a Chinese NPU platform. The implementation systematically reworks core operators, communication mechanisms, memory management, and task scheduling. This article examines its architectural optimizations and the engineering constraints that still leave room for improvement.
1. Custom Operators and Kernel Fusion
LLM inference performance is often constrained by memory bandwidth and access efficiency rather than raw floating-point throughput. The implementation addresses these bottlenecks through extensive operator customization.
A Specialized Operator Library
The development team used a platform-specific operator programming language to build a library containing more than 30 specialized operator modules tailored to the NPU architecture. These modules cover core inference operations, including KV cache reads and writes, weight quantization, and rotary positional encoding.
By directly controlling low-level hardware instructions, custom operators can reduce unnecessary movement of intermediate data and improve compute-unit utilization.
Fusion Across Attention and MoE Operations
In conventional Transformer implementations, operations such as attention projections, gating, and normalization are often executed separately. This implementation fuses previously separate matrix operations, normalization, and residual mixing.
For example, the execution paths for Mega Gate and Mega-MHC in mixture-of-experts (MoE) models combine operations at the operator level. This reduces repeated transfers of intermediate tensors between hardware caches and device memory, helping alleviate memory bandwidth bottlenecks.
2. Memory Management and Task Scheduling
Device memory capacity is a hard constraint for LLM inference, particularly with long contexts. The implementation introduces targeted memory allocation and communication optimizations.
Huge-Page Allocation for the KV Cache
The system uses a dedicated allocation strategy for the KV cache to reduce address translation overhead. Specifically, allocation flags force the KV cache to use 1 GiB huge pages.
This reduces the number of page-table entries and lowers the miss rate of the translation lookaside buffer (TLB), reducing address translation latency. The underlying system also provides a mechanism to query available huge-page capacity, allowing the scheduler to assess usable device memory more accurately.
UDMA-Based Expert Weight Redistribution
In MoE models, expert workloads change dynamically with the distribution of input data. Expert parallel load balancing (EPLB) therefore requires expert weights to be moved between NPU nodes.
The implementation uses UDMA communication kernels for high-speed, cross-node weight transfers. UDMA enables direct device-memory-to-device-memory copies without staging data in host memory, reducing communication latency and system jitter during expert weight redistribution.
3. Architectural Challenges and Areas for Improvement
Despite these systematic operator and memory optimizations, the source-code details and engineering design reveal several limitations. Addressing them will require further development of the platform’s software stack and closer hardware–software integration.
CPU Synchronization Overhead During MoE Prefill
During the prefill stage of MoE inference, expert token dispatch currently forces synchronization between the CPU and NPU. In the code, the synchronization flag is always set to True. The accompanying comments state that this behavior is intended to prevent out-of-memory (OOM) errors.
However, synchronization adds CPU–NPU interaction overhead and interrupts asynchronous execution. Under high request concurrency, it may become a performance bottleneck.
A key area for improvement is replacing this coarse-grained synchronization with more precise device-memory preallocation or dynamic memory monitoring, while maintaining protection against OOM failures.
Inefficiencies in Batched KV Cache Copies
Multi-turn conversations and parallel requests often require large numbers of KV cache blocks to be copied across devices.
In the current NPU implementation, the batched-copy interface performs these transfers by looping over individual asynchronous memory-copy calls. By contrast, mainstream accelerator platforms outside China commonly provide native batch-submission interfaces that package multiple copy operations into a single submission to the underlying driver.
Repeated calls increase API overhead and may prevent full utilization of the underlying DMA channels. Resolving this limitation requires higher-level batch-operation support in the hardware driver layer.
Missing CPU Offload Support for Engram
For the Engram memory-augmentation mechanism, the implementation currently requires vocabulary data and related structures to reside in NPU memory. Users cannot disable this restriction to enable CPU offloading.
Keeping these structures on the NPU preserves memory-access speed, but the Engram vocabulary consumes device memory that could otherwise be allocated to the KV cache.
This trade-off becomes particularly important in long-context inference, where device memory is already scarce. Without a flexible mechanism for moving data between device and host memory, the implementation can substantially limit the maximum number of concurrent requests.
4. Conclusions and Outlook
The open-source implementation demonstrates the engineering work involved in improving LLM inference on Chinese NPU platforms. Operator fusion, huge-page memory allocation, and UDMA communication help unlock more of the hardware’s inference potential.
At the same time, synchronization in MoE communication, the implementation of batched-copy interfaces, and coordination between device and host memory remain important limitations. These issues show that competitive inference performance depends on deeper hardware–software integration, not just isolated kernel optimizations.
For enterprise users evaluating heterogeneous inference infrastructure, hardware specifications alone are insufficient. Software stack maturity and the depth of low-level optimization also need careful assessment.
Established cloud providers, including Baidu AI Cloud, typically use containerized deployment, intelligent scheduling, and unified monitoring and alerting when delivering heterogeneous compute infrastructure. These mechanisms help abstract hardware differences so developers can focus more on application logic.
Continued improvements in asynchronous communication and dynamic memory scheduling should enable Chinese computing platforms to play a larger role in demanding LLM inference deployments.
