已关闭
[Requirement|需求建议]: AvgPool1d/AvgPoolV2 stride > 63 导致编译失败 #2120
gcw_Vjs9aJYP创建于  4月16日关闭于  7月24日
gcw_Vjs9aJYP
4月16日 创建

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

Describe the current behavior / 问题描述 (Mandatory / 必填)

当在 Ascend NPU 上使用 torch.compile (torchair backend) 编译包含 F.avg_pool1d(..., stride=seg_len) 的计算图时,如果 stride > 63(例如
seg_len=100),编译阶段会直接报错并退出。该算子在 CUDA/CPU 后端可正常运行。

Environment / 环境信息 (Mandatory / 必填)

  • Hardware: Ascend 310P (also reproducible on 910B)
  • CANN Version: 7.0.RC1 (or later)
  • PyTorch: 2.1.0
  • torch_npu: 2.1.0
  • torchair: bundled with CANN 7.0 toolkit
  • OS: Linux aarch64 / EulerOS

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

  1. 准备如下最小复现脚本 repro_avgpool.py
import torch                                                                                                                                                                
import torch_npu                                                                                                                                                            
import torchair
                                                                                                                                                                            
x = torch.randn(1, 256, 1000).npu()
config = torchair.CompilerConfig()                                                                                                                                          
backend = torchair.get_npu_backend(compiler_config=config)                                                                                                                  
                                                                                                                                                                            
def fn(t):                                                                                                                                                                  
    return torch.nn.functional.avg_pool1d(t, kernel_size=100, stride=100, ceil_mode=True)                                                                                   
                                                                                                                                                                            
compiled_fn = torch.compile(fn, backend=backend, dynamic=False)                                                                                                             
compiled_fn(x)                                                                                                                                                              
                                                                                                                                                                            
2. 运行脚本:python repro_avgpool.py                                                                                                                                        
3. 观察编译阶段报错。                                                                                                                                                       
                                                               
### Describe the expected behavior / 预期结果 (Mandatory / 必填)
          
F.avg_pool1d 在 stride > 63 时应像 CUDA/CPU 一样正常完成图编译并在 NPU 上执行,不应因 stride 范围限制而强制失败。         
### Related log / screenshot / 日志 / 截图 (Mandatory / 必填)
          
编译阶段典型报错(摘要):                                                                                                                                                  
[ERROR] AvgPoolV2 stride value 100 is out of supported range [1, 63] ...
[ERROR] Build graph failed, op type: AvgPoolV2                                                                                                                              
...                                                                                                                                                                         
RuntimeError: torch.compile with torchair backend failed on Ascend NPU                                                                                                      
                                                                                                                                                                            
当前 workaround 为手动将张量切回 CPU 执行池化,或改用 pad + view + mean 的纯 PyTorch 模拟实现,但这会引入额外的 Host-Device 同步开销。                              
### Special notes for this issue/备注 (Optional / 选填)
          
  影响模型
- CampPlus 说话人分离模型(speech_campplus_sv_zh-cn_16k-common):默认 seg_len=100,触发限制。
- F.avg_pool1d(x, kernel_size=100, stride=100, ceil_mode=True) 无法原生运行。
该限制在语音模型(如 CampPlus / speaker embedding 模型)中非常容易触发,因为默认 seg_len=100 的池化操作是标准实现。           
likedislike
Cchenqi317成员
4月24日 将 zhangyuxiang0119 设为负责人
chenqi317成员
4月24日 评论:

感谢反馈, 已安排committer 确认
assign @zhangyuxiang0119

likedislike
张喻翔张喻翔
4月30日 将 zhao_heng 设为负责人
张喻翔张喻翔
4月30日 移除了负责人 zhangyuxiang0119
Zzhaoheng
5月8日 将 jiangqi2025 设为负责人
Zzhaoheng
5月8日 移除了负责人 zhao_heng
Jjiangqi
5月14日 将 chenyanbin8 设为负责人
Jjiangqi
5月14日 移除了负责人 jiangqi2025
Cchenyanbin8
6月1日 将 yue-ma 设为负责人
Cchenyanbin8
6月1日 移除了负责人 chenyanbin8
Yyue-ma成员
6月25日 修改标题为 “[Requirement|需求建议]: AvgPool1d/AvgPoolV2 stride > 63 导致编译失败”,原标题为“[Bug-Report|缺陷反馈]: AvgPool1d/AvgPoolV2 stride > 63 导致编译失败”
yue-ma成员
6月25日 评论:

你好,AvgPool1d图模式实现下暂不支持stride>63,当前已了解你的需求,正在分析相关方案

likedislike
yuning_chenyuning_chen成员
7月17日 issue状态由 进行中 改变为 技术评审中
yue-ma成员
7月24日 评论:

你好,该问题在3D模式下可以支持,静态图模式下建议可以先通过升维进行规避,动态图模式下将在9.2.0版本支持

def fn(t):
    return torch.nn.functional.avg_pool3d(t.unsqueeze(-2).unsqueeze(-2), kernel_size=(1, 1, 100), stride=(1, 1, 100), ceil_mode=True).squeeze(-2).squeeze(-2)
likedislike
Yyue-ma成员
7月24日 issue状态由 技术评审中 改变为 已解决
Yyue-ma成员
7月24日 关闭了 issue