执行摘要
- 一句话:跳过 PyTorch<2.11 时的 unbacked dynamic shapes 测试
- 推荐动作:该 PR 属于小范围 CI 修复,无需精读。但注释中关于
shape_id 和 mark_unbacked 的说明对理解 dynamic shapes 的版本依赖有一定价值。
功能与动机
修复 ROCm CI 上 PyTorch 2.10.x 环境下 UNBACKED dynamic shapes 测试的 RuntimeError,因为 shape_id 仅在 PyTorch 2.11 及以上版本中支持。PR body 指出 'Qwen2 or Llama declared shape relations...the system would crash',通过此修改可以消除 8 个测试失败。
实现拆解
- 在
tests/compile/test_dynamic_shapes_compilation.py 的 test_dynamic_shapes_compilation 函数开头,新增一个条件跳过逻辑:当 shapes_type == DynamicShapesType.UNBACKED 且 PyTorch 版本低于 2.11.0 时,跳过该测试用例。
- 添加了详细注释(
NOTE[ROCm]),解释 shape_id 的依赖关系和跳过原因,该注释是根据 reviewer 建议加入的。
- 仅修改了测试控制流,未涉及任何生产代码。
- 其他测试参数(BACKED, BACKED_SIZE_OBLIVIOUS, use_aot_compile, use_bytecode_hook, evaluate_guards)不受影响。
关键文件:
tests/compile/test_dynamic_shapes_compilation.py(模块 编译;类别 test;类型 test-coverage): 唯一变更文件,新增了在 PyTorch < 2.11 时跳过 UNBACKED dynamic shapes 测试的条件逻辑。
关键符号:test_dynamic_shapes_compilation
关键源码片段
tests/compile/test_dynamic_shapes_compilation.py
唯一变更文件,新增了在 PyTorch < 2.11 时跳过 UNBACKED dynamic shapes 测试的条件逻辑。
@pytest.mark.parametrize("model_name", get_test_models())
@pytest.mark.parametrize("shapes_type", [DynamicShapesType.BACKED, DynamicShapesType.UNBACKED, DynamicShapesType.BACKED_SIZE_OBLIVIOUS])
@pytest.mark.parametrize("use_aot_compile", ["0", "1"])
@pytest.mark.parametrize("use_bytecode_hook", [True, False])
@pytest.mark.parametrize("evaluate_guards", [False, True])
@pytest.mark.skipif(not is_torch_equal_or_newer("2.10.0"), reason="requires torch 2.10")
def test_dynamic_shapes_compilation(monkeypatch, model_name, shapes_type, use_aot_compile, use_bytecode_hook, evaluate_guards):
"""Test that all dynamic shapes types compile successfully"""
# NOTE[ROCm]: shape_id (used by Qwen2/Llama to relate input dims) only
# landed in torch 2.11, but the ROCm CI still runs torch 2.10.x. On
# older torch there's no way to express it, so unbacked shapes go
# data-dependent and compilation blows up -- nothing to test.
if shapes_type == DynamicShapesType.UNBACKED and not is_torch_equal_or_newer("2.11.0"):
pytest.skip("unbacked dynamic shapes with shape_id require torch>=2.11")
if evaluate_guards and shapes_type == DynamicShapesType.UNBACKED:
pytest.skip("unbacked dynamic shapes do not add guards")
# ... remaining test logic
评论区精华
Reviewer AndreasKaratzas 在评论中建议添加 "NOTE[ROCm]: shape_id etc ..." 注释(原 diff 中已有一个简短注释)。作者采纳了该建议,在最终版本中扩展了注释内容,增加了对 shape_id 和 mark_unbacked 的详细说明。
- 添加 ROCm 注释 (documentation): 作者在最终代码中扩展了注释,详细说明了 shape_id 的版本依赖关系。
风险与影响
- 风险:风险极低:仅修改测试文件中的跳过条件,不涉及任何生产代码。跳过逻辑只对 PyTorch < 2.11 且 shapes_type 为 UNBACKED 的测试生效,不影响其他测试组合。如果未来 PyTorch 2.10.x 环境中出现了
shape_id 的替代方案,此跳过可能导致测试遗漏,但当前无此风险。
- 影响:影响范围仅限于 ROCm CI 上 PyTorch 2.10.x 环境的 UNBACKED dynamic shapes 测试,消除了 8 个测试失败。对用户无影响,对系统行为无改变。
- 风险标记:测试覆盖率调整, 平台特定修复
关联脉络
- PR #44035 [BugFix] Fix
_has_module to verify native deps via trial import: 同为 CI 测试修复,涉及 PyTorch 版本兼容性处理。
参与讨论