_310p/attention/attention_mask.py
查看源码310P 注意力掩码构建器(186 行)。AttentionMaskBuilder310 生成因果加性掩码(gen_causal_additive_mask)、splitfuse 掩码(普通/压缩两种),is_compressed_mask_supported 判断硬件是否支持压缩掩码格式。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\attention\attention_mask.py
is_compressed_mask_supported[2行] 代码量 2 行
__init__[13行] Initializes the AttentionMaskBuilder for the 310P device.
gen_causal_additive_mask[19行] Generates a standard causal lower-triangular attention mask.
get_splitfuse_mask[27行] Generates and formats the attention mask for SplitFuse (chunked prefill) decoding.
get_compressed_splitfuse_mask[19行] Generates the fixed ND attention mask for compressed SplitFuse PA.
get_attention_mask[25行] Retrieves the appropriate attention mask based on the model configuration.
_get_causal_mask[14行] Internal method to get or update the cached causal attention mask.
_get_non_causal_mask[24行] Internal method to get or update the cached non-causal attention mask.
_310p/attention/attention_v1.py
查看源码310P 注意力后端(345 行)。AscendAttentionBackend310 声明后端元信息与 KV cache 形状;AscendAttentionBackendImpl310 实现 prefill/decode/chunked prefill 三条前向(_flash_attention 走 FA、forward_paged_attention 走 PA)与编码器注意力。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\attention\attention_v1.py
__init__[3行] 代码量 3 行
get_kv_cache_shape[26行] Determines the shape of the Key-Value (KV) cache tensor.
get_impl_cls[5行] Returns the implementation class for the attention operations.
get_builder_cls[5行] Returns the metadata builder class specifically for 310P.
get_supported_kernel_block_sizes[2行] 代码量 2 行
_flash_attention[36行] 代码量 36 行
_forward_encoder_attention[16行] 代码量 16 行
forward_paged_attention[38行] Executes Paged Attention (typically for the decode phase).
forward_prefill_310[29行] Executes Flash Attention for the prefill phase on 310P.
forward_chunked_prefill_310[74行] Executes SplitFuse (Chunked Prefill) attention on 310P.
forward_impl[36行] Main dispatch method for attention operations.
_310p/attention/metadata_builder.py
查看源码310P 元数据构建器(158 行)。AscendAttentionMetadataBuilder310 构建 310P 专属注意力元数据;set/get_query_lens_cpu 在不扩展上游 AscendMetadata 的前提下挂载 host 侧 qLens(ATB splitfuse 需要)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\attention\metadata_builder.py
set_query_lens_cpu[3行] Attach host qLens for ATB splitfuse without extending upstream AscendMetadata.
get_query_lens_cpu[5行] 代码量 5 行
__init__[26行] Initializes the metadata builder and the 310P-specific mask builder.
_fill_query_lens_cpu[19行] Pinned CPU per-request query lengths for ATB splitfuse (host qLensTensor).
build[41行] 代码量 41 行
build_for_drafting[9行] 代码量 9 行
310P 块表(199 行)。BlockTable/MultiGroupBlockTable 的 310P 版本:slot mapping 计算(_compute_slot_mapping_numpy 走 NumPy 路径,310P 无 Triton)、块表索引获取与输入归一化。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\block_table.py
compute_slot_mapping[26行] 代码量 26 行
_compute_slot_mapping_numpy[30行] 代码量 30 行
_get_block_table_indices[3行] 代码量 3 行
_normalize_slot_mapping_inputs[19行] 代码量 19 行
_to_numpy[11行] 代码量 11 行
__init__[67行] 代码量 67 行
compute_slot_mapping_draft[16行] 代码量 16 行
_310p/fused_moe/fused_moe.py
查看源码310P MoE 方法(140 行)。AscendUnquantizedFusedMoEMethod310(非量化 MoE 方法)、AscendRoutedExperts310/AscendMoERunner310 的 310P 适配(无 MC2,走 all-gather 路径)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\fused_moe\fused_moe.py
__init__[38行] 代码量 38 行
is_monolithic[2行] 代码量 2 行
maybe_make_prepare_finalize[4行] 代码量 4 行
process_weights_after_loading[10行] 代码量 10 行
apply[30行] 代码量 30 行
_310p/fused_moe/grouped_topk_router.py
查看源码310P 分组 top-k 路由器(64 行)。AscendGroupedTopKRouter310 用分块 softmax 实现 top-k 路由(310P 不支持融合门控算子的替代路径)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\fused_moe\grouped_topk_router.py
_compute_routing[36行] 代码量 36 行
_310p/fused_moe/moe_comm_method.py
查看源码310P MoE 通信(50 行)。AllGatherCommImpl310 用 all-gather + reduce-scatter 做 MoE 通信(_apply_mlp 应用 MLP、_get_token_dispatcher 返回 310P 分发器)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\fused_moe\moe_comm_method.py
__init__[3行] 代码量 3 行
_apply_mlp[2行] 代码量 2 行
_get_token_dispatcher[6行] 代码量 6 行
_310p/fused_moe/moe_mlp.py
查看源码310P MoE MLP(102 行)。quant_apply_mlp/unquant_apply_mlp 的 310P 实现(group_list_type 区分 AscendC 契约),unified_apply_mlp 统一入口。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\fused_moe\moe_mlp.py
quant_apply_mlp[21行] 代码量 21 行
unquant_apply_mlp[22行] 代码量 22 行
unified_apply_mlp[32行] 代码量 32 行
_310p/fused_moe/token_dispatcher.py
查看源码310P token 分发器(88 行)。TokenDispatcherWithAllGather310 用 all-gather 实现 token 分发(无 all-to-all 的 310P 适配)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\fused_moe\token_dispatcher.py
__init__[2行] 代码量 2 行
token_dispatch[52行] 代码量 52 行
_310p/kv_block_zeroer.py
查看源码310P KV 块清零器(82 行)。AscendKVBlockZeroer310 不依赖 Triton(310P 无 Triton-Ascend 时用 NPU 算子实现):init_meta 预计算元数据、zero_block_ids 批量清零。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\kv_block_zeroer.py
__init__[5行] 代码量 5 行
init_meta[34行] 代码量 34 行
zero_block_ids[10行] 代码量 10 行
_310p/model_runner_310p.py
查看源码310P 模型运行器 V1(982 行)。NPUModelRunner310 与 910B 采用不同的 ACL graph 捕获/重放契约:批执行判定与填充(_determine_batch_execution_and_padding)、注意力元数据构建、uniform decode 查询长度临时修改、KV 缓存张量分配与清零元数据初始化。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\model_runner_310p.py
__init__[29行] 代码量 29 行
_update_states[12行] 代码量 12 行
temporary_modify_uniform_decode_query_len[15行] 代码量 15 行
_determine_batch_execution_and_padding[50行] 代码量 50 行
_build_attention_metadata[6行] 代码量 6 行
_pad_query_start_loc_for_fia[33行] 代码量 33 行
_build_attn_state[10行] 代码量 10 行
_prepare_inputs[315行] 310P cannot use the Triton slot-mapping kernel or the generic NPU Add
_dummy_run[44行] 代码量 44 行
_model_forward[50行] 代码量 50 行
_check_and_update_cudagraph_mode[9行] 代码量 9 行
_init_kv_zero_meta[10行] 310P uses torch zeroing because Triton is not available.
initialize_kv_cache_tensors[32行] Override the base class method.
_allocate_kv_cache_tensors[89行] Initializes the KV cache size. The buffer needs to be reshaped to the desired shape before being used by
_prepare_input_ids[92行] Prepare the input IDs for the current batch.
may_reinitialize_input_batch[84行] Re-initialize the input batch if the block sizes are different from
_310p/npu_input_batch.py
查看源码310P 输入批(59 行)。NPUInputBatch310 的 310P 适配版本。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\npu_input_batch.py
__init__[50行] 代码量 50 行
_310p/ops/activation.py
查看源码310P 激活算子(32 行)。AscendSiluAndMul310 用 310P 支持的 NPU 算子组合实现 SiluAndMul。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\activation.py
forward[7行] 代码量 7 行
_310p/ops/causal_conv1d.py
查看源码310P 因果卷积(297 行)。纯 PyTorch 实现(310P 无 Triton kernel):causal_conv1d_fn(支持初始状态与激活)、causal_conv1d_update(decode 增量更新)、causal_conv1d_ref(参考实现)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\causal_conv1d.py
causal_conv1d_ref[47行] PyTorch reference implementation of causal_conv1d.
causal_conv1d_fn[102行] PyTorch implementation of causal_conv1d_fn for 310P.
causal_conv1d_update[139行] PyTorch implementation of causal_conv1d_update for 310P.
_select_state[9行] 代码量 9 行
_run_one[15行] 代码量 15 行
310P 3D 卷积(27 行)。AscendConv3dLayer310 适配视觉编码器卷积层。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\conv.py
forward_oot[4行] 代码量 4 行
_310p/ops/fla/chunk_gated_delta_rule.py
查看源码310P GDN chunk 路径(586 行)。chunk_gated_delta_rule_310 由 AscendC fwd_h/fwd_o kernel 支撑(_require_ascend_chunk_ops 校验);输入归一化支持 TND/变长(_normalize_chunk_inputs/_pad_varlen_to_chunk)、按 WY 前缀构造 kernel 输入(_compute_kernel_inputs_from_torch_wy)、输出 unpad(_unpad_chunk_output);chunk_gated_delta_rule_pytorch 为参考实现。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\fla\chunk_gated_delta_rule.py
_expand_qk_to_v_heads[12行] Expand q/k heads to match v heads for grouped-value-attention semantics.
_iter_seq_ranges[4行] 代码量 4 行
_normalize_chunk_inputs[36行] Normalize inputs to [B, T, H, D] / [B, T, H] while preserving TND support.
_torch_chunk_gated_delta_rule_chunked[98行] Chunked torch implementation aligned with the Qwen3-Next torch path:
_ceil_div[2行] 代码量 2 行
_require_ascend_chunk_ops[10行] 代码量 10 行
_maybe_l2norm[4行] 代码量 4 行
_pad_bthd_to_chunk[29行] 代码量 29 行
_pad_varlen_to_chunk[63行] 代码量 63 行
_prepare_chunk_indices_list[12行] 代码量 12 行
_compute_kernel_inputs_from_torch_wy[48行] Compute the original torch WY prefix and return AscendC kernel layout.
_unpad_chunk_output[20行] 代码量 20 行
chunk_gated_delta_rule_pytorch[78行] Reference-only implementation with vLLM-compatible interface.
chunk_gated_delta_rule_310[117行] 310P chunk GDN path backed by AscendC fwd_h/fwd_o kernels.
_310p/ops/fla/cumpute_causal_conv1d_metadata_310.py
查看源码因果卷积元数据计算(57 行)。compute_causal_conv1d_metadata 从 query_start_loc 推导 GDN causal conv1d 所需的元数据(序列偏移与状态索引)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\fla\cumpute_causal_conv1d_metadata_310.py
compute_causal_conv1d_metadata[52行] 代码量 52 行
_310p/ops/fla/fused_gdn_gating.py
查看源码310P GDN 门控(62 行)。fused_gdn_gating_pytorch 用 PyTorch 实现 GDN 门控计算(A_log/a/b/dt_bias → beta),是 Triton 版的 310P 替代。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\fla\fused_gdn_gating.py
fused_gdn_gating_pytorch[59行] PyTorch implementation of fused_gdn_gating.
_310p/ops/fla/fused_recurrent_gated_delta_rule.py
查看源码310P GDN 递归路径(227 行)。fused_recurrent_gated_delta_rule_pytorch 用 PyTorch 递归实现 GDN delta 规则(decode 期);_expand_to_hv 支持 grouped-value-attention 语义、_infer_num_states/_state_index 管理状态索引。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\fla\fused_recurrent_gated_delta_rule.py
_maybe_l2norm[4行] 代码量 4 行
_expand_to_hv[8行] Expand [H, ...] to [HV, ...] for grouped-value-attention semantics.
_infer_num_states[13行] 代码量 13 行
_state_index[10行] 代码量 10 行
_run_recurrent_gated_delta_rule[135行] Reference PyTorch recurrence for GDN delta rule.
fused_recurrent_gated_delta_rule_pytorch[42行] PyTorch fallback for fused_recurrent_gated_delta_rule.
_310p/ops/fla/gdn_310.py
查看源码310P GDN 注意力(432 行)。npu_recurrent_gated_delta_rule_310 递归路径、AscendGatedDeltaNetAttention310 组装(get_attn_backend/_forward_core);_merge_spec_and_non_spec_outputs_310 把投机与非投机 GDN 输出合并回批次布局;_mask_padded_recurrent_accepted_tokens 掩蔽投机接受的填充 token。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\fla\gdn_310.py
_zero_padded_tokens[21行] 代码量 21 行
_flatten_state_indices[31行] 代码量 31 行
_mask_padded_recurrent_accepted_tokens[10行] 代码量 10 行
npu_recurrent_gated_delta_rule_310[44行] 代码量 44 行
_310p_get_state_dtype[3行] 代码量 3 行
_merge_spec_and_non_spec_outputs_310[25行] Merge spec/non-spec GDN outputs back into the batch layout.
get_attn_backend[6行] 代码量 6 行
_forward_core[239行] 代码量 239 行
_310p/ops/fla/idex.py
查看源码310P chunk 索引工具(42 行)。prepare_chunk_indices_310/prepare_chunk_offsets_310 预计算变长序列的 chunk 索引与偏移。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\fla\idex.py
prepare_chunk_indices_310[10行] 代码量 10 行
prepare_chunk_offsets_310[6行] 代码量 6 行
_310p/ops/fla/l2norm.py
查看源码310P L2 归一化(43 行)。l2norm_310p 用 310P 的 RMSNorm kernel 变通实现末维 L2 归一化(_l2norm_unit_weight 构造单位权重)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\fla\l2norm.py
_l2norm_unit_weight[3行] 代码量 3 行
l2norm_310p[11行] L2-normalize the last dimension using the 310P NPU RMSNorm kernel.
_310p/ops/gdn_attn_builder_310.py
查看源码310P GDN 元数据构建器(259 行)。GDNAttentionMetadataBuilder310 在通用构建器上做 310P 覆盖:prefill 初始状态与 causal conv 元数据、spec/non-spec 的 fallback 元数据、decode/spec 元数据填充。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\gdn_attn_builder_310.py
_build_prefill_has_initial_state_and_causal_conv1d_meta[37行] 代码量 37 行
_attach_non_spec_prefill_fallback_meta[8行] 代码量 8 行
_attach_spec_decode_fallback_meta[8行] 代码量 8 行
_attach_non_spec_decode_fallback_meta[8行] 代码量 8 行
_pad_spec_decode_metadata[63行] 代码量 63 行
_pad_decode_metadata[33行] 代码量 33 行
build[39行] 代码量 39 行
get_builder_cls[2行] 代码量 2 行
_310p/ops/layernorm.py
查看源码310P 归一化算子(68 行)。AscendRMSNorm310/AscendGemmaRMSNorm310/AscendRMSNormGated310(_apply_activation 处理门控激活)的 310P 版本。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\layernorm.py
forward_oot[17行] 代码量 17 行
_apply_activation[6行] 代码量 6 行
_310p/ops/mm_encoder_attention.py
查看源码310P 多模态编码器注意力(161 行)。AscendMMEncoderAttention310(QKV 三维重排 + forward_oot);is_approximate_calculation_supported 判断近似计算支持。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\mm_encoder_attention.py
is_approximate_calculation_supported[2行] 代码量 2 行
__init__[29行] Args:
_reshape_qkv_to_3d[23行] Reshape query, key, value to 3D tensors:
forward_oot[65行] 代码量 65 行
_310p/ops/qwen3vl_310.py
查看源码Qwen3-VL 310P 适配(35 行)。rot_pos_emb_310 替换 Qwen3-VL 视觉旋转位置编码的计算路径。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\qwen3vl_310.py
rot_pos_emb_310[14行] 代码量 14 行
_310p/ops/rotary_embedding.py
查看源码310P RoPE(273 行)。AscendMRotaryEmbedding310/AscendRotaryEmbedding310(set_rope_position_flag_310p 设置位置标志);mrope 支持:merge_mrope_cos_sin_for_apply 合并三分量 cos/sin、set_mrope_apply_rotary_slices 按 positions 构建 cos/sin 视图(每 forward 一次);_apply_rotary_mrope_torch 为对齐 vLLM native 的 PyTorch 路径。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\rotary_embedding.py
_apply_rotary_mrope_torch[14行] PyTorch path aligned with vLLM MRotaryEmbedding.forward_native -> ApplyRotaryEmb.
merge_mrope_cos_sin_for_apply[15行] 代码量 15 行
set_mrope_apply_rotary_slices[51行] Build cos/sin views for `npu_apply_rotary_pos_emb` from positions; must run once per forward before layers.
_rope_forward_oot[65行] 代码量 65 行
prepare_mrope_cos_sin_slices_from_runner[14行] Resolve MRoPE embedding from the runner and populate `_mrope_cos_slice` / `_mrope_sin_slice`.
forward_oot[12行] 代码量 12 行
set_rope_position_flag_310p[2行] 代码量 2 行
_310p/ops/vocab_parallel_embedding.py
查看源码310P 词嵌入(92 行)。AscendVocabParallelEmbedding310/AscendParallelLMHead310/AscendUnquantizedEmbeddingMethod310 的 310P 版本。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\ops\vocab_parallel_embedding.py
process_weights_after_loading[2行] 代码量 2 行
apply[7行] 代码量 7 行
__init__[27行] 代码量 27 行
_310p/quantization/methods/registry.py
查看源码310P 量化 scheme 注册表(41 行)。register_scheme 装饰器按(quant_type, layer_type)注册;get_scheme_class 查询。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\quantization\methods\registry.py
register_scheme[13行] Decorator to register a 310P quantization scheme.
get_scheme_class[3行] Get 310P scheme class for given quant_type and layer_type.
decorator[8行] 代码量 8 行
_310p/quantization/methods/w8a8_base.py
查看源码310P W8A8 基类(44 行)。AscendW8A8Linear310pScheme 定义权重与 per-tensor/per-channel 参数获取接口。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\quantization\methods\w8a8_base.py
get_weight[7行] 代码量 7 行
get_pertensor_param[5行] 代码量 5 行
get_perchannel_param[5行] 代码量 5 行
_310p/quantization/methods/w8a8_dynamic.py
查看源码310P W8A8 动态量化(177 行)。AscendW8A8DynamicLinearMethod310(线性)与 AscendW8A8DynamicFusedMoEMethod310(MoE):动态量化参数获取、apply、加载后权重处理。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\quantization\methods\w8a8_dynamic.py
__init__[4行] 代码量 4 行
get_weight[13行] 代码量 13 行
get_dynamic_quant_param[13行] 代码量 13 行
apply[30行] 代码量 30 行
process_weights_after_loading[5行] 代码量 5 行
get_perchannel_param[9行] 代码量 9 行
_310p/quantization/methods/w8a8_static.py
查看源码310P W8A8 静态量化(98 行)。AscendW8A8LinearMethod310 的静态量化实现。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\quantization\methods\w8a8_static.py
get_perchannel_param[7行] 代码量 7 行
apply[30行] 代码量 30 行
process_weights_after_loading[23行] 代码量 23 行
_310p/quantization/methods/w8a8s.py
查看源码310P W8A8S 稀疏量化(66 行)。AscendW8A8SLinearMethod310 支持 W8A8S 稀疏线性 scheme。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\quantization\methods\w8a8s.py
apply[24行] 代码量 24 行
process_weights_after_loading[6行] 代码量 6 行
_310p/quantization/methods/w8a8sc.py
查看源码310P W8A8SC 量化(104 行)。AscendW8A8SCLinearMethod310 支持 W8A8SC(sparse-compressed)静态线性 scheme。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\quantization\methods\w8a8sc.py
get_weight[32行] Get the weight tensors for the W8A8SC quantization scheme.
apply[22行] 代码量 22 行
process_weights_after_loading[10行] 代码量 10 行
_310p/quantization/modelslim_config.py
查看源码310P ModelSlim 配置(140 行)。AscendModelSlimConfig310 为 ModelSlim 量化配置的 310P 覆盖(get_quant_method);create_scheme_for_layer 按量化描述为层创建 scheme 实例。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\quantization\modelslim_config.py
create_scheme_for_layer[33行] Create a quantization scheme instance for a layer.
get_quant_method[51行] 代码量 51 行
_310p/sample/rejection_sampler.py
查看源码310P 拒绝采样器(113 行)。AscendRejectionSampler310 用 PyTorch recovered-token 路径 + CPU RNG 实现(无 Triton 依赖)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\sample\rejection_sampler.py
_bind_sample_recovered_tokens[7行] 代码量 7 行
forward[9行] 代码量 9 行
sample_recovered_tokens[57行] 代码量 57 行
_310p/sample/sampler.py
查看源码310P 采样器(187 行)。AscendSampler310/AscendTopKTopPSampler310:310P 不支持所需 NPU 随机数路径,随机采样改用 pinned CPU 内存生成均匀数(_prepare_cpu_generators_310p/_generate_request_uniforms_310p)再经 CDF 采样(_sample_from_cdf_310p,仅用 310P 支持的 NPU 算子);fill_exponential_310p CPU 生成指数分布后搬运。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\sample\sampler.py
_prepare_cpu_generators_310p[24行] Return CPU RNGs while preserving requests across batch reordering.
_generate_request_uniforms_310p[18行] Generate one uniform value per request on pinned CPU memory.
_sample_from_cdf_310p[8行] Sample rows of non-negative weights with 310P-supported NPU ops.
fill_exponential_310p[41行] Generate exponential values on CPU and transfer them to NPU.
_random_sample_310p[22行] 310P does not support the required NPU random-generation path.
forward_native[26行] 代码量 26 行
__init__[3行] 代码量 3 行
_310p/sharded_state_loader_310p.py
查看源码310P 分片状态加载器(80 行)。ShardedStateLoader310 保存分片模型(save_model)并生成量化描述(generate_quant_description)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\sharded_state_loader_310p.py
__init__[2行] 代码量 2 行
save_model[18行] 代码量 18 行
generate_quant_description[29行] Generate a mapping of parameter names to their corresponding quantization types.
_310p/spec_decode/llm_base_proposer_310.py
查看源码310P 投机解码 proposer 基类(122 行)。AscendSpecDecodeBaseProposer310 处理 NPU 特有 workaround:_run_merged_draft 合并 draft、set_inputs_first_pass 首趟输入设置。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\spec_decode\llm_base_proposer_310.py
_run_merged_draft[29行] 代码量 29 行
set_inputs_first_pass[60行] 代码量 60 行
_310p/worker/v2/block_table.py
查看源码310P V2 块表(169 行)。Ascend310PBlockTables:CPU 持有的 MRV2 块表(与 310P MRV1 数据路径一致),init_block_table_layout_tensors 布局张量初始化、append_block_ids/apply_staged_writes 增量更新、slot mapping 与 dummy 输出。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\worker\v2\block_table.py
__init__[52行] 代码量 52 行
init_block_table_layout_tensors[2行] 310P does not use Triton pointer tables.
append_block_ids[20行] 代码量 20 行
apply_staged_writes[2行] Block IDs are written to their CPU owner immediately.
_as_numpy[6行] 代码量 6 行
gather_block_tables[24行] 代码量 24 行
compute_slot_mappings[28行] 代码量 28 行
get_dummy_block_tables[4行] 代码量 4 行
get_dummy_slot_mappings[3行] 代码量 3 行
_310p/worker/v2/kv_block_zeroer.py
查看源码310P V2 块清零适配(38 行)。AscendKVBlockZeroer310V2 把 V2 的扁平 block-size 布局归一化后复用 V1 的 310P 清零器。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\worker\v2\kv_block_zeroer.py
init_meta[21行] 代码量 21 行
_310p/worker/v2/model_runner.py
查看源码310P V2 运行器(755 行)。NPUModelRunner310V2:配置校验、310P 输入准备(_prepare_inputs_310p)、KV 规格与初始化、kernel 块大小调整、prefill 输入准备、draft token 合并、采样与注意力准备。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\worker\v2\model_runner.py
__init__[14行] 代码量 14 行
_validate_config[36行] 代码量 36 行
_prepare_inputs_310p[162行] 代码量 162 行
_sync_num_computed_tokens_gpu_from_np[7行] Mirror ``num_computed_tokens_np`` onto GPU before mamba preprocess.
finish_requests[8行] 代码量 8 行
get_kv_cache_spec[13行] Restore linear-attention specs omitted by some upstream V2 versions.
initialize_kv_cache[69行] Allocate 310P attention caches as NZ and hybrid Mamba caches as ND.
_adjust_kernel_block_sizes[25行] 代码量 25 行
_init_kv_zero_meta[9行] 代码量 9 行
_allocate_kv_cache_tensors[120行] Allocate attention caches as NZ and hybrid Mamba state as ND.
_prepare_prefill_inputs[33行] 代码量 33 行
_prepare_pos_seq_lens[25行] 代码量 25 行
_combine_sampled_and_draft_tokens[32行] 代码量 32 行
prepare_attn[28行] 代码量 28 行
sample[19行] 代码量 19 行
postprocess_sampled[41行] 代码量 41 行
_get_valid_query_lens[8行] Return real request query lengths without ACLGraph padding.
postprocess_num_computed_tokens[9行] 代码量 9 行
prepare_inputs[8行] 代码量 8 行
_310p/worker/v2/model_state.py
查看源码310P V2 模型状态(187 行)。_Ascend310PModelStateMixin 提供 310P RoPE/全图 seq_lens 辅助;Ascend310PModelState(dense/VL,无 Triton 采样器与 MRoPE、编码器支持);Ascend310PMambaHybridModelState(hybrid/GDN,保持 Ascend hybrid 契约、换用非 Triton RoPE)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\worker\v2\model_state.py
_replace_310p_rope_state[13行] 代码量 13 行
_record_capture_seq_lens[6行] Record the largest captured view for each physical buffer.
_refresh_capture_seq_lens[7行] Copy runtime lengths to buffers read by FULL graph replay.
prepare_attn[27行] 代码量 27 行
prepare_inputs[18行] 代码量 18 行
custom_sampler[3行] 代码量 3 行
__init__[14行] 代码量 14 行
postprocess_state[22行] 代码量 22 行
_310p/worker/v2/rope.py
查看源码310P V2 RoPE 状态(113 行)。Ascend310PRopeState 无 Triton 的 MRoPE 状态(Qwen3-VL/Qwen3.5):prefill 位置初始化、CPU 位置准备、staged write 应用;get_310p_rope_state 工厂。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\worker\v2\rope.py
get_310p_rope_state[13行] 代码量 13 行
__init__[20行] 代码量 20 行
init_prefill_positions[18行] 代码量 18 行
apply_staged_writes[3行] 代码量 3 行
prepare_positions_cpu[33行] 代码量 33 行
get_positions[2行] 代码量 2 行
_310p/worker/v2/sampler.py
查看源码310P V2 采样器(66 行)。Ascend310PSampler 无 Triton 的采样器:add_request 登记请求 RNG、apply_staged_writes 应用暂存写、__call__ 执行采样。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\worker\v2\sampler.py
__init__[2行] 代码量 2 行
add_request[33行] 代码量 33 行
apply_staged_writes[2行] 代码量 2 行
__call__[10行] 代码量 10 行
_310p/worker/v2/states.py
查看源码310P V2 请求状态(137 行)。Ascend310PStagedWriteTensor 用 CPU 持有实现替代 vLLM 的 Triton staged writes(stage_write/stage_write_elem/apply_write);Ascend310PRequestState 与 MRV1 310P 同款的 CPU 持有模型。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\worker\v2\states.py
__init__[41行] 代码量 41 行
stage_write[10行] 代码量 10 行
stage_write_elem[3行] 代码量 3 行
apply_write[12行] 代码量 12 行
add_request[19行] 代码量 19 行
310P worker(187 行)。NPUWorker310:设备初始化(init_device/_init_device)、ATB 预热(_warm_up_atb)、可用显存判定、分片状态保存、创建 310P 专属 model runner。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\_310p\worker_310p.py
_create_model_runner[11行] 代码量 11 行
init_device[6行] 代码量 6 行
save_sharded_state[20行] 代码量 20 行
determine_available_memory[60行] Profiles the peak memory usage of the model to determine how much
_warm_up_atb[3行] 代码量 3 行
_init_device[49行] 代码量 49 行
device/device_config.py
查看源码设备配置运行时入口(77 行)。DeviceConfig 不可变硬件族配置;get_device_config 返回当前安装对应的配置;check_ascend_device_type 校验安装包与运行时 NPU 匹配;is_310p/is_950 快捷判断。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\device\device_config.py
_device_type_from_build_info[13行] 代码量 13 行
get_device_config[4行] Return the immutable hardware configuration for this installation.
get_ascend_device_type[2行] 代码量 2 行
is_310p[2行] 代码量 2 行
is_950[2行] 代码量 2 行
check_ascend_device_type[13行] Validate that the installed package matches the runtime NPU.
设备算子适配器(1596 行)。BaseDeviceAdaptor 定义全部设备算子接口:reshape_and_cache、npu_fused_infer_attention_score(FIA)、MoE 路由(npu_moe_init_routing/moe_gating_top_k)、分组乘(npu_grouped_matmul_swiglu_quant/gmm2)、动态量化、KV 加载(kv_cache_load)、indexer 后处理、稀疏注意力执行等;A5DeviceAdaptor 覆盖 A5(Ascend950)差异算子(MXFP scale 布局、indexer 量化 scatter 三段式等);Ascend310PDeviceAdaptor 覆盖 310P 差异;get_device_adaptor 按硬件族返回适配器。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\device\device_op.py
get_device_adaptor[7行] 代码量 7 行
reshape_and_cache[8行] 代码量 8 行
npu_fused_infer_attention_score[27行] 代码量 27 行
npu_moe_init_routing[26行] 代码量 26 行
maybe_normalize_mxfp_scale_layout[6行] 代码量 6 行
moe_gating_top_k[30行] 代码量 30 行
npu_mm_reduce_scatter_base[31行] 代码量 31 行
npu_dynamic_quant[23行] 代码量 23 行
npu_grouped_matmul_swiglu_quant[93行] 代码量 93 行
get_quant_gmm2_kwargs[34行] 代码量 34 行
npu_grouped_matmul_gmm2[89行] 代码量 89 行
kv_cache_load[10行] 代码量 10 行
indexer_select_post_process[67行] 代码量 67 行
execute_sparse_flash_attention_process[69行] 代码量 69 行
_execute_kv_quant_sparse_flash_attention[40行] 代码量 40 行
npu_flash_attention[15行] 代码量 15 行
indexer_quantize_query[4行] Quantize indexer query. A5: fp8 quant, no extra scale conversion.
indexer_quant_scatter[18行] Quantize q (fp8) and scatter kv via fused indexer_compress_epilog_v2.
indexer_quant_scatter_part1[13行] Part1 of multi-stream indexer scatter.
dsa_indexer_scatter_scale_part3[4行] Part3 of multi-stream indexer scatter.
warmup_indexer_quant_scatter[11行] Warmup profiling for indexer quant+scatter.
prepare_dsa_indexer_weights[3行] A5: cast indexer weights to float32 (fp8 scale format needs float).
prepare_dsa_indexer_query_scale[3行] A5: cast query dequant scale to float32.
prepare_dsa_indexer_key_scale[3行] A5: cast key dequant scale to float32.
apply_dsa_q_rms[13行] Apply Q RMS norm. A5: uses q_norm_without_weight callable.
unpack_dsa_indexer_kv_cache[5行] Unpack indexer kv_cache tuple.
unpack_dsa_forward_kv_cache[11行] Unpack kv_cache for forward pass. A5: 7-element tuple with
pad_dsa_decode_slot_mapping[13行] A5: pad slot_mapping to target shape for ACL graph compatibility.
get_dsa_decode_cu_seqlens_cmp_kv[3行] A5: cu_seqlens_cmp_kv is always None.
get_dsa_decode_cu_seqlens_ori_kv[15行] A5: compute from cumsum of seq_lens, with caching.
get_dsa_kernel_block_sizes[3行] A5: return supported kernel block sizes.
chunk_scaled_dot_kkt_fwd[26行] 代码量 26 行
solve_tril_16x16[27行] 代码量 27 行
npu_gemma_rms_norm[3行] 代码量 3 行
fused_gdn_gating[2行] 代码量 2 行
split_qkv_rmsnorm_rope[27行] 代码量 27 行
npu_moe_token_unpermute[4行] 代码量 4 行
index_fill[23行] 代码量 23 行
纯硬件识别(75 行)。AscendDeviceType 枚举内部硬件族;device_type_from_soc_version 把编译期 SOC_VERSION 解析为硬件族;device_type_from_runtime_soc 解析 torch-npu 报告的运行时 SOC 版本。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\device\hardware.py
device_type_from_soc_version[10行] Resolve a build-time SOC_VERSION value to a hardware family.
device_type_from_runtime_soc[12行] Resolve the numeric SOC version reported by torch-npu.
device/hardware_profile.py
查看源码硬件能力档案(233 行)。HardwareCapability/AttentionBackendFamily/CPUBindingMode/DeviceAdaptorFamily/DeviceAddressingMode/QuantizationBackendFamily/WeightLayoutPolicy 定义正交能力维度;HardwareProfile 为一个 SoC 族的不可变能力与实现选择集合(supports 查询);get_hardware_profile/get_current_hardware_profile 按设备类型取档案,供共享业务逻辑按硬件分派。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\device\hardware_profile.py
get_hardware_profile[7行] Return the immutable profile registered for ``device_type``.
get_current_hardware_profile[4行] Return the profile selected by the current device configuration.
supports[4行] Return whether this hardware family provides ``capability``.
设备算子工具(139 行)。npu_large_head_prefill_attention 大头 prefill 注意力(KV 头多于 Q 头场景):_gather_paged_kv_to_dense 把分页 KV 按块表聚成稠密张量后走普通注意力算子。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\device\utils.py
npu_large_head_prefill_attention[50行] 代码量 50 行
_get_large_head_prefill_kv[34行] 代码量 34 行
_gather_paged_kv_to_dense[25行] 代码量 25 行
device_allocator/camem.py
查看源码CANN 内存池分配器(310 行)。CaMemAllocator 单例管理 CANN 张量内存池:python_malloc/free_callback 对接可插拔分配器、use_memory_pool_with_allocator 启用池、sleep/wake_up 释放/恢复池内存(睡眠模式基础)、get_current_usage 用量统计;find_loaded_library 定位已加载的 C库;create_and_map/unmap_and_release 管理分配句柄。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\device_allocator\camem.py
find_loaded_library[23行] According to according to https://man7.org/linux/man-pages/man5/proc_pid_maps.5.html,
create_and_map[2行] 代码量 2 行
unmap_and_release[2行] 代码量 2 行
get_pluggable_allocator[7行] 代码量 7 行
use_memory_pool_with_allocator[8行] 代码量 8 行
get_instance[9行] CaMemAllocator is a singleton class.
__init__[11行] 代码量 11 行
python_malloc_callback[7行] Internal method to store the allocation data
python_free_callback[8行] Internal method to look up the allocation data
sleep[46行] Put the allocator in sleep mode.
wake_up[28行] Wake up the allocator from sleep mode.
use_allocation_tag[8行] Temporarily override the tag assigned to new allocations.
use_memory_pool[34行] A context manager to use the memory pool.
get_current_usage[9行] Get the total number of bytes allocated in the memory pool.
device_allocator/sleep_mem_optimized.py
查看源码睡眠唤醒管理器族(186 行)。SleepWakeupManager:sleep 时释放非持久显存(_measure_memory_released 实测释放量)、wakeup 恢复;AclGraphSleepWakeupManager 额外清理注意力 workspace 与重置图参数;HcclSleepWakeupManager 销毁/恢复 HCCL 通信组(iter_alive_group_coordinators/refresh_moe_hccl_groups)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\device_allocator\sleep_mem_optimized.py
__init__[3行] 代码量 3 行
_measure_memory_released[5行] 代码量 5 行
sleep[9行] 代码量 9 行
wakeup[5行] 代码量 5 行
clear_attention_workspaces[5行] 代码量 5 行
clear_all_attention_workspaces[4行] 代码量 4 行
reset_graph_params[10行] 代码量 10 行
reset_all_graph_params[7行] 代码量 7 行
reset_model_runner_graph_manager[8行] 代码量 8 行
iter_alive_group_coordinators[8行] 代码量 8 行
destroy_hccl[6行] 代码量 6 行
restore_hccl[6行] 代码量 6 行
refresh_moe_hccl_groups[8行] 代码量 8 行
ec_manager/score_ec_manager.py
查看源码基于打分的编码器缓存管理器(522 行)。ScoreEncoderCacheManager 管理多模态编码器缓存的进出:score 为缓存项打分、should_promote 判断晋升 NPU、evict_from_npu 驱逐、check_and_update_cache 更新、allocate/free 管理配额(cal_theory_cost_storage_cost 理论存储成本);ScoreEncoderCacheConfig 策略配置;_check_invariant 不变量检查。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\ec_manager\score_ec_manager.py
from_dict[7行] 代码量 7 行
__post_init__[31行] 代码量 31 行
create_manager[7行] 代码量 7 行
__init__[62行] 代码量 62 行
score[4行] Score an entry, including clock only for NPU residency.
evict_from_npu[10行] Evict an entry from the NPU cache.
should_promote[53行] Determine whether an entry in the CPU cache should be promoted to the NPU cache.
check_and_update_cache[50行] Check whether the multimodal embedding corresponding to the current input
on_request[5行] 代码量 5 行
can_allocate[45行] Determine whether CPU cache space can be allocated for the current input.
cal_theory_cost_storage_cost[19行] Compute the theoretical recomputation cost per storage slot.
allocate[34行] Allocate a CPU cache entry for the current input.
free_encoder_input[20行] 代码量 20 行
get_manager_metadata[15行] 代码量 15 行
get_freed_mm_hashes[3行] Report evictions through layer-specific manager metadata.
_check_invariant[54行] Validate internal state in unit tests and debugging.
reset[27行] Reset the encoder cache to its initial state.
eplb/adaptor/vllm_adaptor.py
查看源码EPLB 的 vLLM 适配器(222 行)。VllmEplbAdaptor 连接 EPLB 核心与 vLLM 模型:注册层(register_layer)、初始化专家参数与缓冲、读取 rank 专家负载(get_rank_expert_workload)、清除负载数(clear_all_moe_loads)、执行专家映射/权重/log2phy 更新(do_update_*)、导出张量到文件。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\eplb\adaptor\vllm_adaptor.py
register_layer[7行] Register a MoE layer for EPLB. Called during layer initialization.
__init__[33行] 代码量 33 行
init_buffer_tensor[19行] 代码量 19 行
init_expert_param_per_layer[30行] 代码量 30 行
get_rank_expert_workload[4行] 代码量 4 行
clear_all_moe_loads[3行] 代码量 3 行
_export_tensor_to_file[23行] 代码量 23 行
do_update_expert_map[2行] 代码量 2 行
do_update_expert_weight[8行] 代码量 8 行
do_update_log2phy_map[3行] 代码量 3 行
get_global_expert_map[8行] 代码量 8 行
eplb/core/eplb_device_transfer_loader.py
查看源码专家权重 D2D 搬运器(138 行)。D2DExpertWeightLoader 在设备间直接搬运专家权重:generate_expert_d2d_transfer_task 生成搬运任务、asyn_expert_weight_transfer 异步执行、update_expert_map_and_weight 更新映射与权重(ExpertWeightUpdateState 跟踪状态)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\eplb\core\eplb_device_transfer_loader.py
__init__[9行] 代码量 9 行
set_adator[2行] 代码量 2 行
generate_expert_d2d_transfer_task[35行] 代码量 35 行
set_log2phy_map[2行] 代码量 2 行
asyn_expert_weight_transfer[11行] 代码量 11 行
update_expert_map_and_weight[42行] 代码量 42 行
eplb/core/eplb_utils.py
查看源码EPLB 工具(145 行)。init_eplb_config 初始化 EPLB 配置(专家数/冗余数/共享专家)、generate_global_placement 生成全局部署、generate_log2phy_map 生成逻辑到物理映射、expert_file_to_tensor 从文件读专家映射。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\eplb\core\eplb_utils.py
expert_file_to_tensor[17行] 代码量 17 行
generate_global_placement[25行] 代码量 25 行
init_eplb_config[44行] 代码量 44 行
generate_log2phy_map[27行] 代码量 27 行
eplb/core/eplb_worker.py
查看源码EPLB worker(410 行)。EplbWorker 执行重均衡:fetch_and_sum_load_info 拉取并汇总负载、calculate_rebalance_experts 计算重均衡方案(compose_expert_update_info_greedy 贪心组合)、update_expert_map 应用映射、check_expert_placement 校验;_compute_imbalance/_calculate_hotness 计算不均衡度与热点;EplbProcess 管理独立 worker 进程。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\eplb\core\eplb_worker.py
__init__[26行] Args:
do_update[69行] 代码量 69 行
check_expert_placement[37行] 代码量 37 行
compose_expert_update_info_greedy[56行] 代码量 56 行
calculate_rebalance_experts[9行] Compute `new_map` by calling the `rebalance_experts` method of the policy instance.
get_init_expert_maps[5行] Read the initial expert_map from shared_dict.
fetch_and_sum_load_info[6行] Each time the subprocess is awakened, read the latest moe_load
update_expert_map[2行] 代码量 2 行
global2local[14行] 代码量 14 行
local2global[19行] 代码量 19 行
pack_update_info[28行] Pack a list of update info tuples for efficient IPC.
_compute_imbalance[19行] 代码量 19 行
_calculate_hotness[11行] 代码量 11 行
worker_process[37行] Subprocess entry: bind to specified NPU, loop waiting for planner_q to wake up,
_launch_process[8行] Use spawn method to launch subprocess and return (planner_q, block_update_q, proc).
eplb/core/policy/policy_abstract.py
查看源码EPLB 策略抽象(30 行)。EplbPolicy 定义 rebalance_experts 接口。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\eplb\core\policy\policy_abstract.py
rebalance_experts[23行] Pass in the weights and return expert replication and placement under relevant constraints.
eplb/core/policy/policy_default_eplb.py
查看源码默认 EPLB 策略(350 行)。DefaultEplb 实现专家重均衡:add_redundant 添加冗余副本、compute_balanced_pack(_redundancy) 计算均衡打包、constraint_expert_local_exchange 限制本局交换、get_redundant_num 冗余数;DynamicTable 动态路由表。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\eplb\core\policy\policy_default_eplb.py
add_redundant[13行] 代码量 13 行
original_compute_balanced_pack_redundancy[77行] 代码量 77 行
compute_balanced_pack_redundancy[66行] 代码量 66 行
compute_balanced_pack[42行] 代码量 42 行
get_redundant_num[3行] 代码量 3 行
calculate_max_heat_per_layer[6行] 代码量 6 行
constraint_expert_local_exchange[31行] 代码量 31 行
rebalance_experts[68行] 代码量 68 行
eplb/core/policy/policy_factory.py
查看源码EPLB 策略工厂(41 行)。PolicyFactory.generate_policy 按配置名创建策略实例(default/flashlb/swift/random)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\eplb\core\policy\policy_factory.py
generate_policy[28行] 代码量 28 行
eplb/core/policy/policy_flashlb.py
查看源码FlashLB 快速负载均衡策略(1026 行)。基于专家负载统计(mu/var/cov)的部署优化:副本数分配三算法(min_max_replica/max_delta_replica/percentage_replica)、LPT 部署(lpt_deployment)、设备方差增量更新(compute_updated_device_variance)、均衡评分(compute_score);FlashTree 支持邻居搜索与均衡性优化;FlashLB 主类:滑动/增量统计更新(sliding_update_stats/incremental_update_stats)、热点注册(register_hotness)、更新必要性判断(need_update)、最小化重部署(minimize_redeploy_with_inner_permutation);warm_up 用哑数据预热。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\eplb\core\policy\policy_flashlb.py
min_max_replica[18行] Wrapper for original min-max replica allocation
max_delta_replica[38行] Maximum delta replica allocation algorithm
percentage_replica[50行] Proportional replica allocation algorithm
make_replica[14行] 代码量 14 行
compute_updated_device_variance[33行] Compute updated device variance after adding a new expert
lpt_deployment[79行] Largest Processing Time (LPT) deployment algorithm
compute_score[30行] Calculate load balance score: (max_device_load * num_devices) / total_load
generate_layered_experts[49行] Generate layered expert deployment matrix
warm_up[10行] Warm up FlashLB algorithm with dummy data
__init__[23行] Initialize FlashLB policy with dynamic configuration
compute_statistics[23行] Compute mean, variance and covariance matrix from time series data
neighbor_search[39行] Local neighbor search for optimal replica number
optimize_balanceness[114行] 代码量 114 行
sliding_update_stats[43行] Update statistics with sliding window (replace old data with new data)
incremental_update_stats[42行] Incrementally update statistics with new data (expand window)
register_hotness[52行] Update expert hotness statistics with sliding window for all layers
need_update[27行] Check if layer needs load balance update
compute_match[22行] Compute match matrix between source and destination expert counts
minimize_redeploy_with_inner_permutation[61行] Minimize expert redeployment by permuting destination rows/columns
rebalance_experts[117行] Main expert rebalance entry point
_lpt_deployment[3行] 代码量 3 行
get_score[34行] Wrapper to compute load balance score for replica allocation simulation
eplb/core/policy/policy_random.py
查看源码随机负载均衡策略(26 行)。RandomLoadBalance.rebalance_experts 随机重排专家部署(基线/测试用)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\eplb\core\policy\policy_random.py
rebalance_experts[15行] 代码量 15 行
eplb/core/policy/policy_swift_balancer.py
查看源码SwiftBalancer 策略(751 行)。SwiftBalanceEplb 实现专家重部署:统计专家分布(statistics_expert_distribution)、冗余分配(compute_redundant_assignments/distribute_redundant_experts/redundancy_again)、未部署 rank 填充(fill_in_undeployed_ranks)、跨 rank 专家交换(swap_experts_between_ranks/expert_exchange_between_ranks)、层热度与不均衡计算。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\eplb\core\policy\policy_swift_balancer.py
__init__[13行] 代码量 13 行
calculate_max_heat_per_layer[6行] 代码量 6 行
get_original_workload[18行] Accumulate workload for each routed expert
constraint_expert_local_exchange[32行] Align the new deployment with the old deployment
calculate_imbalance[32行] Calculate the imbalance degree of each layer.
statistics_expert_distribution[35行] Statistics on the distribution of redundant experts and logical
compute_redundant_assignments[51行] Reconfigure redundant experts based on current expert workload and
fill_in_undeployed_ranks[44行] reselect and assign redundant experts to the ranks
non_redundant_expert_information[35行] Statistics on the status of logical experts on each rank
recomputing_initial_weight[23行] Calculate the load of the logic expert again based
distribute_redundant_experts[62行] Assign redundant experts to ranks
redundancy_again[58行] Calculate the status of a single node after redundant expert
redundant_expert_deployment[55行] Calculate the status of each node after reconfiguring redundant experts;
swap_experts_between_ranks[38行] Find the optimal experts for workload reduction
expert_exchange_between_ranks[85行] Perform inter-rank expert exchange within a single node
exchange_experts[30行] For each node after redundancy, perform inter-rank expert
rebalance_experts[86行] Rebalance experts based on workload and deployment strategy.
EPLB 更新协调器(192 行)。EplbUpdator 驱动一次专家重均衡生命周期:forward_before/forward_end 挂钩前向、compute_and_set_moe_load 计算并设置 MoE 负载、update_iteration/update_expert_weight_flag 触发 worker 更新、wakeup_eplb_worker 唤醒 worker 进程、warm_up_eplb 预热。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\eplb\eplb_updator.py
__init__[8行] 代码量 8 行
set_adaptor[8行] 代码量 8 行
init_eplb[27行] 代码量 27 行
update_iteration[11行] 代码量 11 行
get_update_info_flag[2行] 代码量 2 行
wakeup_eplb_worker_flag[2行] 代码量 2 行
update_expert_weight_flag[5行] 代码量 5 行
wakeup_eplb_worker[2行] 代码量 2 行
forward_before[22行] 代码量 22 行
forward_end[15行] 代码量 15 行
compute_and_set_moe_load[11行] 代码量 11 行
warm_up_eplb[27行] 代码量 27 行
shutdown[8行] Clean up the EPLB process.
MoE LoRA 执行器(396 行)。AscendFusedMoEWithLoRA 为 Ascend 原生 MoE-LoRA 包装(_build_lora_context 构建 LoRA 上下文、set_mapping);AscendFusedMoE3DWithLoRA 支持 w1+w3 已融合为 3D 权重的 checkpoint;索引处理:prepare_lora_indices 截断/填充/TP 切分 token→LoRA 索引、preprocess/postprocess_lora_indices 为 AlltoAll 路径展开重排与还原、all2all_lora_indices 跨 EP 交换;路由恢复:_recover_moe_lora_routing_allgather/all2all 按 dispatch 路径恢复每行 (expert_id, lora_slot);delta 注入:moe_lora_apply_w13/w2 在激活前/下采样后叠加 LoRA 增量;sync_lora_context 推送/清除通信单例上的上下文。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\lora\fused_moe.py
has_lora[3行] Return whether the current batch contains at least one LoRA token.
reset_lora_indices[4行] 代码量 4 行
prepare_lora_indices[22行] Truncate, pad, and TP-split the per-token LoRA index tensor,
preprocess_lora_indices[22行] Expand and permute LoRA token indices for the AlltoAll dispatch path.
postprocess_lora_indices[20行] Re-permute exchanged LoRA indices to align with the global token
all2all_lora_indices[23行] Exchange permuted LoRA indices across EP ranks via all_to_all.
sync_lora_context[11行] Push ``lora_context`` onto MoE communication singletons, or clear
_assert_ascend_moe_lora_supported[18行] 代码量 18 行
_recover_moe_lora_routing_allgather[24行] Recover per-permuted-row (expert_id, lora_slot) for the dispatched rows.
_recover_moe_lora_routing_all2all[35行] Recover per-row (expert_id, lora_id) for the AlltoAll dispatched tokens.
moe_lora_apply_w13[25行] Add the w13 LoRA delta into ``gate_up_out`` (in place), before activation.
moe_lora_apply_w2[24行] Add the w2 LoRA delta into ``down_out`` (in place), after the down GMM.
__init__[4行] 代码量 4 行
_build_lora_context[4行] 代码量 4 行
set_mapping[13行] 代码量 13 行
LoRA 核心算子(122 行)。BGMV/S GMV 两类 batched 分组乘:bgmv_shrink/expand/expand_slice(按 token 的 LoRA 索引)与 sgmv_shrink/expand/expand_slice(按序列段),调用 vllm_ascend_C 自定义算子完成 LoRA 下投影/上投影。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\lora\lora_ops.py
bgmv_shrink[14行] 代码量 14 行
bgmv_expand[15行] 代码量 15 行
bgmv_expand_slice[12行] 代码量 12 行
sgmv_shrink[15行] 代码量 15 行
sgmv_expand[21行] 代码量 21 行
sgmv_expand_slice[17行] 代码量 17 行
Punica LoRA 元数据管理(470 行)。PunicaWrapperNPU 管理同批多 LoRA 的元数据与执行:update_metadata 按批刷新索引;shrink/expand 各分 prefill/decode 两路径(_shrink_prefill/_shrink_decode/_expand_*);add_shrink/add_expand 组合调用、add_lora_embedding/add_lora_linear 处理嵌入与普通线性层的 LoRA;_get_token_lora_indices 换算 token 级 LoRA 索引。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\lora\punica_npu.py
__init__[30行] 代码量 30 行
update_metadata[18行] 代码量 18 行
_shrink_prefill[17行] 代码量 17 行
_shrink_decode[8行] 代码量 8 行
_expand_prefill[17行] 代码量 17 行
_expand_decode[8行] 代码量 8 行
_expand_slice_prefill[21行] 代码量 21 行
_expand_slice_decode[18行] 代码量 18 行
_get_token_lora_indices[2行] 代码量 2 行
_apply_expand[17行] Perform the ` y[:,y_offset:y_offset+y_slice_size]+=x@w_t_all`
_apply_shrink[14行] Perform the ` y+=x@w_t_all` computation, which is suitable for the
add_shrink[30行] Performs GEMM for multiple slices of lora_a.
add_expand[41行] Performs GEMM and bias addition for multiple slices of lora_b.
add_lora_embedding[20行] Applies lora specifically for VocabParallelEmbeddingWithLoRA.
add_lora_linear[46行] Applicable to linear-related lora.
add_lora_fused_moe[87行] Ascend-native fused MoE LoRA (v2): static-shape per-row gather via the
add_lora_logits[40行] Applies lora specifically for LogitsProcessorWithLoRA.
可扩展的量化 MoE LoRA(280 行)。register_quant_moe_lora_impl 按 quant_type 注册实现、quant_apply_mlp_with_moe_lora 把活跃的量化 MoE LoRA 批次分派到后端;_apply_dynamic_int8_moe_lora 在 INT8 基础专家上以 BF16/FP16 边界注入 LoRA(_validate_dynamic_int8_activations 校验激活);_apply_moe_activation 对齐非量化路径的激活语义。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\lora\quant_moe.py
register_quant_moe_lora_impl[17行] Register one quantized MoE LoRA implementation.
_get_quant_moe_lora_impl[9行] 代码量 9 行
quant_apply_mlp_with_moe_lora[6行] Dispatch an active quantized MoE LoRA batch to its backend.
validate_quant_moe_lora_activation_input[10行] Validate activations before quantized MoE LoRA prepare/dispatch.
_apply_moe_activation[31行] Match the activation semantics of the common unquantized MoE path.
_validate_dynamic_int8_activations[6行] 代码量 6 行
_apply_dynamic_int8_moe_lora[123行] Run INT8 base experts and inject LoRA at BF16/FP16 boundaries.
decorator[8行] 代码量 8 行
LoRA 类刷新工具(19 行)。refresh_all_lora_classes 按 vLLM 版本刷新全部 LoRA 相关类的基类绑定(多版本兼容)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\lora\utils.py
refresh_all_lora_classes[11行] 代码量 11 行
model_executor/offloader/base.py
查看源码offloader 工厂(28 行)。create_offloader 按配置创建 Ascend 感知的 CPU offloader,同时保留 vLLM 默认行为。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_executor\offloader\base.py
create_offloader[18行] Create an Ascend-aware offloader while preserving vLLM defaults.
model_executor/offloader/prefetch.py
查看源码预取式 CPU offload(201 行)。AscendPrefetchOffloader 复用 vLLM 行为但支持 NZ 静态缓冲:mark_prefetch_offload_nz_weight 标记需 NZ 格式的参数、_format_static_buffers_for_nz 把静态缓冲转型为 FRACTAL_NZ;_ModuleOffloader 包装模块 offload(_capture_static_buffer_formats_from_npu_params 从 NPU 参数捕获静态缓冲格式);ParamInfo 携带格式要求。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_executor\offloader\prefetch.py
mark_prefetch_offload_nz_weight[3行] Mark a parameter whose prefetch static buffer must use NZ format.
_is_using_nz_weight[11行] if its current NPU storage format is FRACTAL_NZ.
_is_prefetch_offload_nz_weight[2行] 代码量 2 行
_format_static_buffers_for_nz[23行] Cast static buffers to NZ format for keys whose parameters require it.
__init__[16行] 代码量 16 行
wrap_modules[12行] 代码量 12 行
post_init[14行] 代码量 14 行
_capture_static_buffer_formats_from_npu_params[13行] This function should be invoked during the `process_weights_after_loading`.
_wrap_process_weights_for_format_detection[10行] maybe_trans_nz was called only in quantization scenario
_wrap_process_weights[8行] 代码量 8 行
get_param_infos[16行] 代码量 16 行
wrapped_process_weights[4行] 代码量 4 行
model_executor/warmup/kernel_warmup.py
查看源码kernel 预热调度(49 行)。kernel_warmup 在 ACL graph 捕获前预热模型执行用到的 Triton kernel(_run_warmup 逐项执行并容错)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_executor\warmup\kernel_warmup.py
_run_warmup[9行] 代码量 9 行
kernel_warmup[14行] Run Triton kernel warmups before ACL graph capture.
model_executor/warmup/penalties_triton_warmup.py
查看源码惩罚 kernel 预热(78 行)。penalties_triton_warmup 在首次带惩罚采样前 JIT bincount 与惩罚 Triton kernel(_make_history_tokens 构造哑 token 历史)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_executor\warmup\penalties_triton_warmup.py
_local_vocab_size[4行] 代码量 4 行
_make_history_tokens[20行] Build dummy prompt/output token ids for penalty warmup.
penalties_triton_warmup[29行] JIT bincount and penalty Triton kernels before the first sampling with penalties.
model_executor/warmup/rejection_sampler_triton_warmup.py
查看源码拒绝采样 kernel 预热(416 行)。rejection_sampler_triton_warmup 在首个投机请求前按全部 constexpr 组合预热 kernel:collect_warmup_rejection_block_sizes/collect_warmup_batch_sizes 收集代表性 batch/BLOCK_SIZE、_warm_greedy/_warm_rejection_random/_warm_sample_recovered/_warm_expand/_warm_prepare_inputs 各分支预热、_collect_no_draft_probs_values 对齐在线路径参数。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_executor\warmup\rejection_sampler_triton_warmup.py
collect_warmup_rejection_block_sizes[19行] Return one representative batch_size per distinct ``BLOCK_SIZE``.
collect_warmup_batch_sizes[6行] 代码量 6 行
_is_ngram_spec_method[6行] 代码量 6 行
_collect_no_draft_probs_values[10行] Return ``NO_DRAFT_PROBS`` values that match the live rejection_sample path.
_make_rejection_tensors[71行] Build dummy tensors for recovered / random / greedy warmup launches.
_warm_prepare_inputs[29行] Warm ``prepare_inputs_padded_kernel`` once.
_warm_expand[16行] Warm expand kernel for one ``BLOCK_SIZE``, covering int32 and float32 dtypes.
_warm_greedy[29行] Warm greedy rejection for ``is_greedy=None`` and non-None paths.
_warm_sample_recovered[25行] Warm ``sample_recovered_tokens_kernel`` for one constexpr combination.
_warm_rejection_random[60行] Warm random or block-verify rejection kernel for one constexpr combination.
rejection_sampler_triton_warmup[85行] JIT rejection sampler Triton kernels before the first spec-decode request.
model_executor/warmup/rms_triton_warmup.py
查看源码QK RMS kernel 预热(87 行)。triton_rms_warmup 判断模型是否使用 triton_q_rms(_model_uses_triton_q_rms)并按 BLOCK_M 常量组合预热(collect_triton_rms_warmup_block_m_values)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_executor\warmup\rms_triton_warmup.py
_model_uses_triton_q_rms[12行] 代码量 12 行
_variance_epsilon[6行] 代码量 6 行
collect_triton_rms_warmup_block_m_values[7行] ``BLOCK_M`` constexpr values selected by ``triton_q_rms``.
triton_rms_warmup[35行] JIT ``triton_q_rms`` kernels before the first real call.
model_loader/netloader/__init__.py
查看源码NetLoader 插件注册(20 行)。register_netloader 把弹性加载器注册为 vLLM 模型加载插件。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_loader\netloader\__init__.py
register_netloader[3行] Register the NetLoader plugin.
model_loader/netloader/executor/elastic_load.py
查看源码HCCL 弹性加载执行器(630 行)。P2PSend/P2PLoP2P 用 HCCL 后端分布式收发模型参数;张量收集:_collect_processed_layout_tensors 收集 int8_cache=no 的处理后布局张量、_iter_raw_send/recv_transfer_params 枚举收发参数;HCCL 传输的格式处理:_hccl_transfer_tensor 转连续 FRACTAL_ND、_cast_tensor_to_fractal_nz 传后恢复 NZ、W4A8 的 int32 打包 NZ 经 int8 底层导出(_cast_packed_int32_via_int8);清单机制:build_transfer_shape_manifest/reshape_transfer_items_to_manifest/validate_transfer_items_numel_against_manifest 保证收发双方形状一致(HCCL 前 fail-fast)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_loader\netloader\executor\elastic_load.py
_is_transferable_tensor[2行] 代码量 2 行
_iter_tensors_in_value[29行] 代码量 29 行
_try_collect_transferable_tensor[15行] 代码量 15 行
_collect_processed_layout_tensors[27行] Collect live inference tensors for int8_cache=no processed-weight transfer.
_iter_raw_send_transfer_params[5行] 代码量 5 行
_iter_raw_recv_transfer_params[5行] 代码量 5 行
register_processed_layout_transfer_items[6行] Register processed-layout transfer items after weights are finalized.
cache_processed_layout_transfer_manifest[5行] Cache processed-layout transfer items on the model after process_weights.
get_cached_processed_layout_transfer_items[5行] 代码量 5 行
build_transfer_shape_manifest[5行] Build a name-to-shape manifest for processed-layout transfer.
reshape_tensor_to_manifest_shape[38行] View a received tensor into the seed/manifest shape when numel matches.
reshape_transfer_items_to_manifest[16行] Reshape received tensors to match the server transfer manifest.
validate_transfer_items_numel_against_manifest[29行] Fail-fast before HCCL: local tensors must match seed manifest numel.
_get_send_transfer_items[13行] 代码量 13 行
_get_recv_transfer_items[7行] 代码量 7 行
_get_npu_format_int[7行] 代码量 7 行
_is_fractal_nz_tensor[2行] 代码量 2 行
_is_packed_int32_nz_tensor[3行] W4A8 packs int8 NZ as int32 via ``view``; TransData cannot cast that int32 NZ.
_cast_packed_int32_via_int8[20行] Export/import W4A8 packed int32 through the underlying int8 layout.
_cast_tensor_to_fractal_nd[9行] Cast an NPU tensor to FRACTAL_ND for HCCL transfer.
_cast_tensor_to_fractal_nz[9行] Cast an NPU tensor back to FRACTAL_NZ after HCCL transfer.
_hccl_transfer_tensor[3行] Prepare a processed-layout tensor for HCCL: contiguous FRACTAL_ND.
synchronize_npu[5行] Synchronize NPU when the active device type is NPU.
_prepare_hccl_recv_buffer[11行] Processed-layout recv: FRACTAL_ND buffer + whether to restore FRACTAL_NZ.
_finalize_hccl_recv_buffer[9行] Write HCCL recv results back to the target tensor, restoring FRACTAL_NZ if needed.
__init__[23行] Initializes the P2PSend instance.
load[111行] Loads the model parameters using HCCL backend.
send[89行] Sends the model parameters using HCCL backend.
_recv_all[20行] 代码量 20 行
_send_all[19行] 代码量 19 行
model_loader/netloader/executor/netloader_pg.py
查看源码无状态进程组(180 行)。stateless_init_process_group 初始化不绑定全局状态的进程组(用于加载期通信);destroy_stateless_process_group 销毁并手动 GC。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_loader\netloader\executor\netloader_pg.py
stateless_init_process_group[120行] Initializes a stateless process group.
destroy_stateless_process_group[27行] Destroy a stateless process group.
is_valid_ipv6_address[6行] 代码量 6 行
get_tcp_uri[5行] 代码量 5 行
model_loader/netloader/interaction/elastic.py
查看源码弹性加载 TCP 交互(527 行)。ElasticServer/ElasticClient 处理 Netloader 的服务端/客户端逻辑:TCP JSON 消息收发(_recv_json_message 完整读取)、传输清单注册(register_transfer_manifest/_parse_transfer_shape_manifest)、客户端注册与连接生命周期管理。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_loader\netloader\interaction\elastic.py
_recv_json_message[28行] Receive one complete JSON object from a TCP socket.
_parse_transfer_shape_manifest[14行] 代码量 14 行
__init__[82行] Initializes the ElasticServer instance.
close[11行] Closes the socket connection.
__enter__[5行] Context manager enter method.
__exit__[5行] Context manager exit method.
__del__[7行] Destructor method to ensure socket is closed.
send_str[10行] Sends a string over the socket connection.
recv_json[5行] Receive one JSON object over the socket connection.
register[60行] Registers the client with the server.
register_transfer_manifest[16行] Register processed-layout transfer manifest after weights are finalized.
start[7行] Starts the server to handle incoming connections.
elastic_client_handler[8行] Handles incoming client connections.
register_handler[123行] Handles the registration of a client.
is_valid_data[25行] Validates the received data.
model_loader/netloader/load.py
查看源码弹性加载入口(107 行)。elastic_load 跨多设备弹性加载模型权重(device_id/model_path/sources/tp/pp 参数组织加载拓扑)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_loader\netloader\load.py
elastic_load[83行] Loads a model using elastic loading across multiple devices.
model_loader/netloader/netloader.py
查看源码弹性加载器本体(581 行)。ModelNetLoaderElastic:load_model 驱动加载(draft 模型先同步目标加载器 _sync_target_netloader_before_draft)、load_weights 权重写入、download_model 下载;静态 forward context 快照与恢复(_snapshot/_remove_new_static_forward_context_keys)保证加载前后一致;revert_to_default 回退默认加载器;pre_transfer_weight_processing 解包 MoE 共享专家校验。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_loader\netloader\netloader.py
pre_transfer_weight_processing[33行] Unwrap MoE shared-expert validation during pre-transfer process_weights.
_unwrap_quant_method[13行] 代码量 13 行
__init__[81行] Initializes the ModelNetLoaderElastic with configuration.
_is_draft_model[3行] Check whether the model_config corresponds to a draft model for speculative decoding.
_sync_target_netloader_before_draft[13行] 代码量 13 行
_get_static_forward_context[6行] 代码量 6 行
_iter_static_forward_contexts[17行] Yield unique (source_name, context_dict) pairs for this and current vllm config.
_snapshot_static_forward_context_keys[9行] Snapshot context keys before initialize_model so fallback can drop only new ones.
_remove_new_static_forward_context_keys[16行] Remove keys added after snapshot; preserve target registrations on draft fallback.
load_model[281行] Loads the model using the specified configuration.
revert_to_default[40行] Reverts to the default model loading logic when elastic loading fails or is not applicable.
download_model[2行] 代码量 2 行
load_weights[2行] 代码量 2 行
model_loader/netloader/utils.py
查看源码NetLoader 工具(63 行)。find_free_port 找空闲端口、is_valid_path_prefix 校验路径前缀。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_loader\netloader\utils.py
find_free_port[10行] Finds a free port on the local machine.
is_valid_path_prefix[28行] Checks if the provided path prefix is valid.
model_loader/rfork/__init__.py
查看源码RFork 加载器插件注册(20 行)。register_rforkloader 注册 RFork 模型加载器。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_loader\rfork\__init__.py
register_rforkloader[3行] Register the RFork model loader plugin.
model_loader/rfork/rfork_loader.py
查看源码RFork 模型加载器(436 行)。RForkModelLoader 从种子实例(已加载同权重的运行实例)fork 加速加载:load_model 判断 draft/EP/PP rank(_is_draft_model/_get_ep_rank/_get_pp_rank)、_requires_processed_layout_transfer 决定布局、_ensure_rfork_worker 保证 worker 就绪;兼容处理:_reset_process_global_model_state 清理被丢弃模型的全局注册、_rfork_skip_unquantized_moe_post_load_processing 跳过非量化 MoE 后处理(dense 层照常)、动态 EPLB 判断。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_loader\rfork\rfork_loader.py
_is_mtp_hf_config[15行] 代码量 15 行
_is_draft_model_config[10行] 代码量 10 行
_is_draft_model[6行] 代码量 6 行
_get_rfork_worker_attr[2行] 代码量 2 行
_get_ep_rank[9行] 代码量 9 行
_get_pp_rank[8行] 代码量 8 行
_make_fallback_load_config[5行] 代码量 5 行
_reset_process_global_model_state[35行] Remove process-global layer registries a discarded RFork model left behind.
_iter_ascend_moe_quant_methods[16行] Yield each quant method owned by an Ascend MoE runner once.
_rfork_pre_transfer_weight_processing[17行] Use the unwrapped MoE post-load step so RFork pre-transfer skips shared-expert validation.
_is_dynamic_eplb_enabled[7行] 代码量 7 行
_rfork_skip_unquantized_moe_post_load_processing[22行] Suppress unquantized MoE post-load processing; dense layers still run theirs.
_noop_process_weights_after_loading[2行] 代码量 2 行
__init__[51行] 代码量 51 行
download_model[2行] 代码量 2 行
load_weights[2行] 代码量 2 行
_ensure_rfork_worker[31行] 代码量 31 行
_requires_processed_layout_transfer[2行] 代码量 2 行
load_model[115行] 代码量 115 行
_get_extra_config[5行] 代码量 5 行
_get_extra_config_float[17行] 代码量 17 行
model_loader/rfork/rfork_worker.py
查看源码RFork worker(145 行)。RForkWorker 执行种子传输:is_seed_available 检查种子、pre_transfer/transfer/post_transfer 三段传输、reset_transfer_state 重置、start_seed_service 作为种子方提供服务。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_loader\rfork\rfork_worker.py
__init__[33行] 代码量 33 行
is_seed_available[3行] 代码量 3 行
pre_transfer[9行] 代码量 9 行
reset_transfer_state[6行] 代码量 6 行
transfer[18行] 代码量 18 行
post_transfer[7行] 代码量 7 行
start_seed_service[35行] 代码量 35 行
model_loader/rfork/seed_protocol.py
查看源码RFork 种子协议(242 行)。RForkSeedProtocol 管理种子实例的获取与归还:get_local_seed_key 构造本地种子键(按 PD 分离模式/node rank/TP rank/部署策略)、get_seed/release_seed/report_seed 与种子服务端交互(_request_timeout_sec 超时控制)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_loader\rfork\seed_protocol.py
get_local_seed_key[2行] 代码量 2 行
__init__[36行] 代码量 36 行
_request_timeout_sec[2行] 代码量 2 行
_ensure_scheduler_url_set[5行] 代码量 5 行
get_seed[43行] 代码量 43 行
release_seed[31行] 代码量 31 行
report_seed[54行] 代码量 54 行
model_loader/rfork/seed_server.py
查看源码RFork 种子服务端(141 行)。start_rfork_server/start_fastapi_server 启动 FastAPI 种子服务(健康检查超时、传输引擎信息注册),供其他实例拉取权重。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_loader\rfork\seed_server.py
start_fastapi_server[54行] 代码量 54 行
start_rfork_server[56行] 代码量 56 行
get_rfork_transfer_engine_info[4行] 代码量 4 行
get_rfork_transfer_engine_shape_info[4行] 代码量 4 行
rfork_fetch_seed[2行] 代码量 2 行
health_check_with_key[4行] 代码量 4 行
model_loader/rfork/transfer_backend.py
查看源码RFork 传输后端(625 行)。RForkTransferBackend 管理传输引擎:init_transfer_engine 初始化、register/unregister_memory_region 注册内存区、recv_from_source 从种子拉取;张量收集与对齐:_collect_processed_layout_tensors/_collect_checkpoint_layout_tensors 按布局收集可传张量、_reshape_tensor_to_seed_shape 对齐种子形状、_iter_transfer_chunks 按地址块切分传输块(_block_contains_weight_ptr 判断归属);get_remote_instance_weight_shape_info 查询远端形状信息。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\model_loader\rfork\transfer_backend.py
_normalize_weight_shape[8行] 代码量 8 行
_parse_weight_info[15行] 代码量 15 行
_reshape_tensor_to_seed_shape[34行] 代码量 34 行
_update_registered_weight_shape[7行] 代码量 7 行
_numel_from_shape[5行] 代码量 5 行
_is_transferable_tensor[2行] 代码量 2 行
_is_tensor_on_transfer_device[2行] 代码量 2 行
_iter_tensors_in_value[29行] 代码量 29 行
_try_collect_transferable_tensor[16行] 代码量 16 行
_collect_processed_layout_tensors[36行] 代码量 36 行
_collect_checkpoint_layout_tensors[35行] 代码量 35 行
_iter_transferable_tensors[5行] 代码量 5 行
_block_contains_weight_ptr[3行] 代码量 3 行
_iter_transfer_chunks[35行] 代码量 35 行
get_remote_instance_transfer_engine_info[28行] 代码量 28 行
get_remote_instance_weight_shape_info[27行] 代码量 27 行
__init__[9行] 代码量 9 行
init_transfer_engine[26行] 代码量 26 行
is_initialized[2行] 代码量 2 行
_get_transfer_engine[4行] 代码量 4 行
register_memory_region[66行] 代码量 66 行
unregister_memory_region[27行] 代码量 27 行
recv_from_source[135行] 代码量 135 行
observability/handlers.py
查看源码Ascend 指标处理器(95 行)。_register_eplb_metrics 注册 EPLB 指标;eplb_do_update_hotness_handler 记录 rank-0 worker 暴露的聚合专家热度。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\observability\handlers.py
_register_eplb_metrics[20行] 代码量 20 行
eplb_do_update_hotness_handler[49行] Record the aggregated expert hotness exposed by the EPLB rank-0 worker.
observability/provider.py
查看源码指标提供者(21 行)。get_metric_provider 惰性返回 MS Service Metric 提供者(避免硬依赖)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\observability\provider.py
get_metric_provider[14行] Return the provider lazily so vLLM Ascend has no hard Core dependency.
patch/platform/patch_balance_schedule.py
查看源码均衡调度 patch(912 行)。BalanceScheduler 按 DP rank 负载把请求均衡分派:balance_gather 汇聚各 rank 负载、schedule 重排请求;BalanceDPEngineCoreProc 提供 DP engine core 钩子(_has_global_unfinished_reqs);_balance_run_engine_core 替换 engine core 主循环;_balance_scheduling_enabled 判断启用。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_balance_schedule.py
_balance_scheduling_enabled[18行] 代码量 18 行
_balance_run_engine_core[7行] 代码量 7 行
__init__[40行] 代码量 40 行
balance_gather[17行] All-gather per-rank running counts into ``self.balance_queue``.
schedule[669行] 代码量 669 行
_has_global_unfinished_reqs[10行] 代码量 10 行
patch/platform/patch_distributed.py
查看源码分布式 310P 适配 patch(89 行)。communication_adaptation_310p 调整 310P 的通信后端选择;NullHandle 提供空 wait 的异步句柄占位。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_distributed.py
communication_adaptation_310p[53行] 代码量 53 行
__init__[2行] 代码量 2 行
wait[2行] 代码量 2 行
broadcast310p_wrapper[18行] 代码量 18 行
all_reduce_wrapper_310p[25行] 代码量 25 行
broadcast310p[15行] 代码量 15 行
all_reduce[22行] 代码量 22 行
patch/platform/patch_dp_device_ids.py
查看源码DP 设备 ID 解析 patch(71 行)。_patched_get_physical_gpu_ids_for_local_dp_rank 修正 vLLM 在 DP 下解析物理设备 ID 的逻辑(支持设备控制环境变量与用户指定 ID 列表)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_dp_device_ids.py
_patched_get_physical_gpu_ids_for_local_dp_rank[29行] 代码量 29 行
patch/platform/patch_dyntra_lb_core.py
查看源码DyntraLB 引擎核 patch(547 行)。DyntraLBDPEngineCoreProc 在 DP engine core 中驱动负载均衡:run_balance_load 周期触发、_do_lb_allgather 全局汇聚、_balance_load 计算并应用迁移修改(_RequestItem/_CardData/_Modification 描述请求、卡与修改);_has_global_unfinished_reqs_with_diagnostics 带诊断的全局未完成判断;_print_* 系列按诊断开关输出负载与修改详情;_dyntra_lb_run_engine_core 替换 engine core 主循环。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_dyntra_lb_core.py
_get_dyntra_lb_config[13行] 代码量 13 行
_dyntra_lb_enabled[2行] 代码量 2 行
_print_rank_0[4行] 代码量 4 行
_print_requests_by_rank[15行] 代码量 15 行
_print_modifications[14行] 代码量 14 行
_has_global_unfinished_reqs_with_diagnostics[4行] 代码量 4 行
_dyntra_lb_run_engine_core[16行] 代码量 16 行
_balance_load[200行] 代码量 200 行
_init_data_parallel[68行] 代码量 68 行
add_request[7行] 代码量 7 行
run_balance_load[52行] 代码量 52 行
_has_global_unfinished_reqs[17行] 代码量 17 行
_do_lb_allgather[47行] 代码量 47 行
calc_bubble[7行] 代码量 7 行
perform_swap[13行] 代码量 13 行
perform_pull_in[9行] 代码量 9 行
fill_running_from_waiting[10行] 代码量 10 行
find_best_swap[25行] 代码量 25 行
try_drop_for_throughput[38行] 代码量 38 行
patch/platform/patch_eplb.py
查看源码EPLB 构建 patch(138 行)。收窄 vLLM EPLB 在 Ascend 上的构建与提交:_wrap_communicator_factory 包装通信器工厂、_wrap_move_to_workspace 延迟 worker 确认直到 Ascend commit 钩子完成(_DeferredConsumedEvent)、_CudaAlikeEplbPlatformProxy 让 NPU 平台通过 EPLB 的 CUDA 类校验。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_eplb.py
_is_npu_platform[2行] 代码量 2 行
_patch_parallel_config[4行] 代码量 4 行
_wrap_communicator_factory[14行] 代码量 14 行
_patch_communicator_factory[7行] 代码量 7 行
_wrap_move_to_workspace[37行] 代码量 37 行
_patch_async_move_to_workspace[4行] 代码量 4 行
__init__[2行] 代码量 2 行
record[5行] 代码量 5 行
flush[4行] 代码量 4 行
is_cuda_alike[2行] 代码量 2 行
__getattr__[2行] 代码量 2 行
_create_eplb_communicator[5行] 代码量 5 行
_move_to_workspace[28行] 代码量 28 行
patch/platform/patch_fused_moe.py
查看源码FusedMoE EPLB 接入 patch(192 行)。_adapt_eplb_router 只挂接 Ascend 的 EPLB 状态与映射操作(_ascend_apply_eplb_mapping);_ascend_FusedMoE 替换 FusedMoE 构造以接入 Ascend 路由专家。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_fused_moe.py
_ascend_apply_eplb_mapping[18行] 代码量 18 行
_adapt_eplb_router[17行] Attach only the Ascend EPLB state and mapping operation.
_ascend_FusedMoE[91行] 代码量 91 行
patch/platform/patch_kv_cache_coordinator.py
查看源码混合 KV 协调器 patch(654 行)。AscendHybridKVCacheCoordinator 处理多 KV 类型混合模型:verify_and_split_kv_cache_groups 校验并拆组、find_longest_cache_hit 找最长命中(_cache_hit_alignment_tokens 对齐 token、_get_effective_block_size 有效块大小);_select_kv_token_budget 计算 KV token 预算;DSV4 spec 识别。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_kv_cache_coordinator.py
_select_kv_token_budget[7行] 代码量 7 行
_is_deepseek_v4_kv_cache_spec[14行] 代码量 14 行
_is_deepseek_v4_kv_cache_config[2行] 代码量 2 行
_cache_hit_alignment_tokens[4行] 代码量 4 行
_get_effective_block_size[7行] 代码量 7 行
verify_and_split_kv_cache_groups[68行] Groups KV cache groups by their spec type for efficient batch processing
find_longest_cache_hit[122行] Find the longest cache hit using an iterative fixed-point algorithm.
get_kv_cache_coordinator[71行] 代码量 71 行
__init__[106行] 代码量 106 行
_get_block_hashes[2行] 代码量 2 行
patch/platform/patch_kv_cache_utils.py
查看源码KV cache 工具 patch(392 行)。_ascend_resolve_kv_cache_block_sizes 解析 Ascend 兼容的块大小;group_and_unify_kv_cache_specs 把 KV spec 分组并统一为 UniformType(_get_kv_cache_groups_uniform_groups/uniform_page_size);_get_kimi_k3_dspark_mixed_kv_cache_groups 构建拓扑无关的 Kimi K3 DSpark 调度组;_get_kv_cache_config_deepseek_v4 做 DSV4 的 KV 张量布局规划;_kv_cache_config_has_mamba_layers 识别嵌在 UniformType 组内的 Mamba 层。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_kv_cache_utils.py
_ascend_resolve_kv_cache_block_sizes[34行] Ascend-compatible resolve_kv_cache_block_sizes.
_get_kimi_k3_dspark_mixed_kv_cache_groups[85行] Build topology-independent Kimi K3 DSpark scheduler groups.
_get_kv_cache_groups_uniform_page_size[7行] 代码量 7 行
_kv_cache_config_has_mamba_layers[3行] Recognize Mamba layers nested in UniformType cache groups.
group_and_unify_kv_cache_specs[32行] Group the KV cache specs and unify each group into one UniformTypeKVCacheSpecs.
_get_kv_cache_groups_uniform_groups[90行] Generate the KV cache groups from the grouped specs.
_get_kv_cache_config_deepseek_v4[61行] DeepseekV4 KV cache tensor layout planning.
_uniform_type_max_num_blocks_per_req[12行] Preserve the inner spec's block-table width.
patch/platform/patch_mamba_config.py
查看源码Mamba 配置 patch(149 行)。verify_and_update_config 保证注意力层页大小不小于 Mamba 状态页大小;_using_kv_store 检查是否用 AscendStoreConnector。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_mamba_config.py
_using_kv_store[16行] Check whether AscendStoreConnector is used.
verify_and_update_config[116行] Ensure that page size of attention layers is greater than or
patch/platform/patch_mamba_config_310.py
查看源码310P Mamba 配置 patch(103 行)。verify_and_update_config 的 310P 变体(同样的页大小约束校验)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_mamba_config_310.py
verify_and_update_config[85行] Ensure that page size of attention layers is greater than or
patch/platform/patch_mamba_manager.py
查看源码Mamba 管理器 patch(88 行)。AscendMambaManager 提供 Mamba 状态的缓存命中查找(find_longest_cache_hit)与分配块数计算(get_num_blocks_to_allocate)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_mamba_manager.py
__init__[3行] 代码量 3 行
find_longest_cache_hit[23行] 代码量 23 行
get_num_blocks_to_allocate[36行] 代码量 36 行
patch/platform/patch_minimax_m2_config.py
查看源码MiniMax-M2 配置 patch(136 行)。_patched_verify_quantization 注入 ModelConfig 量化校验的中间行为:按模型类型判断并禁用 FP8(_should_disable_fp8/_disable_fp8);_patched_verify_cuda_graph 校验 cudagraph 兼容性。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_minimax_m2_config.py
_get_model_type[21行] 代码量 21 行
_should_disable_fp8[2行] 代码量 2 行
_disable_fp8[7行] 代码量 7 行
_patched_verify_quantization[34行] Inject mid-function behavior for ModelConfig._verify_quantization.
_patched_verify_cuda_graph[20行] 代码量 20 行
_platform_verify_hook[7行] 代码量 7 行
patch/platform/patch_mla_prefill_backend.py
查看源码MLA prefill 后端 patch(48 行)。AscendMLAPrefillBackend 声明可用性(is_available)并实现 prefill 新 token 与上下文 chunk 两段执行(run_prefill_new_tokens/run_prefill_context_chunk)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_mla_prefill_backend.py
get_name[2行] 代码量 2 行
is_available[2行] 代码量 2 行
run_prefill_new_tokens[8行] 代码量 8 行
run_prefill_context_chunk[8行] 代码量 8 行
patch/platform/patch_multiproc_executor.py
查看源码多进程执行器 patch(211 行)。AscendMultiprocExecutor 适配 Ascend 的多进程执行:_get_parallel_sizes 取并行规模、_is_driver_indentify driver worker;AscendWorkerProc.make_worker_process 定制 worker 进程创建。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_multiproc_executor.py
_init_executor[115行] 代码量 115 行
_get_parallel_sizes[12行] 代码量 12 行
_post_init_executor[2行] 代码量 2 行
_is_driver_worker[2行] 代码量 2 行
make_worker_process[46行] 代码量 46 行
patch/platform/patch_pp_mtp.py
查看源码PP+MTP 运行时支持 backport(349 行)。让 MTP 投机解码在流水线并行下工作:_patch_scheduler_update_after_schedule/update_from_output/make_cached_request_data 修调度器、_update_pp_mtp_spec_token_ids 维护跨 PP 的投机 token、_patch_model_runner_output/_patch_engine_core 修输出与引擎核;PD prefill 节点判断与 IPC 运行时 patch 变体。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_pp_mtp.py
_is_pd_prefill_node[12行] 代码量 12 行
_use_pp_mtp_runtime_patch[5行] 代码量 5 行
_use_pp_ipc_runtime_patch[4行] 代码量 4 行
_patch_model_runner_output[22行] 代码量 22 行
_patch_engine_core[27行] 代码量 27 行
_patch_scheduler_update_after_schedule[33行] 代码量 33 行
_patch_scheduler_make_cached_request_data[55行] 代码量 55 行
_update_pp_mtp_spec_token_ids[26行] 代码量 26 行
_patch_scheduler_update_from_output[54行] 代码量 54 行
_patch_model_config_validation[41行] 代码量 41 行
_apply_patch[11行] 代码量 11 行
_patched_post_step[15行] 代码量 15 行
_patched_update_after_schedule[17行] 代码量 17 行
_patched_make_cached_request_data[39行] 代码量 39 行
_patched_update_from_output[42行] 代码量 42 行
_patched_verify_with_parallel_config[25行] 代码量 25 行
_patched_init[3行] 代码量 3 行
patch/platform/patch_profiling_chunk.py
查看源码profiling chunk patch(229 行)。_record_execution_timing 记录执行耗时供在线模型修正;_ensure_update_from_output_wrapped/_ensure_schedule_wrapped 包装调度器方法传递计时信号;_patched_run_engine_core 在 EngineCore 初始化时触发 profiling 与计时钩子。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_profiling_chunk.py
_record_execution_timing[83行] Record execution timing for online model refinement.
_ensure_update_from_output_wrapped[16行] Wrap scheduler.update_from_output to record execution timing.
_ensure_schedule_wrapped[24行] Wrap scheduler.schedule to propagate timing-done signal via scheduler_output.
_apply_profiling_patches[24行] Patch ``EngineCore.__init__`` to trigger profiling and timing hooks.
_patched_run_engine_core[3行] 代码量 3 行
_wrapped_update_from_output[3行] 代码量 3 行
_wrapped_schedule[5行] 代码量 5 行
_patched_engine_core_init[9行] 代码量 9 行
patch/platform/patch_speculative_config.py
查看源码投机配置 patch(54 行)。_normalize_legacy_qwen3_dspark_config 归一化旧版 Qwen3 DSpark 配置;_dspark_post_init 补充 DSpark 配置的后置初始化。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_speculative_config.py
_normalize_legacy_qwen3_dspark_config[13行] 代码量 13 行
_dspark_post_init[11行] 代码量 11 行
_validate_dspark_architecture[3行] 代码量 3 行
patch/platform/patch_structured_output.py
查看源码结构化输出 patch(134 行)。允许按请求选择结构化输出后端:_request_backend/_sampling_params_backend 解析请求级后端、_raise_mixed_backend 拒绝混用;_patch_sampling_params_validation/_patch_structured_output_manager 注入校验与管理器行为。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_structured_output.py
_request_backend[8行] 代码量 8 行
_backend_name_from_instance[15行] 代码量 15 行
_raise_mixed_backend[8行] 代码量 8 行
_sampling_params_backend[4行] 代码量 4 行
_structured_outputs_config_from_call[12行] 代码量 12 行
_patch_sampling_params_validation[29行] 代码量 29 行
_patch_structured_output_manager[24行] 代码量 24 行
_validate_structured_outputs[22行] 代码量 22 行
grammar_init[18行] 代码量 18 行
patch/platform/patch_torch_accelerator.py
查看源码torch accelerator patch(23 行)。patch_empty_cache 修正空缓存调用在 NPU 上的行为。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_torch_accelerator.py
patch_empty_cache[2行] 代码量 2 行
patch/platform/patch_use_v2_model_runner.py
查看源码V2 运行器开关 patch(45 行)。_patched_use_v2_model_runner 直接读 VLLM_USE_V2_MODEL_RUNNER 环境变量;_patched_get_unsupported_features/_patched_validate_v2_model_runner 放开 V2 特性校验。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_use_v2_model_runner.py
_patched_use_v2_model_runner[13行] Return VLLM_USE_V2_MODEL_RUNNER env directly.
_patched_get_unsupported_features[7行] 代码量 7 行
_patched_validate_v2_model_runner[4行] 代码量 4 行
patch/platform/patch_vision.py
查看源码视觉模型 patch(69 行)。_patched_fused_input_norm_forward 修正视觉 fused input norm 前向(按 grid_thw 与视觉 dtype);install_patch 安装。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\platform\patch_vision.py
_patched_fused_input_norm_forward[19行] 代码量 19 行
install_patch[4行] 代码量 4 行
patch/worker/_hccl_pg_registry.py
查看源码HCCL 进程组复用注册表(295 行)。HcclPgRegistry 以(ranks/backend/pg_options/reuse_domain)为键复用 HCCL 组:acquire/release/clear 管理生命周期;make_hccl_pg_key 构造哈希键、_normalize_hccl_pg_options 归一化选项、_is_non_group_member 处理非组成员哨兵。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\_hccl_pg_registry.py
make_hccl_pg_key[27行] Return a hashable key that identifies a shared HCCL process group.
_normalize_hccl_pg_options[20行] 代码量 20 行
_has_unknown_non_default_fields[34行] 代码量 34 行
_global_ranks_match_requested_ranks[25行] 代码量 25 行
_freeze_for_key[10行] 代码量 10 行
_is_default_option_value[14行] 代码量 14 行
_is_non_group_member[7行] 代码量 7 行
_load_non_group_member_sentinel[7行] 代码量 7 行
_destroy_process_group[4行] 代码量 4 行
__init__[3行] 代码量 3 行
acquire[30行] 代码量 30 行
release[15行] 代码量 15 行
clear[3行] 代码量 3 行
patch/worker/patch_bind_kv_cache.py
查看源码KV cache 绑定 patch(50 行)。bind_kv_cache 把分配好的 KV cache 同时绑到 ModelRunner 与 forward context(处理注意力模块数与 runner 缓存数不一致的情况)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_bind_kv_cache.py
bind_kv_cache[39行] Bind the allocated KV cache to both ModelRunner and forward context so
patch/worker/patch_cudagraph.py
查看源码cudagraph patch(38 行)。_create_padded_batch_descriptor 修正填充批描述符的构建(LoRA 活跃数等字段)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_cudagraph.py
_create_padded_batch_descriptor[30行] 代码量 30 行
patch/worker/patch_deepseek_v2.py
查看源码DeepSeek-V2 patch(357 行)。_deepseek_v2_mla_attention_init 修正 MLA 注意力初始化(indexer 初始化跳过判断 _should_skip_indexer_init);_patched_forward 替换模型前向以适配 NPU。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_deepseek_v2.py
_should_skip_indexer_init[19行] 代码量 19 行
_deepseek_v2_mla_attention_init[231行] 代码量 231 行
_patched_forward[62行] 代码量 62 行
patch/worker/patch_distributed.py
查看源码分布式 patch(254 行)。GroupCoordinatorPatch 扩展 vLLM GroupCoordinator:_init_device_groups/_init_device_communicator 初始化设备组与通信器、_release_hccl_resources/destroy_hccl/restore_hccl 支持睡眠模式的 HCCL 销毁与恢复;_create_device_group 创建设备组时经 HCCL 注册表复用组(_acquire_hccl_group,_resolve_reuse_domain 决定复用域);_patch_destroy_distributed_environment 包装销毁流程。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_distributed.py
_normalize_backend[2行] 代码量 2 行
_resolve_reuse_domain[5行] 代码量 5 行
_create_device_group[10行] 代码量 10 行
_acquire_hccl_group[19行] 代码量 19 行
_wrap_destroy_distributed_environment[13行] 代码量 13 行
_patch_destroy_distributed_environment[4行] 代码量 4 行
wrapped[5行] 代码量 5 行
__init__[54行] 代码量 54 行
_init_device_groups[27行] 代码量 27 行
_init_device_communicator[9行] 代码量 9 行
_release_hccl_resources[21行] 代码量 21 行
destroy[17行] 代码量 17 行
destroy_hccl[7行] Release the HCCL process group.
restore_hccl[9行] Recreate the HCCL process group in place after sleep mode.
patch/worker/patch_eagle3_init.py
查看源码Eagle3 初始化 patch(129 行)。修正 PP 下 Eagle3 draft 模型的 target_layer_num(_patched_eagle3_llama_init/_patched_eagle3_deepseek_v2_init 分别覆盖 Llama 与 DeepSeek-V2 版本)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_eagle3_init.py
_patched_eagle3_llama_init[35行] 代码量 35 行
_patched_eagle3_deepseek_v2_init[25行] 代码量 25 行
patch/worker/patch_eagle3_pp_aux.py
查看源码Eagle3 PP 辅助隐藏层 patch(238 行)。把 Eagle3 的 aux hidden states 经 PP 管线传播:_extract_aux_from_intermediate 从中间张量提取、_make_deepseek_v2_forward/_make_eagle_mixin_forward 生成带传播的前向、_patch_make_empty_intermediate_tensors 补缓冲、patch_eagle3_pp_aux_propagation 安装。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_eagle3_pp_aux.py
_extract_aux_from_intermediate[10行] 代码量 10 行
_make_deepseek_v2_forward[71行] 代码量 71 行
_make_eagle_mixin_forward[48行] 代码量 48 行
_patch_make_empty_intermediate_tensors[23行] 代码量 23 行
patch_eagle3_pp_aux_propagation[29行] 代码量 29 行
pp_eagle3_forward[45行] 代码量 45 行
pp_make_empty_intermediate_tensors[14行] 代码量 14 行
patch/worker/patch_kimi_k25.py
查看源码Kimi K2.5 patch(95 行)。AscendLearnable2DInterpPosEmbDivided_fixed 修正可学习二维插值位置编码的前向(get_rope_shape 计算形状)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_kimi_k25.py
get_rope_shape[11行] 代码量 11 行
forward[29行] 代码量 29 行
_patched_moonvit_to[6行] 代码量 6 行
patch/worker/patch_mamba_utils.py
查看源码Mamba 工具 patch(512 行)。preprocess_mamba 把上一步 Mamba 状态拷到新块(抢占恢复);拷贝实现双路径:Triton 批量拷贝(_can_launch_triton_batch_memcpy/_batch_memcpy_triton/_stage_mamba_copy_metadata/_do_mamba_copy_block_npu,指针元数据在预处理期暂存)与 PyTorch 回退(_collect_mamba_copy_meta_torch/_do_mamba_copy_block_torch);层级拷贝:prepare_mamba_copy_by_layer/do_mamba_copy_block_for_layer/finish_mamba_copy_by_layer 服务层级执行;_postprocess_mamba_align_gpu_cpu_fallback 为 310P 的 CPU 回退。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_mamba_utils.py
_can_launch_triton_batch_memcpy[2行] 代码量 2 行
_get_mamba_groups[23行] Find Mamba groups, including uniform worker-side group wrappers.
_batch_memcpy_triton[9行] 代码量 9 行
_stage_mamba_copy_metadata[8行] Stage pointer metadata while input-preparation buffers are protected.
_do_mamba_copy_block_npu[10行] Copy state after KV load using metadata staged during preprocessing.
_tensor_view_from_data_ptr[21行] 代码量 21 行
_get_tensor_copy_pairs[4行] 代码量 4 行
_collect_mamba_copy_meta_torch[34行] 代码量 34 行
_do_mamba_copy_block_torch[14行] 代码量 14 行
_postprocess_mamba_align_gpu_cpu_fallback[71行] CPU fallback for 310P where the Triton fused postprocess is unavailable.
_batch_memcpy_unavailable[5行] 代码量 5 行
_reset_layerwise_copy_meta[6行] 代码量 6 行
_collect_mamba_copy_meta_with_layers[48行] Collect copy metadata grouped per layer (triton pointer path).
prepare_mamba_copy_by_layer[30行] Stage all layer copy metadata before layerwise model execution.
do_mamba_copy_block_for_layer[23行] Copy one layer's running state after its layerwise load completes.
finish_mamba_copy_by_layer[9行] 代码量 9 行
_patched_create[7行] 代码量 7 行
preprocess_mamba[85行] Copy the mamba state of previous step to the last
patch/worker/patch_minimax_m2.py
查看源码MiniMax-M2 patch(54 行)。_patch_forward 替换其位置编码-隐藏层前向以适配 NPU。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_minimax_m2.py
_patch_forward[23行] 代码量 23 行
patch/worker/patch_qwen3_5.py
查看源码Qwen3.5 patch(243 行)。AscendQwen3NextAttention/AscendQwen3_5DecoderLayer 替换前向(_uses_multimodal_rope 判断多模态 RoPE),适配 NPU 注意力路径。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_qwen3_5.py
_uses_multimodal_rope[3行] Return whether a Qwen3.5 attention layer exposes multimodal RoPE.
_ascend_all_gather_hidden_and_residual[12行] 代码量 12 行
forward[43行] 代码量 43 行
qwen3_5_mtp_forward[61行] 代码量 61 行
patch/worker/patch_qwen3_dflash.py
查看源码Qwen3 DFlash patch(81 行)。precompute_and_store_context_kv 预计算并存储上下文 KV(draft 复用);_patched_read_mask_embedding 修正 read mask 嵌入。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_qwen3_dflash.py
precompute_and_store_context_kv[58行] 代码量 58 行
_patched_read_mask_embedding[5行] 代码量 5 行
patch/worker/patch_qwen3vl.py
查看源码Qwen3-VL patch(105 行)。forward_with_split_qkv_rmsnorm_mrope 用融合 kernel 替换视觉 QKV+norm+mrope;_fast_pos_embed_interpolate 加速位置嵌入插值;tensor_parallel_wrap 包张量并行;patch_qwen3_vl_moe_pp_layer_range 修 PP 层范围。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_qwen3vl.py
tensor_parallel_wrap[13行] 代码量 13 行
forward_with_split_qkv_rmsnorm_mrope[33行] 代码量 33 行
_fast_pos_embed_interpolate[15行] 代码量 15 行
patch_qwen3_vl_moe_pp_layer_range[11行] 代码量 11 行
wrap[10行] 代码量 10 行
patch/worker/patch_routed_experts_capture.py
查看源码专家路由捕获 patch(188 行)。capture 在 graph 捕获期为特定层捕获专家路由决策(topk_ids),供 EPLB 负载统计在图模式下工作。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_routed_experts_capture.py
capture[151行] Capture expert routing decisions for a specific layer.
patch/worker/patch_step3p5.py
查看源码Step3.5 patch(69 行)。_patched_attention_forward 替换 Step3.5 注意力前向以适配 NPU。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_step3p5.py
_patched_attention_forward[41行] 代码量 41 行
patch/worker/patch_triton.py
查看源码Triton patch(118 行)。修正 Triton-Ascend 在特定版本下的行为差异(kernel launch/编译选项适配)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_triton.py
_fused_post_conv_prep_pytorch[36行] 代码量 36 行
_fused_recurrent_packed_decode_pytorch[55行] 代码量 55 行
_l2norm[3行] 代码量 3 行
patch/worker/patch_v2/patch_attn_utils.py
查看源码V2 注意力工具 patch(21 行)。_get_ascend_sfa_indexer_backend 返回 Ascend SFA indexer 后端(替换 vLLM V2 的默认选择)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_v2\patch_attn_utils.py
_get_ascend_sfa_indexer_backend[2行] 代码量 2 行
patch/worker/patch_v2/patch_dspark.py
查看源码DSpark 加载 patch(94 行)。_load_dspark_model_with_target_quant 让 DSpark draft 继承目标模型的量化配置(避免 draft 用错量化方案)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_v2\patch_dspark.py
_load_dspark_model_with_target_quant[37行] 代码量 37 行
should_share[6行] 代码量 6 行
patch/worker/patch_v2/patch_spec_pp.py
查看源码V2 PP 投机解码 patch(93 行)。install_spec_pp_token_broadcast 把已接受 token 与下一 draft token 经同一 V2 PP 槽位广播(投机解码在 PP 下的 token 传递)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_v2\patch_spec_pp.py
install_spec_pp_token_broadcast[83行] Send accepted and next-draft tokens through the same V2 PP slot.
get_prev_sampled_outputs[34行] 代码量 34 行
broadcast[11行] 代码量 11 行
broadcast_draft_tokens[18行] 代码量 18 行
patch/worker/patch_v2/patch_uva.py
查看源码UVA 适配 patch(171 行)。NPU 不直接支持 UVA 张量:UvaBufferWrapper 包装 CPU 缓冲监控修改(MonitoredNumPyArray/MonitoredTorchVector 记录 __setitem__),按需同步;is_uva_available/check_triton_ascend_version_valid 探测特性可用性;get_row_indices_from_key 解析行索引。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\patch\worker\patch_v2\patch_uva.py
check_triton_ascend_version_valid[16行] Check triton-ascend version and warn about UVA feature disablement.
is_uva_available[9行] check if uva feature is supported in this environment
get_row_indices_from_key[21行] get the set of row indices involved in the given key.
__init__[5行] 代码量 5 行
__setitem__[6行] 代码量 6 行
__getitem__[2行] 代码量 2 行
__getattr__[2行] 代码量 2 行
_mark_cpu_modified[2行] 代码量 2 行
cpu[2行] 代码量 2 行
np[2行] 代码量 2 行
uva[20行] Get the device data of the buffer.
profiler/torch_npu_profiler.py
查看源码torch_npu 性能分析器包装(86 行)。TorchNPUProfilerWrapper 继承 vLLM WorkerProfiler 接入 torch_npu.profiler:_create_profiler 创建、_start/_stop 启停、_profiler_step 步进。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\profiler\torch_npu_profiler.py
__init__[3行] 代码量 3 行
_create_profiler[41行] 代码量 41 行
_start[2行] 代码量 2 行
_stop[2行] 代码量 2 行
_profiler_step[2行] 代码量 2 行
quantization/__init__.py
查看源码量化包入口(57 行)。通过 __getattr__ 惰性导出各配置类与 scheme,避免循环导入。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\__init__.py
__getattr__[18行] 代码量 18 行
quantization/configs/compressed_tensors_config.py
查看源码LLM-Compressor 量化配置(415 行)。AscendCompressedTensorsConfig 解析 compressed_tensors 格式 checkpoint:_detect_quant_type 探测量化类型、_quantization_scheme_map_from_config 构建 scheme 映射、_add_fused_moe_to_target_scheme_map 补 MoE 目标、get_quant_method 按层返回方法(_get_linear_scheme/_get_moe_scheme)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\configs\compressed_tensors_config.py
__init__[13行] 代码量 13 行
get_name[2行] 代码量 2 行
get_supported_act_dtypes[2行] 代码量 2 行
get_min_capability[2行] 代码量 2 行
get_config_filenames[2行] 代码量 2 行
_add_fused_moe_to_target_scheme_map[10行] Helper function to update target_scheme_map
from_config[11行] 代码量 11 行
_quantization_scheme_map_from_config[33行] Build target scheme map from config.
get_quant_method[39行] 代码量 39 行
_get_linear_scheme[18行] Get the linear quantization scheme for a layer.
_get_moe_scheme[21行] Get the MoE quantization scheme for a layer.
_get_quant_args[36行] Extract quantization arguments for a layer.
get_scheme_dict[33行] Extract the QuantizationArgs for a given layer.
_create_scheme_for_layer_type[32行] Create the appropriate Ascend scheme based on quantization args and layer type.
_detect_quant_type[37行] Detect the quantization type from quantization arguments.
_is_static_tensor_w8a8[10行] 代码量 10 行
_is_dynamic_token_w8a8[10行] 代码量 10 行
_is_dynamic_token_w4a8[11行] 代码量 11 行
_is_w4a16[15行] 代码量 15 行
apply_vllm_mapper[3行] 代码量 3 行
quantization/configs/fp8_config.py
查看源码FP8 配置(144 行)。AscendFp8Config 服务通用 HF fp8 格式 checkpoint(_verify_block_quantization 校验块量化);AscendDeepseekV4FP8Config 为 DSV4 变体。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\configs\fp8_config.py
__init__[3行] 代码量 3 行
get_min_capability[2行] 代码量 2 行
_verify_block_quantization[15行] 代码量 15 行
get_quant_method[25行] 代码量 25 行
quantization/configs/modelopt_mxfp8_config.py
查看源码ModelOpt MXFP8 配置(88 行)。AscendModelOptMxFp8Config 加载 ModelOpt 兼容的 MXFP8 checkpoint 并映射到 Ascend 方法。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\configs\modelopt_mxfp8_config.py
get_min_capability[2行] 代码量 2 行
get_quant_method[48行] 代码量 48 行
quantization/configs/modelslim_config.py
查看源码ModelSlim 量化配置(1118 行,量化配置主文件)。AscendModelSlimConfig 解析华为 ModelSlim 格式:量化类型判定(get_linear_quant_type/get_quant_type_for_layer)、按层创建 scheme(create_scheme_for_layer)、打包模块映射(get_packed_modules_mapping 按模型类型)、MoE scale-bias 名称映射(_make_modelslim_moe_weight_loader)、Kimi K3 混合 KDA 投影识别(uses_kimi_k3_mixed_kda_projection)、前缀重映射(quant_prefix_mapper)、层跳过判断;_is_missing_v_shard 处理 Gemma4 重复 v_proj 缺失分片。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\configs\modelslim_config.py
_make_modelslim_moe_weight_loader[27行] Map ModelSlim MoE scale-bias names to the upstream scale path.
get_packed_modules_mapping[32行] Get packed modules mapping for a model type.
_is_missing_v_shard[11行] Return whether the missing shard is Gemma4's replicated v_proj.
get_linear_quant_type[40行] Determine the quantization type for a linear layer.
get_quant_type_for_layer[30行] Determine the quantization type for a layer.
create_scheme_for_layer[37行] Create a quantization scheme instance for a layer.
modelslim_moe_weight_loader[19行] 代码量 19 行
__init__[8行] 代码量 8 行
__repr__[2行] 代码量 2 行
get_name[2行] 代码量 2 行
get_supported_act_dtypes[2行] 代码量 2 行
get_min_capability[3行] 代码量 3 行
get_config_filenames[7行] 代码量 7 行
from_config[2行] 代码量 2 行
override_quantization_method[6行] 代码量 6 行
apply_vllm_mapper[29行] Apply the vLLM model-specific mapper to this quantization config.
get_cache_scale_mapper[37行] Upstream use staticmethod, but we need to use instance attribute
uses_kimi_k3_mixed_kda_projection[18行] Return whether Kimi K3's packed KDA input must be split.
_has_quant_weight[8行] 代码量 8 行
quant_prefix_mapper[34行] 代码量 34 行
get_quant_method[74行] 代码量 74 行
is_layer_skipped_ascend[38行] 代码量 38 行
is_fa_quant_layer[6行] 代码量 6 行
enabling_fa_quant[10行] 代码量 10 行
is_indexer_quant_layer[6行] 代码量 6 行
is_c8_quant_layer[6行] 代码量 6 行
get_kv_quant_dtype[14行] 代码量 14 行
get_kv_quant_split_factor[6行] 代码量 6 行
maybe_update_config[99行] Load the ModelSlim quantization config from model directory.
_apply_extra_quant_adaptations[73行] Apply extra adaptations to the quant_description dict.
_add_kvcache_quant_metadata[19行] 代码量 19 行
quantization/method_adapters.py
查看源码量化方法适配器(323 行)。AscendLinearMethod/AscendKVCacheMethod/AscendFusedMoEMethod/AscendEmbeddingMethod 把 vLLM 的量化方法接口桥接到 Ascend scheme 体系(create_weights/process_weights_after_loading/apply/get_computed_params;MoE 含 is_monolithic/maybe_make_prepare_finalize/get_eplb_weight_views/supports_eplb)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\method_adapters.py
_forwardable_weight_attrs[2行] 代码量 2 行
__init__[2行] 代码量 2 行
create_weights[32行] 代码量 32 行
process_weights_after_loading[3行] 代码量 3 行
get_computed_params[11行] Return parameter name patterns that are computed, not loaded.
apply[17行] 代码量 17 行
is_monolithic[2行] 代码量 2 行
maybe_make_prepare_finalize[4行] 代码量 4 行
get_eplb_weight_views[2行] 代码量 2 行
get_fused_moe_quant_config[2行] 代码量 2 行
supports_eplb[3行] 代码量 3 行
quantization/methods/__init__.py
查看源码量化 scheme 汇出(129 行)。is_mx_quant_type 判断是否 MX(microscaling)类量化。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\__init__.py
is_mx_quant_type[12行] Checks if the quantization method is a microscaling (MX) type.
quantization/methods/base.py
查看源码量化 scheme 抽象基类(287 行)。AscendLinearScheme(权重与 per-tensor/per-channel/per-group 参数、apply)、AscendAttentionScheme(注意力量化)、AscendMoEScheme(MoE:动态量化参数/EPLB 权重视图);get_moe_num_logical_experts 计算逻辑专家数。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\base.py
get_moe_num_logical_experts[12行] 代码量 12 行
get_weight[15行] Return weight tensor specifications for MoE layer.
get_pertensor_param[11行] Return per-tensor parameter specifications (e.g., input_scale).
get_perchannel_param[11行] Return per-channel parameter specifications (e.g., weight_scale).
get_pergroup_param[15行] Return per-group parameter specifications.
apply[21行] Forward computation for MoE layer.
process_weights_after_loading[7行] Post-loading weight processing for MoE layer.
create_weights[7行] Create weights for attention quantization.
get_dynamic_quant_param[15行] Return dynamic quantization parameters for MoE layer.
get_eplb_weight_views[3行] Return expert-first weight views consumed by upstream EPLB.
quantization/methods/kv_cache/kv_c8.py
查看源码C8 INT8 KV cache 量化(164 行)。AscendC8KVCacheAttentionMethod(稠密注意力如 Qwen3:scale/offset 权重加载 _c8_kv_scale_weight_loader)、AscendFAQuantAttentionMethod/AscendSFAQuantAttentionMethod(MLA/SFA 的 FAKQuant,_fa_quant_weight_loader)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\kv_cache\kv_c8.py
_fa_quant_weight_loader[16行] Weight loader for MLA-based C8 (FAKQuant) models.
_c8_kv_scale_weight_loader[7行] Weight loader for dense-attention C8 KV cache scales/offsets.
__init__[7行] 代码量 7 行
create_weights[21行] 代码量 21 行
process_weights_after_loading[5行] 代码量 5 行
apply[18行] 代码量 18 行
quantization/methods/registry.py
查看源码scheme 注册表(62 行)。register_scheme 装饰器按(quant_type, layer_type)注册 scheme 类;get_scheme_class 查询。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\registry.py
register_scheme[26行] Decorator to register a quantization scheme.
get_scheme_class[11行] Get scheme class for given quant_type and layer_type.
decorator[8行] 代码量 8 行
quantization/methods/w4a4/w4a4_flatquant.py
查看源码W4A4 FlatQuant(175 行)。AscendW4A4FlatQuantDynamicLinearMethod:Kronecker 分解量化(solve_kronecker_decompose 找 a²-b²=n、batched_kronecker_quant 批量量化)、pack_int4_weights 打包 int4。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\w4a4\w4a4_flatquant.py
pack_int4_weights[6行] Pack int4 weights for NPU.
solve_kronecker_decompose[16行] Find (a-b, a+b) such that a² - b² = n.
batched_kronecker_quant[19行] Batched Kronecker quantization with batch size limit handling.
__init__[2行] 代码量 2 行
get_weight[8行] 代码量 8 行
get_pertensor_param[7行] 代码量 7 行
get_perchannel_param[9行] 代码量 9 行
apply[39行] 代码量 39 行
process_weights_after_loading[11行] 代码量 11 行
quantization/methods/w4a4/w4a4_laos_dynamic.py
查看源码W4A4 LAOS 动态量化(76 行)。AscendW4A4LaosDynamicLinearMethod 的 per-channel 参数与 apply。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\w4a4\w4a4_laos_dynamic.py
__init__[2行] 代码量 2 行
get_weight[3行] 代码量 3 行
get_perchannel_param[5行] 代码量 5 行
apply[23行] 代码量 23 行
process_weights_after_loading[4行] 代码量 4 行
quantization/methods/w4a4/w4a4_mxfp4.py
查看源码W4A4 MXFP4(229 行)。AscendW4A4MXFP4DynamicLinearMethod(per-group 参数)与 AscendW4A4MXFP4DynamicFusedMoEMethod(MoE:动态量化参数/EPLB 视图)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\w4a4\w4a4_mxfp4.py
__init__[5行] 代码量 5 行
get_weight[11行] 代码量 11 行
get_pergroup_param[6行] 代码量 6 行
apply[37行] 代码量 37 行
process_weights_after_loading[11行] 代码量 11 行
get_dynamic_quant_param[12行] 代码量 12 行
get_eplb_weight_views[7行] 代码量 7 行
quantization/methods/w4a4/w4a4_mxfp4_flatquant.py
查看源码W4A4 MXFP4 FlatQuant(167 行)。AscendW4A4MXFP4FlatQuantDynamicLinearMethod 结合 Kronecker 分解与 MXFP4(get_decompose_dim 求分解维度)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\w4a4\w4a4_mxfp4_flatquant.py
get_decompose_dim[21行] Get decomposed dimensions for Kronecker quantization.
__init__[11行] 代码量 11 行
get_weight[7行] 代码量 7 行
get_pertensor_param[14行] 代码量 14 行
get_pergroup_param[7行] 代码量 7 行
apply[41行] 代码量 41 行
process_weights_after_loading[23行] 代码量 23 行
quantization/methods/w4a8/w4a8.py
查看源码W4A8 动态量化(410 行)。AscendW4A8DynamicFusedMoEMethod:三种格式支持(compressed_tensors/modelslim)、int4→int8 打包(_pack_int4_to_int8/_pack_to_int32)、per-channel scale 压缩(maybe_squeeze_per_channel_weight_scale/_process_scale)、EPLB 权重视图。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\w4a8\w4a8.py
__init__[28行] 代码量 28 行
get_weight[16行] 代码量 16 行
get_dynamic_quant_param[9行] 代码量 9 行
get_dynamic_quant_param_compressed_tensors[9行] 代码量 9 行
get_dynamic_quant_param_modelslim[17行] 代码量 17 行
apply[71行] 代码量 71 行
get_eplb_weight_views[31行] 代码量 31 行
maybe_squeeze_per_channel_weight_scale[4行] 代码量 4 行
_pack_to_int32[6行] 代码量 6 行
_process_scale[6行] 代码量 6 行
_pack_int4_to_int8[10行] 代码量 10 行
process_weights_after_loading[43行] 代码量 43 行
process_weights_after_loading_compressed_tensors[26行] 代码量 26 行
process_weights_after_loading_modelslim[10行] 代码量 10 行
update_bias_compressed_tensors[6行] 代码量 6 行
quantization/methods/w4a8/w4a8_mxfp4.py
查看源码W4A8 MXFP(245 行)。AscendW4A8MXFPDynamicLinearMethod/FusedMoEMethod(microscaling 量化);AscendW4A8MXFPDSDynamicFusedMoEMethod 为 DeepSeek 原生 w4a8 mxfp(128×128 块)变体。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\w4a8\w4a8_mxfp4.py
__init__[5行] 代码量 5 行
get_weight[11行] 代码量 11 行
get_pergroup_param[6行] 代码量 6 行
apply[37行] 代码量 37 行
process_weights_after_loading[23行] 代码量 23 行
get_dynamic_quant_param[15行] 代码量 15 行
quantization/methods/w8a8/fp8_block.py
查看源码块状 FP8(364 行)。服务原生 fp8 checkpoint:resolve_block_scales 把块 scale 展开为稠密矩阵、_mx_quantize 再量化为 MXFP8(含 uint8 scale);_supports_mx_regroup 检查 regroup 条件、_is_absorbed_by_attention 识别被 MLA/SFA 吸收的投影;AscendFp8BlockLinearMethod/AscendFp8BlockFusedMoEMethod(专家按需再量化 _requantize_experts_inplace/bf16 回退)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\w8a8\fp8_block.py
resolve_block_scales[39行] Expand a block-wise FP8 matrix into a dense ``out_dtype`` matrix.
_mx_quantize[14行] Re-quantize a dense matrix to MXFP8, returning the weight and uint8 scale.
_supports_mx_regroup[2行] 代码量 2 行
_is_absorbed_by_attention[8行] True for projections that MLA/SFA folds into its own weights.
__init__[15行] 代码量 15 行
get_weight[11行] 代码量 11 行
get_pergroup_param[12行] 代码量 12 行
process_weights_after_loading[28行] 代码量 28 行
apply[18行] 代码量 18 行
bf16_method[8行] The unquantized MoE method that serves resolved bfloat16 experts.
get_dynamic_quant_param[17行] 代码量 17 行
_resolve_experts[10行] Expand every expert of one MoE weight into the model dtype.
_requantize_experts_inplace[26行] Rewrite every expert of one MoE weight from block-wise FP8 to MXFP8.
get_eplb_weight_views[3行] 代码量 3 行
quantization/methods/w8a8/w8a8_dynamic.py
查看源码W8A8 动态量化(350 行)。AscendW8A8DynamicLinearMethod/FusedMoEMethod:per-channel 权重 + 激活动态量化(scale_from_float_to_int64 做 int64 scale 转换)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\w8a8\w8a8_dynamic.py
scale_from_float_to_int64[8行] Convert float32 scale to int64 representation.
__init__[20行] 代码量 20 行
get_weight[11行] 代码量 11 行
get_perchannel_param[9行] 代码量 9 行
apply[78行] 代码量 78 行
process_weights_after_loading[55行] 代码量 55 行
get_dynamic_quant_param[13行] 代码量 13 行
get_eplb_weight_views[40行] 代码量 40 行
quantization/methods/w8a8/w8a8_mxfp8.py
查看源码W8A8 MXFP8(472 行)。AscendW8A8MXFP8DynamicLinearMethod/FusedMoEMethod(microscaling FP8,restore_weights_for_rl_loading 支持 RL 权重重载);AscendW8A8MXFP8DSDynamicLinearMethod 为 DeepSeek 原生 128×128 块变体。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\w8a8\w8a8_mxfp8.py
__init__[9行] 代码量 9 行
get_weight[11行] 代码量 11 行
get_pergroup_param[10行] 代码量 10 行
apply[40行] 代码量 40 行
process_weights_after_loading[22行] 代码量 22 行
restore_weights_for_rl_loading[53行] Restore weights to original shapes for RL weight reloading.
get_dynamic_quant_param[12行] 代码量 12 行
get_eplb_weight_views[7行] 代码量 7 行
_restore[15行] Helper to restore a single MoE weight and its scale using safe memory copies.
quantization/methods/w8a8/w8a8_pdmix.py
查看源码W8A8 PD 混合量化(85 行)。AscendW8A8PDMixLinearMethod 支持 prefill-decode 混合精度量化(per-tensor + per-channel 参数并存)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\w8a8\w8a8_pdmix.py
__init__[6行] 代码量 6 行
get_weight[2行] 代码量 2 行
get_pertensor_param[2行] 代码量 2 行
get_perchannel_param[6行] 代码量 6 行
apply[11行] 代码量 11 行
process_weights_after_loading[4行] 代码量 4 行
quantization/methods/w8a8/w8a8_static.py
查看源码W8A8 静态量化(137 行)。AscendW8A8LinearMethod:静态 per-tensor/per-channel 参数,apply 走量化 GEMM。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\w8a8\w8a8_static.py
__init__[2行] 代码量 2 行
get_weight[8行] 代码量 8 行
get_pertensor_param[5行] 代码量 5 行
get_perchannel_param[14行] 代码量 14 行
apply[29行] 代码量 29 行
process_weights_after_loading[19行] 代码量 19 行
quantization/methods/w8a8/w8a8fp8_dynamic.py
查看源码W8A8FP8 动态量化(103 行)。AscendW8A8FP8DynamicLinearMethod/FusedMoEMethod:INT8 权重 + FP8 激活动态量化的组合 scheme。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\w8a8\w8a8fp8_dynamic.py
__init__[2行] 代码量 2 行
get_weight[11行] 代码量 11 行
get_perchannel_param[9行] 代码量 9 行
apply[13行] 代码量 13 行
get_dynamic_quant_param[13行] 代码量 13 行
quantization/methods/wna16/w4a16.py
查看源码W4A16(316 行)。AscendW4A16FusedMoEMethod:int4 权重 int32 打包/解包(pack_to_int32/unpack_from_int32)、MoE 动态激活量化参数。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\wna16\w4a16.py
unpack_from_int32[48行] Unpacks quantized weights from int32 format back to original bits.
pack_to_int32[24行] Packs quantized weights into int32 format for storage.
__init__[7行] 代码量 7 行
get_weight[25行] 代码量 25 行
get_dynamic_quant_param[33行] 代码量 33 行
apply[34行] 代码量 34 行
process_weights_after_loading[33行] 代码量 33 行
quantization/methods/wna16/w4a16_mxfp4.py
查看源码W4A16 MXFP4(150 行)。AscendW4A16MXFP4FusedMoEMethod:FP4 打包解包(unpack_uint8_to_fp4_return_float32)与 MoE 集成。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\wna16\w4a16_mxfp4.py
unpack_uint8_to_fp4_return_float32[12行] 代码量 12 行
__init__[5行] 代码量 5 行
get_weight[21行] 代码量 21 行
get_dynamic_quant_param[16行] 代码量 16 行
apply[36行] 代码量 36 行
process_weights_after_loading[13行] 代码量 13 行
quantization/methods/wna16/w8a16.py
查看源码W8A16(78 行)。AscendW8A16LinearMethod:INT8 权重 FP16 激活,per-channel 参数。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\methods\wna16\w8a16.py
__init__[2行] 代码量 2 行
get_weight[8行] 代码量 8 行
get_perchannel_param[9行] 代码量 9 行
apply[15行] 代码量 15 行
process_weights_after_loading[5行] 代码量 5 行
quantization/quant_parser.py
查看源码量化参数解析(68 行)。QuantTypeMapping.get_quant_settings 查询量化设置;get_rollback_quant_type 解析回退量化类型;parse_mxfp_quant_params/parse_quant_moe_down_proj_params 解析 MXFP 与 MoE 下投影量化参数。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\quant_parser.py
get_rollback_quant_type[6行] 代码量 6 行
parse_mxfp_quant_params[7行] 代码量 7 行
parse_quant_moe_down_proj_params[14行] 代码量 14 行
get_quant_settings[2行] 代码量 2 行
quantization/tp_weight_switch.py
查看源码TP 全量权重切换(296 行)。TPWeightSwitchMixin 为线性方法提供可选的 TP 分片↔全量切换:enable_tp_weight_switch 启用(分配可复用缓冲)、split_tensor_for_tp 切分、all_gather_tp_weight/wait_tp_weight_all_gather 异步 all-gather、switch_tp_weight 切换;TPWeightGatherSpec/TPWeightRepeatSpec 描述需要 gather/repeat 的张量属性;TPWeightSwitchState 管理缓冲与未完成集合通信。服务 DSA-CP/SFA-CP 的 o_proj 全量权重计算。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\tp_weight_switch.py
split_tensor_for_tp[17行] Slice one TP shard from a full tensor.
enable_tp_weight_switch[123行] Allocate TP/full aliases and buffers for one compatible linear layer.
all_gather_tp_weight[21行] All-gather every TP-sharded tensor in ``state``.
wait_tp_weight_all_gather[6行] 代码量 6 行
switch_tp_weight[16行] Switch layer tensor attributes between TP-local and full views.
quantization/utils.py
查看源码量化工具(276 行)。detect_quantization_method 从模型文件自动探测量化方法、maybe_auto_detect_quantization 应用到 vllm_config;is_fused_moe_layer 判断 MoE 层;get_dynamic_mx_quant_scale_alg 选择 MX scale 算法;get_model_file 获取模型文件(本地或远端);enable_fa_quant 判断 FA 量化启用。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\quantization\utils.py
is_fused_moe_layer[4行] 代码量 4 行
get_dynamic_mx_quant_scale_alg[35行] Select the MX scale algorithm used by DynamicMxQuantV3.
get_model_file[48行] Get a file from local model directory or download from remote repo.
detect_quantization_method[56行] Auto-detect the quantization method from model files.
maybe_auto_detect_quantization[74行] Auto-detect and apply the quantization method on *vllm_config*.
enable_fa_quant[10行] 代码量 10 行
采样惩罚入口(45 行)。apply_all_penalties 用 Triton-Ascend 一次性施加出现/频率/重复三类惩罚(_convert_to_tensors 把 list-of-list 的输出 token 转填充张量)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\sample\penalties.py
_convert_to_tensors[10行] Convert output_token_ids (list of lists) to padded tensor.
apply_all_penalties[21行] Apply penalties to logits via Triton-Ascend.
sample/rejection_sampler.py
查看源码拒绝采样器(1737 行)。AscendRejectionSampler 为投机解码的 Ascend 优化实现:prepare_sampling 准备、apply_penalties/apply_logits_processors 应用惩罚与 logit 处理器、forward 主入口(含进出日志);核心采样函数按贪婪/随机/block-verify 分派:rejection_sample(分布式场景)、rejection_greedy_sample_pytorch(含 spec_len_1 特例)、rejection_random_sample_pytorch/block_verify_pytorch、sample_recovered_tokens_pytorch(拒绝处从目标分布恢复采样)、expand_batch_to_tokens/expand_pytorch 批级到 token 级扩展、greedy_sample/apply_sampling_constraints 辅助。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\sample\rejection_sampler.py
greedy_sample[17行] 代码量 17 行
apply_sampling_constraints[67行] Process logits based on sampling metadata for distributed scenario.
rejection_sample[484行] Rejection sampling for speculative decoding in distributed setting.
expand_batch_to_tokens[41行] Expand [batch_size] tensor to [num_tokens] tensor based on the number of
sample_recovered_tokens[78行] 代码量 78 行
rejection_greedy_sample_spec_len_1_pytorch[25行] 代码量 25 行
rejection_greedy_sample_pytorch[70行] 代码量 70 行
rejection_random_sample_pytorch[179行] This function implements the Speculative Decoding rejection sampling step.
expand_pytorch[45行] This function broadcasts batch-level values (input_ptr) to token-level
sample_recovered_tokens_pytorch[122行] When a draft token is rejected, we must sample a "recovered" token from
rejection_random_sample_block_verify_pytorch[114行] 代码量 114 行
sample_recovered_tokens_blockwise_pytorch[140行] 代码量 140 行
apply_penalties[32行] 代码量 32 行
prepare_sampling[5行] 代码量 5 行
__init__[16行] 代码量 16 行
apply_logits_processors[51行] 代码量 51 行
forward[111行] Args:
_log_rejection_sampler_entry[31行] DFX entry probe for rejection sampling.
_log_rejection_sampler_exit[32行] DFX exit probe (acceptance signal) for rejection sampling.
采样器(274 行)。AscendSampler 组织完整采样流程(greedy_sample/apply_penalties/prepare_sampling);AscendTopKTopPSampler 应用 top-k/top-p(_apply_top_k_top_p_torch_npu 走 NPU 算子、_apply_top_k_top_p_pytorch 回退);random_sample 按概率随机采样(配合 CPU 生成器)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\sample\sampler.py
random_sample[25行] Randomly sample from the probabilities.
_apply_top_k_top_p_pytorch[73行] 代码量 73 行
_apply_top_k_top_p_torch_npu[31行] 代码量 31 行
apply_penalties[24行] Use Triton-Ascend penalties on NPU when Triton is available; else vLLM default.
__init__[4行] 代码量 4 行
prepare_sampling[5行] 代码量 5 行
greedy_sample[20行] 代码量 20 行
forward_native[38行] Override pytorch native implementation to torch_npu
spec_decode/__init__.py
查看源码投机解码入口(61 行)。get_spec_decode_method 按配置的投机方法创建对应的 Ascend proposer 实例。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\spec_decode\__init__.py
get_spec_decode_method[26行] 代码量 26 行
spec_decode/dflash2_proposer.py
查看源码DFlash2 proposer(107 行)。AscendDflash2Proposer:与 DFlash 相同输入布局但用选择器替代 argmax——greedy_select_path 从 anchor 沿候选表贪心走出最佳路径、compute_draft_token_ids 产出 draft 序列、_maybe_share_lm_head 共享输出头;is_dflash2_draft 判断配置。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\spec_decode\dflash2_proposer.py
is_dflash2_draft[5行] True when method is dflash and the draft architecture is DFlash2DraftModel.
greedy_select_path[26行] Walk the best path from the verified anchor (T=0).
__init__[21行] 代码量 21 行
_maybe_share_lm_head[8行] 代码量 8 行
compute_draft_token_ids[26行] 代码量 26 行
spec_decode/dflash_proposer.py
查看源码DFlash proposer(311 行)。AscendDflashProposer:set_inputs_first_pass 首趟输入设置、build_model_inputs_first_pass 构建首趟模型输入、dummy_run 哑运行;_compute_num_programs 计算 copy_and_expand kernel 的启动程序数。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\spec_decode\dflash_proposer.py
_compute_num_programs[17行] Number of programs to launch for copy_and_expand_dflash_and_dspark_inputs_kernel:
__init__[58行] 代码量 58 行
set_inputs_first_pass[88行] 代码量 88 行
dummy_run[99行] 代码量 99 行
build_model_inputs_first_pass[19行] 代码量 19 行
_raise_if_multimodal[2行] 代码量 2 行
spec_decode/draft_proposer.py
查看源码通用 draft 模型 proposer(17 行)。AscendDraftModelProposer 包装标准 draft 模型(Eagle 类通用骨架)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\spec_decode\draft_proposer.py
__init__[9行] 代码量 9 行
spec_decode/dspark_proposer.py
查看源码DSpark proposer(389 行)。AscendDSparkProposer:_compute_confidence 计算置信度、initialize_attn_backend 初始化 draft 注意力后端、set_per_group_attn_metadata 按 KV 组设置元数据、set_inputs_first_pass/dummy_run。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\spec_decode\dspark_proposer.py
__init__[76行] 代码量 76 行
_compute_confidence[18行] 代码量 18 行
initialize_attn_backend[74行] 代码量 74 行
set_per_group_attn_metadata[8行] 代码量 8 行
set_inputs_first_pass[119行] 代码量 119 行
dummy_run[60行] 代码量 60 行
spec_decode/eagle_proposer.py
查看源码Eagle proposer(12 行)。AscendEagleProposer 薄包装(复用基类能力)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\spec_decode\eagle_proposer.py
__init__[2行] 代码量 2 行
spec_decode/extract_hidden_states_proposer.py
查看源码辅助隐藏层提取 proposer(198 行)。AscendExtractHiddenStatesProposer 提取并缓存目标模型中间层 hidden states 供 Eagle3 类 draft 使用:_determine_batch_execution_and_padding 批执行判定、prepare_next_token_ids_padded 准备填充后的下一 token ID。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\spec_decode\extract_hidden_states_proposer.py
__init__[3行] 代码量 3 行
_determine_batch_execution_and_padding[70行] Determine cudagraph mode and padded token count for this proposer step.
dummy_run[42行] Dummy run for ACL graph capture.
prepare_next_token_ids_padded[41行] Prepare next token IDs for speculative decoding.
spec_decode/llm_base_proposer.py
查看源码proposer 基类(2417 行,投机解码最大文件)。AscendSpecDecodeBaseProposer 是全部 draft proposer 的基座:模型加载与共享(load_model/_maybe_share_embeddings/_maybe_share_lm_head/_maybe_share_topk_indices)、D2T 变换移除(_maybe_remove_d2t)、图参数更新(_update_full_graph_params_if_needed)、提议主流程(_propose/_sample_draft_from_logits)、多模态图像 token 索引(_get_multimodal_image_token_index)、GLM 系列判断与 padded drafter 批次守卫。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\spec_decode\llm_base_proposer.py
greedy_sample[15行] 代码量 15 行
_is_glm_model[9行] Return True if the target model belongs to the GLM series.
_get_multimodal_image_token_index[21行] 代码量 21 行
__init__[137行] 代码量 137 行
_raise_if_padded_drafter_batch_disabled_and_full_graph_enabled[11行] 代码量 11 行
_maybe_remove_d2t[8行] Drop the identity d2t mapping of a full-vocab EAGLE3 draft.
_get_model[24行] Default method to call get_model(). Can be overridden by subclasses which
load_model[104行] 代码量 104 行
_maybe_share_embeddings[80行] Some draft models may not have their own embedding layers, and some may
_maybe_share_lm_head[69行] 代码量 69 行
_maybe_share_topk_indices[15行] 代码量 15 行
get_model[5行] 代码量 5 行
shallow_copy_metadata[4行] 代码量 4 行
dummy_run[184行] 代码量 184 行
_update_full_graph_params_if_needed[8行] 代码量 8 行
_propose[324行] 代码量 324 行
_sample_draft_from_logits[25行] Sample draft tokens from logits.
compute_draft_token_ids[27行] Compute draft token ids (and optionally draft probs).
_run_merged_draft[377行] 代码量 377 行
set_inputs_first_pass[166行] 代码量 166 行
model_returns_tuple[19行] 代码量 19 行
attn_update_stack_num_spec_norm[215行] 代码量 215 行
prepare_next_token_ids_padded[61行] This function is used to prepare the inputs for speculative decoding.
prepare_inputs[131行] This function is used to prepare the inputs for speculative decoding.
prepare_inputs_padded[97行] This function is used to prepare the inputs for speculative decoding
_update_full_graph_params[12行] 代码量 12 行
_adjust_tensor[8行] 代码量 8 行
maybe_pad_and_reduce[6行] 代码量 6 行
maybe_all_gather_and_unpad[20行] 代码量 20 行
_align_tensor_and_indices[41行] Align the tensor (either draft_token_ids or logits) and token_indices_to_sample
build_draft_attn_metadata[50行] 代码量 50 行
_pad_draft_buffers[17行] 代码量 17 行
spec_decode/medusa_proposer.py
查看源码Medusa proposer(72 行)。AscendMedusaProposer 用 Medusa 头生成多 token 候选(propose/dummy_run)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\spec_decode\medusa_proposer.py
dummy_run[29行] 代码量 29 行
propose[27行] 代码量 27 行
spec_decode/ngram_proposer.py
查看源码NGram proposer(60 行)。AscendNgramProposer 基于已生成文本的 n-gram 匹配生成 draft(propose/load_model/dummy_run)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\spec_decode\ngram_proposer.py
__init__[3行] 代码量 3 行
load_model[3行] 代码量 3 行
dummy_run[13行] 代码量 13 行
propose[32行] 代码量 32 行
spec_decode/ngram_proposer_npu.py
查看源码NGram proposer NPU 版(35 行)。AscendNgramProposerNPU 把 n-gram 匹配下推到设备端 Triton kernel(对应 ops/triton/spec_decode/ngram.py)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\spec_decode\ngram_proposer_npu.py
__init__[2行] 代码量 2 行
load_model[3行] 代码量 3 行
dummy_run[13行] 代码量 13 行
propose[8行] 代码量 8 行
spec_decode/step3p5.py
查看源码Step3.5 MTP proposer(818 行)。AscendStep3p5MTPProposer 支持每个 MTP 层独立 KV cache 组:set_per_group_attn_metadata/_seed_graph_capture_per_group_metadata 按组设元数据与图捕获种子、_slot_mapping_buffer_for_group/_common_attn_metadata_for_group 组级缓冲与元数据、_build_step_attn_metadatas/_sample_draft_tokens_for_step 按步构建、_run_window_draft_steps 窗口式 draft 步进、_roll_window_inputs_only 滚动输入、_create_draft_vllm_config/validate_same_kv_cache_group 配置与校验。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\spec_decode\step3p5.py
__init__[16行] 代码量 16 行
set_per_group_attn_metadata[8行] 代码量 8 行
_seed_graph_capture_per_group_metadata[20行] 代码量 20 行
_slot_mapping_buffer_for_group[12行] 代码量 12 行
_common_attn_metadata_for_group[25行] 代码量 25 行
_build_step_attn_metadatas[48行] Build base-proposer-style per-step metadata for Step3.5 MTP.
_sample_draft_tokens_for_step[29行] GPU Step3.5 sampling semantics with Ascend TP/reduce-sample paths.
dummy_run[112行] 代码量 112 行
_propose[185行] 代码量 185 行
_run_merged_draft[76行] Base MTP execution flow with Step3.5 step-aware layer/head selection.
_roll_window_inputs_only[18行] 代码量 18 行
_run_window_draft_steps[103行] Run the Step3.5 MTP full-window layer chain.
_ensure_draft_layer_types_cover_mtp_layers[14行] 代码量 14 行
_create_draft_vllm_config[19行] 代码量 19 行
validate_same_kv_cache_group[3行] Step3.5 MTP draft layers may span multiple KV cache groups.
initialize_attn_backend[70行] 代码量 70 行
spec_decode/suffix_proposer.py
查看源码后缀解码 proposer(37 行)。AscendSuffixDecodingProposer 基于后缀树匹配生成 draft(propose/dummy_run)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\spec_decode\suffix_proposer.py
__init__[3行] 代码量 3 行
dummy_run[13行] 代码量 13 行
propose[14行] 代码量 14 行
投机解码工具(588 行)。异步漂移修正:update_num_computed_tokens_for_batch_change/correct_optimistic_seq_lens_cpu 修正异步投机解码的已计算 token 数与乐观 seq lens;SlidingWindowAdapter 为 draft 模型(EAGLE3/DFlash/DSpark)提供滑窗注意力(compute_sliding_window_block_table/apply);patch_tensor_parallel_group 临时替换全局 TP 组;DynamicSpecScheduler 为 DFlash/DSpark 共享的动态验证调度器(token 概率更新、验证预算计算与分配)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\spec_decode\utils.py
update_num_computed_tokens_for_batch_change[26行] Correct num_computed_tokens for async spec decode drift.
correct_optimistic_seq_lens_cpu[39行] Correct ``optimistic_seq_lens_cpu`` for async spec decode drift.
patch_tensor_parallel_group[14行] Temporarily swap the global TP group for draft-model spec decode.
_maybe_eager_context[14行] 代码量 14 行
__init__[101行] 代码量 101 行
compute_sliding_window_block_table[28行] 代码量 28 行
apply[21行] 代码量 21 行
update[30行] 代码量 30 行
_compute_dflash_token_probs[28行] Estimate DFlash token acceptance probabilities.
_compute_dspark_token_probs[59行] Estimate DSpark token acceptance probabilities.
_update_from_token_probs[22行] Run the shared dynamic speculative scheduling pipeline.
compute_verify_budget[43行] Periodically recompute the shared per-request verify budget.
allocate_verify_budget[69行] Distribute the global verification budget across requests.
xlite 工具(449 行)。XModel/XModelConfig 提供安全属性设置的 xlite 运行时模型包装(向后兼容);AttnMetadataRouter 路由不同类型注意力元数据(on_device/cu_query_lens/block_tables/seq_lens 等统一访问);AttributeSetterMixin 安全属性混入;get_layer_weights 按 WeightGetterConfig 从层序列提取权重(支持二次展平与后处理);get_nested_attr/get_dotted_attr 嵌套属性读取。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\xlite\utils.py
set_dummy_tensor[14行] Rebind the module-level :data:`_DUMMY_TENSOR` placeholder.
get_nested_attr[22行] Get/collect a nested attribute from an object.
get_dotted_attr[16行] Get a nested attribute from an object using a dotted attribute string.
get_layer_weights[90行] Extract specified weights from a sequence of layers with optional secondary flattening and post-processing.
__init_subclass__[6行] 代码量 6 行
_get_thread_local[8行] Lazily initialize a per-instance, per-thread local storage without going through __setattr__.
__setattr__[13行] 代码量 13 行
condition[23行] Context manager that gates attribute setting on `match_condition`. Supports nested conditions, which are
on_device[16行] Context manager to temporarily set the device for the router. This is useful for cases where we want to
__getattr__[6行] Route attribute access to the appropriate handler method based on the attribute name.
cu_query_lens[15行] Get the cumulative query lengths from the attention metadata, if available.
block_tables[25行] Get the block tables from the attention metadata, if available.
seq_lens[17行] Return the per-sequence `seq_lens` tensor in a device-safe torch.Tensor form.
num_prefills[5行] 代码量 5 行
num_decodes[5行] 代码量 5 行
num_decode_tokens[5行] 代码量 5 行
num_actual_tokens[6行] Return the number of actual tokens (excluding padding).
xlite 集成模块(886 行)。把 vLLM 模型转换为 xlite 图运行时表示:XliteModelBase 适配基座(KV cache 提取、模型配置构建、频率表预计算、NZ 张量判断、deq_scale 变换);按架构派生:StandardXliteModel/QwenMoeXliteModel/Glm4MoeXliteModel/DeepseekV3XliteModel(MLA)/DeepseekV32XliteModel(DSA)/MiniMaxM2XliteModel;get_adapter_xlite_model 按配置选择适配器;XliteWrapper 图化包装器在 xlite 与原 runnable 路径间分派(register_kv_caches/__call__)。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\xlite\xlite.py
get_adapter_xlite_model[18行] Look up and initialize the appropriate xlite model adapter based on the architecture specified in vLLM config and
__init_subclass__[18行] Automatically register subclasses in the architecture strategy map and metadata type set.
__init__[40行] Initialize xlite runtime, model tensors, and hidden-state workspace.
extract_kv_cache[17行] 代码量 17 行
_build_model_config[14行] 代码量 14 行
_build_model[11行] 代码量 11 行
_get_layers_and_model_prefix[15行] Extract transformer layers and parameter prefix from runnable.
_precompute_freqs_cis[50行] Precompute Yarn-style RoPE frequency cache for DeepseekV3 MLA attention.
is_tensor_nz[11行] Check if a tensor is in NZ format.
all_tensors_zero[16行] Check if all tensors in the list/tuple are zero tensors.
_transform_deq_scale[16行] Repack a dequantization scale into the fixpipe hardware's expected format.
hf_text_config[8行] Convenience property to access HuggingFace text configuration from vLLM config.
hf_vision_config[8行] Convenience property to access HuggingFace vision configuration from vLLM config, if exists.
init_matmul_weights[36行] Initialize MatMul-related weights with quantization support.
__getattr__[16行] Proxy unknown attributes to the wrapped runnable model.
register_kv_caches[7行] Register KV cache references used by xlite runtime.
__call__[103行] Run one forward step through xlite graph or fallback runnable path.
set_xlite_attr[2行] 代码量 2 行
find_correction_dim[2行] 代码量 2 行
find_correction_range[4行] 代码量 4 行
linear_ramp_factor[5行] 代码量 5 行
xlite/xlite_model_runner.py
查看源码xlite 模型运行器(95 行)。XliteModelRunner 覆盖 get_model/load_model 返回 xlite 包装模型、initialize_kv_cache 初始化 KV、_bypass_xlite_wrapper 判断绕过条件、_should_build_dummy_attn_metadata 判断哑元数据构建。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\xlite\xlite_model_runner.py
get_model[4行] Returns the unwrapper fallback model. See :meth:`NPUModelRunner.get_model` for details.
load_model[6行] 代码量 6 行
_bypass_xlite_wrapper[11行] Temporarily route ``self.model`` to the native runnable.
initialize_kv_cache[3行] 代码量 3 行
_should_build_dummy_attn_metadata[14行] Override to build attention metadata during dummy_run when xlite is enable.
model[3行] 代码量 3 行
runner_enabled[3行] If the current model forward backend is the xlite runner.
xlite/xlite_worker.py
查看源码xlite worker(30 行)。XliteWorker 基于 NPUWorker,仅覆盖 init_device 加入 xlite 专属初始化。
D:\demo\202609\vllm-ascend\vllm-ascend-main\vllm_ascend\xlite\xlite_worker.py
init_device[6行] Override init_device to init xlite model runner