From fb85541c5d47f7a56ac32d0dc7f528f22fa4bc7f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 19 Sep 2025 19:32:17 +0100 Subject: [PATCH] Require `torch>=1.11` for CoreML exports (#22162) Co-authored-by: UltralyticsAssistant --- tests/test_exports.py | 6 +++--- ultralytics/engine/exporter.py | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_exports.py b/tests/test_exports.py index 70c9ca29..74277861 100644 --- a/tests/test_exports.py +++ b/tests/test_exports.py @@ -20,7 +20,7 @@ from ultralytics.utils import ( WINDOWS, checks, ) -from ultralytics.utils.torch_utils import TORCH_1_9, TORCH_1_13, TORCH_2_1 +from ultralytics.utils.torch_utils import TORCH_1_11, TORCH_1_13, TORCH_2_1 def test_export_torchscript(): @@ -117,7 +117,7 @@ def test_export_torchscript_matrix(task, dynamic, int8, half, batch, nms): @pytest.mark.slow @pytest.mark.skipif(not MACOS, reason="CoreML inference only supported on macOS") -@pytest.mark.skipif(not TORCH_1_9, reason="CoreML>=7.2 not supported with PyTorch<=1.8") +@pytest.mark.skipif(not TORCH_1_11, reason="CoreML export requires torch>=1.11") @pytest.mark.skipif(checks.IS_PYTHON_3_13, reason="CoreML not supported in Python 3.13") @pytest.mark.parametrize( "task, dynamic, int8, half, nms, batch", @@ -169,7 +169,7 @@ def test_export_tflite_matrix(task, dynamic, int8, half, batch, nms): Path(file).unlink() # cleanup -@pytest.mark.skipif(not TORCH_1_9, reason="CoreML>=7.2 not supported with PyTorch<=1.8") +@pytest.mark.skipif(not TORCH_1_11, reason="CoreML export requires torch>=1.11") @pytest.mark.skipif(WINDOWS, reason="CoreML not supported on Windows") # RuntimeError: BlobWriter not loaded @pytest.mark.skipif(LINUX and ARM64, reason="CoreML not supported on aarch64 Linux") @pytest.mark.skipif(checks.IS_PYTHON_3_13, reason="CoreML not supported in Python 3.13") diff --git a/ultralytics/engine/exporter.py b/ultralytics/engine/exporter.py index 1eeeb56e..6fe17dc6 100644 --- a/ultralytics/engine/exporter.py +++ b/ultralytics/engine/exporter.py @@ -112,7 +112,7 @@ from ultralytics.utils.metrics import batch_probiou from ultralytics.utils.nms import TorchNMS from ultralytics.utils.ops import Profile from ultralytics.utils.patches import arange_patch -from ultralytics.utils.torch_utils import TORCH_1_13, TORCH_2_1, select_device +from ultralytics.utils.torch_utils import TORCH_1_11, TORCH_1_13, TORCH_2_1, select_device def export_formats(): @@ -867,6 +867,7 @@ class Exporter: LOGGER.info(f"\n{prefix} starting export with coremltools {ct.__version__}...") assert not WINDOWS, "CoreML export is not supported on Windows, please run on macOS or Linux." + assert TORCH_1_11, "CoreML export requires torch>=1.11" assert self.args.batch == 1, "CoreML batch sizes > 1 are not supported. Please retry at 'batch=1'." f = self.file.with_suffix(".mlmodel" if mlmodel else ".mlpackage") if f.is_dir():