models 包注册入口(56 行)。register_model 把 Ascend 定制的模型架构(DeepSeek-V4、Kimi K3、MiniMax-M3 系列、各 draft 模型等)注册进 vLLM 的模型注册表,使平台加载模型时命中 NPU 实现而非上游版本。
类: 无
funcregister_model[53行] 将模型架构名注册到 vLLM ModelRegistry(Kimi/DeepSeek/MiniMax/Qwen等)
models\deepseek_mtp.py
查看源码DeepSeek MTP(Multi-Token Prediction)投机层适配(81 行)。AscendDeepSeekMTP 实现 MTP 模块:forward 前向、load_weights 加载(_rewrite_spec_layer_name 重写投机层权重名以对齐 checkpoint)、_maybe_set_own_lm_head 在需要时为 draft 设置独立输出头;AscendGlmMoeDsaForCausalLM 为 GLM-MoE-DSA 的权重加载适配。
类: AscendDeepSeekMTP, AscendGlmMoeDsaForCausalLM
func__init__[5行] 初始化类实例(绑定配置、参数、模块)
funcforward[12行] attention 前向入口
func_maybe_set_own_lm_head[19行] 条件性设置自定义 lm_head
funcload_weights[7行] 加载权重到模型
func_rewrite_spec_layer_name[5行] 重写 spec 层的名称
Kimi K3 模型适配(871 行)。AscendKimiMoE 用 vLLM 标准 MoE 接口组装 Kimi K3 的专家层;AscendKimiMLAAttention 仅扩展 DSpark RoPE 元数据部分(其余沿用上游通用 Kimi MLA);AscendKimiDecoderLayer 沿上游解码层结构接 Ascend 注意力后端(_run_self_attn/forward_attn_residual);AscendKimiLinearModel 组装文本主体并处理权重加载;AscendKimiLinearForCausalLM/AscendKimiK3ForConditionalGeneration 分别为文本因果 LM 与多模态包装(保留 vLLM 0.27 状态/缓存接口、支持 DSpark 辅助捕获物化);AscendKimiK3MultiModalProjector 多模态投影器(可选 ModelSlim 输出旋转);_apply_ascend_attn_res 用原生算子实现 Kimi 规范的残差混合。
类: AscendKimiMoE, AscendKimiMLAAttention, AscendKimiDecoderLayer, AscendKimiLinearModel, AscendKimiLinearForCausalLM, AscendKimiK3MultiModalProjector, AscendKimiK3ForConditionalGeneration
func_apply_ascend_attn_res[34行] 应用 Kimi 学习到的残差混合(用原生 NPU ops)
func__init__[114行] 初始化类实例(绑定配置、参数、模块)
funcforward[6行] attention 前向入口
func_attention_layer[2行] attention 层实例
funcis_vl_first_layer[2行] 判断是否是 VL 的第一层
funclayer_name[2行] 当前层的名称
funcimpl[2行] impl 实例变量
funckv_cache[2行] kv cache 实例变量
funckv_cache_dtype[2行] kv cache dtype
func_k_scale[2行] K cache 缩放因子
func_run_self_attn[7行] 运行 self-attention 子层
funcforward_attn_residual[44行] 应用 attention residual 块(Kimi 特有)
funcget_layer[7行] 按 layer_idx 返回 layer 实例
funcload_weights[25行] 加载权重到模型
funcremap_mixed_gate_weights[14行] 重映射混合 gate 权重到正确的 expert index
funcset_dspark_aux_capture_materialized[2行] 为 DSpark 附加捕获启用物化
models\kimi_k3_dspark.py
查看源码Kimi K3 DSpark draft 模型(364 行)。AscendK3DSparkModel 提供 precompute_and_store_context_kv 预计算并缓存上下文 KV 供 draft 多步复用,forward 执行 draft 前向;AscendK3DSparkDecoderLayer 为 draft 解码层;AscendK3DSparkForCausalLM 组织整体(get_draft_attn_causal 决定 draft 注意力因果性、load_weights、embed_input_ids)。
类: AscendK3DSparkDecoderLayer, AscendK3DSparkModel, AscendK3DSparkForCausalLM
func_uses_causal_draft_attention[5行] 是否使用因果 draft attention
func__init__[32行] 初始化类实例(绑定配置、参数、模块)
funcforward[18行] attention 前向入口
funcprecompute_and_store_context_kv[28行] 预计算并存储 context 阶段 KV
funcget_draft_attn_causal[3行] 取得 draft attention 是否因果
funcload_weights[54行] 加载权重到模型
funcembed_input_ids[30行] Embed draft tokens and replace multimodal placeholder positions.
models\kimi_k3_mtp.py
查看源码Kimi K3 MTP draft 模型(93 行)。AscendKimiK3MultiTokenPredictorLayer 为单层 MTP 预测层,AscendKimiK3MultiTokenPredictor 组装 MTP 模块,AscendKimiK3MTP 为对 vLLM 注册暴露的完整 draft 模型包装。
类: AscendKimiK3MultiTokenPredictorLayer, AscendKimiK3MultiTokenPredictor, AscendKimiK3MTP
func__init__[8行] 初始化类实例(绑定配置、参数、模块)
models\llama_eagle3.py
查看源码Llama Eagle3 draft 模型(140 行)。AscendEagle3LlamaForCausalLM 加载 Eagle3 draft 权重并执行 draft 前向;针对 QuaRot 旋转的 draft 训练方式:get_embedding_tensor 扫描目录找 embedding 张量、_find_safetensors_weight 定位目标张量避免加载无关分片、load_quarot_target_layer 把目标层词表分片装入 draft 的未旋转隐藏基、compute_rotation_matrix3 计算三层 hidden_states 的反旋转矩阵。
类: AscendEagle3LlamaForCausalLM
funcget_embedding_tensor[12行] Scans the directory and returns the first tensor found that contains 'embed' in its key.
func_find_safetensors_weight[20行] Locate one target tensor without loading unrelated checkpoint shards.
funcload_quarot_target_layer[42行] Load one target vocab shard into the draft's unrotated hidden basis.
funccompute_rotation_matrix3[3行] Anti-rotate matrix for 3 layers of hidden_states.
func__init__[5行] 初始化类实例(绑定配置、参数、模块)
funcload_weights[26行] 加载权重到模型
models\llama_eagle3_vwn.py
查看源码Llama Eagle3 的 VWN(vocab-未旋转网络)变体(257 行)。PreVwnLayerV1 为前置 VWN 层、VwnLlamaDecoderLayer/VwnLlamaModel 组成 VWN 主体(替代标准解码层栈);Eagle3VwnLlamaForCausalLM 提供 compute_logits 与 combine_hidden_states(合并多源 hidden states 供 draft 使用),是 Eagle3 在 VWN 投影结构下的 Ascend 实现。
类: PreVwnLayerV1, VwnLlamaDecoderLayer, VwnLlamaModel, Eagle3VwnLlamaForCausalLM
func_linear[10行] 内部线性层调用
func__init__[39行] 初始化类实例(绑定配置、参数、模块)
funcforward[9行] attention 前向入口
funccompute_logits[22行] 从 hidden states 计算最终 logits
funccombine_hidden_states[21行] 合并 hidden states(Eagle3 等)
models\qwen3_dflash2.py
查看源码Qwen3 DFlash2 draft 模型(309 行)。DFlashGroupedConv 用分组卷积从 anchor hidden states 一次性卷出多步 draft 的 delta/base(prepare/finish 管理卷积前后状态);DFlash2Qwen3DecoderLayer 为 draft 解码层;CandidateSelector 基于 _score_edges 对候选边打分(前驱/后继表 + unary logits + anchor token)选 top-k 候选路径;DFlash2Qwen3Model/DFlash2Qwen3ForCausalLM 组装模型并提供 compute_candidates 候选计算接口。
类: DFlashGroupedConv, DFlash2Qwen3DecoderLayer, CandidateSelector, DFlash2Qwen3Model, DFlash2Qwen3ForCausalLM
func_grouped_conv[21行]
func__init__[14行] 初始化类实例(绑定配置、参数、模块)
func_convolve[10行]
funcprepare[5行]
funcfinish[2行]
funcforward[24行] attention 前向入口
func_score_edges[19行]
funcembed_input_ids[2行] 将 input_ids 嵌入为 hidden states
funccompute_candidates[23行]
models\qwen3_dspark.py
查看源码Qwen3 DSpark draft 模型(173 行)。DSparkConfidenceHead 为置信度头(对 draft 候选打置信分);AscendQwen3DSparkForCausalLM 组织 draft 模型:compute_confidence 输出置信度、load_weights 处理 process_weight 的旋转权重合并(linear_weight+rotation_weight)。
类: DSparkConfidenceHead, AscendQwen3DSparkForCausalLM
funcprocess_weight[16行]
func__init__[13行] 初始化类实例(绑定配置、参数、模块)
funcforward[8行] attention 前向入口
func_get_confidence_relative_name[10行]
funccompute_confidence[6行] Per-position acceptance probability for each drafted token.
funcload_weights[69行] 加载权重到模型
models\deepseek_v4\__init__.py
查看源码models.deepseek_v4 子包标记。该包实现 DeepSeek-V4 在 Ascend 上的完整适配:主模型、lightning indexer、KV 压缩器、SWA 缓存、DSpark draft 与 MTP。
类: 无
(无函数)
models\deepseek_v4\compressor.py
查看源码DeepSeek-V4 KV 压缩器(238 行)。Compressor 把长上下文 KV 压缩为低秩表示(_compute_metadata 构建压缩元数据、forward 执行压缩);AscendCompressorMetadata 携带压缩 KV 与压缩器状态缓存的请求级元数据;AscendCompressorStateCache 管理压缩器状态的分页缓存:get_kv_cache_spec 定义缓存规格、get_attn_backend 选择配套后端。
类: AscendCompressorStateCache, Compressor
func__init__[77行] 初始化类实例(绑定配置、参数、模块)
funcget_kv_cache_spec[15行]
funcforward[32行] attention 前向入口
funcget_attn_backend[11行] 根据 vllm_config 返回 attention backend 类
func_compute_metadata[31行]
models\deepseek_v4\dspark.py
查看源码DeepSeek-V4 DSpark draft 模型(547 行)。DSparkMarkovHead 实现 Markov 式候选头(embed/bias);DSparkConfidenceHead 置信度头;DeepseekV4DSparkModel 组装 draft 主体:_project_shared_kv 投影共享 KV、_store_standard_swa_kv 存标准 SWA KV、precompute_and_store_context_kv 预计算上下文 KV、hc_head/Markov embed/bias 接口与 compute_logits;DSparkDeepseekV4ForCausalLM 为注册包装:set_moe_parameters、map_draft_to_target(draft→目标 token 映射)、compute_draft_logits、_remap_dspark_name 权重名重映射。
类: DSparkMarkovHead, DSparkConfidenceHead, DeepseekV4DSparkModel, DSparkDeepseekV4ForCausalLM
func_apply_dsv4_rope[14行]
func_get_dspark_num_mtp_layers[5行]
func__init__[21行] 初始化类实例(绑定配置、参数、模块)
funcembed[2行]
funcbias[2行]
funcforward[10行] attention 前向入口
funcget_draft_kv_cache_layer_names[2行]
funccombine_hidden_states[2行] 合并 hidden states(Eagle3 等)
func_project_shared_kv[11行]
func_store_standard_swa_kv[24行]
funcprecompute_and_store_context_kv[11行] 预计算并存储 context 阶段 KV
funchc_head[8行]
funcmarkov_embed[2行]
funcmarkov_bias[2行]
funccompute_logits[11行] 从 hidden states 计算最终 logits
funcget_expert_mapping[9行]
funcset_moe_parameters[18行]
funccompute_draft_logits[3行]
funcmap_draft_to_target[2行]
funccompute_confidence[4行] Per-position acceptance probability for each drafted token.
funcload_weights[95行] 加载权重到模型
func_remap_dspark_name[40行]
models\deepseek_v4\indexer.py
查看源码DeepSeek-V4 lightning indexer(718 行)。Hadamard 工具:hadamard_linear 快速 Hadamard 变换线性层、hadamard_scale/rotate_activation 激活旋转;AscendDeepseekV4IndexerCache 管理 indexer K/scale 分页缓存(get_kv_cache_spec/get_attn_backend);IndexerOverlapPlan 把主注意力压缩器的工作安排在 indexer 选择周围重叠执行;AscendIndexerOps 封装设备算子序列:解包 indexer KV 缓存、量化 query/key、更新 scale 缓存、select_topk 及量化-更新-选择融合路径;DeepseekV4Indexer 为 indexer 层本体:多流路径(_cv_compute_query_and_update_cache_multistream/_select_topk_multistream)与串行路径(_select_topk_serial)、topk 索引缓存复用、forward 主入口。
类: AscendDeepseekV4IndexerCache, DeepseekV4Indexer
funchadamard_linear[8行]
funchadamard_scale[4行] Scale and reshape the output of hadamard_linear.
funcrotate_activation[3行]
func_is_w8a8_dynamic[7行] True iff ``linear`` is wired up with ``AscendW8A8DynamicLinearMethod``.
func__init__[74行] 初始化类实例(绑定配置、参数、模块)
funcget_kv_cache_spec[23行]
funcforward[61行] attention 前向入口
funcget_attn_backend[11行] 根据 vllm_config 返回 attention backend 类
funcunpack_dsa_indexer_kv_cache[2行]
funcquantize_query[2行]
funcquantize_key_and_update_cache[13行]
funcupdate_scale_cache[11行]
funcselect_topk[31行]
funcquantize_update_cache_and_select_topk[27行]
func_get_indexer_cache_metadata[9行]
funcupdate_cache[35行] Update Indexer caches without projecting queries or selecting TopK.
func_get_cached_topk_indices[7行]
func_update_cached_topk_indices[12行]
func_cv_compute_query_and_update_cache_multistream[119行] Compute the Indexer query and update its cache.
func_select_topk_multistream[35行] Overlap Indexer selection inputs with caller-provided main-stream work.
func_indexer_qkv_prepare[66行]
func_select_topk_serial[45行]
models\deepseek_v4\model.py
查看源码DeepSeek-V4 主模型(1280 行)。AscendDeepseekV4SWACache 管理 SWA(滑窗注意力)层缓存(spec/forward/后端选择);RoPE:precompute_freqs_cis_cpu 预计算复指数频率表、apply_rotary_emb 应用/逆变换;DeepseekV4Attention 注意力层、DeepseekV4MoE 专家层(DeepseekV2MLP 为共享专家 MLP)、DeepseekV2DecoderLayer(hc_pre/hc_post 挂钩)、DeepseekV4Model 主体(hc_head 接口);yarn_get_mscale/_get_llama_4_scaling 支持 YaRN 与 Llama4 位置缩放;AscendDeepseekV4ForCausalLM 为完整包装(MTP 目标 hidden states、辅助隐藏层设置、专家映射、权重加载)。
类: AscendDeepseekV4SWACache, DeepseekV2MLP, DeepseekV4MoE, DeepseekV4Attention, DeepseekV2DecoderLayer, DeepseekV4Model, DeepseekV2MixtureOfExperts, AscendDeepseekV4ForCausalLM
func__init__[22行] 初始化类实例(绑定配置、参数、模块)
funcget_kv_cache_spec[15行]
funcforward[9行] attention 前向入口
funcget_attn_backend[4行] 根据 vllm_config 返回 attention backend 类
funcprecompute_freqs_cis_cpu[36行] Precomputes frequency-based complex exponential values for rotary positional embeddings.
funcfind_correction_dim[2行]
funcfind_correction_range[4行]
funclinear_ramp_factor[6行]
funcapply_rotary_emb[22行] Applies rotary positional embeddings to the input tensor.
funcget_spec_layer_idx_from_weight_name[4行]
funcyarn_get_mscale[6行]
func_get_llama_4_scaling[6行]
funchc_pre[5行]
funchc_post[5行]
funcmake_empty_intermediate_tensors[14行]
funcembed_input_ids[2行] 将 input_ids 嵌入为 hidden states
funchc_head[8行]
funcextract_moe_parameters[17行]
funcupdate_physical_experts_metadata[14行]
funcset_moe_parameters[20行]
funccompute_logits[6行] 从 hidden states 计算最终 logits
funcget_expert_mapping[12行]
funcget_mtp_target_hidden_states[5行] Pre-hc_head residual stream buffer (max_num_batched_tokens,
funcset_aux_hidden_state_layers[2行]
funcload_weights[221行] 加载权重到模型
models\deepseek_v4\mtp.py
查看源码DeepSeek-V4 MTP 投机模块(530 行)。DeepSeekMultiTokenPredictorLayer 单层 MTP(forward/hc_head);DeepSeekMultiTokenPredictor 组装嵌入与前向;DeepSeekV4MTP 为注册包装:set_moe_parameters、embed_input_ids、compute_logits、load_weights(_rewrite_spec_layer_name 重写投机层名、no_mtp_block_in_name 判断)、SharedHead 共享输出头。
类: SharedHead, DeepSeekMultiTokenPredictorLayer, DeepSeekMultiTokenPredictor, DeepSeekV4MTP
func__init__[7行] 初始化类实例(绑定配置、参数、模块)
funcforward[11行] attention 前向入口
funchc_head[8行]
funcembed_input_ids[2行] 将 input_ids 嵌入为 hidden states
funccompute_logits[6行] 从 hidden states 计算最终 logits
funcset_moe_parameters[19行]
funcload_weights[227行] 加载权重到模型
func_rewrite_spec_layer_name[29行] 重写 spec 层的名称
funcno_mtp_block_in_name[14行]
models\layer\__init__.py
查看源码models.layer 子包标记。
类: 无
(无函数)
models\layer\attention\__init__.py
查看源码models.layer.attention 子包标记。
类: 无
(无函数)
models\layer\attention\layer.py
查看源码DSA 注意力层定义(214 行)。DSAAttention 是 DeepSeek-V4 稀疏注意力的层封装(forward/process_weights_after_loading/get_attn_backend/get_kv_cache_spec);dsv4_block_sizes 决定内核块大小表:显式请求 A5 BF16 KV 时用 A5 专用表,否则用上游表(get_dsv4_block_sizes 提供两套取值)。
类: DSAAttention
funcget_dsv4_block_sizes[22行]
funcdsv4_block_sizes[5行] Return the A5 BF16 KV table when explicitly requested, else the upstream table.
func__init__[95行] 初始化类实例(绑定配置、参数、模块)
funcforward[8行] attention 前向入口
funcprocess_weights_after_loading[3行] 权重加载后的后处理(如 layout cast、NZ 转换)
funcget_attn_backend[2行] 根据 vllm_config 返回 attention backend 类
funcget_kv_cache_spec[25行]
models\minimax_m3\__init__.py
查看源码models.minimax_m3 子包标记(21 行,含包初始化逻辑)。
类: 无
(无函数)
models\minimax_m3\minimax_m3.py
查看源码MiniMax-M3 主模型(1368 行)。MiniMaxM3SparseAttention 实现块稀疏注意力 + lightning indexer(get_attn_backend/get_kv_cache_spec/_insert_kv 写入、_sparse_prepare/_run_sparse_attention 稀疏执行、_qk_norm/_index_qk_norm 归一化);MiniMaxM3SwiGLUOAI 为 OAI 风格 SwiGLU 激活(gate/up 打包输入);MLP/MoE(ebias_weight_loader 专家偏置加载)/Attention/DecoderLayer/Model 标准层级;MiniMaxM3SparseForCausalLM 完整包装(Eagle3 辅助隐藏层、专家映射、MTP 层名识别 get_spec_layer_idx_from_weight_name);_scatter_index_cache 把 index key 写入分页缓存。
类: MiniMaxM3SparseAttention, MiniMaxM3SwiGLUOAI, MiniMaxM3MLP, MiniMaxM3MoE, MiniMaxM3Attention, MiniMaxM3DecoderLayer, MiniMaxM3Model, MiniMaxM3SparseForCausalLM
func_scatter_index_cache[32行] Write MiniMax-M3 index keys into the paged cache.
func__init__[22行] 初始化类实例(绑定配置、参数、模块)
funcget_attn_backend[2行] 根据 vllm_config 返回 attention backend 类
funcget_kv_cache_spec[9行]
func_insert_kv[36行]
func_sparse_prepare[53行]
func_run_sparse_attention[13行] Insert KV, build sparse top-k indices, then run sparse attention.
funcforward[10行] attention 前向入口
func_qk_norm[8行]
func_index_qk_norm[8行]
func_sparse_attention_layer_ids[8行]
func_get_text_config[2行]
func_get_max_position_embeddings[6行]
func_get_rope_parameters[10行]
func_is_w8a8_mxfp8_linear[4行]
funcebias_weight_loader[3行]
funcembed_input_ids[2行] 将 input_ids 嵌入为 hidden states
func_set_aux_hidden_state_layers[5行]
funcset_aux_hidden_state_layers[2行]
funcget_expert_mapping[2行]
funcload_weights[27行] 加载权重到模型
funcmark_loaded[4行]
funcmark_skipped[4行]
funcget_eagle3_default_aux_hidden_state_layers[3行]
func_set_moe_parameters[32行]
funcupdate_physical_experts_metadata[16行]
funccompute_logits[6行] 从 hidden states 计算最终 logits
functext_weights[9行]
funcget_spec_layer_idx_from_weight_name[7行]
models\minimax_m3\minimax_m3_vl.py
查看源码MiniMax-M3 多模态包装(453 行)。MiniMaxM3SparseForConditionalGeneration 处理图像/视频输入(_parse_and_validate_image/video_input、_process_image/video_input、embed_multimodal),同步 MoE 参数并暴露 lm_head;MiniMaxM3VLModel 为视觉语言主体;_install_fused_allreduce_norm_fallback 回退 vLLM 的 CUDA-only allreduce+norm 融合模块避免在 Ascend 上导入失败。
类: MiniMaxM3VLModel, MiniMaxM3SparseForConditionalGeneration
func_load_vllm_minimax_m3_common_module[19行]
func_install_fused_allreduce_norm_fallback[33行] Avoid importing vLLM's CUDA-only fusion module on Ascend.
funcfused_allreduce_gemma_rms_norm[22行]
func__init__[31行] 初始化类实例(绑定配置、参数、模块)
funcforward[14行] attention 前向入口
funcget_placeholder_str[6行]
func_sync_moe_parameters[13行]
funcupdate_physical_experts_metadata[10行]
funclm_head[2行]
func_parse_and_validate_image_input[17行]
func_parse_and_validate_video_input[17行]
func_process_image_input[24行]
func_process_video_input[24行]
func_parse_and_validate_multimodal_inputs[12行]
funcembed_multimodal[12行]
funcembed_input_ids[13行] 将 input_ids 嵌入为 hidden states
funccompute_logits[2行] 从 hidden states 计算最终 logits
funcset_aux_hidden_state_layers[2行]
funcget_eagle3_default_aux_hidden_state_layers[2行]
funcget_expert_mapping[2行]
funcload_weights[31行] 加载权重到模型
funccounted_weights[16行]
models\minimax_m3\msa_m3.py
查看源码MiniMax-M3 稀疏注意力后端族(1316 行)。Indexer 侧:AscendMiniMaxM3IndexerBackend(后端元信息)、IndexerCache(K 缓存规格)、Prefill/Decode/Metadata 元数据、MetadataBuilder(含 TP 分片打分元数据 _build_tp_score_metadata)、IndexerImpl(decode topk TP 分片 _decode_topk_tp_sharded)、Indexer 层;Sparse 侧:AscendMiniMaxM3SparseBackend/Metadata/MetadataBuilder/Impl 稀疏注意力主计算;AscendMiniMaxM3QKVParallelLinearWithIndexer 融合 [Q|K|V|index_q|index_k] 列并行 GEMM(shard 校验/偏移映射/两种 weight_loader)、AscendMiniMaxM3IndexerLinear 合并 [index_q|index_k] 投影;minimax_m3_sparse_forward 注册为自定义算子(带 fake 实现)供 torch.compile 切图。
类: AscendMiniMaxM3IndexerBackend, AscendMiniMaxM3IndexerCache, AscendMiniMaxM3IndexerMetadata, AscendMiniMaxM3IndexerMetadataBuilder, AscendMiniMaxM3IndexerImpl, AscendMiniMaxM3Indexer, AscendMiniMaxM3SparseBackend, AscendMiniMaxM3SparseMetadata, AscendMiniMaxM3SparseMetadataBuilder, AscendMiniMaxM3SparseImpl, AscendMiniMaxM3QKVParallelLinearWithIndexer, AscendMiniMaxM3IndexerLinear
func_should_use_tp_sharded_index_decode[5行]
func_active_decode_num_reqs[9行] Return the number of real decode requests, ignoring FIA/graph padding.
func_active_prefill_num_reqs[24行] Return real prefill requests, ignoring FIA/SP tail padding segments.
funcget_name[2行] 返回后端的注册名称
funcget_impl_cls[2行] 返回 attention 实现类
funcget_builder_cls[2行] 返回 attention metadata builder 类
funcget_supported_head_sizes[2行] 返回支持的 head 大小列表
funcget_supported_kernel_block_sizes[2行] 返回支持的 kernel 块大小列表
funcis_sparse[2行]
funcget_kv_cache_shape[8行] 返回 KV 缓存张量形状
funcget_kv_cache_stride_order[6行]
func__init__[38行] 初始化类实例(绑定配置、参数、模块)
funcget_kv_cache_spec[7行]
funcforward[4行] attention 前向入口
funcget_attn_backend[2行] 根据 vllm_config 返回 attention backend 类
func_build_tp_score_metadata[25行] Package graph-stable inputs; derive TP tensors in model forward.
funcbuild[74行] 构造 attention metadata
func_decode_topk_tp_sharded[55行]
funcupdate_graph_params[16行] No-op: sparse-attention replay parameters are owned by its metadata
funcindex_cache[2行]
funcvalidate_shard_id[7行]
func_get_shard_offset_mapping[5行]
func_get_shard_size_mapping[5行]
funcweight_loader_v2[25行]
funcweight_loader[27行]
func_quant_description_value[8行]
func_sparse_proj_quant_type[19行]
func_use_fused_qkv_indexer[22行]
func_register_m3_sparse_packed_modules[12行]
funcminimax_m3_sparse_forward[18行]
funcminimax_m3_sparse_forward_fake[10行]
models\minimax_m3\ops\__init__.py
查看源码models.minimax_m3.ops 子包标记。
类: 无
(无函数)
models\minimax_m3\ops\msa_m3_npu.py
查看源码MiniMax-M3 NPU 稀疏算子集(639 行)。q2k→k2q CSR 索引转换(_k2q_csr_block_stats/_npu_k2q_csr)把查询主导的稀疏索引转为键主导 CSR 供 AscendC 算子消费;index 打分:_minimax_m3_index_score 调捆绑 AscendC 算子计算索引分、minimax_m3_index_prefill(prefill 打分 + 块 topk 收尾)、minimax_m3_index_decode(decode 打分 + 非融合局部 topk)、minimax_m3_index_tp_block_parallel_decode(TP 分块并行打包打分与 topk);稀疏注意力:minimax_m3_sparse_attn 按 A3/A5 硬件分发(_minimax_m3_sparse_attn_a3/a5)、minimax_m3_sparse_attn_decode 走 AscendC 稀疏注意力算子;MiniMaxM3TPDecodeScoreMetadata 保证 TP decode 打分的图稳定输入。
类: 无
func_k2q_csr_block_stats[9行] Derive ``(total_rows, max_kv)`` from ``cu_block_lens`` on host.
func_npu_k2q_csr[32行] Convert MiniMax-M3 q2k indices to k2q CSR on NPU.
func_as_ascendc_index_kv_cache[13行] Convert the runtime index K cache to the AscendC BBND layout.
func_split_main_kv_cache[19行]
func_select_num_idx_from_topk[2行]
func_build_cu_block_lens[18行] Build cumulative logical KV-block counts for each prefill request.
func_minimax_m3_index_score[35行] Compute MSA index scores with the bundled AscendC operator.
funcminimax_m3_index_prefill[44行] Compute AscendC prefill scores and finalize their block TopK.
func_index_score_topk_candidates[77行] Return global block IDs and scores after exactly one local TopK.
func_minimax_m3_index_decode[40行] Run AscendC decode score followed by one non-fused local TopK.
funcminimax_m3_index_decode[31行] Compute AscendC decode scores and return their block TopK.
funcminimax_m3_index_tp_block_parallel_decode[100行] Run packed-query scoring and TopK over TP-sharded KV blocks.
func_minimax_m3_sparse_attn_a3[30行]
func_minimax_m3_sparse_attn_a5[45行]
funcminimax_m3_sparse_attn[30行]
funcminimax_m3_sparse_attn_decode[34行] Run sparse decode through the AscendC sparse-attention operator.
models\minimax_m3\ops\msa_m3_triton.py
查看源码MiniMax-M3 Triton kernel 集(1638 行,非 A5 平台)。index 打分:_prefill_index_score_kernel 对每个可见稀疏块算一个最大点积分、_decode_index_score_kernel decode 打分;topk:_mask_decode_topk_indices_kernel/_mask_prefill_topk_indices_kernel 失效块掩码、_prepare_prefill_topk_scores_kernel 应用 init/local 优先级填充无效尾部;稀疏注意力:_gqa_sparse_fwd_kernel(prefill,block_size_q==1)/_gqa_sparse_decode_kernel(decode split-K)+ _merge_topk_attn_out_kernel 合并多块输出与 LSE;包装函数 minimax_m3_index_score/topk/decode 与 minimax_m3_sparse_attn/decode 组织 kernel launch;_copy_topk_indices/values 复制并填充 topk 结果;_detected_aicore_count/_is_arch_support_pdl 做硬件适配。
类: 无
func_as_triton_index_kv_cache[15行] Normalizes the index-key cache to [num_blocks, 128, head_dim].
func_split_triton_main_kv_cache[19行]
func_is_arch_support_pdl[5行]
func_sparse_attn_num_stages_kwarg[20行] Triton ``num_stages`` override for the sparse-attn GEMM kernels.
func_detected_aicore_count[17行] Returns the detected Ascend AI Core count, or zero on fallback.
func_prefill_index_score_kernel[159行] Computes one max dot-product score per visible sparse block.
func_decode_index_score_kernel[150行]
func_mask_decode_topk_indices_kernel[34行]
func_prepare_prefill_topk_scores_kernel[115行] Applies init/local priorities and fills the invalid score tail.
func_mask_prefill_topk_indices_kernel[58行] Replaces invalid prefill top-k block IDs with ``-1``.
func_gqa_sparse_fwd_kernel[151行]
func_gqa_sparse_decode_kernel[189行]
func_merge_topk_attn_out_kernel[46行]
func_copy_topk_indices[23行] Copies top-k indices into an int32 result and pads missing slots.
func_copy_topk_values[17行] Copies top-k scores into an fp32 result and pads missing slots.
funcminimax_m3_index_score[63行] Computes one block score for every visible prefill KV block.
funcminimax_m3_index_topk[79行] Finalizes prefill scores and returns zero-based block IDs.
funcminimax_m3_index_decode[123行] Computes decode block scores and returns zero-based top-k block IDs.
funcminimax_m3_sparse_attn[60行] GQA block-sparse attention over the selected blocks. block_size_q == 1.
funcminimax_m3_sparse_attn_decode[113行] GQA block-sparse attention for decode (split-K over the top-k blocks).
models\minimax_m3\ops\msa_m3_triton_a5.py
查看源码MiniMax-M3 A5 平台 Triton kernel 集(1417 行)。与通用版对应但按 A5 特性调优:_decode_qk_score_kernel 单程序处理一个 query/chunk 的 decode QK 块打分、_index_block_score_kernel 索引块打分;topk 准备/掩码 kernel(prefill 与 decode 两套 init/local 掩码构建 _build_decode_index_score_masks);稀疏注意力 _gqa_sparse_fwd_kernel/_gqa_sparse_decode_kernel + _merge_topk_attn_out_kernel;对外的 minimax_m3_index_score/topk/decode、minimax_m3_sparse_attn/decode 接口与通用版一致(torch.topk + 失效索引掩码);_prune_decode_index_score_configs/_sparse_attn_num_stages_kwarg 做 kernel 配置裁剪与调优。
类: 无
func_as_triton_main_kv_cache[12行]
func_as_triton_index_kv_cache[15行] Normalize Ascend indexer cache to ``[num_blocks, 128, head_dim]``.
func_is_arch_support_pdl[5行]
func_sparse_attn_num_stages_kwarg[12行] Triton ``num_stages`` override for the sparse-attn GEMM kernels.
func_decode_qk_score_target_programs[13行]
func_prune_decode_index_score_configs[6行]
func_index_block_score_kernel[101行]
func_decode_qk_score_kernel[115行] Compute decode QK block scores with one program per query/chunk.
func_decode_index_score_pad_tail_kernel[36行]
func_topk_index_mask_invalid_kernel[31行]
func_prefill_index_score_prepare_for_topk_kernel[44行]
func_topk_index_mask_invalid_prefill_kernel[30行]
func_decode_index_score_masks_kernel[49行]
func_build_decode_index_score_masks[39行] Build bool init/local masks for decode index scoring via Triton.
funcminimax_m3_index_score[57行] Compute per-token index scores for each visible sparse block.
funcminimax_m3_index_topk[65行] Select index top-k from a precomputed score tensor (torch.topk).
funcminimax_m3_index_decode[117行] Decode index block-score + top-k (torch.topk + invalid-index mask).
func_gqa_sparse_fwd_kernel[137行]
func_gqa_sparse_decode_kernel[155行]
func_merge_topk_attn_out_kernel[45行]
funcminimax_m3_sparse_attn[57行] GQA block-sparse attention over the selected blocks. block_size_q == 1.
funcminimax_m3_sparse_attn_decode[91行] GQA block-sparse attention for decode (split-K over the top-k blocks).