[KMCompiler] [ttx/npu] add DeepSeek-V4 operator moe_gating_topk_hash - #418
[KMCompiler] [ttx/npu] add DeepSeek-V4 operator moe_gating_topk_hash#418YangLong114514 wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the MojoMoEGatingTopKHash operator and its NPU-specific Triton backend implementation TTXMoEGatingTopKHash to support hash-based MoE gating for DeepSeek-V4 routing, complete with accuracy tests and performance benchmarks. The review feedback suggests key optimizations and stability enhancements, such as utilizing propagate_nan=tl.PropagateNan.ALL in tl.max to align with NPU hardware behavior, masking logits before exponentiation to avoid overflow, hoisting tle.dsa.alloc out of the loop to eliminate allocation overhead, and adopting F.softplus in the PyTorch reference implementation for better numerical stability.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Description
Add a TTX Triton implementation of
MojoMoEGatingTopKHashfor DeepSeek-V4 Hash-MoE routing on Ascend 910B.The implementation uses a TLE DSA fast path when
triton.experimental.tleis available and falls back to standard Triton otherwise.Changes
MojoMoEGatingTopKHashcore operator and Torch reference implementation.sigmoid/sqrt_softpluswithout_flag=False.tle.dsa.copyGM-to-UB DMA and UB-sidetl.gather.norm_outallocation and writeback on the optimized path.Performance
Test environment: Ascend 910B, TTX Triton backend,
bfloat16.V4-Flash
Configuration:
256 experts,k=6,routed_scaling_factor=1.5,sqrt_softplus.[1, 256][16, 256][64, 256][128, 256][256, 256][512, 256][1024, 256][4096, 256][8192, 256]V4-Pro
Configuration:
384 experts,k=6,routed_scaling_factor=2.5,sqrt_softplus.[1, 384][16, 384][64, 384][128, 384][256, 384][512, 384][1024, 384][4096, 384][8192, 384]Accuracy Test
All 37 accuracy test cases passed with
mixed_tol=True.Coverage includes:
float32,float16,bfloat16softmax,sigmoid,sqrt_softplus64,128,256,384,5121,4,6,8,64out_flag:TrueandFalse0.5,1.0,2.5