Prhub

#44256 [ROCm][CI] Skip unbacked dynamic shapes tests on PyTorch < 2.11

原始 PR 作者 JartX 合并时间 2026-06-02 08:09 文件变更 1 提交数 1 评论 1 代码增减 +9 / -0

执行摘要

跳过 PyTorch<2.11 时的 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 个测试失败。

该 PR 属于小范围 CI 修复,无需精读。但注释中关于 shape_idmark_unbacked 的说明对理解 dynamic shapes 的版本依赖有一定价值。

讨论亮点

Reviewer AndreasKaratzas 在评论中建议添加 "NOTE[ROCm]: shape_id etc ..." 注释(原 diff 中已有一个简短注释)。作者采纳了该建议,在最终版本中扩展了注释内容,增加了对 shape_idmark_unbacked 的详细说明。

实现拆解

  1. tests/compile/test_dynamic_shapes_compilation.pytest_dynamic_shapes_compilation 函数开头,新增一个条件跳过逻辑:当 shapes_type == DynamicShapesType.UNBACKED 且 PyTorch 版本低于 2.11.0 时,跳过该测试用例。
  2. 添加了详细注释(NOTE[ROCm]),解释 shape_id 的依赖关系和跳过原因,该注释是根据 reviewer 建议加入的。
  3. 仅修改了测试控制流,未涉及任何生产代码。
  4. 其他测试参数(BACKED, BACKED_SIZE_OBLIVIOUS, use_aot_compile, use_bytecode_hook, evaluate_guards)不受影响。
文件 模块 状态 重要度
tests/compile/test_dynamic_shapes_compilation.py 编译 modified 4.4

关键符号

test_dynamic_shapes_compilation

关键源码片段

tests/compile/test_dynamic_shapes_compilation.py test-coverage

唯一变更文件,新增了在 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

评论区精华

添加 ROCm 注释 documentation

AndreasKaratzas 要求添加 'NOTE[ROCm]: shape_id etc ...' 注释以解释跳过原因。

结论:作者在最终代码中扩展了注释,详细说明了 shape_id 的版本依赖关系。 · 已解决

风险与影响

风险极低:仅修改测试文件中的跳过条件,不涉及任何生产代码。跳过逻辑只对 PyTorch < 2.11 且 shapes_type 为 UNBACKED 的测试生效,不影响其他测试组合。如果未来 PyTorch 2.10.x 环境中出现了 shape_id 的替代方案,此跳过可能导致测试遗漏,但当前无此风险。

影响范围仅限于 ROCm CI 上 PyTorch 2.10.x 环境的 UNBACKED dynamic shapes 测试,消除了 8 个测试失败。对用户无影响,对系统行为无改变。

测试覆盖率调整 平台特定修复

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论