|
| 1 | +# Copyright 2026 Apple Inc. |
| 2 | +# |
| 3 | +# Use of this source code is governed by a BSD-3-Clause license that can |
| 4 | +# be found in the LICENSE file or at https://opensource.org/licenses/BSD-3-Clause |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | +from coreai_opt._utils.version_utils import torchao_torch_incompatibility |
| 9 | + |
| 10 | +INCOMPATIBLE = [ |
| 11 | + ("0.18.0", "2.8.0"), |
| 12 | + ("0.18.0", "2.9.1"), |
| 13 | + ("0.18.0", "2.10.0"), |
| 14 | + ("0.18.0", "2.10.0+cu128"), |
| 15 | + ("0.19.0", "2.10.0"), |
| 16 | + # A source-built torchao reports a local version, which sorts above the base. |
| 17 | + ("0.18.0+gitabc1234", "2.10.0"), |
| 18 | +] |
| 19 | + |
| 20 | +COMPATIBLE = [ |
| 21 | + # torch is new enough. |
| 22 | + ("0.18.0", "2.11.0"), |
| 23 | + ("0.18.0", "2.11.0+cu128"), |
| 24 | + ("0.18.0", "2.12.0.dev20260805+cu128"), |
| 25 | + # A 2.11 pre-release counts as 2.11. |
| 26 | + ("0.18.0", "2.11.0rc1"), |
| 27 | + # torchao still supports older torch. |
| 28 | + ("0.17.0", "2.8.0"), |
| 29 | + ("0.16.0", "2.10.0"), |
| 30 | + ("0.15.0", "2.8.0"), |
| 31 | +] |
| 32 | + |
| 33 | + |
| 34 | +@pytest.mark.parametrize(("torchao_version", "torch_version"), INCOMPATIBLE) |
| 35 | +def test_returns_message_for_incompatible_pair(torchao_version, torch_version): |
| 36 | + message = torchao_torch_incompatibility(torchao_version, torch_version) |
| 37 | + |
| 38 | + assert message is not None |
| 39 | + assert torchao_version in message |
| 40 | + assert torch_version in message |
| 41 | + assert "https://github.com/pytorch/ao/releases/tag/v0.18.0" in message |
| 42 | + |
| 43 | + |
| 44 | +@pytest.mark.parametrize(("torchao_version", "torch_version"), COMPATIBLE) |
| 45 | +def test_returns_none_for_compatible_pair(torchao_version, torch_version): |
| 46 | + assert torchao_torch_incompatibility(torchao_version, torch_version) is None |
0 commit comments