From aa2f02c3740fb69aaf9b21c169ffed558147e3d8 Mon Sep 17 00:00:00 2001 From: Christian Bourjau Date: Wed, 3 Jun 2026 17:37:24 +0200 Subject: [PATCH 1/2] Add failing test case --- tests/test_value_propagation.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/test_value_propagation.py b/tests/test_value_propagation.py index 5ab4c1d..c69d6b4 100644 --- a/tests/test_value_propagation.py +++ b/tests/test_value_propagation.py @@ -9,7 +9,7 @@ import spox import spox._future -import spox.opset.ai.onnx.ml.v3 as ml +import spox.opset.ai.onnx.ml.v4 as ml import spox.opset.ai.onnx.v22 as op from spox import Optional, Sequence, Tensor, Type, Var, argument from spox._graph import arguments, results @@ -259,3 +259,17 @@ def test_strings(): x, y = op.const(["foo"]), op.const(["bar"]) np.testing.assert_equal(op.string_concat(x, y)._value.value, np.array(["foobar"])) # type: ignore + + +def test_value_prop_ort_cse_bug_mitigation(): + """Test mitigation against ort CSE crash.""" + # A constant string input so value propagation actually runs. + x = op.const(np.array(["a"], dtype=np.str_)) + + y = ml.label_encoder( + x, + keys_tensor=np.array(["a"], dtype=np.str_), + values_tensor=np.array(["b"], dtype=np.str_), + default_tensor=np.array(["MISSING"], dtype=np.str_), + ) + assert y._value is not None From 5631d12a70c68c6a44cbbcded81162c42d332bd2 Mon Sep 17 00:00:00 2001 From: Christian Bourjau Date: Wed, 3 Jun 2026 17:42:00 +0200 Subject: [PATCH 2/2] Fix and changelog --- CHANGELOG.rst | 8 ++++++++ src/spox/_value_prop.py | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d2816a1..b70db1e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,14 @@ Change log ========== +0.17.2 (2026-06-04) +------------------- + +**Other change** + +- Disable onnxruntime optimization passes in value propagation as a mitigation for https://github.com/microsoft/onnxruntime/issues/28413 and to speed-up session creation. + + 0.17.1 (2026-02-17) ------------------- diff --git a/src/spox/_value_prop.py b/src/spox/_value_prop.py index cbdfdb3..469142c 100644 --- a/src/spox/_value_prop.py +++ b/src/spox/_value_prop.py @@ -146,13 +146,14 @@ def _run_reference_implementation( def _run_onnxruntime( model: onnx.ModelProto, input_feed: dict[str, ORTValue] ) -> dict[str, ORTValue]: - import onnxruntime + import onnxruntime as ort # Silence possible warnings during execution (especially constant folding) - options = onnxruntime.SessionOptions() + options = ort.SessionOptions() options.log_severity_level = 3 + options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_DISABLE_ALL try: - session = onnxruntime.InferenceSession(model.SerializeToString(), options) + session = ort.InferenceSession(model.SerializeToString(), options) output_names = [output.name for output in session.get_outputs()] output_feed = dict(zip(output_names, session.run(None, input_feed))) except Exception as e: