Closed
[Feature]: 支持 ascend 自定义图优化 pass 的动态 shape #3101
dezheng889Add on Jul 22Closed at Jul 23
Jul 22 Added label: feature
Jul 22 Associated pull request
Jul 23 Close issue
Jul 24 Added label: resolved
Aug 13 Associated pull request
Aug 13 Added label: bot-triaged
TorchNPU-Bot
Aug 13 Comments:
Aug 13 Comments:
检测到当前 issue 已关联 PR,自动添加标签:bot-triaged


Aug 19 Associated pull request
Aug 20 Associated pull request
Sep 17 Associated pull request
提交提案之前,请先检索仓库内是否已有相同的提案,如已有请在同一提案中进行讨论。
💻 需求背景、当前现状、期望实现的功能内容、具体的设计方案、以及测试方案
背景 / 目的
当前
torch_npu/_inductor/fx_passes/ascend_custom_passes下的图优化 pass 依赖静态 shape(维度为具体整数),在动态 shape(维度为 SymInt)场景下会因
get_node_shape返回 None、显式 SymInt bailout、以及基于具体整数的比较而失效。本次改动构建符号 shape 基础能力,使这些优化在动态 shape 下达到与静态 shape 等价的
优化效果。
主要改动
utils/symbolic_shape_util.py:设备无关、免 guard 的符号推理工具层(从支配输入 anchor 构造 sym_size 引用,dominance 安全)
utils/get_binary_fold_result.py:get_node_shape增加allow_symbolic双轨;binary fold、slice、slice_scatter、pad 维度提取全部支持符号
ascend_custom_passes/ascend_graph_pass.py:各 pass 符号化改造pad_slice、repeat_to_expand、iota/arange dtype 降级、batch embedding fusion
NPU_INDUCTOR_DYNAMIC_FX_PASS:关闭时所有符号处理退化为原静态行为(含 materialize 硬闸门),保证静态场景零回归
测试
test/_inductor/test_dynamic_shape_fx_passes.py:设备无关单测/集成测试,纯 CPU 可运行,覆盖工具层三值/归一/物化/值域、各 pass 动态 shape 行为、
边界保护(不可判定、秩不一致、异号符号、开关关闭)与静态回归
兼容性 / 风险
替代方案
补充说明
欢迎加入社区,感谢您对社区的贡献 🎉!