MoE Data Selection on Domestic NPU Platforms: Component Design and Porting Considerations

    This article examines a data selection component for token routing and dispatch in MoE training on domestic NPU platforms. It covers the background of porting from GPU-centric stacks, architecture differences, coordination with matrix, communication, and cache operators, a 128-card supernode scenario, a scheduling pseudocode example, and common porting and debugging issues.

    As large language model parameter counts continue to grow, sparse architectures such as Mixture-of-Experts (MoE) have become increasingly common. In these models, only a small number of experts are activated for each token, so routing massive numbers of tokens to the appropriate experts directly affects training throughput. In this article, “data selection” refers specifically to token routing and dispatch filtering in MoE training. It is not the same as general data cleaning or data sampling.

    1. Background

    For a long time, mainstream AI training ecosystems have been built around specific overseas GPUs and their closed-source software stacks. Hardware specifications for domestic compute platforms continue to improve, but their software ecosystems are relatively weak and often limit actual training efficiency. To migrate training code smoothly from mainstream GPUs to domestic NPUs, one team chose to start with infrastructure components and open-sourced a set of compute and communication components for domestic compute platforms. The data selection component is most closely tied to MoE training and is a key part of this effort.

    Directly porting code written for GPUs to an NPU usually does not exploit NPU performance. The component’s approach is to redesign the data distribution and selection logic at a low level while maintaining interface correspondence with existing GPU open-source components, thereby reducing migration cost.

    2. Architecture Differences and Porting Points

    GPUs and NPUs use different compute models, so these differences need to be understood before porting. The table below lists common comparison dimensions. For specific parameters, refer to the target hardware’s official documentation.

    Dimension General-purpose GPU (SIMT-based) Domestic NPU (Cube-based compute array)
    Compute model Many threads execute the same instruction in parallel Matrix compute units and vector units work in coordination
    Memory hierarchy Registers, shared memory, device memory On-chip buffers, unified cache, device memory (naming varies by vendor)
    Data layout Common layouts are typically used Data often needs to be reordered to meet alignment requirements of compute units
    Porting action Existing operator libraries can often be reused directly Rewrite or replace operators with irregular memory access; adjust data layout

    Token selection involves many conditional checks and irregular data movement, which can easily become a performance bottleneck on NPUs. The component therefore rearranges data load and store formats at a low level so that memory access is as close to contiguous access as possible, reducing data movement overhead.

    The component is described as using a “high-level language compiler tool” for operator generation and optimization, but the tool name, version, compiler options, and supported NPU model range are not specified. Before porting, confirm these details in the component documentation. Without them, the porting steps cannot be reproduced, and it is impossible to determine whether compiler optimizations for the selection logic are effective.

    3. Coordinating with Matrix Compute, Communication, and Cache Operators

    1. Coordination with matrix compute libraries: Selected data blocks need to be sent directly to expert networks for matrix multiplication. The component outputs aligned data blocks, which can reduce extra memory copies and format conversions. During integration, confirm that input alignment requirements match the matrix compute library version.

    2. Coordination with distributed communication libraries: During cross-node routing, selection results need to be sent over the network to other devices. The component provides asynchronous communication interfaces to overlap compute and communication as much as possible. Whether overlap is actually achieved depends on whether the communication library supports asynchronous send and receive. Use profiling tools to confirm this.

    3. Coordination with cache processing operators: When processing long sequences and KV cache, the selection process calls cache operators to look up historical information. In long-context training, the memory access pattern in this step can significantly affect overall efficiency.

    4. 128-Card Supernode Scenario

    The development team and a hardware vendor conducted joint validation on a 128-card supernode. At large scale, routing requests are highly concurrent, and the inter-chip interconnect network can easily become congested. The component uses three mechanisms for this scenario:

    1. Topology-aware routing: Routing and selection are prioritized within the same supernode to reduce cross-node data transfer.
    2. Communication and compute overlap: While sending the selection results of the previous batch, the component computes the selection for the current batch to reduce waiting time.
    3. Adaptive flow control: When routing traffic bursts occur, the send rate is adjusted dynamically to reduce the risk of training stalls caused by congestion.

    The source material states that these optimizations improved results in several key tests, but it does not provide test conditions, baseline versions, or measurement methodology. Readers should not treat such numbers as general conclusions. To evaluate the effect, measure on your own cluster: under the same model, batch size, and sequence length, compare per-step latency and communication share before and after migration.

    5. General Scheduling Pseudocode

    The pseudocode below shows how compute and communication are organized. It is for illustration only and is not directly runnable.

    1. # Pseudocode: for illustration only, not directly runnable
    2. def run_data_select_step(token_batch, router_weights, device_mesh):
    3. # 1. Compute routing decisions to determine which expert each token is sent to
    4. routing_decisions = compute_routing(router_weights, token_batch)
    5. # 2. Select and pack locally, calling compiler-generated optimized operators
    6. packed_data = local_select_and_pack(token_batch, routing_decisions)
    7. # 3. Asynchronously send packed data to target devices
    8. comm_handle = device_mesh.async_send(packed_data, routing_decisions)
    9. # 4. Simultaneously receive data sent from other devices
    10. received_data = device_mesh.async_recv()
    11. # 5. Wait for communication to complete
    12. comm_handle.wait()
    13. processed_tokens = concatenate_and_unpack(received_data)
    14. # 6. Pass to the matrix compute library for expert forward computation
    15. return matrix_multiply_library.forward(processed_tokens)

    To make this logic actually run, at least the following prerequisites need to be addressed: the initialization method and topology parameters of device_mesh, the size of communication buffers, version matching between operator libraries and communication libraries, and exception handling and timeout retry logic. Synchronization semantics also need to be confirmed: after async_recv and before wait, can the receive buffer be read?

    6. Common Issues and Precautions

    What should be changed first? It is advisable to ensure the correctness of selection and packing results before optimizing performance. Use a small-scale model and a fixed random seed to compare whether routing results are consistent before and after migration.

    How should communication buffers be sized? If the buffer is too small, waiting will occur frequently; if it is too large, it will consume device memory. Usually, start with a small value that works, then adjust gradually based on communication time and memory headroom.

    How can you tell whether the bottleneck is selection or communication? Use profiling tools to separately measure selection operator time, communication wait time, and matrix compute time. If communication wait accounts for a high share, check topology and concurrency settings first. If selection operator time is high, check the memory access layout first.

    What about device memory fragmentation? Frequent packing can cause memory fragmentation. It is recommended to monitor the fragmentation rate and set a fallback strategy for memory allocation, such as a preallocated fixed-size buffer pool.

    Conclusion

    Data selection is a critical part of MoE training throughput. Components of this kind on domestic NPUs provide a reference approach for migration and adaptation: reorder data layouts, overlap compute and communication, and use topology for routing. However, the performance numbers in the source material lack test conditions, and details about the compiler tool and versions are incomplete. Before adoption, consult the official documentation, perform measurements on your own model and cluster, and then decide how much to invest.