Skip to content

Commit 50320d5

Browse files
authored
build: update to latest torchao version (#63)
* build: raise torchao ceiling to 0.18.0 torchao 0.18.0 was released; raise the project-dependency ceiling so the torch_2_11 group can pin it. * build: pin torch_2_11 group to torchao 0.18.0 Keep the highest-torch dependency group (torch==2.11.0, already the project's torch ceiling) aligned with the newly-raised torchao ceiling. * build: temporarily exempt torchao from exclude-newer torchao 0.18.0 was released within the last 3 days, so the security-motivated exclude-newer window blocks resolving it. Exempt it the same way coreai-core/coreai-torch are exempted, until the release ages past the window or this is reverted before merge. * docs: add towncrier news fragment * build: revert torchao exclusion from exclude newer as it has been 3 days * build: declare packaging as a runtime dependency src/coreai_opt/_utils/version_utils.py imports packaging at module scope on the plain `import coreai_opt` path, but packaging was only ever declared in the dev dependency group, which pip never installs. A clean `pip install coreai-opt` therefore fails on import. * feat: add torchao/torch compatibility check helper torchao 0.18.0 removed its torch < 2.11 code paths and skips loading its compiled extensions on older torch (see https://github.com/pytorch/ao/releases/tag/v0.18.0). Add a pure query function describing when an installed torchao/torch pair is unsupported, plus type hints on the existing version_ge. * feat: warn on import for unsupported torchao/torch pairs Read torchao's version via importlib.metadata rather than torchao.__version__: on torch < 2.10, importing torchao >= 0.18.0 raises ImportError, so the warning must be emitted before the imports below reach torchao. * docs: add towncrier fragment for the torchao/torch warning * build: remove changelog.d/63.added.1 * fix: add back exclusion for coreai-torch and coreai-core
1 parent e3fa491 commit 50320d5

5 files changed

Lines changed: 98 additions & 6 deletions

File tree

changelog.d/63.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added support for torchao 0.18.0.

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ dependencies = [
3535
# kmeans1d C++ core (a C++ toolchain must also be present on the host).
3636
"ninja>=1.11",
3737
"numpy>=2",
38+
"packaging>=23.0",
3839
"pydantic>=2.0.0",
3940
"pyyaml>=6.0",
4041
"rich>=13.0.0",
@@ -48,7 +49,7 @@ dependencies = [
4849
# version >= 0.15.0 for torch version >= 2.9.0. Opting option 1.
4950
# These torch versions must be in bounds of torch_2_8, torch_2_9, torch_2_10, and torch_2_11
5051
"torch>=2.8.0,<=2.11.0",
51-
"torchao>=0.15.0,<=0.17.0",
52+
"torchao>=0.15.0,<=0.18.0",
5253
"tqdm>=4.65",
5354
]
5455
[[project.authors]]
@@ -138,7 +139,7 @@ torch_2_10 = [
138139
]
139140
torch_2_11 = [
140141
"torch==2.11.0",
141-
"torchao==0.17.0",
142+
"torchao==0.18.0",
142143
"torchvision==0.26.0",
143144
]
144145
torch_2_8 = [

src/coreai_opt/__init__.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,24 @@
88
For deployment via Core AI on Apple Silicon.
99
"""
1010

11-
from . import palettization, pruning, quantization
12-
from ._about import __version__
13-
from .common import CoreMLExportError, ExportBackend
11+
import importlib.metadata
12+
import warnings
13+
14+
import torch
15+
16+
from coreai_opt._utils.version_utils import (
17+
torchao_torch_incompatibility as _torchao_torch_incompatibility,
18+
)
19+
20+
_incompatibility = _torchao_torch_incompatibility(
21+
importlib.metadata.version("torchao"), torch.__version__
22+
)
23+
if _incompatibility:
24+
warnings.warn(_incompatibility, UserWarning, stacklevel=2)
25+
26+
from . import palettization, pruning, quantization # noqa: E402
27+
from ._about import __version__ # noqa: E402
28+
from .common import CoreMLExportError, ExportBackend # noqa: E402
1429

1530
__all__ = [
1631
"CoreMLExportError",

src/coreai_opt/_utils/version_utils.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,37 @@
33
# Use of this source code is governed by a BSD-3-Clause license that can
44
# be found in the LICENSE file or at https://opensource.org/licenses/BSD-3-Clause
55

6+
from types import ModuleType
7+
68
from packaging import version
79

810

9-
def version_ge(module, target_version):
11+
def version_ge(module: ModuleType, target_version: str) -> bool:
1012
return version.parse(module.__version__) >= version.parse(target_version)
13+
14+
15+
_MIN_TORCHAO_REQUIRING_TORCH_2_11 = "0.18.0"
16+
_MIN_TORCH_FOR_NEW_TORCHAO = "2.11.0.dev0"
17+
_TORCHAO_RELEASE_NOTES_URL = "https://github.com/pytorch/ao/releases/tag/v0.18.0"
18+
19+
20+
def torchao_torch_incompatibility(torchao_version: str, torch_version: str) -> str | None:
21+
"""Describe why the installed torchao and torch versions are incompatible.
22+
23+
Args:
24+
torchao_version: The installed torchao version.
25+
torch_version: The installed torch version.
26+
27+
Returns:
28+
A message explaining the incompatibility, or ``None`` if the pair is supported.
29+
"""
30+
if version.parse(torchao_version) < version.parse(_MIN_TORCHAO_REQUIRING_TORCH_2_11):
31+
return None
32+
if version.parse(torch_version) >= version.parse(_MIN_TORCH_FOR_NEW_TORCHAO):
33+
return None
34+
return (
35+
f"torchao {torchao_version} does not support torch<2.11 "
36+
f"(found torch {torch_version}). See the torchao "
37+
f"{_MIN_TORCHAO_REQUIRING_TORCH_2_11} release notes for more information: "
38+
f"{_TORCHAO_RELEASE_NOTES_URL}"
39+
)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)