diff --git a/CHANGELOG.md b/CHANGELOG.md index 99dc1f5..4a0cca9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ under Unreleased and move into a version section at release time. ## Unreleased +### Changed + +- The ultralytics integration now requires ultralytics 8.0.200 or later + (was 8.0.0). Earlier 8.0.x releases keep their helpers under + `ultralytics.yolo.utils`, and the integration turned itself off on them + without a word. `instrument("ultralytics")` now logs a warning naming the + installed version instead. + ### Fixed - The gguf integration now tracks `Llama.create_chat_completion()` and diff --git a/docs/compatibility.md b/docs/compatibility.md index cae8d07..d75350e 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -64,8 +64,6 @@ To run the full matrix locally: `python scripts/run_compat_local.py`. | `transformers` | `min` | `transformers==4.40.0`, `torch==2.4.1`, `numpy==1.26.4` | 3.10, 3.11, 3.12, 3.13 | | `transformers` | `min` (`py3.13` override) | `transformers==4.45.0`, `torch==2.5.0`, `numpy==2.1.3` | 3.13 | | `transformers` | `current` | `transformers==5.20.1`, `torch==2.14.1`, `numpy==2.2.6` | 3.10, 3.11, 3.12, 3.13 | -| `ultralytics` | `min` | `ultralytics==8.0.0`, `numpy==1.26.4` | 3.10, 3.11, 3.12, 3.13 | -| `ultralytics` | `min` (`py3.12` override) | `ultralytics==8.0.0`, `numpy==1.26.4`, `setuptools==75.8.0` | 3.12 | -| `ultralytics` | `min` (`py3.13` override) | `ultralytics==8.0.0`, `numpy==1.26.4`, `setuptools==75.8.0` | 3.13 | +| `ultralytics` | `min` | `ultralytics==8.0.200`, `numpy==1.26.4` | 3.10, 3.11, 3.12, 3.13 | | `ultralytics` | `current` | `ultralytics==8.4.182`, `numpy==2.2.6` | 3.10, 3.11, 3.12, 3.13 | | `mlx` | `current` | `mlx==0.32.4`, `mlx-lm==0.32.2` | 3.12, 3.13 | diff --git a/scripts/compat_matrix.py b/scripts/compat_matrix.py index 95caa85..03b618d 100644 --- a/scripts/compat_matrix.py +++ b/scripts/compat_matrix.py @@ -52,7 +52,7 @@ "current": ["transformers==5.20.1", "torch==2.14.1", "numpy==2.2.6"], }, "ultralytics": { - "min": ["ultralytics==8.0.0", "numpy==1.26.4"], + "min": ["ultralytics==8.0.200", "numpy==1.26.4"], "current": ["ultralytics==8.4.182", "numpy==2.2.6"], }, "mlx": { @@ -110,14 +110,6 @@ "3.10": ["tensorflow==2.21.0", "keras==3.12.4", "numpy==2.2.6"], }, }, - "ultralytics": { - # ultralytics 8.0.0 imports pkg_resources without declaring setuptools, - # which Python 3.12+ environments no longer include. - "min": { - "3.12": ["ultralytics==8.0.0", "numpy==1.26.4", "setuptools==75.8.0"], - "3.13": ["ultralytics==8.0.0", "numpy==1.26.4", "setuptools==75.8.0"], - }, - }, "transformers": { "min": { "3.13": ["transformers==4.45.0", "torch==2.5.0", "numpy==2.1.3"], diff --git a/tests/compat/test_ultralytics_compat.py b/tests/compat/test_ultralytics_compat.py index ffd8e4f..f22267f 100644 --- a/tests/compat/test_ultralytics_compat.py +++ b/tests/compat/test_ultralytics_compat.py @@ -1,20 +1,9 @@ from __future__ import annotations -import importlib.util - import pytest import ultralytics from PIL import Image -# Early 8.0.x releases keep their helpers in ultralytics.yolo.utils. The -# integration imports ultralytics.utils, so on those releases it is off. -LEGACY_LAYOUT = importlib.util.find_spec("ultralytics.utils") is None -legacy_xfail = pytest.mark.xfail( - LEGACY_LAYOUT, - strict=True, - reason="integration is disabled on ultralytics without ultralytics.utils (#71)", -) - @pytest.fixture def yolo(compat_client): @@ -25,19 +14,17 @@ def yolo(compat_client): @pytest.fixture def image(tmp_path) -> str: - # A file path: ultralytics 8.0.0 can't take a numpy array as the source. + # A file path is a source every supported ultralytics release accepts. path = tmp_path / "blank.png" Image.new("RGB", (64, 64)).save(path) return str(path) -@legacy_xfail def test_yolo_load_is_tracked(compat_client, yolo): compat_client.one("model_load") assert compat_client.of_type("model_download") == [] -@legacy_xfail def test_yolo_call_is_tracked(compat_client, yolo, image): results = yolo(image, imgsz=64, verbose=False) assert len(results) == 1 diff --git a/tests/test_integrations_ultralytics.py b/tests/test_integrations_ultralytics.py index c740418..dc49c2d 100644 --- a/tests/test_integrations_ultralytics.py +++ b/tests/test_integrations_ultralytics.py @@ -2,10 +2,12 @@ from __future__ import annotations +import types from unittest.mock import MagicMock, patch import pytest +import wildedge.integrations.ultralytics as ultralytics_mod from wildedge.integrations.ultralytics import ( YOLO_FAMILY_RE, UltralyticsExtractor, @@ -445,3 +447,20 @@ def test_extractor_install_hooks_batch_size_from_list_source(publish_spy): frames = [np.zeros((480, 640, 3), dtype=np.uint8)] * 3 model(frames) assert publish_spy.events[0]["inference"]["batch_size"] == 3 + + +def test_unsupported_ultralytics_version_warns_and_does_not_patch(monkeypatch, caplog): + fake_yolo = type("YOLO", (), {"__init__": lambda self, *a, **k: None}) + original_init = fake_yolo.__init__ + monkeypatch.setattr( + ultralytics_mod, "_ultralytics", types.SimpleNamespace(YOLO=fake_yolo) + ) + monkeypatch.setattr(ultralytics_mod, "_unsupported_ultralytics_version", "8.0.0") + monkeypatch.setattr(ultralytics_mod, "_ultralytics_patched", False) + + with caplog.at_level("WARNING", logger="wildedge"): + UltralyticsExtractor.install_auto_load_patch(lambda: None) + + assert fake_yolo.__init__ is original_init + messages = [r.getMessage() for r in caplog.records] + assert any("ultralytics 8.0.0 is older than 8.0.200" in m for m in messages) diff --git a/wildedge/integrations/ultralytics.py b/wildedge/integrations/ultralytics.py index e96a9e9..4a822d3 100644 --- a/wildedge/integrations/ultralytics.py +++ b/wildedge/integrations/ultralytics.py @@ -27,14 +27,28 @@ from wildedge.model import ModelInfo from wildedge.timing import elapsed_ms +# Oldest supported release; earlier ones keep their helpers under +# ultralytics.yolo.utils instead of ultralytics.utils. +MIN_ULTRALYTICS_VERSION = "8.0.200" + try: import ultralytics as _ultralytics - from ultralytics.utils import ( - WEIGHTS_DIR as _ULTRALYTICS_WEIGHTS_DIR, # type: ignore[import-untyped] - ) except ImportError: _ultralytics = None # type: ignore[assignment] - _ULTRALYTICS_WEIGHTS_DIR = None # type: ignore[assignment] + +_ULTRALYTICS_WEIGHTS_DIR = None +# Set when ultralytics is installed but older than MIN_ULTRALYTICS_VERSION. +_unsupported_ultralytics_version: str | None = None +if _ultralytics is not None: + try: + from ultralytics.utils import ( + WEIGHTS_DIR as _ULTRALYTICS_WEIGHTS_DIR, # type: ignore[import-untyped] + ) + except ImportError: + _unsupported_ultralytics_version = getattr( + _ultralytics, "__version__", "unknown" + ) + _ultralytics = None # type: ignore[assignment] try: import numpy as np # type: ignore[import-untyped] @@ -393,6 +407,14 @@ def install_auto_load_patch(cls, client_ref: object) -> None: is emitted with the file size and the total load duration. """ global _ultralytics_patched + if _unsupported_ultralytics_version is not None: + logger.warning( + "wildedge: ultralytics %s is older than %s, the oldest supported " + "release; the ultralytics integration is disabled", + _unsupported_ultralytics_version, + MIN_ULTRALYTICS_VERSION, + ) + return if _ultralytics_patched or _ultralytics is None: return