From 15c73b244158705a6b7d6be4deab2e083de09b99 Mon Sep 17 00:00:00 2001 From: bodapatisaikrishna Date: Sun, 13 Sep 2026 23:22:45 +0530 Subject: [PATCH] fix: fall back to onnxruntime/coremltools on Python 3.12+ tensorflow/tensorflow-macos never published a cp312 wheel below version 2.16 (verified against PyPI release metadata), but the dependency markers cap both at <2.15.1 while still activating for python_version >= 3.11 (non-Darwin) / > 3.11 (Darwin) -- an unsatisfiable constraint on Python 3.12. Fixes #203 (same root cause as #159, #188). Simply raising the version cap is not safe: tensorflow-macos==2.16.2 fails to load the bundled SavedModel with AttributeError("'_UserObject' object has no attribute 'add_slot'"), Keras 3's optimizer object graph being incompatible with the old checkpoint. Verified this empirically before choosing the fix below. basic_pitch already bundles the model in ONNX/TFLite/CoreML formats and already has fallback backend-selection logic. On Python 3.12+: exclude tensorflow(-macos) (both in `dependencies` and the `[tf]` extra) so it isn't attempted where it can't work; add onnxruntime (has cp312+ wheels) for non-Darwin, since coremltools is already an unconditional Darwin dependency and becomes the default there for free. Added the Python :: 3.12 classifier. Verified ONNX and CoreML backends produce output matching the current TensorFlow 2.15.0 path (28 note events, matching sums) via direct predict() calls, and verified the full fix end-to-end on real Python 3.12.0 macOS arm64: install resolves cleanly, auto-selects coremltools, and produces matching inference output. --- pyproject.toml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e8dc15c3..52f63ba9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,6 +15,7 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: CPython", ] dependencies = [ @@ -22,13 +23,18 @@ dependencies = [ "librosa>=0.8.0", "mir_eval>=0.6.0", "numpy>=1.18", - "onnxruntime; platform_system == 'Windows' and python_version < '3.11'", + # tensorflow(-macos) has no cp312 wheels below 2.16, and the bundled SavedModel + # can't be loaded by tensorflow>=2.16 (Keras 3's optimizer object graph is + # incompatible: "'_UserObject' object has no attribute 'add_slot'"), so on + # Python 3.12+ this falls back to onnxruntime (or, on Darwin, coremltools, + # already a dependency there) instead of an unsatisfiable/broken TF pin. + "onnxruntime; (platform_system == 'Windows' and python_version < '3.11') or (platform_system != 'Darwin' and python_version >= '3.12')", "pretty_midi>=0.2.9", "resampy>=0.2.2,<0.4.3", "scikit-learn", "scipy>=1.4.1", - "tensorflow>=2.4.1,<2.15.1; platform_system != 'Darwin' and python_version >= '3.11'", - "tensorflow-macos>=2.4.1,<2.15.1; platform_system == 'Darwin' and python_version > '3.11'", + "tensorflow>=2.4.1,<2.15.1; platform_system != 'Darwin' and python_version >= '3.11' and python_version < '3.12'", + "tensorflow-macos>=2.4.1,<2.15.1; platform_system == 'Darwin' and python_version > '3.11' and python_version < '3.12'", "tflite-runtime; platform_system == 'Linux' and python_version < '3.11'", "typing_extensions", ] @@ -68,8 +74,12 @@ test = [ "mido" ] tf = [ - "tensorflow>=2.4.1,<2.15.1; platform_system != 'Darwin'", - "tensorflow-macos>=2.4.1,<2.15.1; platform_system == 'Darwin' and python_version > '3.7'", + # See the `dependencies` comment above: no tensorflow(-macos) release both has + # cp312 wheels and can load the bundled SavedModel, so this extra is + # unavailable on Python 3.12+ rather than installing a backend that can't + # read the model. + "tensorflow>=2.4.1,<2.15.1; platform_system != 'Darwin' and python_version < '3.12'", + "tensorflow-macos>=2.4.1,<2.15.1; platform_system == 'Darwin' and python_version > '3.7' and python_version < '3.12'", ] coreml = ["coremltools"] onnx = ["onnxruntime"]