Skip to content

Commit 020734a

Browse files
committed
[tmva][sofie] Require onnx>=1.19.1 for tests
In commit 178a9f9, I activated several SOFIE tests by moving the SOFIE PyTorch and Keras parsers out of `tmva/pymva`, because SOFIE and PyMVA are unrelated and we lost test coverage for these SOFIE parsers, because `tmva-pymva` is always disabled. But as reported in #20571, we now see SOFIE test failures on macOS because `torch.onnx` implicitly required `onnx>=1.19.1`, although this is not part of the `torch` dependencies as `onnx` support is optional. However, `onnx>=1.19.1` can't be installed on macOS because the transient update of `ml_dtypes` is conflicting with the current version of the `tensorflow` package. To get out of this, we have to check `onnx>=1.19.1` ourselves and disable some tests if the version is older. This is the solution with the least test coverage regression. There is even no coverage regression at all, if you compare to the state before 178a9f9 a few days ago. We should also consider to require `onnx>=1.19.1` in our `requirements.txt` in the future, so our users don't face similar trouble from exporting PyTorch models to onnx. But this should only be done once we are sure that it can also be installed on macOS without breaking something else. Closes #20571.
1 parent 1df6d55 commit 020734a

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

tmva/sofie/test/CMakeLists.txt

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,36 @@ endif()
108108
# Look for needed Python modules
109109
ROOT_FIND_PYTHON_MODULE(torch)
110110
ROOT_FIND_PYTHON_MODULE(keras)
111+
ROOT_FIND_PYTHON_MODULE(onnx)
111112

112-
if (ROOT_TORCH_FOUND)
113+
114+
# Some tests need to be disabled when the onnx version is too low, because then
115+
# onnx is not compatible with PyTorch. This is not encoded in the PyTorch
116+
# dependency resolution, because onnx is an optional dependency of PyTorch. So
117+
# we have to take care of onnx version checks ourselves. See also:
118+
# https://github.com/root-project/root/issues/20571
119+
#
120+
# TODO: We can't enforce this minimum onnx version in the global
121+
# requirements.txt yet, because the transient update of ml_dtypes is
122+
# conflicting with the current version of the tensorflow package on the macOS
123+
# runners. Once we have installed onnx>=1.19.1 on all of our CI nodes that
124+
# install onnx, we should also consider requiring this minimum version from our
125+
# users, se they don't face bad surprises when exporting PyTorch models to
126+
# onnx.
127+
set(minimum_onnx_version "1.19.1")
128+
if (NOT ROOT_ONNX_FOUND)
129+
set(minimum_onnx_found FALSE)
130+
elseif (NOT DEFINED ROOT_ONNX_VERSION)
131+
message(WARNING "onnx found, but version unknown — cannot verify compatibility.")
132+
set(minimum_onnx_found TRUE) # In this case we assume it is of the right version
133+
elseif (ROOT_ONNX_VERSION VERSION_LESS ${minimum_onnx_version})
134+
message(WARNING "onnx version ${ROOT_ONNX_VERSION} found, but we only support onnx>=${minimum_onnx_version} for compatibility reasons. Some TMVA-SOFIE tests will be disabled.")
135+
set(minimum_onnx_found FALSE)
136+
else()
137+
set(minimum_onnx_found TRUE)
138+
endif()
139+
140+
if (minimum_onnx_found AND ROOT_TORCH_FOUND)
113141
configure_file(Conv1dModelGenerator.py Conv1dModelGenerator.py COPYONLY)
114142
configure_file(Conv2dModelGenerator.py Conv2dModelGenerator.py COPYONLY)
115143
configure_file(Conv3dModelGenerator.py Conv3dModelGenerator.py COPYONLY)
@@ -129,8 +157,8 @@ if (ROOT_TORCH_FOUND)
129157
endif()
130158
endif()
131159

132-
# Any reatures that link against libpython are disabled if built with tpython=OFF
133-
if (tpython AND ROOT_TORCH_FOUND AND BLAS_FOUND)
160+
# Any features that link against libpython are disabled if built with tpython=OFF
161+
if (minimum_onnx_found AND tpython AND ROOT_TORCH_FOUND AND BLAS_FOUND)
134162
configure_file(generatePyTorchModelClassification.py generatePyTorchModelClassification.py COPYONLY)
135163
configure_file(generatePyTorchModelMulticlass.py generatePyTorchModelMulticlass.py COPYONLY)
136164
configure_file(generatePyTorchModelRegression.py generatePyTorchModelRegression.py COPYONLY)
@@ -151,7 +179,7 @@ if (tpython AND ROOT_TORCH_FOUND AND BLAS_FOUND)
151179
endif()
152180

153181

154-
# Any reatures that link against libpython are disabled if built with tpython=OFF
182+
# Any features that link against libpython are disabled if built with tpython=OFF
155183
if (tpython AND ROOT_KERAS_FOUND AND BLAS_FOUND)
156184

157185
set(unsupported_keras_version "3.10.0")

0 commit comments

Comments
 (0)