Files
project_6/upstream_ref/xllm/docs/zh/features/groupgemm.md
EX Engine 002f9879b2 ref(upstream): FULL TREE — Deep-Spark xllm (1470) + ds_vllm csrc/models (703)
Replaces cherry-picked upstream_ref with complete source trees.

xllm/ — Iluvatar official C++ inference engine (15MB, 1470 files)
  Complete: kernels → layers → models → runtime → scheduler → api
  Excluded: .git, binary images, third_party submodule checkouts

ds_vllm/ — Iluvatar official vllm fork (8MB, 703 files)
  Included: csrc/ (ALL CUDA kernels), fused_moe/, qwen3_5 model, _custom_ops
  Excluded: tests, benchmarks, docs, examples (not needed for reference)

Critical call chains now fully traceable:
  MoE: moe_topk_softmax_kernels.cuh → ixformer.h → fused_moe.cpp → layer
  GDN: qwen3_gated_delta_net_base.cpp → qwen3_5_gated_delta_net.cpp
  Attention: ixformer.h → xllm_paged_attention → attention.cpp
2026-08-10 02:54:03 +00:00

1.8 KiB
Raw Blame History

GroupGEMM算子优化

背景

混合专家(Mixture of Experts, MoE)架构已成为扩展大规模语言模型的重要范式其核心思想是将输入token动态路由至不同的专家子网络进行处理。在推理过程中GroupGEMM算子是MoE架构的关键计算单元负责高效执行多个专家矩阵乘法的并行计算且在整个推理耗时中占据主导地位。

功能介绍

结合当前GroupGEMM的性能瓶颈为I/O受限提出了一种优化方案通过索引重排替代数据拷贝取消了对token向量的多次复制改为维护专家分配的索引表。通过该行号索引直接将token映射到相应的专家计算单元并将token的分配调度与矩阵乘法融合为一个单一的kernel。

用户接口

算子直调API

aclnnStatus aclnnIndexGroupMatmulGetWorkspaceSize(
    const aclTensorList *x,
    const aclTensorList *weight,
    const aclTensorList *scale,
    const aclTensorList *perTokenScale,
    const aclTensor *groupList,
    const aclTensorList *out,
    uint64_t *workspaceSize,
    aclOpExecutor **executor);

aclnnStatus aclnnIndexGroupMatmul(
    void *workspace,
    uint64_t workspaceSize,
    aclOpExecutor *executor,
    aclrtStream stream);
  • x: 输入的张量列表,包含待处理的数据。
  • weight: 权重张量,包含模型的参数。
  • scale: 缩放因子,用于调整输入张量的值。
  • perTokenScale:每个token的缩放因子用于动态调整。
  • groupList: 专家组列表,指示哪些专家参与计算。
  • out: 输出张量列表,存储计算结果。

性能效果

groupmatmul

  • 优化后的GroupMatmul算子在计算时间上表现出明显的优势尤其是在k为128m为64情况下如图所示优化后算子计算延时 减少50%