已关闭
[Bug]: vLLM_Ascend使用编译后的自定义算子, 给出报错:Cannot prepare for replay during capturing stage. during NPU graph capture. If you need this call to be captured, please file an issue. #310
(5.1创建于  2月4日关闭于  3月4日
(5.1
(5.1
2月4日 创建

在提交问题之前,请通过搜索现有和历史问题确保该问题尚未被提出并解决。

您的环境信息

-- CANN 版本 (e.g., CANN 3.0.x,5.x.x):  8.3.RC2
-- Pytorch/Torch_npu 版本 (e.g., v2.1.0, v2.6.0): v2.8.0, v2.8.0
-- Python 版本 (e.g., Python 3.7.5): 3.11.13
-- 操作系统版本 (e.g., Ubuntu 18.04): Ubuntu 22.04.5

🐛 请描述bug

有以下函数使用torch compile编译:

config = torchair.CompilerConfig()
config.mode = "reduce-overhead"
npu_backend = torchair.get_npu_backend(compiler_config=config)
@torch.compile(dynamic=True, backend=npu_backend)
def token_drop(router_logits: torch.Tensor, topk_weights: torch.Tensor, topk_ids: torch.Tensor, num_global_experts: int, load_factor: float) -> tuple[torch.Tensor, torch.Tensor]:
    
    topk = topk_weights.size(-1)

    # put the topk weights into the full expert size
    topk_masked_scores = torch.zeros_like(router_logits).scatter(1, topk_ids, topk_weights) # n_tokens, num_global_experts

    # get topk mask into full expert size
    topk_mask = torch.zeros_like(router_logits).int().scatter(1, topk_ids, 1).bool() # n_tokens, num_global_experts

    # calculate expert capacity as the load_factor times average load
    # round up the expert capacity to integer
    expert_capacity = math.ceil((topk_weights.size(0) * topk / float(num_global_experts)) * load_factor)
    # prune the scores based on expert capacity
    _, capacity_indices = torch.topk(topk_masked_scores, k=expert_capacity, dim=0, sorted=False) # expert_capacity, num_global_experts

    # get capacity mask in shape of (n_tokens, num_global_experts)
    capacity_mask = torch.zeros_like(router_logits).bool().scatter(0, capacity_indices, True) # n_tokens, num_global_experts

    # get final mask which satisfy both topk and capacity constrains
    final_mask = topk_mask & capacity_mask  # n_tokens, num_global_experts

    final_topk_ids = topk_ids.masked_fill(~final_mask.gather(1, topk_ids), -1)
    final_topk_weights = topk_weights.masked_fill(~final_mask.gather(1, topk_ids), 0.0)

    return final_topk_weights, final_topk_ids

添加到vllm_ascend中使用:

class AscendUnquantizedFusedMoEMethod(UnquantizedFusedMoEMethod):
  def apply(self,
                layer: torch.nn.Module,
                x: torch.Tensor,
                ...
               ) -> torch.Tensor:

          topk_weights, topk_ids = select_experts(
              hidden_states=x,
              ...
              )

          if envs.VLLM_ENABLE_TOKEN_DROP:
              load_factor = envs.VLLM_TOKEN_DROP_LOAD_FACTOR
              topk_weights, topk_ids = token_drop(
                  router_logits, topk_weights, topk_ids,
                  global_num_experts, load_factor)
           
           ....

vllm启动参数如下:

MODEL_PATH=/data/yiwu/models/qwen3-30b-a3b/
pretrained=${MODEL_PATH},tensor_parallel_size=8,max_model_len=131072,max_num_batched_tokens=65536,max_num_seqs=16,enforce_eager=False,gpu_memory_utilization=0.9,trust_remote_code=True,block_size=64,swap_space=16,load_format=safetensors,enable_expert_parallel=True,enable_prefix_caching=False,disable_sliding_window=True

启动后给出以下报错:

(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/vllm-workspace/vllm/vllm/model_executor/layers/fused_moe/layer.py", line 2082, in moe_forward
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     return self.forward_impl(hidden_states, router_logits)
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/vllm-workspace/vllm-ascend/vllm_ascend/ops/fused_moe/fused_moe.py", line 460, in forward_impl
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     final_hidden_states = self.quant_method.apply(
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]                           ^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/vllm-workspace/vllm-ascend/vllm_ascend/ops/fused_moe/fused_moe.py", line 190, in apply
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     topk_weights, topk_ids = token_drop(
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]                              ^^^^^^^^^^^
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/usr/local/python3.11.13/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py", line 736, in compile_wrapper
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     return fn(*args, **kwargs)
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]            ^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/vllm-workspace/vllm-ascend/vllm_ascend/ops/fused_moe/fused_moe.py", line 72, in token_drop
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     @torch.compile(dynamic=True, backend=npu_backend)
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/usr/local/python3.11.13/lib/python3.11/site-packages/torch/_dynamo/eval_frame.py", line 929, in _fn
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     return fn(*args, **kwargs)
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]            ^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/usr/local/python3.11.13/lib/python3.11/site-packages/torch/_functorch/aot_autograd.py", line 1241, in forward
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     return compiled_fn(full_args)
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]            ^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/usr/local/python3.11.13/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 384, in runtime_wrapper
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     all_outs = call_func_at_runtime_with_args(
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/usr/local/python3.11.13/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/utils.py", line 126, in call_func_at_runtime_with_args
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     out = normalize_as_list(f(args))
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]                             ^^^^^^^
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/usr/local/python3.11.13/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 750, in inner_fn
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     outs = compiled_fn(args)
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]            ^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/usr/local/python3.11.13/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/runtime_wrappers.py", line 556, in wrapper
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     return compiled_fn(runtime_args)
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]            ^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/usr/local/python3.11.13/lib/python3.11/site-packages/torch/_functorch/_aot_autograd/utils.py", line 100, in g
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     return f(*args)
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]            ^^^^^^^^
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/usr/local/python3.11.13/lib/python3.11/site-packages/torch_npu/dynamo/torchair/npu_fx_compiler.py", line 355, in __call__
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     gm_result = self.runner(*args, **kwargs)
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/usr/local/python3.11.13/lib/python3.11/site-packages/torch_npu/dynamo/torchair/_acl_concrete_graph/fx2acl_converter.py", line 105, in __call__
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     self.graph.run(fn_key, *args, **kwargs)
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/usr/local/python3.11.13/lib/python3.11/site-packages/torch_npu/dynamo/torchair/_acl_concrete_graph/acl_graph.py", line 980, in run
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     self._graphs_meta[graph_key].replay_func(*args, **kwargs)
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/usr/local/python3.11.13/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1773, in _wrapped_call_impl
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     return self._call_impl(*args, **kwargs)
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/usr/local/python3.11.13/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1784, in _call_impl
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     return forward_call(*args, **kwargs)
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/usr/local/python3.11.13/lib/python3.11/site-packages/torch_npu/dynamo/torchair/_acl_concrete_graph/acl_graph.py", line 419, in forward
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     self._replay_graph.replay()
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]   File "/usr/local/python3.11.13/lib/python3.11/site-packages/torch_npu/npu/graphs.py", line 225, in replay
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824]     super().replay()
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824] RuntimeError: Cannot prepare for replay during capturing stage. during NPU graph capture. If you need this call to be captured, please file an issue. Current npuStreamCaptureStatus: npuStreamCaptureStatusActive
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824] [ERROR] 2026-02-04-13:50:20 (PID:482628, Device:1, RankID:-1) ERR00007 PTA feature not supported
(EngineCore_DP0 pid=482617) (Worker_TP1_EP1 pid=482628) ERROR 02-04 13:50:20 [multiproc_executor.py:824] 
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866] EngineCore failed to start.
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866] Traceback (most recent call last):
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]   File "/vllm-workspace/vllm/vllm/v1/engine/core.py", line 857, in run_engine_core
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]     engine_core = EngineCoreProc(*args, **kwargs)
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]   File "/vllm-workspace/vllm/vllm/v1/engine/core.py", line 637, in __init__
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]     super().__init__(
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]   File "/vllm-workspace/vllm/vllm/v1/engine/core.py", line 109, in __init__
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]     num_gpu_blocks, num_cpu_blocks, kv_cache_config = self._initialize_kv_caches(
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]   File "/vllm-workspace/vllm/vllm/v1/engine/core.py", line 256, in _initialize_kv_caches
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]     self.model_executor.initialize_from_config(kv_cache_configs)
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]   File "/vllm-workspace/vllm/vllm/v1/executor/abstract.py", line 116, in initialize_from_config
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]     self.collective_rpc("compile_or_warm_up_model")
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]   File "/vllm-workspace/vllm/vllm/v1/executor/multiproc_executor.py", line 359, in collective_rpc
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]     return aggregate(get_response())
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]                      ^^^^^^^^^^^^^^
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]   File "/vllm-workspace/vllm/vllm/v1/executor/multiproc_executor.py", line 342, in get_response
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866]     raise RuntimeError(
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866] RuntimeError: Worker failed with error 'Cannot prepare for replay during capturing stage. during NPU graph capture. If you need this call to be captured, please file an issue. Current npuStreamCaptureStatus: npuStreamCaptureStatusActive
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:20 [core.py:866] [ERROR] 2026-02-04-13:50:20 (PID:482624, Device:0, RankID:-1) ERR00007 PTA feature not supported', please check the stack trace above for the root cause
(EngineCore_DP0 pid=482617) ERROR 02-04 13:50:21 [multiproc_executor.py:231] Worker proc VllmWorker-0 died unexpectedly, shutting down executor.
[DEBUG] TORCHAIR(482370,python3.11):2026-02-04 13:50:21.933.878 [static_kernel.py:198]482370 no static kernel uninstall paths recorded, skip uninstall static kernels
[ERROR] 2026-02-04-13:50:21 (PID:482370, Device:-1, RankID:-1) ERR99999 UNKNOWN applicaiton exception

完整日志见附件.f9e0d7dbdfc54872adf9514a4e0099b8.log
然而,如果不将该函数放置在vlllm内部, 而是单独测试又可正常运行, 测试代码如下:

import torch_npu
import torch
import torchair
import math
config = torchair.CompilerConfig()
config.mode = "reduce-overhead"
npu_backend = torchair.get_npu_backend(compiler_config=config)
@torch.compile(dynamic=True, backend=npu_backend)
def token_drop(router_logits: torch.Tensor, topk_weights: torch.Tensor, topk_ids: torch.Tensor, num_global_experts: int, load_factor: float) -> tuple[torch.Tensor, torch.Tensor]:
    
    topk = topk_weights.size(-1)

    # put the topk weights into the full expert size
    topk_masked_scores = torch.zeros_like(router_logits).scatter(1, topk_ids, topk_weights) # n_tokens, num_global_experts

    # get topk mask into full expert size
    topk_mask = torch.zeros_like(router_logits).int().scatter(1, topk_ids, 1).bool() # n_tokens, num_global_experts

    # calculate expert capacity as the load_factor times average load
    # round up the expert capacity to integer
    expert_capacity = math.ceil((topk_weights.size(0) * topk / float(num_global_experts)) * load_factor)
    # prune the scores based on expert capacity
    _, capacity_indices = torch.topk(topk_masked_scores, k=expert_capacity, dim=0, sorted=False) # expert_capacity, num_global_experts

    # get capacity mask in shape of (n_tokens, num_global_experts)
    capacity_mask = torch.zeros_like(router_logits).bool().scatter(0, capacity_indices, True) # n_tokens, num_global_experts

    # get final mask which satisfy both topk and capacity constrains
    final_mask = topk_mask & capacity_mask  # n_tokens, num_global_experts

    final_topk_ids = topk_ids.masked_fill(~final_mask.gather(1, topk_ids), -1)
    final_topk_weights = topk_weights.masked_fill(~final_mask.gather(1, topk_ids), 0.0)

    return final_topk_weights, final_topk_ids

def test_token_drop():
    router_logits = torch.tensor([[0.1, 0.2, 0.3, 0.4], [0.4, 0.3, 0.2, 0.1], [0.2, 0.3, 0.4, 0.1], [0.3, 0.4, 0.1, 0.2]], device='npu')
    topk_weights = torch.tensor([[0.4, 0.3], [0.4, 0.3], [0.4, 0.3], [0.4, 0.3]], device='npu')
    topk_ids = torch.tensor([[3, 2], [0, 1], [2, 1], [1, 0]], device='npu')
    num_global_experts = 4
    load_factor = 1.0

    final_topk_weights, final_topk_ids = token_drop(router_logits, topk_weights, topk_ids, num_global_experts, load_factor)

    print("Final TopK Weights:\n", final_topk_weights)
    print("Final TopK IDs:\n", final_topk_ids)
if __name__ == "__main__":
    test_token_drop()

likedislike
(5.1(5.1
2月4日 添加了label:bug
SunYapingSunYaping成员
2月5日 将 dddxhh 设为负责人
huangfei成员
2月6日 评论:

尊敬的开发者您好,根据提供的报错日志,当replay时,当前流状态不应是capture,请问下 整体网络执行时,如何调用该部分代码?

likedislike
(5.1
(5.1
2月7日 评论:

尊敬的开发者您好,根据提供的报错日志,当replay时,当前流状态不是capture,请问下 整体网络执行时,如何调用该部分代码?

@dddxhh

在vllm_ascend中:

class AscendUnquantizedFusedMoEMethod(UnquantizedFusedMoEMethod):
  def apply(self,
                layer: torch.nn.Module,
                x: torch.Tensor,
                ...
               ) -> torch.Tensor:

          topk_weights, topk_ids = select_experts(
              hidden_states=x,
              ...
              )

          if envs.VLLM_ENABLE_TOKEN_DROP:
              load_factor = envs.VLLM_TOKEN_DROP_LOAD_FACTOR
              topk_weights, topk_ids = token_drop(
                  router_logits, topk_weights, topk_ids,
                  global_num_experts, load_factor)
           
           ....

AscendUnquantizedFusedMoEMethod.apply是模型的MoE层前向计算的接口, 在该接口内调用token_drop方法.
vllm_ascend会在服务启动前先进行一次dummy_run来进行capture_model的操作.
当前报错是在这个阶段发生的, 详细调用栈可见上面提供的附件的日志.

likedislike
huangfei成员
2月10日 评论:

尊敬的开发者您好,根据日志分析,capture了两个graph,均进行了多次replay 。
在进行input size 为 {[32, 8],[32, 128],[32, 8],128} 的 最后一次replay时,发生报错, 请确认下最后一次replay的触发和 之前的replay的区别, 以及是否存在嵌套执行的情况

likedislike
wbigat
wbigat成员
2月10日 评论:

@torch.compile(dynamic=True, backend=npu_backend)
def token_drop(router_logits: torch.Tensor, topk_weights: torch.Tensor, topk_ids: torch.Tensor, num_global_experts: int, load_factor: float) -> tuple[torch.Tensor, torch.Tensor]:

示例代码里面这一段,看起来是重复编译了。

token_drop本身触发了compile,vllm 也有整个模型粒度的compile。应该是用法错误,去掉下这边的装饰再验证下。

likedislike
(5.1
(5.1
2月16日 评论:

去掉了装饰器即可正常运行,模型粒度的compile会自动对内部的自定义函数进行编译吗

likedislike
huangfei成员
2月24日 评论:

在comile范围内部的会根据配置进行入图编译

likedislike
SunYaping
SunYaping成员
2月25日 评论:

去掉了装饰器即可正常运行,模型粒度的compile会自动对内部的自定义函数进行编译吗

@weixi 开发者你好,欢迎添加小助手联系方式,加入TorchAir技术交流群,可以和技术专家们共同探讨~

likedislike
SunYapingSunYaping成员
3月4日 issue状态由 TODO 改变为 DONE
SunYapingSunYaping成员
3月4日 关闭了 issue