已关闭
[Bug]: 配置acl graph模式,使用msprof采集profiling发现相同的算子出现了两次,感觉是图似乎被执行了两次。这是符合预期的吗 #487
shi-rui创建于  5月26日关闭于  5月28日
shi-rui
5月26日 创建

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

您的环境信息

-- CANN 版本 (e.g., 5.x.x, 8.x.x):  
-- Pytorch/Torch_npu 版本 (e.g., v2.6.0, v2.9.0):
-- Python 版本 (e.g., Python3.9.x, Python3.11.x):
-- 操作系统版本 (e.g., Ubuntu 18.04, EulerOs 2.0):

Pytorch 2.10
python 3.10

🐛 请描述bug

下面这样的代码,执行msprof python3 xxx.py。然后profiling里面会出现2次mm, 2次qbmm,但图里面其实只调用了一次

class NetPTA(torch.nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x, weight, bias, per_token_scale, scale, x2_dtype, output_dtype, mm1, mm2):
        weight = weight.transpose(-2, -1)
        scale = scale.transpose(-3, -2)
        res0 = torch.matmul(mm1, mm2)

        output = torch_npu.npu_quant_matmul(x, weight, scale, bias=bias if bias is not None else None, pertoken_scale=per_token_scale,
                                              pertoken_scale_dtype = torch_npu.float8_e8m0fnu, scale_dtype = torch_npu.float8_e8m0fnu,
                                              output_dtype=output_dtype, x1_dtype=None, x2_dtype = x2_dtype,
                                              group_sizes = [0, 0, MX_GROUP_SIZE], y_scale = None)
        return output,res0

torch._dynamo.config.inline_inbuilt_nn_modules = False
compile_options = {
            "frozen_parameter": True,
            "static_kernel_compile": True,
            "clone_input": False,
            }
model = torch.compile(model, dynamic=False, fullgraph=True, backend="npugraph_ex", options=compile_options)
out,_ = model(x_npu, weight_npu, bias_npu, pertoken_scale_npu, scale_npu, x2_dtype, output_dtype, mm1, mm2)
likedislike
Sshi-rui
5月26日 添加了label:bug
yuanjun_liyuanjun_li成员
5月26日 将 yuanjun_li 设为负责人
yuanjun_li
yuanjun_li成员
5月26日 评论:

图中有几个modelexecute呢?是否也是多个

也可以使用torch的实现进行profiling:
https://www.hiascend.com/document/detail/zh/Pytorch/2600/apiref/torchnpuCustomsapi/docs/zh/custom_APIs/torch_npu-profiler/torch_npu-profiler-profile.md

likedislike
shi-rui
5月26日 评论:

图中有几个modelexecute呢?是否也是多个

也可以使用torch的实现进行profiling:
https://www.hiascend.com/document/detail/zh/Pytorch/2600/apiref/torchnpuCustomsapi/docs/zh/custom_APIs/torch_npu-profiler/torch_npu-profiler-profile.md

@yuanjun_li

多少个modelexecute可以在哪里配置? 我针对acl graph的全部配置就是
torch._dynamo.config.inline_inbuilt_nn_modules = False
compile_options = {
"frozen_parameter": True,
"static_kernel_compile": True,
"clone_input": False,
}
没有看到哪里有显式配置这个

likedislike
yuanjun_li
yuanjun_li成员
5月26日 评论:

你好,是指profile图中有几个 Model@ModelExecute
image.png

likedislike
shi-rui
5月28日 评论:

profiler需要指定warmp_up的数量,规避static第一次run。已解决

likedislike
Sshi-rui
5月28日 issue状态由 TODO 改变为 DONE
Sshi-rui
5月28日 关闭了 issue
yuanjun_li
yuanjun_li成员
5月28日 评论:

两次为 静态kernel首次运行 + 真正执行,正常行为;

likedislike