已开启
【API一致性任务】 torch.compiler.assume_constant_result NPU兼容性测试补齐 #3036
2501_93637465创建于 7月18日
7月18日 关联了pull request:test(dynamo): cover assume_constant_result on NPU
7月18日 关联了pull request:test(dynamo): cover assume_constant_result on NPU
7月18日 关联了pull request:test(dynamo): cover assume_constant_result on NPU
7月18日 关联了pull request:test(dynamo): cover assume_constant_result on NPU
7月18日 关联了pull request:docs: mark assume_constant_result as supported
7月18日 修改了issue 的描述
7月21日 修改了issue 的描述
7月21日 修改了issue 的描述
7月28日 添加了label:bot-triaged
TorchNPU-Bot
7月28日 评论:
7月28日 评论:
检测到当前 issue 已关联 PR !41989,自动添加标签:bot-triaged


14 天前 修改标题为 “【API一致性任务】 torch.compiler.assume_constant_result NPU兼容性测试补齐”,原标题为“[API一致性] torch.compiler.assume_constant_result NPU兼容性测试补齐”
14 天前 修改标题为 “【API一致性任务】 torch.compiler.assume_constant_result NPU兼容性测试补齐”,原标题为“[API一致性] torch.compiler.assume_constant_result NPU兼容性测试补齐”
14 天前 关联了看板:FrameworkPTAdapter 版本issue看板
14 天前 添加了label:help-wantedevent: api-consistency
TorchNPU-Bot
14 天前 评论:
14 天前 评论:
检测到社区任务相关 issue,自动添加标签:event: api-consistency、help-wanted


关联任务
https://gitcode.com/Ascend/pytorch/issues/2990
API
torch.compiler.assume_constant_result问题描述
该 API 在昇腾 NPU 环境中功能正常,与 PyTorch 原生行为一致,但当前缺少独立的 NPU 兼容性测试覆盖。
适配方案
新增独立测试,验证:
torch.compile正常执行;不需要新增 torch_npu 算子实现。
验证结果
已在 Ascend 910、PyTorch 2.10.0、torch_npu 2.10.0 环境验证通过。
相关 PR:
相关 PR
NPU 兼容性测试
原生 API 支持资料
当前进展
API 功能验证、各版本测试提交及原生 API 支持资料提交均已完成。后续跟进各 PR 的持续集成流水线与维护者评审。
涉及分支
master、v2.7.1、v2.9.0、v2.10.0、v2.11.0、v2.12.0
API 功能介绍
torch.compiler.assume_constant_result是一个装饰器,用于将被装饰函数标记为“返回结果可视为常量”。在
torch.compile编译过程中,编译器可以将该函数的结果作为常量处理,并优化掉对应的函数调用。该接口返回被装饰的原函数。调用者需要保证函数结果确实满足常量假设。PyTorch 不会主动验证该假设是否成立,如果错误使用,可能导致编译结果与实际执行结果不一致。
上游社区测试用例情况
PyTorch v2.7.1 上游社区已有以下相关测试:
test/dynamo/test_decorators.py::DecoratorTests::test_assume_constant_result_on_user_defined_fn验证用户自定义函数使用
torch._dynamo.assume_constant_result装饰后,在 eager 模式和torch.compile模式下的执行结果一致。test/dynamo/test_decorators.py::DecoratorTests::test_assume_constant_result_on_computation_with_graph_input验证被装饰函数读取计算图输入并参与控制流判断时,eager 模式和编译模式的执行结果一致。
test/dynamo/test_compile.py::PublicTorchCompilerTests::test_dynamo_signatures验证公开接口
torch.compiler.assume_constant_result与内部接口torch._dynamo.assume_constant_result的函数签名一致。上游功能测试主要覆盖
torch._dynamo.assume_constant_result的通用 TorchDynamo 行为,公开接口仅进行了签名一致性检查,未直接覆盖 Ascend NPU 环境。本任务补充
torch.compiler.assume_constant_result在 Ascend NPU 环境下的直接验证,检查接口可用性以及 eager 模式与torch.compile模式的结果一致性。