ops 包入口(54 行)。register_dummy_fusion_op 注册 dummyFusionOp 占位融合算子(供 torch.compile 融合体系挂接),是自定义算子注册体系的组成部分。
类: 无
func__init__[2行] 初始化类实例(绑定配置、参数、模块)
funcregister_dummy_fusion_op[9行] 注册 dummy fusion op(用于占位)
(已列出全部 2 个函数)
激活函数算子族(86 行)。为 NPU 实现的 CustomOp:AscendQuickGELU(QuickGELU)、AscendSiluAndMul(Silu×门控乘,NPU 融合实现)、AscendSiluAndMulWithClamp(带 clamp 的变体)、AscendSwigluOAIAndMul(OAI 风格 SwiGLU)、AscendSwigluStepAndMul(SwigluStep,带 limit 截断),均通过 forward_oot 走 NPU 算子路径。
类: AscendQuickGELU, AscendSiluAndMul, AscendSiluAndMulWithClamp
funcforward_oot[7行] out-of-tree NPU forward 实现
funcswiglu_oai_forward[8行] OAI 版 SwiGLU 前向
func__init__[2行] 初始化类实例(绑定配置、参数、模块)
funcswiglustep_forward[24行] Step 版 SwiGLU 前向
(已列出全部 4 个函数)
ops\bailing_moe_linear_attn.py
查看源码BailingMoE 线性注意力的 NPU 友好替换(169 行)。AscendBailingMoELinearAttention 作为上游类的 drop-in 替换:_prefill_and_mix_infer 处理 prefill 与混合推理、_decode_infer 处理 decode、_forward 分发,配合 Triton lightning attention kernel 在 NPU 上执行。
类: AscendBailingMoELinearAttention
func_prefill_and_mix_infer[14行] prefill 与混合推理入口
func_decode_infer[16行] decode 推理入口
func_forward[86行] 内部前向实现
(已列出全部 3 个函数)
3D 卷积层适配(26 行)。AscendConv3dLayer 用 forward_oot 把 vLLM 的 Conv3dLayer(视觉编码器用)映射到 NPU 卷积实现。
类: AscendConv3dLayer
funcforward_oot[3行] out-of-tree NPU forward 实现
(已列出全部 1 个函数)
Vector/Cube 分离线性层(145 行)。CVLinearWrapper 把一个普通 Linear 拆成两段:quantize 段(Vector 单元做量化)+ matmul 段(Cube 单元做矩阵乘),用于 W8A8 动态量化场景的算力单元优化;自动检测量化方式(_detect_w8a8_dynamic)与通信方式(_detect_communication),属性转发保持与原 Linear 兼容。
类: 无
func__init__[12行] 初始化类实例(绑定配置、参数、模块)
func_detect_w8a8_dynamic[9行] 检测是否 w8a8 dynamic 量化
func_detect_communication[19行] 检测通信方式(allgather/all2all)
funcquantize[19行] Execute only the quantization step (Vector operator).
funcmatmul[36行] Execute only the matrix multiplication step (Cube operator).
funcforward[4行] attention 前向入口
funcweight[2行] 权重属性
func__getattr__[3行] Delegate undefined attributes to the inner linear object
(已列出全部 8 个函数)
DeepSeek 稀疏注意力算子入口(266 行)。dsa_forward 注册为自定义算子(带 fake 实现)供 torch.compile 切图;AscendDeepseekSparseAttention 组装 SFA V2 所需模块(DSAModules)并执行前向;_build_kv_cache 构建 impl.forward 需要的 6 元组 KV cache、unfold_kvcache 展开缓存视图。
类: AscendDeepseekSparseAttention
func__init__[90行] 初始化类实例(绑定配置、参数、模块)
funcforward[18行] attention 前向入口
funcdsa_forward[19行] DSA NPU 前向实现
funcdsa_forward_fake[6行] DSA NPU forward 的 meta/fake 实现
func_build_kv_cache[53行] Construct the 6-tuple KV cache used by impl.forward().
funcunfold_kvcache[4行] 将 MLA KV cache 拆分为 kc 和 kpe
(已列出全部 6 个函数)
Gated DeltaNet(GDN)注意力算子(605 行)。AscendGatedDeltaNetAttention 实现门控增量线性注意力:_probe_fused_chunk 探测融合 chunk kernel 可用性、_chunk_gated_delta_rule_fused 融合 chunk 计算、_split_ba_for_tp 做 TP 切分、get_state_shape 声明状态形状、_warmup_prefill_kernels(含 v0202 变体)预热 prefill kernel、_forward_core 主计算。
类: AscendGatedDeltaNetAttention
func_probe_fused_chunk[46行] 探测 CANN fused chunk 可用性
func_chunk_gated_delta_rule_fused[55行] fused chunk 模式 gated delta rule
func_split_ba_for_tp[4行] 为 TP 切分 BA(gated delta rule 中间变量)
funcget_state_shape[12行] 取得 SSM 状态张量形状
func_warmup_prefill_kernels[2行] warmup prefill 内核
func_warmup_prefill_kernels_v0202[2行] warmup prefill 内核(v0.20.2)
funcget_attn_backend[2行] 根据 vllm_config 返回 attention backend 类
funcforward[81行] attention 前向入口
func_forward_core[343行] Core attention computation (called by custom op).
(已列出全部 9 个函数)
ops\gdn_attn_builder.py
查看源码GDN 注意力元数据构建器(923 行)。AscendGDNAttentionMetadataBuilder 为 GDN 构建各类元数据:chunked prefill(GDNChunkedPrefillMetadata)、causal conv1d(普通/投机两种)、prefill/decode/spec decode 元数据;处理细节:_stable_argsort_for_npu NPU 友好稳定排序、_treat_single_token_prefills_with_state_as_decodes 把带状态的单 token prefill 按 decode 处理、_compact_empty_segments 丢弃零长段使 AscendC fwd_h/fwd_o 索引对齐、_pad_non_spec_decode_graph_inputs/_reset_spec_decode_graph_inputs 图捕获输入管理;AscendGDNAttentionBackend 提供 builder 类。
类: AscendGDNAttentionMetadataBuilder, AscendGDNAttentionBackend
func_stable_argsort_for_npu[4行] NPU 友好的稳定 argsort
func_treat_single_token_prefills_with_state_as_decodes[24行] Use decode metadata for one-token stateful prompt chunks.
func_build_actual_seq_lengths[15行]
func_compact_empty_segments[25行] Drop zero-length segments so AscendC fwd_h/fwd_o indexing lines up.
func_build_non_spec_chunked_prefill_metadata[49行]
func__init__[56行] 初始化类实例(绑定配置、参数、模块)
func_init_reorder_batch_threshold[22行]
func_copy_sequence_indices_to_device[23行]
func_pad_non_spec_decode_graph_inputs[31行] Refresh fixed buffers consumed by a non-spec decode graph.
func_reset_spec_decode_graph_inputs[6行] Make a captured speculative branch a no-op for this replay.
func_attach_non_spec_prefill_metadata[36行]
func_attach_spec_decode_metadata[35行]
func_attach_non_spec_decode_metadata[34行]
func_fold_spec_sized_prefill_chunks_into_spec[35行] Advance stateful spec-width prompt chunks through live spec inputs.
funcbuild[368行] 构造 attention metadata
func_build_prefill_has_initial_state_and_causal_conv1d_meta[36行]
funcget_builder_cls[2行] 返回 attention metadata builder 类
(已列出全部 17 个函数)
Kimi K3 KDA(knee delta attention)Ascend 后端(544 行)。AscendKimiK3DeltaAttention 用 AscendC prefill 与 recurrent kernel 实现 KDA:_run_causal_conv1d/_pack_conv_weights 因果卷积、_run_recurrent 递归路径、_run_prefill chunk 路径;_prepare_beta 把 vLLM 0.27 的 packed beta 转成 AscendC 契约格式;_zero_padded_output/_zero_padded_recurrent_output 清除图填充行。
类: AscendKimiK3DeltaAttention
func_zero_padded_output[12行] Clear graph-padding rows using a device-side live-token count.
func_zero_padded_recurrent_output[6行] Clear graph-padding rows skipped by recurrent KDA.
func_prepare_beta[6行] Convert vLLM 0.27's packed raw beta to the AscendC contract.
func__init__[71行] 初始化类实例(绑定配置、参数、模块)
funcprocess_weights_and_pack[4行]
funcget_attn_backend[2行] 根据 vllm_config 返回 attention backend 类
funcforward[37行] attention 前向入口
func_run_causal_conv1d[29行]
func_pack_conv_weights[16行]
func_run_recurrent[33行]
func_run_prefill[53行]
func_forward[224行] 内部前向实现
(已列出全部 12 个函数)
归一化算子族(215 行)。AscendRMSNorm(含 bias 权重加载 _bias_weight_loader)、AscendGemmaRMSNorm(Gemma 风格)、LayerNormFn(通用 LayerNorm)、AscendRMSNormGated(门控 RMSNorm)、AscendFusedRMSNormGated(在上游 FLA CustomOp 边界使用 Ascend 融合 kernel),全部走 NPU 融合算子路径。
类: AscendRMSNorm, AscendGemmaRMSNorm, LayerNormFn, AscendRMSNormGated, AscendFusedRMSNormGated
func__init__[32行] 初始化类实例(绑定配置、参数、模块)
func_bias_weight_loader[13行]
funcforward_oot[3行] out-of-tree NPU forward 实现
funcforward[44行] attention 前向入口
funcreset_parameters[2行]
(已列出全部 5 个函数)
并行线性层族(585 行)。AscendUnquantizedLinearMethod 非量化线性方法(process_weights_after_loading 做 NZ 格式转换 _should_keep_nd_for_compatibility_weight、apply 调 unquantized_gemm 自定义算子);层实现:AscendQKVParallelLinear(QKV 融合列并行)、AscendMergedColumnParallelLinear(多列打包)、AscendColumnParallelLinear/AscendRowParallelLinear(列/行并行)、AscendReplicatedLinear(副本);各层 forward 按通信组与量化方式选择最优路径(支持 TP 切分、all-reduce/reduce-scatter、custom op 注册)。
类: AscendUnquantizedLinearMethod, AscendLinearBase, AscendQKVParallelLinear, AscendMergedColumnParallelLinear, AscendRowParallelLinear, AscendColumnParallelLinear, AscendReplicatedLinear
funcunquantized_gemm[6行] 非量化 GEMM:F.linear(x, weight, bias)
funcunquantized_gemm_fake[7行] unquantized_gemm 的 fake 实现(用于 meta tensor)
func_should_keep_nd_for_compatibility_weight[6行] 判断是否应保持 ND layout(兼容权重)
funcprocess_weights_after_loading[13行] 权重加载后的后处理(如 layout cast、NZ 转换)
funcapply[7行] 对输入张量应用 Linear 计算
func__init__[58行] 初始化类实例(绑定配置、参数、模块)
funcforward[8行] attention 前向入口
funcweight_loader[41行]
(已列出全部 8 个函数)
线性层并行算子定制(387 行)。CustomLinearOp 及其派生(CustomColumnParallelOp/CustomRowParallelOp/CustomReplicatedOp)把线性层的通信与计算封装为可替换算子:comm_group 按层前缀选通信组、apply_impl 定制前向;专用变体:MLPColumnParallelOp/MLPRowParallelOp(MoE MLP 共享专家)、DSV4OProjColumn/RowParallelOp(DSV4 o_proj)、OProjRowParallelOp、ShardedCPColumnParallelOp(CP 分片);_is_shared_expert_layer 判断共享专家层、get_parallel_op/get_replicated_op 按前缀与层类型返回对应算子、is_moe_layer 判断 MoE 层。
类: CustomColumnParallelOp, CustomRowParallelOp, CustomReplicatedOp, MLPColumnParallelOp, MLPRowParallelOp, DSV4OProjColumnParallelOp, DSV4OProjRowParallelOp, OProjRowParallelOp, ShardedCPColumnParallelOp
func__init__[2行] 初始化类实例(绑定配置、参数、模块)
funccomm_group[3行]
functp_rank[2行]
functp_size[2行]
funcupdate_attrs[4行]
funcapply_impl[11行]
funcapply[6行] 对输入张量应用 Linear 计算
funcget_input_parallel[6行]
func_is_shared_expert_layer[2行]
func_get_column_parallel_op[10行]
func_get_row_parallel_op[8行]
funcget_parallel_op[37行]
funcget_replicated_op[6行] 按 layer 特征选择合适的复制 op 类
funcis_moe_layer[20行]
funcget_moe_params[9行]
(已列出全部 15 个函数)
MLA 算子入口(199 行)。mla_forward 注册为自定义算子(带 fake);AscendMultiHeadLatentAttention 组织 MLA 层前向;IndexerWrapper 包装 DeepSeek V3.2 的 lightning indexer 供注意力层调用。
类: IndexerWrapper, AscendMultiHeadLatentAttention
func__init__[85行] 初始化类实例(绑定配置、参数、模块)
funcforward[15行] attention 前向入口
funcwrapped_process_weights[6行]
funcmla_forward[14行]
funcmla_forward_fake[6行]
(已列出全部 5 个函数)
ops\mm_encoder_attention.py
查看源码多模态编码器注意力(352 行)。AscendMMEncoderAttention 实现上游 MMEncoderAttention 的 Ascend 版:_reshape_qkv_to_3d 三维重排、_maybe_pad_qkv 填充、_maybe_compute_cu_seqlens 计算变长序列偏移、_run_vit_fia 走 ViT FIA 融合推理注意力;两条前向路径:_forward_eager_fia(eager)与 _forward_capture_fia(ACL graph 捕获),_maybe_unpad_output/_restore_batch_output 恢复输出布局。
类: AscendMMEncoderAttention
func__init__[27行] 初始化类实例(绑定配置、参数、模块)
func_reshape_qkv_to_3d[23行] Reshape query, key, value to 3D tensors:
func_maybe_pad_qkv[14行]
func_maybe_compute_cu_seqlens[18行]
func_maybe_unpad_output[7行]
func_restore_batch_layout[10行]
func_run_vit_fia[42行]
func_forward_eager_fia[26行]
func_forward_capture_fia[92行]
funcforward_oot[35行] out-of-tree NPU forward 实现
(已列出全部 10 个函数)
Qwen2 定制解码器(356 行)。AscendCustomQwen2Decoder 构建优化版定制模型(_create_optimized_custom_model);AscendQwen2Model/AscendQwen2DecoderLayer/AscendQwen2Attention/AscendQwen2RMSNorm 为全套 NPU 化组件;optimized_apply_rotary_pos_emb 为优化的 RoPE 应用。该文件是早期自研解码器实现(vllm-ascend 项目历史代码)。
类: AscendCustomQwen2Decoder, CustomQwen2ModelInner, AscendQwen2Model, AscendQwen2DecoderLayer, AscendQwen2Attention, AscendQwen2RMSNorm
func__init__[4行] 初始化类实例(绑定配置、参数、模块)
func_create_optimized_custom_model[93行]
funcforward[32行] attention 前向入口
func_create_npu_optimized_mask[45行] 4D Mask generation optimized for NPU
func_create_standard_causal_mask[10行] Standard causal mask (when token_type_ids is None)
funcoptimized_apply_rotary_pos_emb[6行]
(已列出全部 6 个函数)
ops\register_custom_ops.py
查看源码自定义算子注册中心(213 行)。注册一批 torch 自定义算子(带 fake 实现):EP 通信算子 _maybe_all_gather_and_maybe_unpad(EP all-gather + 按 DP 分布 unpad)与 _maybe_pad_and_reduce(pad + reduce-scatter)、_quantize 动态量化、_rope_forward_oot、_muls_add;_get_ep_local_sizes/_pad_to_ep_local_size 保证 EP all-gather 输入各 rank 第一维一致。这些算子是 torch.compile 切图与融合的基本单元。
类: 无
func_get_ep_local_sizes[13行] 返回 SP token layout(仅 MoE runner 安装时)
func_pad_to_ep_local_size[9行] 把 EP all-gather 输入 pad 到相同第一维
func_maybe_all_gather_and_maybe_unpad_impl[30行] EP all-gather + 按 DP token 分布 unpad
func_maybe_pad_and_reduce_impl[36行] 仅用于 EP 通信场景:按 DP token 分布 pad 后做 EP reduce_scatter。
func_maybe_all_gather_and_maybe_unpad_fake[8行]
func_maybe_pad_and_reduce_fake[12行]
func_quantize_impl[4行]
func_quantize_impl_fake[4行]
func_rope_forward_oot_impl_fake[10行]
func_muls_add_impl_fake[6行]
(已列出全部 10 个函数)
ops\rel_pos_attention.py
查看源码相对位置注意力(68 行)。AscendRelPosAttention 实现带相对位置编码的注意力前向(用于特定模型架构的小众注意力形态)。
类: AscendRelPosAttention
func__init__[19行] 初始化类实例(绑定配置、参数、模块)
funcforward[42行] attention 前向入口
(已列出全部 2 个函数)
DSV4 专用 RoPE(311 行)。ComplexExpRotaryEmbedding 复指数旋转嵌入(precompute_freqs_cis 预计算频率表);get_cos_and_sin_dsa 按位置取 cos/sin(支持缓存与 draft 索引)、get_full_cos_and_sin_dsa 取整组预计算缓存;RopeGlobalState/RopeDataProxy 管理全局 RoPE 数据与填充代理。
类: ComplexExpRotaryEmbedding
func__init__[76行] 初始化类实例(绑定配置、参数、模块)
funcpad_to[19行] Return a new proxy whose underlying tensors are padded to ``target_len`` along ``dim``.
func__getitem__[32行]
funcget_cos_and_sin_dsa[55行] DSA 路径下按 positions 取 cos/sin
funcget_full_cos_and_sin_dsa[22行] Return the full precomputed RoPE cache for a registered DSA RoPE group.
funcprecompute_freqs_cis[47行]
funcyarn_find_correction_dim[7行]
funcyarn_find_correction_range[14行]
funcyarn_linear_ramp_mask[7行]
funcforward[18行] attention 前向入口
funcextra_repr[2行]
(已列出全部 11 个函数)
ops\rotary_embedding.py
查看源码RoPE 算子族(578 行)。AscendRotaryEmbedding/AscendYaRNRotaryEmbedding/AscendDeepseekScalingRotaryEmbedding(YaRN 缩放,_yarn_* 系列计算 mscale/ramp/校正维度)/AscendMRotaryEmbedding(多模态 mrope,支持 Triton 路径)/AscendApplyRotaryEmb;缓存管理:set_cos_and_sin 预计算解码期 cos/sin(按最大请求数与每请求 token 数)、get_cos_and_sin_mla 按位置取用(带缓存)、update_cos_sin/get_cos_and_sin_slice 滑动更新;rope_forward_oot 为统一前向入口(注册自定义算子)。
类: AscendRotaryEmbedding, AscendYaRNRotaryEmbedding, AscendDeepseekScalingRotaryEmbedding, AscendMRotaryEmbedding, AscendApplyRotaryEmb
funcset_cos_and_sin[25行] 按模型需要分配并初始化 cos/sin 缓存
funcget_cos_and_sin_mla[13行] MLA 路径下按 positions 取 cos/sin
func_record_cos_sin_cache[5行]
func_record_cos_and_sin_cache[5行]
func_record_cos_and_sin_cache_interleaved[9行]
funcupdate_cos_sin[18行] 更新 rotary embedding 的 cos/sin 缓存
funcget_cos_and_sin_slice[2行]
funcrope_forward_oot[39行]
func__init__[11行] 初始化类实例(绑定配置、参数、模块)
funcforward_oot[29行] out-of-tree NPU forward 实现
func_yarn_get_mscale[4行]
func_rotate_half[5行] Rotates half the hidden dims of the input.
func_yarn_linear_ramp_mask[7行]
func_yarn_find_correction_dim[5行]
func_yarn_find_correction_range[6行]
func_apply_rotary_pos_emb[45行] Applies Rotary Position Embedding to the query and key tensors.
func_set_cos_sin_cache[32行]
funcforward[18行] attention 前向入口
funcforward_triton[40行]
(已列出全部 19 个函数)
ops\vocab_parallel_embedding.py
查看源码词嵌入与输出头(411 行)。AscendVocabParallelEmbedding 注册为自定义算子:_mask_input_for_vocab_range 越界掩码、_forward_embed_tp 走 embedding TP 路径、_forward_origin 常规路径;AscendParallelLMHead 并行输出头;lmhead_all_to_all 做 lm-head TP 的 all-to-all(把 [N, V/P] 部分词表重分布为 [N/P, V] 全词表);AscendLogitsProcessor logits 处理器(_get_logits 分派 lmhead TP 路径 _get_logits_lmheadtp 或常规路径 _get_logits_normal,_apply_head 应用输出头)。
类: AscendVocabParallelEmbedding, AscendParallelLMHead, AscendLogitsProcessor
func__init__[38行] 初始化类实例(绑定配置、参数、模块)
func_mask_input_for_vocab_range[26行]
funcforward[5行] attention 前向入口
func_forward_embed_tp[58行]
func_forward_origin[29行]
funclmhead_all_to_all[41行] All-to-all for lm-head TP: redistribute `[N, V/P]` (all tokens, partial
func_apply_head[7行]
func_get_logits[10行]
func_get_logits_lmheadtp[20行]
func_get_logits_normal[19行]
(已列出全部 10 个函数)
ops\fused_moe\__init__.py
查看源码ops.fused_moe 子包标记。该包实现 MoE(专家混合)全链路:路由、token 分发、专家计算、通信策略与 EPLB。
类: 无
ops\fused_moe\eplb.py
查看源码EPLB 专家映射算子(138 行)。build_expert_replica_routing_table 构建逻辑专家→物理副本的周期路由表;map_to_physical 经路由表把逻辑专家 ID 映射为全局物理 ID;map_to_physical_and_record 在收集开启时同时记录负载(带 fake 实现供 torch.compile)。
类: 无
funcbuild_expert_replica_routing_table[25行] Build a rank-aware table for routing logical experts to replicas.
funcmap_to_physical[48行] Map logical expert IDs to global physical IDs through a periodic table.
funcmap_to_physical_and_record[33行] Map logical IDs and record load only while collection is enabled.
func_map_to_physical_and_record_fake[8行]
(已列出全部 4 个函数)
ops\fused_moe\force_eplb.py
查看源码强制 EPLB 路由(142 行)。build_force_eplb_topk 在 ACL graph 捕获前构建确定性路由表;get_force_eplb_topk 在策略启用时返回确定性轮询(round-robin)专家 ID(_build_round_robin_topk),用于 EPLB 重排期间的稳定路由测试。
类: 无
func_build_or_get_topk[35行]
funcbuild_force_eplb_topk[28行] Build force-EPLB tables before ACLGraph capture.
funcget_force_eplb_topk[17行] Return deterministic round-robin ids when the policy is enabled.
func_build_round_robin_topk[35行]
(已列出全部 4 个函数)
ops\fused_moe\fused_moe.py
查看源码MoE 运行器(336 行)。AscendMoERunner 驱动融合 MoE 执行:is_internal_router 判断内部路由、use_dp_chunking 判断 DP 分块、_fused_output_is_reduced 判断输出已归约、共享专家并行模式(_get_shared_expert_parallel_mode)、三级输出归约控制(_maybe_reduce_shared/routed/final_output)、set_lora_context。
类: AscendMoERunner
func__init__[59行] 初始化类实例(绑定配置、参数、模块)
funcis_internal_router[9行]
funcuse_dp_chunking[4行] Ascend uses its own forward_impl path, not the FlashInfer Cutlass
func_fused_output_is_reduced[12行]
func_get_shared_expert_parallel_mode[5行]
func_reduce_shared_output_if_needed[12行]
funclocal_num_experts[3行] Number of physical experts managed by this EPLB layer.
funcep_rank[2行]
func_maybe_reduce_shared_expert_output[11行]
func_maybe_reduce_routed_output_before_transform[17行]
func_maybe_reduce_final_output[16行]
funcset_lora_context[4行]
func_forward_impl[64行]
(已列出全部 13 个函数)
ops\fused_moe\gate_linear.py
查看源码MoE 门控线性层(63 行)。AscendGateLinear 替换 vLLM 的 GateLinear(路由打分入口),forward 走 NPU 优化路径。
类: AscendGateLinear
func__init__[19行] 初始化类实例(绑定配置、参数、模块)
funcforward[10行] attention 前向入口
(已列出全部 2 个函数)
ops\fused_moe\moe_comm_method.py
查看源码MoE 通信方法族(492 行)。MoECommMethod 基类定义 prepare/finalize/fused_experts 流程与 LoRA 上下文;实现按场景选择:AllGatherCommImpl(all-gather + reduce-scatter)、MC2CommImpl(华为 MC2 通信算子,pad_and_split_input_ids 做输入切分)、AlltoAllCommImpl(标准 all-to-all)、FusedMC2CommImpl(融合 MC2 + CANN megamoe:_init_mega_moe_symm_buffer 对称内存缓冲、_apply_cann_mega_moe 一体化执行);get_moe_comm_method/setup_moe_comm_method 管理全局选择;FusedExpertsResult 承载专家计算结果。
类: MoECommMethod, AllGatherCommImpl, MC2CommImpl, AlltoAllCommImpl, FusedMC2CommImpl
funcget_moe_comm_method[2行]
funcsetup_moe_comm_method[8行]
func__init__[14行] 初始化类实例(绑定配置、参数、模块)
funcset_lora_context[4行]
funcprepare[13行]
funcfinalize[8行]
funcfused_experts[45行]
func_apply_mlp[2行]
func_get_token_dispatcher[2行]
func_get_prepare_finalize[2行]
funcpad_and_split_input_ids[2行]
func_init_mega_moe_symm_buffer[79行]
func_apply_cann_mega_moe[83行]
functo_list[2行]
(已列出全部 14 个函数)
ops\fused_moe\moe_mlp.py
查看源码MoE MLP 计算核心(884 行)。quant_apply_mlp 量化路径(gmm 分组乘 + swiglu + 量化,支持 group_list)、unquant_apply_mlp 非量化路径(gmm + 激活 + bias);融合判定:_custom_gmm_swiglu_enabled/_gmm_swiglu_quant_fusion_enabled 决定是否走 gmm+swiglu(+quant) 融合算子;scale 准备(_prepare_dequant_swiglu_weight_scale/_prepare_swigluoai_grouped_matmul_scales);激活变体:_apply_situ/_apply_clipped_swiglu/_swiglu_oai_dynamic_mx_quant;cumsum_group_list 把专家分组列表转成累计形式(不同 AscendC 算子契约互转);unified_apply_mlp 统一入口。
类: 无
func_custom_gmm_swiglu_enabled[3行]
func_gmm_swiglu_quant_fusion_enabled[6行]
funccumsum_group_list[30行]
func_require_single_tensor_for_swiglu_quant[8行]
func_prepare_dequant_swiglu_weight_scale[18行]
func_prepare_swigluoai_grouped_matmul_scales[5行]
func_apply_situ[14行] Match SituAndMul.forward_native without constructing a CustomOp in forward.
func_apply_clipped_swiglu[23行]
func_swiglu_oai_dynamic_mx_quant[24行]
funcquant_apply_mlp[457行]
funcunquant_apply_mlp[123行]
funcunified_apply_mlp[111行] Unified MoE MLP entry.
(已列出全部 12 个函数)
ops\fused_moe\moe_utils.py
查看源码MoE 通信与 CANN 工具(169 行)。async_all_to_all 异步 all-to-all(带事件)、gather_from_sequence_parallel_region 序列并行收集(AG 前向/RS 反向)、_gather_along_first_dim 沿首维拼接;load_cann_mega_moe_ops 加载 CANN megamoe 算子(_get_cann_mega_moe_quant_settings 量化设置);get_moe_num_logical_experts 计算逻辑专家数(扣冗余与共享专家);enable_fusion_gmmswigluquant 查询 gmm+swiglu+quant 融合开关。
类: 无
funcasync_all_to_all[37行]
func_gather_along_first_dim[31行] Gather tensors and concatenate along the first dimension.
funcgather_from_sequence_parallel_region[7行] Wrapper for autograd function: forward: AG, backward: RS
funcload_cann_mega_moe_ops[5行]
func_get_cann_mega_moe_quant_settings[24行]
funcget_moe_num_logical_experts[12行]
funcenable_fusion_gmmswigluquant[5行]
(已列出全部 7 个函数)
ops\fused_moe\prepare_finalize.py
查看源码MoE 通信策略实现(573 行)。PrepareAndFinalize 抽象基类定义 prepare/finalize 两阶段;三种策略:PrepareAndFinalizeWithAll2All(all-to-all 切分,含 _restore_tp_across_dp 跨 DP 恢复 TP)、PrepareAndFinalizeWithMC2(MC2,基于 all2all 加华为通信算子)、PrepareAndFinalizeWithAllGather(all-gather + reduce-scatter,支持 EP 序列并行 _use_ep_sequence_parallel,按 EP/DP 组分别处理 prepare/finalize 与输入填充)。
类: PrepareAndFinalize, PrepareAndFinalizeWithAll2All, PrepareAndFinalizeWithMC2, PrepareAndFinalizeWithAllGather
func__init__[3行] 初始化类实例(绑定配置、参数、模块)
funcset_lora_context[2行]
funcprepare[18行] Preparation steps:
funcfinalize[17行] Finalization steps:
func_restore_tp_across_dp[8行] Restore original TP configuration.
funcpad_and_split_input_ids[22行]
func_use_ep_sequence_parallel[8行] Whether MoE itself must use the EP sequence-parallel path.
func_prepare_with_ep_group[54行]
func_prepare_with_dp_group[54行] Preparation steps:
funcall_gather_input_id_with_dp_group[9行]
func_finalize_with_ep_group[17行] Argument `reduce_results` is not needed in this func. Given sequence parallelism is enabled:
func_finalize_with_dp_group[18行] Finalization steps:
(已列出全部 12 个函数)
ops\fused_moe\routed_experts.py
查看源码路由专家容器(593 行)。AscendRoutedExperts 管理 MoE 专家权重全生命周期:get_expert_weights 获取权重、EPLB 初始化(init_eplb/make_eplb_placement_config)、专家映射三件套(ascend_expert_map 构建映射/update_expert_map 更新/get_log2phy_map 逻辑到物理映射)、量化方式选择(_get_quant_method/quant_type)、权重视图(get_eplb_weight_views/EplbExpertTensorList 兼容上游 EPLB 权重契约)、forward_impl 执行;AscendUnquantizedFusedMoEMethod 为非量化 MoE 方法(is_monolithic 判断单体执行、set_lora_context);use_multistage_eplb_load 判断是否按步保留专家负载向量。
类: AscendUnquantizedFusedMoEMethod, EplbExpertTensorList, AscendRoutedExperts
func__init__[38行] 初始化类实例(绑定配置、参数、模块)
funcset_lora_context[2行]
funcis_monolithic[2行]
funcmaybe_make_prepare_finalize[4行]
funcget_eplb_weight_views[7行]
funcprocess_weights_after_loading[31行] 权重加载后的后处理(如 layout cast、NZ 转换)
funcapply[70行] 对输入张量应用 Linear 计算
funcuse_multistage_eplb_load[3行] Whether EPLB should retain a separate expert-load vector per step.
funcmake_eplb_placement_config[7行] Build the minimal config view consumed by init_eplb_config.
funcshape[2行]
func__torch_function__[5行]
funcget_expert_weights[34行]
funcinit_eplb[86行]
func_promote_attr_to_buffer[7行] Move an existing tensor attribute onto a Level-2 restorable named buffer.
func_get_quant_method[4行]
funcget_eplb_parameter[3行] Return an expert parameter from the refactored weight owner.
funcascend_expert_map[5行] Return the global-to-local map used by Ascend MoE execution.
funcupdate_expert_map[7行] Update the upstream map or preserve the legacy Ascend update API.
funcget_log2phy_map[2行]
funcep_rank[2行]
... 还有 4 个函数
ops\fused_moe\shared_experts.py
查看源码共享专家执行器(418 行)。AscendSharedExperts 实现所有 token 共享的专家计算:part1/part2 两段 MLP、并行模式(SharedExpertParallelMode 决定激活与权重布局)、DP 本地输入准备与输出收尾(_prepare_local_dp_input/_finalize_local_dp_output)、SP 输入收集(_gather_sp_input)、pad + reduce-scatter(_pad_and_reduce_scatter)、prepare_input_before_routed_experts 在路由专家前预计算;FusedMoEEvents 携带执行事件。
类: SharedExpertParallelMode
func__init__[41行] 初始化类实例(绑定配置、参数、模块)
funcwrapped_process_weights[4行]
funcset_lora_context[2行]
funcvalidate_consistency[37行] Validate that split shared expert computation matches integrated computation.
funcpart1[3行]
funcpart2[9行]
funcparallel_mode[20行] Resolve the effective activation/weight layout for this forward.
func_prepare_local_dp_input[18行]
func_finalize_local_dp_output[10行]
func_gather_sp_input[10行] Gather SP-sharded activations to the full sequence via TP all-gather + unpad.
func_pad_and_reduce_scatter[15行] Pad the full output to a TP multiple, then reduce-scatter to the SP shard.
funcprepare_input_before_routed_experts[14行] Start the SP-only input all-gather on the shared-expert stream.
funcforward[158行] attention 前向入口
funcmaybe_wait_event[3行]
(已列出全部 14 个函数)
ops\fused_moe\token_dispatcher.py
查看源码MoE token 分发器族(719 行)。MoETokenDispatcher 基类定义 token_dispatch/token_combine;实现:TokenDispatcherWithMC2(MC2 分发,refresh_hccl_group 刷新组、get_dispatch_mc2_kwargs/get_combine_mc_kwargs 构造算子参数)、TokenDispatcherWithAllGather(all-gather 分发)、TokenDispatcherWithAll2AllV(all-to-all:_dispatch_preprocess/_preprocess/_dispatch_postprocess 与 combine 对应三段处理);_get_expert_token_nums_type 判断专家 token 数张量类型。
类: MoETokenDispatcher, TokenDispatcherWithMC2, TokenDispatcherWithAllGather, TokenDispatcherWithAll2AllV
func_get_expert_token_nums_type[6行]
func__init__[7行] 初始化类实例(绑定配置、参数、模块)
funcset_lora_context[2行]
funcep_group[3行] Get expert model parallel group.
funcep_rank[2行]
funcep_size[2行]
functoken_dispatch[83行]
functoken_combine[20行]
funcrefresh_hccl_group[6行] Refresh MC2 communicator metadata after HCCL groups are recreated.
funcget_dispatch_mc2_kwargs[73行]
funcget_combine_mc_kwargs[58行]
func_dispatch_preprocess[35行]
func_preprocess[44行]
func_dispatch_postprocess[38行]
func_combine_preprocess[8行]
func_combine_postprocess[14行]
(已列出全部 16 个函数)
ops\fused_moe\dataclass\__init__.py
查看源码fused_moe.dataclass 子包标记。该包定义 MoE 流水线的类型化数据结构。
类: 无
ops\fused_moe\dataclass\fused_experts.py
查看源码MoE 专家计算数据类(136 行)。MoEWeights 携带稠密/量化权重载荷;MoEFusedExpertsInput 为路由专家管线顶层输入;build_fused_experts_input 构建工厂函数。
类: 无
funcbuild_fused_experts_input[71行]
(已列出全部 1 个函数)
ops\fused_moe\dataclass\moe_mlp.py
查看源码MoE MLP 计算输入数据类(114 行)。MoEMlpComputeInput 描述一次 MLP 计算的全部输入;build_mlp_compute_input 构建工厂。
类: 无
funcbuild_mlp_compute_input[53行]
(已列出全部 1 个函数)
ops\fused_moe\dataclass\moe_quant.py
查看源码MoE 量化参数数据类(159 行)。MoEQuantParams 携带量化模式/后端覆盖/MXFP 叶配置,提供模式判断(is_quant/is_mxfp/is_w4a4_mxfp/is_int_quant/is_fp8/use_w4a8_per_channel_gmm_swiglu)与类型查询(get_dst_type/get_scale_type);MoEMxfpParams 为 MXFP 内部精度设置;build_quant_params/_build_mxfp_params 构建工厂。
类: 无
funcis_quant[2行]
funcis_mxfp[2行]
funcis_w4a4_mxfp[2行]
funcis_int_quant[2行]
funcis_fp8[2行]
funcuse_w4a8_per_channel_gmm_swiglu[2行]
funcdispatch_with_quant[9行]
funcget_dst_type[9行]
funcget_scale_type[7行]
func_build_mxfp_params[32行]
funcbuild_quant_params[23行]
(已列出全部 11 个函数)
ops\fused_moe\dataclass\prepare_finalize.py
查看源码MoE prepare 阶段输出数据类(30 行)。MoEPrepareOutput 承载 prepare 阶段的类型化输出。
类: 无
ops\fused_moe\dataclass\router_input.py
查看源码MoE 路由输入数据类(39 行)。MoeRouterInput 携带一次 MoE 调用的路由与分发侧输入。
类: 无
ops\fused_moe\dataclass\token_dispatcher.py
查看源码token 分发数据类(97 行)。MoEMC2CombineMetadata/MoEAllGatherCombineMetadata/MoEAllToAllCombineMetadata 三种 combine 元数据;MoETokenDispatchInput/MoETokenDispatchOutput 分发输入输出;build_token_dispatch_input 构建工厂。
类: MoETokenDispatchOutput
funcbuild_token_dispatch_input[11行]
(已列出全部 1 个函数)
ops\fused_moe\router\__init__.py
查看源码fused_moe.router 子包标记(9 行)。
类: 无
ops\fused_moe\router\fused_topk_router.py
查看源码融合 top-k 路由器(159 行)。AscendFusedTopKRouter 对接 Ascend 的专家选择算子(npu_moe_gating_top_k):is_fused_supported 判断融合支持、_compute_routing 执行路由计算(softmax + top-k + 归一化)。
类: AscendFusedTopKRouter
func__init__[34行] 初始化类实例(绑定配置、参数、模块)
funcis_fused_supported[17行]
func_compute_routing[76行]
(已列出全部 3 个函数)
ops\fused_moe\router\grouped_topk_router.py
查看源码分组 top-k 路由器(129 行)。AscendGroupedTopKRouter 用于 DeepSeek 等分组路由模型:routing_method_type 映射路由方法、_native_grouped_topk 原生分组 top-k、_renormalize_topk_weights 权重重归一化、_compute_routing 主计算。
类: AscendGroupedTopKRouter
func__init__[27行] 初始化类实例(绑定配置、参数、模块)
funcrouting_method_type[9行]
func_renormalize_topk_weights[7行]
func_native_grouped_topk[20行]
func_compute_routing[50行]
(已列出全部 5 个函数)
ops\fused_moe\router\router_factory.py
查看源码路由器工厂(114 行)。check_npu_moe_gating_top_k 校验当前配置可否走 NPU 门控 top-k 算子;create_ascend_fused_moe_router 按 top_k/分组/归一化配置创建对应的路由器实例。
类: 无
funccheck_npu_moe_gating_top_k[19行]
funccreate_ascend_fused_moe_router[79行]
(已列出全部 2 个函数)
ops\triton\__init__.py
查看源码ops.triton 子包标记。该包收录 NPU 上的 Triton kernel(Triton-Ascend 后端),覆盖激活、采样、FLA 线性注意力、KDA、Mamba、投机解码等。
类: 无
ops\triton\batch_memcpy.py
查看源码批量内存拷贝 Triton kernel(31 行)。batch_memcpy_kernel 按指针/大小数组批量拷贝多段内存,用于小段聚合拷贝场景。
类: 无
funcbatch_memcpy_kernel[22行]
(已列出全部 1 个函数)
ops\triton\bincount.py
查看源码token 计数 Triton kernel(149 行)。token_bin_counts_and_mask_kernel 按批次行统计 token 出现次数(bincount)并生成掩码;get_token_bin_counts_and_mask_triton 为包装入口,供采样惩罚计算使用。
类: 无
functoken_bin_counts_and_mask_kernel[48行] Count token occurrences per batch row.
funcget_token_bin_counts_and_mask_triton[61行] Triton-Ascend implementation of token bin counting.
(已列出全部 2 个函数)
ops\triton\compute_slot_mapping.py
查看源码slot mapping 计算 Triton kernel(84 行)。_compute_slot_mapping_kernel 按请求位置与块表计算每个 token 的 KV cache slot(query_start_loc + block_table 查表),_next_power_of_2 计算 kernel 块大小。
类: 无
func_next_power_of_2[2行]
func_compute_slot_mapping_kernel[73行]
(已列出全部 2 个函数)
DSA-CP 本地元数据 kernel(41 行)。build_local_metadata_triton 融合计算本地 token 元数据(local query_start_loc/seq_lens),供 DSA 上下文并行使用。
类: 无
funcbuild_local_metadata_triton[37行] Fused NPU kernel for local token metadata computation
(已列出全部 1 个函数)
EPLB 映射 Triton kernel(76 行)。map_to_physical_and_record_triton/_map_to_physical_and_record_kernel 在设备端完成逻辑→物理专家映射并按需记录负载(含 num_unpadded_tokens 处理),替代 torch 实现减少 host 同步。
类: 无
func_map_to_physical_and_record_kernel[37行]
funcmap_to_physical_and_record_triton[29行] Map logical IDs and optionally record physical-expert load.
(已列出全部 2 个函数)
ops\triton\fused_gdn_gating.py
查看源码GDN 门控融合 kernel(99 行)。fused_gdn_gating_patch 融合计算 Gated DeltaNet 的 beta/gating(A_log/a/b/dt_bias 参与),fused_gdn_gating_kernel 为实现 kernel。
类: 无
funcfused_gdn_gating_kernel[43行]
funcfused_gdn_gating_patch[41行]
(已列出全部 2 个函数)
ops\triton\layernorm_gated.py
查看源码门控 LayerNorm Triton kernel(168 行)。_layer_norm_fwd_1pass_kernel_npu 单遍 LayerNorm(带可选残差 Z 与 Mean 输出);layer_norm_fwd_npu 为包装入口。
类: 无
func_layer_norm_fwd_1pass_kernel_npu[85行]
funclayer_norm_fwd_npu[66行]
(已列出全部 2 个函数)
ops\triton\mul_add.py
查看源码乘加 Triton kernel(57 行)。muls_add_kernel/muls_add_triton 计算 x*scale+y(与 compilation passes 的 muls_add 融合配套的独立实现)。
类: 无
funcmuls_add_kernel[19行]
funcmuls_add_triton[29行]
(已列出全部 2 个函数)
ops\triton\muls_add.py
查看源码乘加 Triton kernel(57 行)。与 mul_add.py 内容相同的重复实现(muls_add_kernel/muls_add_triton),历史遗留副本。
类: 无
funcmuls_add_kernel[19行]
funcmuls_add_triton[29行]
(已列出全部 2 个函数)
ops\triton\penalty.py
查看源码采样惩罚 Triton kernel(162 行)。apply_all_penalties_kernel 一次性施加重复/频率/出现三类惩罚(就地修改 logits);apply_penalties_triton 组织输入(prompt/output 掩码与 bin 计数);_apply_all_penalties_triton 接受预计算计数的快速路径。
类: 无
funcapply_all_penalties_kernel[63行] Apply repetition, frequency, and presence penalties to logits in place.
funcapply_penalties_triton[28行] Apply penalties to logits in place. Same interface as
func_apply_all_penalties_triton[33行] Apply all penalties given precomputed bin counts and masks.
(已列出全部 3 个函数)
ops\triton\reject_sample.py
查看源码拒绝采样 Triton kernel 集(776 行)。覆盖投机解码验证采样的各分支:贪婪(rejection_greedy_sample_triton 及 spec_len_1 特例)、随机(rejection_random_sample_kernel 与 block verify 变体)、恢复 token 采样(sample_recovered_tokens_kernel);expand_triton 把接受位置扩展到输出序列;bonus_renew 更新 bonus token;cal_grid_and_block_size 计算 launch 配置。
类: 无
funccal_grid_and_block_size[9行]
funcrejection_greedy_sample_spec_len_1_triton[36行]
funcbonus_renew[9行]
funcrejection_greedy_sample_triton[77行]
funcrejection_random_sample_kernel[182行]
funcexpand_kernel[27行]
funcsample_recovered_tokens_kernel[125行]
funcrejection_greedy_sample_with_triton[44行]
funcexpand_triton[14行]
funcrejection_random_sample_block_verify_kernel[195行]
(已列出全部 10 个函数)
ops\triton\rms_norm.py
查看源码RMSNorm Triton kernel(71 行)。triton_rms_kernel 按行计算 RMS 归一化;triton_q_rms 对 Q 张量归一化(q/norm 前处理用)。
类: 无
functriton_rms_kernel[28行]
functriton_q_rms[32行]
(已列出全部 2 个函数)
RoPE Triton kernel(431 行)。_triton_rope 对 q/k 应用旋转嵌入(双输入)、_triton_rope_siso 单输入变体(qk 拼接);rope_forward_triton/rope_forward_triton_siso 为包装入口(支持 cos/sin 分离或 cos_sin_cache 合一)。
类: 无
func_triton_rope[154行] This triton kernel applies rotary embedding on q and k.
func_triton_rope_siso[73行]
funcrope_forward_triton[96行]
funcrope_forward_triton_siso[78行]
(已列出全部 4 个函数)
SFA DCP 融合通信 kernel(425 行)。pack_sfa_dcp_output_lse 把跨步 SFA 输出与 FP32 LSE 打包进一个 HCCL 载荷(_pack_sfa_dcp_output_lse_kernel);fused_sfa_dcp_lse_combine 解包并按 LSE 合并各 rank 输出(_fused_sfa_dcp_lse_combine_kernel);sfa_dcp_a2a_fused_combine 串联打包 + 一次 HCCL All2All + 融合 LSE 合并;sfa_dcp_a2a_fused 注册为自定义算子(带 fake),_validate_sfa_dcp_inputs/_lse_pack_dim 做校验与类型选择。
类: 无
func_pack_sfa_dcp_output_lse_kernel[91行]
func_fused_sfa_dcp_lse_combine_kernel[102行]
func_lse_pack_dim[6行]
func_validate_sfa_dcp_inputs[42行]
funcpack_sfa_dcp_output_lse[36行] Pack strided SFA output and FP32 LSE into one HCCL payload.
funcfused_sfa_dcp_lse_combine[49行] Unpack one HCCL payload and merge rank outputs using their LSE.
funcsfa_dcp_a2a_fused_combine[17行] Run stride-aware pack, one HCCL All2All, and fused LSE combine.
funcsfa_dcp_a2a_fused[25行] Custom-op entry point for fused SFA DCP output post-processing.
funcsfa_dcp_a2a_fused_fake[17行] Propagate output metadata for torch.compile without running HCCL.
(已列出全部 9 个函数)
ops\triton\sparse_index_remap.py
查看源码稀疏索引重映射 Triton kernel(182 行)。remap_sparse_indices_triton 把全局视图的 topk 索引重映射到 DCP 本地视图(DCP 场景);remap_sparse_indices_fused_kernel 融合重映射+按块紧凑+尾部预填,remap_sparse_indices_compact_gather_kernel 按块序聚拢到行首。
类: 无
funcremap_sparse_indices_fused_kernel[53行] Fused remap + per-chunk compaction + output tail pre-fill.
funcremap_sparse_indices_compact_gather_kernel[22行] Gather chunks to the row front in chunk order.
funcremap_sparse_indices_triton[76行] Triton replacement for the torch implementation in
(已列出全部 3 个函数)
ops\triton\triton_utils.py
查看源码Triton 工具(66 行)。_resolve_triton_ascend_op 解析 triton_ascend 算子;init_device_properties_triton 初始化设备属性;get_aicore_num/get_vectorcore_num 查询 AI Core/向量核数量(供 kernel 调优)。
类: 无
func_resolve_triton_ascend_op[17行]
funcinit_device_properties_triton[9行]
funcget_aicore_num[4行]
funcget_vectorcore_num[4行]
(已列出全部 4 个函数)
ops\triton\activation\__init__.py
查看源码ops.triton.activation 子包标记。
类: 无
ops\triton\activation\swiglu_quant.py
查看源码SwiGLU+量化融合 Triton kernel(102 行)。_swiglu_quant_kernel 按 group_list 分组做 SwiGLU 并量化输出(out+scale);swiglu_quant 包装入口(支持 group_list 类型选择与按需量化)。
类: 无
func_swiglu_quant_kernel[56行]
funcswiglu_quant[37行]
(已列出全部 2 个函数)
ops\triton\activation\swiglustep.py
查看源码SwigluStep 激活 Triton kernel(130 行)。_swiglustep_kernel 实现融合 SwigluStep:silu(gate).clamp(max=limit) * up.clamp(±limit);swiglustep_forward_triton 为入口。
类: 无
func_swiglustep_kernel[38行]
funcswiglustep_forward_triton[46行] Fused SwigluStep: silu(gate).clamp(max=limit) * up.clamp(±limit).
(已列出全部 2 个函数)
ops\triton\batch_invariant\__init__.py
查看源码ops.triton.batch_invariant 子包标记。该包提供批不变算子(同输入不同 batch 下逐位一致),供 batch_invariant 模式使用。
类: 无
ops\triton\batch_invariant\matmul.py
查看源码批不变矩阵乘(448 行)。持久化 kernel:matmul_bias_persistent_kernel/matmul_persistent(x@y+bias)、linear_persistent_kernel/linear_persistent(x@y^T,固定 grid 保证归约顺序一致);对外批不变接口:mm/bmm/addmm/matmul/linear_batch_invariant。
类: 无
funcmatmul_bias_persistent_kernel[74行]
funcmatmul_persistent[75行] Implement matrix multiplication with optional bias using Triton: x @ y + bias (if bias is not None)
funclinear_persistent_kernel[67行]
funclinear_persistent[103行] Implement matrix multiplication with Triton: x @ y^T
funcmm_batch_invariant[2行]
funcbmm_batch_invariant[15行]
funcaddmm_batch_invariant[6行]
funcmatmul_batch_invariant[56行]
funclinear_batch_invariant[9行]
(已列出全部 9 个函数)
ops\triton\batch_invariant\mean.py
查看源码批不变 mean(173 行)。mean_kernel 沿单维求均值的 Triton kernel(固定归约顺序);mean_dim 为 torch.mean 的单维 Triton 实现;mean_batch_invariant 批不变包装。
类: 无
funcmean_kernel[43行] Kernel for computing mean along a single dimension.
funcmean_dim[85行] Triton implementation of torch.mean with single dimension reduction.
funcmean_batch_invariant[17行]
(已列出全部 3 个函数)
ops\triton\batch_invariant\rmsnorm.py
查看源码批不变 RMSNorm(153 行)。_rms_norm_kernel 对二维输入沿末维 RMS 归一化(固定 grid);rms_norm Triton 实现;rms_norm_batch_invariant 批不变包装。
类: 无
func_rms_norm_kernel[54行] Compute RMS normalization along the last dimension of a 2D tensor.
funcrms_norm[52行] Compute RMS normalization using Triton kernel with fixed grid size.
funcrms_norm_batch_invariant[19行] Batch-invariant wrapper for RMS normalization.
(已列出全部 3 个函数)
ops\triton\batch_invariant\softmax.py
查看源码批不变 softmax(38 行)。softmax_batch_invariant 提供批不变的 softmax 实现(固定归约顺序保证逐位一致)。
类: 无
funcsoftmax_batch_invariant[17行]
(已列出全部 1 个函数)
ops\triton\fla\__init__.py
查看源码ops.triton.fla 子包标记。该包是 Flash Linear Attention(线性注意力)kernel 集,服务 Gated DeltaNet 类模型。
类: 无
ops\triton\fla\chunk.py
查看源码FLA chunk 前向主入口(386 行)。chunk_gated_delta_rule_fwd 执行分块门控增量规则前向;ChunkGatedDeltaRuleFunction 为 autograd Function;chunk_gated_delta_rule 对外入口(q/k/v/g/beta/scale)。
类: ChunkGatedDeltaRuleFunction
funcchunk_gated_delta_rule_fwd[189行]
funcforward[32行] attention 前向入口
funcchunk_gated_delta_rule[128行] Args:
(已列出全部 3 个函数)
ops\triton\fla\chunk_delta_h.py
查看源码FLA 状态传递 kernel(244 行)。chunk_gated_delta_rule_fwd_h_blockdim64(blockdim64 配置)计算每 chunk 的隐状态传递 h;chunk_gated_delta_rule_fwd_h 为包装(支持 initial_state 与最终状态输出)。
类: 无
funcchunk_gated_delta_rule_fwd_kernel_h_blockdim64[147行]
funcchunk_gated_delta_rule_fwd_h[66行]
funcgrid[2行]
(已列出全部 3 个函数)
ops\triton\fla\chunk_delta_hupdate.py
查看源码FLA 状态增量更新 kernel(219 行)。chunk_gated_delta_rule_fwd_kernel_hupdate_blockdim64 按变长序列(cu_seqlens/chunk_offsets)增量更新隐状态;chunk_gated_delta_rule_fwd_hupdate 为包装。
类: 无
funcchunk_gated_delta_rule_fwd_kernel_hupdate_blockdim64[130行]
funcchunk_gated_delta_rule_fwd_hupdate[61行]
funcgrid[2行]
(已列出全部 3 个函数)
ops\triton\fla\chunk_o.py
查看源码FLA 输出计算 kernel(163 行)。chunk_fwd_kernel_o 用 chunk 状态 h 计算注意力输出 o;chunk_fwd_o 为包装(含 scale)。
类: 无
funcchunk_fwd_kernel_o[84行]
funcchunk_fwd_o[52行]
funcgrid[2行]
(已列出全部 3 个函数)
ops\triton\fla\chunk_scaled_dot_kkt.py
查看源码FLA KKT 内积 kernel(155 行)。chunk_scaled_dot_kkt_fwd_kernel 计算 beta·K·K^T(chunk 内三角矩阵 A);chunk_scaled_dot_kkt_fwd 包装(按 cu_seqlens/chunk_indices 变长处理)。
类: 无
funcchunk_scaled_dot_kkt_fwd_kernel[61行]
funcchunk_scaled_dot_kkt_fwd[66行] Compute beta * K * K^T.
(已列出全部 2 个函数)
ops\triton\fla\cumsum.py
查看源码FLA 门控累计和 kernel(144 行)。chunk_local_cumsum_scalar_kernel 计算 chunk 内标量门控 g 的局部累计和;chunk_local_cumsum_scalar/chunk_local_cumsum 包装(支持反向与 scale)。
类: 无
funcchunk_local_cumsum_scalar_kernel[53行]
funcchunk_local_cumsum_scalar[37行]
funcchunk_local_cumsum[29行]
(已列出全部 3 个函数)
ops\triton\fla\fused_qkvzba_split_reshape.py
查看源码FLA 融合拆分 kernel(225 行)。fused_qkvzba_split_reshape_cat_kernel 一次 kernel 完成 mixed_qkvz/mixed_ba 的拆分与重排(产出 mixed_qkv/z/b/a);fused_qkvzba_split_reshape 包装(按 QK/V 头数与头维度配置)。
类: 无
funcfused_qkvzba_split_reshape_cat_kernel[121行] Fused kernel to split and reshape mixed QKVZ and BA tensors.
funcfused_qkvzba_split_reshape_cat[82行]
(已列出全部 2 个函数)
ops\triton\fla\l2norm.py
查看源码FLA L2 归一化 kernel(66 行)。l2norm_fwd_kernel2_loop 沿头维做 L2 归一化;l2norm_fwd 包装(可指定输出 dtype)。
类: 无
funcl2norm_fwd_kernel2_loop[14行]
funcl2norm_fwd[33行]
(已列出全部 2 个函数)
ops\triton\fla\layernorm_guard.py
查看源码FLA LayerNorm kernel(198 行)。layer_norm_fwd_kernel 单遍 LayerNorm(带残差);_layer_norm_fwd/LayerNormFn 包装为函数式接口,作为 FLA 管线的守卫实现。
类: LayerNormFn
funclayer_norm_fwd_kernel[70行]
func_layer_norm_fwd[63行]
funcforward[38行] attention 前向入口
(已列出全部 3 个函数)
ops\triton\fla\solve_tril.py
查看源码FLA 三角矩阵求逆 kernel(404 行)。solve_tril_16x16_kernel 求 16×16 块 (I+A)^-1;merge_16x16_to_32x32/64x64_inverse_kernel 逐级合并为大块逆矩阵;solve_tril 对外入口(变长 cu_seqlens 支持)。
类: 无
funcsolve_tril_16x16_kernel[113行]
funcmerge_16x16_to_32x32_inverse_kernel[60行]
funcmerge_16x16_to_64x64_inverse_kernel[126行]
funcsolve_tril[74行] Compute the inverse of the matrix I + A
(已列出全部 4 个函数)
ops\triton\fla\utils.py
查看源码FLA 工具(133 行)。prepare_lens/prepare_chunk_indices/prepare_final_chunk_indices/prepare_chunk_offsets/prepare_update_chunk_offsets 预计算变长序列的 chunk 元数据;input_guard 装饰器保证输入连续并按输入设置设备;safe_exp 数值安全指数;_clear_ssm_states_kernel/clear_ssm_states 按行清零 SSM 状态。
类: 无
funcprepare_lens[2行]
funcprepare_chunk_indices[3行]
funcprepare_final_chunk_indices[3行]
funcprepare_chunk_offsets[2行]
funcprepare_update_chunk_offsets[2行]
funcinput_guard[30行] A decorator to make sure all input tensors are contiguous and set the device based on input tensors.
funcwrapper[22行]
funcsafe_exp[2行]
func_clear_ssm_states_kernel[18行]
funcclear_ssm_states[36行] Zero out specific rows for the SSM states
(已列出全部 10 个函数)
ops\triton\fla\wy_fast.py
查看源码FLA W/U 重计算 kernel(143 行)。recompute_w_u_fwd_kernel 计算 chunk 的 W(状态修正)与 U(值投影);recompute_w_u_fwd 包装(含 g_cumsum 与 A 输入)。
类: 无
funcrecompute_w_u_fwd_kernel[75行]
funcrecompute_w_u_fwd[46行]
(已列出全部 2 个函数)
ops\triton\kda\__init__.py
查看源码ops.triton.kda 子包标记。该包是 Kimi KDA(delta attention)专用 kernel 集,与 fla 包对应但按 KDA 门控(gk 逐维门控)定制。
类: 无
ops\triton\kda\chunk_delta_h.py
查看源码KDA 状态传递 kernel(328 行)。chunk_gated_delta_rule_fwd_kernel_h_blockdim64_kda 计算带逐维门控 gk 的 chunk 隐状态;chunk_gated_delta_rule_fwd_h_kda 包装(支持 initial_state)。
类: 无
funcchunk_gated_delta_rule_fwd_kernel_h_blockdim64_kda[232行]
funcchunk_gated_delta_rule_fwd_h_kda[59行]
funcgrid[2行]
(已列出全部 3 个函数)
ops\triton\kda\cumsum.py
查看源码KDA 累计和 kernel(274 行)。chunk_local_cumsum_scalar_kernel/chunk_local_cumsum_vector_kernel 分别处理标量与向量门控的 chunk 内累计和;chunk_local_cumsum 为统一入口(按输入形状分派)。
类: 无
funcchunk_local_cumsum_scalar_kernel[53行]
funcchunk_local_cumsum_scalar[37行]
funcchunk_local_cumsum_vector_kernel[70行]
funcchunk_local_cumsum_vector[38行]
funcgrid[2行]
funcchunk_local_cumsum[41行]
(已列出全部 6 个函数)
ops\triton\kda\fused_recurrent_kda.py
查看源码KDA 融合递归 kernel(158 行)。fused_recurrent_gated_delta_rule_fwd_kernel 实现 decode 期逐步递归计算(q/k/v/g/beta 单步状态更新与输出)。
类: 无
funcfused_recurrent_gated_delta_rule_fwd_kernel[135行]
(已列出全部 1 个函数)
ops\triton\kda\kda.py
查看源码KDA kernel 总集(1332 行)。递归路径:fused_recurrent_kda_fwd/fused_recurrent_kda;chunk 路径:chunk_kda_scaled_dot_kkt_fwd(intra_sub_inter/intra_sub_intra 两级 kernel 计算 beta·K·K^T)、recompute_w_u_fwd、chunk_gla_fwd_o_gk(输出计算)、chunk_kda_fwd/chunk_kda 组装;门控归一化:layer_norm_gated_fwd 系列 kernel 与 rms_norm_gated(gated activation);kda_gate_fwd_kernel/fused_kda_gate 融合门控(g/A/g_bias/beta/threshold)。
类: 无
funcfused_recurrent_kda_fwd[75行]
funcfused_recurrent_kda[37行]
funclayer_norm_gated_fwd_kernel[69行]
funclayer_norm_gated_fwd_kernel1[65行]
funclayer_norm_gated_fwd[77行]
funcrms_norm_gated[33行]
funcchunk_kda_scaled_dot_kkt_fwd_kernel_intra_sub_inter[143行]
funcchunk_kda_scaled_dot_kkt_fwd_kernel_intra_sub_intra[88行]
funcchunk_kda_scaled_dot_kkt_fwd[82行] Compute beta * K * K^T.
funcrecompute_w_u_fwd_kernel[137行]
funcrecompute_w_u_fwd[45行]
funcchunk_gla_fwd_kernel_o[103行]
funcchunk_gla_fwd_o_gk[39行]
funcgrid[2行]
funcchunk_kda_fwd[77行]
funcchunk_kda[34行]
funckda_gate_fwd_kernel[58行]
funcfused_kda_gate[45行] Forward pass for KDA gate:
(已列出全部 18 个函数)
ops\triton\kda\l2norm.py
查看源码KDA L2 归一化 kernel(100 行)。l2norm_fwd_persistent_kernel(持久化)与 l2norm_fwd_tiled_kernel(分块)两种实现;l2norm_fwd 按 use_tiled_kernel 选择。
类: 无
funcl2norm_fwd_persistent_kernel[16行]
funcl2norm_fwd_tiled_kernel[13行]
funcl2norm_fwd[48行]
(已列出全部 3 个函数)
ops\triton\kda\solve_tril.py
查看源码KDA 三角矩阵求逆 kernel(402 行)。solve_tril_16x16_kernel_kda、merge_16x16_to_32x32/64x64_inverse_kernel_kda 与 fla 版对应;solve_tril_kda 对外入口。
类: 无
funcsolve_tril_16x16_kernel_kda[48行]
funcmerge_16x16_to_32x32_inverse_kernel_kda[79行]
funcmerge_16x16_to_64x64_inverse_kernel_kda[174行]
funcsolve_tril_kda[51行] Compute the inverse of the matrix I + A
(已列出全部 4 个函数)
ops\triton\kda\utils.py
查看源码KDA 工具(97 行)。tensor_cache 装饰器按张量对象身份缓存派生元数据;prepare_lens/prepare_chunk_indices/prepare_chunk_offsets 预计算变长元数据;input_guard 连续性与设备守卫。
类: 无
functensor_cache[26行] Cache recent tensor-derived metadata keyed by tensor object identity.
funcwrapper[22行]
funcprepare_lens[2行]
funcprepare_chunk_indices[3行]
funcprepare_chunk_offsets[2行]
funcinput_guard[30行] A decorator to make sure all input tensors are contiguous and set the device based on input tensors.
(已列出全部 6 个函数)
ops\triton\kimi_k3\__init__.py
查看源码ops.triton.kimi_k3 子包标记:Kimi K3 专用 Triton 融合 kernel。
类: 无
ops\triton\kimi_k3\attention_residual.py
查看源码K3 注意力残差混合融合 kernel(116 行)。_apply_attn_res_kernel 在设备端计算 K3 的学习型残差流 softmax 混合(prefix_sum/block_residual/proj/norm 参与);apply_attn_res 包装(按有效块数裁剪)。
类: 无
func_apply_attn_res_kernel[56行]
funcapply_attn_res[39行] Return K3's learned softmax mixture of residual streams.
(已列出全部 2 个函数)
ops\triton\linearnorm\__init__.py
查看源码ops.triton.linearnorm 子包标记。该包实现 QKV 分裂+RMSNorm+RoPE 的融合 kernel 族。
类: 无
ops\triton\linearnorm\split_qkv_rmsnorm_mrope.py
查看源码分裂+RMSNorm+mRoPE 融合 kernel(427 行)。split_qkv_rmsnorm_mrope_kernel 一次完成 QKV 分裂、Q/K 各自 RMSNorm 与多模态 mrope 旋转;triton_split_qkv_rmsnorm_mrope 注册为自定义算子(带 fake)。
类: 无
funcsplit_qkv_rmsnorm_mrope_kernel[251行]
functriton_split_qkv_rmsnorm_mrope[85行]
functriton_split_qkv_rmsnorm_mrope_fake[50行]
(已列出全部 3 个函数)
ops\triton\linearnorm\split_qkv_rmsnorm_rope.py
查看源码分裂+RMSNorm+RoPE 融合 kernel(390 行)。split_qkv_rmsnorm_rope_kernel 融合 QKV 分裂、Q/K RMSNorm(带 bias)与 RoPE;split_qkv_rmsnorm_rope_impl 为实现入口(带 fake),按 cos_sin_cache 与 positions 查表旋转。
类: 无
funcsplit_qkv_rmsnorm_rope_kernel[236行]
funcsplit_qkv_rmsnorm_rope_impl[81行]
funcsplit_qkv_rmsnorm_rope_impl_fake[35行]
(已列出全部 3 个函数)
ops\triton\linearnorm\split_qkv_rmsnorm_rope_simt.py
查看源码SIMT 版分裂+RMSNorm+RoPE kernel(386 行)。与上一文件功能相同但走 SIMT 路径:precompute_rope_cos_sin_kernel 预计算 cos/sin、split_qkv_rmsnorm_rope_simt_kernel 融合主 kernel;适用于不同代际硬件的指令集差异。
类: 无
funcprecompute_rope_cos_sin_kernel[28行]
funcsplit_qkv_rmsnorm_rope_simt_kernel[217行]
funcsplit_qkv_rmsnorm_rope_simt_impl[82行]
funcsplit_qkv_rmsnorm_rope_simt_impl_fake[35行]
(已列出全部 4 个函数)
ops\triton\linearnorm\split_qkv_tp_rmsnorm_rope.py
查看源码TP 分裂+RMSNorm+RoPE kernel(376 行)。两段 kernel:_split_qkv_and_compute_local_qk_var_kernel(Grid Stride + 批量加载 + 预计算倒数)做 QKV 分裂并计算本地 QK 方差、_apply_global_rmsnorm_kernel 用全局方差完成归一化与旋转;split_qkv_tp_rmsnorm_rope_impl 为入口(TP 分片下跨 rank 两段式归一化)。
类: 无
func_split_qkv_and_compute_local_qk_var_kernel[87行] Grid Stride Loop + batch loading + precomputed reciprocal.
func_apply_global_rmsnorm_kernel[123行]
funcsplit_qkv_tp_rmsnorm_rope_impl[79行]
funcsplit_qkv_tp_rmsnorm_rope_impl_fake[33行]
(已列出全部 4 个函数)
ops\triton\mamba\__init__.py
查看源码ops.triton.mamba 子包标记。该包含 Mamba/线性注意力混合模型的 Triton kernel。
类: 无
ops\triton\mamba\causal_conv1d.py
查看源码因果卷积辅助 kernel(14 行)。extract_last_width 提取每序列卷积窗口末位值(decode 期因果卷积的增量输出)。
类: 无
funcextract_last_width[6行]
(已列出全部 1 个函数)
ops\triton\mamba\lightning_attn.py
查看源码lightning attention NPU kernel(627 行)。BailingMoE 线性注意力的 NPU 实现:_fwd_diag_kernel 对角块注意力和 _fwd_none_diag_kernel 非对角块(KV 状态参与)、_fwd_kv_parallel/_fwd_kv_reduce 计算 KV 状态并行与归约(含 KV_HISTORY);lightning_attention_npu 为前向入口(ed 衰减、block_size 分块、kv_history 状态);AscendLightningAttentionKernel 暴露 jit_linear_forward_prefix 供 prefill 前缀复用。
类: _attention
func_fwd_diag_kernel[112行]
func_fwd_kv_parallel[103行]
func_fwd_kv_reduce[61行]
func_fwd_none_diag_kernel[68行]
funcforward[156行] attention 前向入口
funclightning_attention_npu[38行] lightning attention forward pass (NPU-friendly).
funcjit_linear_forward_prefix[30行]
(已列出全部 7 个函数)
ops\triton\mamba\postprocess.py
查看源码Mamba 后处理 kernel 集(429 行)。包含 Mamba 混合模型推理后处理的 Triton kernel(状态整理与输出变换等,服务于 GDN/Mamba 管线末端)。
类: 无
funcpostprocess_mamba_fused_kernel[203行] Fused GPU kernel for postprocess_mamba that computes decisions AND performs
(已列出全部 1 个函数)
ops\triton\spec_decode\__init__.py
查看源码ops.triton.spec_decode 子包标记。
类: 无
ops\triton\spec_decode\ngram.py
查看源码NGram 投机解码 kernel(259 行)。ngram_spec_decode_kernel 在设备端从已生成 token 序列匹配 n-gram 并产出 draft token;triton_ngram_spec_decode 包装(含 discard 请求掩码、最小 n 配置)。
类: 无
funcngram_spec_decode_kernel[179行]
functriton_ngram_spec_decode[72行]
(已列出全部 2 个函数)
ops\triton\spec_decode\utils.py
查看源码投机解码辅助 kernel(213 行)。prepare_inputs_padded_kernel 准备填充后的投机输入(合法 token 计数、待采样索引、拒绝数);copy_and_expand_dflash_and_dspark_inputs_kernel 复制并展开 DFlash/DSpark 的输入(token/位置/slot);dflash2_greedy_selector_walk_kernel 沿候选表贪心走选出最终 draft 序列。
类: 无
funcprepare_inputs_padded_kernel[44行]
funccopy_and_expand_dflash_and_dspark_inputs_kernel[109行]
funcdflash2_greedy_selector_walk_kernel[33行]
(已列出全部 3 个函数)
ops\triton\v2\__init__.py
查看源码ops.triton.v2 子包标记。该包服务 V2 运行器的专用 kernel。
类: 无
ops\triton\v2\apply_grammar_bitmask.py
查看源码语法掩码应用 kernel(110 行)。_apply_grammar_bitmask_kernel_impl 按语法约束位掩码屏蔽 logits 的非法 token;_ApplyGrammarBitmaskKernelLauncher 把上游逻辑 grid 映射到 Ascend VectorCore 启动网格(__getitem__ 适配)。
类: 无
func_apply_grammar_bitmask_kernel_impl[41行]
func__getitem__[34行]
funclaunch[25行]
(已列出全部 3 个函数)
ops\triton\v2\mamba\__init__.py
查看源码ops.triton.v2.mamba 子包标记。
类: 无
ops\triton\v2\mamba\precopy.py
查看源码Mamba 状态预拷贝融合 kernel(178 行)。precopy_mamba_align_fused_kernel 按 block table 一次性拷贝多个 Mamba 状态块(_copy_mamba_state_block 单块拷贝,避免拷贝循环内指针转换),对齐 V2 运行器的状态布局。
类: 无
func_copy_mamba_state_block[103行] Copy one Mamba state block without casting pointers in copy loops.
funcprecopy_mamba_align_fused_kernel[65行]
(已列出全部 2 个函数)
ops\triton\v2\metrics\__init__.py
查看源码ops.triton.v2.metrics 子包标记。
类: 无
ops\triton\v2\metrics\num_nans.py
查看源码NaN 计数 kernel(39 行)。_num_nans_kernel 统计 logits 中的 NaN 数量;get_num_nans 为入口,用于数值健康监控。
类: 无
func_num_nans_kernel[17行]
funcget_num_nans[13行]
(已列出全部 2 个函数)
ops\triton\v2\sample\__init__.py
查看源码ops.triton.v2.sample 子包标记。
类: 无
ops\triton\v2\sample\fill_logprob_token_idx.py
查看源码logprob token 索引填充 kernel(54 行)。_fill_logprob_token_ids_kernel 把采样 token 与 topk 索引填入 logprob 输出缓冲(带有效掩码),服务 V2 采样管线的 logprob 计算。
类: 无
func_fill_logprob_token_ids_kernel[49行]
(已列出全部 1 个函数)