PR编号 PR链接 PR标题 PR提交人(真实姓名) 部门 PR提交时间 合入态 检视者 模块检视者approve 李佳伟approve 模块检视者SLA 李佳伟检视SLA 今天是否完成检视
190660 https://github.com/pytorch/pytorch/pull/190660 [Testcase Refactoring] Decouple test_compiled_autograd.py from CUDA-specific 彭业庆 小巧灵 2026-07-21 20:10 Open-ChangesRequested 陈睿敏 No No 17.7天 0.0天
190668 https://github.com/pytorch/pytorch/pull/190668 [Testcase Refactoring] Decouple test_autoheuristic.py from CUDA-specific 彭业庆 小巧灵 2026-07-21 21:40 Open-ChangesRequested 陈睿敏 No No 17.7天 0.0天
191077 https://github.com/pytorch/pytorch/pull/191077 [Testcase Refactoring] Replace test_device with capability-based device filtering in test_flex_attention 徐立为 小巧灵 2026-07-25 10:25 Open-ChangesRequested 陈睿敏 No No 0.0天 0.0天
191093 https://github.com/pytorch/pytorch/pull/191093 [Testcase Refactoring] 1. Add instantiate_device_type_tests to generalize device types. 2. Add proper hw_classification attribute to test classes. 3. Replace the default Benchmarker with InductorBenchmarker. 王彦兵 小巧灵 2026-07-25 18:08 Open-ChangesRequested 陈睿敏 No No 0.0天 0.0天
191319 https://github.com/pytorch/pytorch/pull/191319 [Testcase Refactoring] 1. Changed instantiate_device_type_tests from a whitelist to a blacklist. 2. Add proper hw_classification attribute to test classes. 王彦兵 小巧灵 2026-07-28 16:47 Open-ChangesRequested 陈睿敏 No No 17.7天 0.0天
192484 https://github.com/pytorch/pytorch/pull/192484 [Testcase Refactoring] Decouple test_aot_inductor_package.py from CUDA-specific 彭业庆 小巧灵 2026-08-07 16:29 Open-ChangesRequested 陈睿敏 No No 0.0天 0.0天
192713 https://github.com/pytorch/pytorch/pull/192713 [Testcase Refactoring] Migrate test_max_autotune to instantiate_device_type_tests 徐立为 小巧灵 2026-08-10 11:04 Open-ChangesRequested 陈睿敏 No No 0.0天 0.0天
192970 https://github.com/pytorch/pytorch/pull/192970 [Dynamo] Register out-of-tree backend current_stream into handler table via DeviceInterface iteration 刘妍 框架 2026-08-11 18:55 Open-ChangesRequested 陈睿敏 No No 14.5天 0.0天
193077 https://github.com/pytorch/pytorch/pull/193077 [Testcase Refactoring] Migrate test_flex_decoding to capability-based skip mechanism 徐立为 小巧灵 2026-08-12 10:52 Open-ChangesRequested 陈睿敏 No No 0.0天 0.0天
193147 https://github.com/pytorch/pytorch/pull/193147 [Testcase Refactoring] 1. Add instantiate_device_type_tests to generalize device types. 2. Add proper hw_classification attribute to test classes. 王彦兵 小巧灵 2026-08-12 20:20 Open-ChangesRequested 陈睿敏 No No 3.8天 0.0天
193296 https://github.com/pytorch/pytorch/pull/193296 [Testcase Refactoring] Use has_capabilities guard in test_fused_attention 徐立为 小巧灵 2026-08-13 14:22 Open-ChangesRequested 陈睿敏 No No 0.0天 0.0天
193482 https://github.com/pytorch/pytorch/pull/193482 [Test] Decouple Triton kernel tests from device selection 彭良龙 小巧灵 2026-08-14 11:23 Open-ChangesRequested 陈睿敏 No No 0.0天 0.0天
193759 https://github.com/pytorch/pytorch/pull/193759 [Testcase Refactoring] Decouple test_config.py from CUDA-specific 彭业庆 小巧灵 2026-08-17 10:44 Open-ChangesRequested 陈睿敏 No No 0.0天 0.0天
193783 https://github.com/pytorch/pytorch/pull/193783 [Testcase Refactoring] Decouple test_benchmarking.py from CUDA-specific 彭业庆 小巧灵 2026-08-17 17:20 Open-ChangesRequested 陈睿敏 No No 0.0天 0.0天
193796 https://github.com/pytorch/pytorch/pull/193796 [Testcase Refactoring] Decouple test_aoti_cross_compile_windows.py from CUDA-specific 彭业庆 小巧灵 2026-08-17 20:04 Open-ChangesRequested 陈睿敏 No No 0.0天 0.0天
194029 https://github.com/pytorch/pytorch/pull/194029 [Testcase Refactoring]Refactor test_torchinductor_dynamic_shapes.py for multi-accelerator s… 陈萌 小巧灵 2026-08-19 10:48 Open-ChangesRequested 陈睿敏 No No 4.6天 0.0天


test_torchinductor.py硬件解耦改造方案(讨论稿)1. 背景与目标
目标文件为
test/inductor/test_torchinductor.py。本轮硬件解耦希望:"cuda"/"xpu"等设备硬编码,使注册完成的 PrivateUse1 后端更容易进入测试矩阵。HardwareClassification选择运行。本文只记录方案讨论,不替代基于最新 upstream 重新生成的逐方法分析报告。
1.1 硬前提:保持外部协议
本次改造不能影响依赖方继续使用
test_torchinductor.py。以下接口与行为必须保持兼容:CommonTemplate、CpuTests、GPUTests、copy_tests以及各类辅助函数和TestFailure的导入方式;copy_tests的调用签名、默认复制规则、测试名后缀、skip/xfail/expected-failure 元数据传播方式;CommonTemplate、CpuTests、GPUTests的现有用法;如果一个方案必须同步迁移所有外部依赖方,或者只能通过改变上述协议才能落地,它就不属于本次改造范围。
2. 文件原本的作用
test_torchinductor.py是 Inductor 核心测试语料库和生成入口,不是普通的“一个源类对应一个运行类”文件。它主要验证:3. 当前架构
3.1
CommonTemplateCommonTemplate不继承TestCase,本身不是 unittest 运行类。它是可复用的测试体模板:self.device获取目标设备;self.common获取编译/对比策略;instantiate_parametrized_tests先展开 dtype、shape 和配置参数;3.2
copy_testscopy_tests将模板方法物化到CpuTests、GPUTests或外部派生类中,并:_cpu/_cuda/_xpu等 suffix,形成稳定的运行时 test ID。3.3 当前扩展性的边界
当前架构已支持“外部后端手工定义类并复用模板”,但不等于“注册 DeviceTypeTestBase 后自然进入矩阵”:
GPU_TYPE只在 CUDA、MPS、XPU、MTIA 中选择;RUN_GPU/HAS_GPU不会因普通 PrivateUse1 注册而自然成立;check_model_gpu使用全局GPU_TYPE,而非实际注入的 device;GPUTests同时含有普通 accelerator 与 CUDA/Triton 专属语义,无法添加唯一正确的类级标签。4. 为什么不能像普通测试类一样改
CommonTemplate源方法可生成 CPU 和 ACCELERATOR 多个运行目标,源模板没有单一HardwareClassification。HardwareClassification只作用于实际 unittest 类,不支持在混合类中按方法过滤。CommonTemplate已经做参数化展开,不能对同一类再叠加instantiate_device_type_tests。5. 方案评估
已否决方案 A:整体迁移到标准 device-type 测试架构
将所有模板方法按 GENERIC/CPU/ACCELERATOR/CUDA 拆分,并改用
instantiate_device_type_tests。这个方向在抽象上最接近普通测试文件,但不满足本次“保持外部协议”的硬前提:
CommonTemplate不再是原来的完整模板集合,外部转换逻辑获得的方法集会变化;copy_tests的复制协议会被标准展开机制取代或绕过,依赖其命名、过滤和元数据传播的调用方会受到影响;CpuTests、GPUTests的生成方式、类结构和 test ID 可能变化,直接实例化它们的外部用法不再等价;GPUTests。因此方案 A 不是本次可选实施方案。只有未来明确允许同步迁移全部消费者、接受对外协议变化并进行独立架构重构时,才值得重新评估。
方案 B:分类感知的物化层
“物化”是指把模板测试转换成 unittest 可以执行的具体测试。当前
copy_tests已经承担这个职责:方案 B 是让
copy_tests根据测试分类,把方法分别复制到 CPU、ACCELERATOR、CUDA 等运行类,再给这些类添加对应标签。capability 仍只负责运行前的能力检查,不参与分类。这个方案的问题在于
GPUTests同时包含通用 accelerator 和 CUDA/Triton 专属测试:GPUTests,就无法添加唯一正确的类级标签;GPUTests,会改变外部直接实例化、继承和转换它的行为;因此,方案 B 只能做不参与 discovery 的“影子物化”,用于生成分类映射和比较 test ID;它不能作为正式改造方案。正式物化只有在能够证明
GPUTests外部行为完全不变且不会重复 discovery 时,才可重新考虑。方案 C:保留当前文件,由外部后端适配器调用
PrivateUse1 后端自行定义 TestCase、device、runner 和用例过滤,继续调用
copy_tests。方案 D:有限解耦,保留生成框架为专项例外
只处理能局部证明安全的具体 CPU 类、独立类标签和明确设备硬编码;
CommonTemplate/copy_tests/RUN_GPU/GPU_TYPE在本轮保留。6. 当前推荐的实施方式
方案 A 和正式物化方案 B 均不满足当前兼容前提。当前建议用影子物化建立证据,并以方案 D 作为正式代码修改边界:
agent_space建立不参与 unittest discovery 的影子物化工具,比较分类映射、test ID 和元数据。CommonTemplate/copy_tests/GPUTests生成链作为专项例外;capability 也不能用来掩盖这个混合类问题。7. 主要风险
GPU_TYPE同时控制 runner、设备和 suffix,机械替换可导致运行设备与 test ID 不一致。8. 行为一致性门禁
每个阶段必须满足:
CommonTemplate、copy_tests、CpuTests、GPUTests、辅助函数和TestFailure的现有外部调用方式保持可用;任一门禁无法闭合时,停止该阶段,不继续叠加后续分类、矩阵扩展或 capability 修改。
9. 当前结论
CommonTemplate/copy_tests是有意设计的 Inductor 测试生成架构,其中copy_tests已经承担物化职责。方案 A 和正式物化方案 B 都会改变运行类或外部协议,当前均不实施。影子物化只用于分析;正式修改采用方案 D 的边界,必要时由方案 C 提供短期外部适配。