OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[Python API] Add a deprecation warning for "precise_0" behavior (#37565)
Alicja Miloszewska8c89911875be
diff --git a/src/bindings/python/src/pyopenvino/graph/rt_map.cpp b/src/bindings/python/src/pyopenvino/graph/rt_map.cppindex bd07de590ec..1bde1cfe0cb 100644--- a/src/bindings/python/src/pyopenvino/graph/rt_map.cpp+++ b/src/bindings/python/src/pyopenvino/graph/rt_map.cpp@@ -74,10 +74,20 @@ void regclass_graph_PyRTMap(py::module m) {return PyRTMap();}));- py_map.def("__setitem__", [](PyRTMap& m, const std::string& k, const std::string v) {+ auto warn_if_precise = [](const std::string& key) {+ if (key == "precise_0") {+ Common::utils::deprecation_warning(+ "Setting 'precise_0' on node rt_info",+ "2027.0",+ "This relies on a deprecated internal C++ API attribute (DisableFP16Compression).");+ }+ };+ py_map.def("__setitem__", [warn_if_precise](PyRTMap& m, const std::string& k, const std::string v) {+ warn_if_precise(k);m[k] = v;});- py_map.def("__setitem__", [](PyRTMap& m, const std::string& k, const int64_t v) {+ py_map.def("__setitem__", [warn_if_precise](PyRTMap& m, const std::string& k, const int64_t v) {+ warn_if_precise(k);m[k] = v;});py_map.def("__getitem__", [](PyRTMap& m, const std::string& k) -> py::object {diff --git a/src/bindings/python/tests/test_runtime/test_model.py b/src/bindings/python/tests/test_runtime/test_model.pyindex 6fbb0226423..6c74d0fa69d 100644--- a/src/bindings/python/tests/test_runtime/test_model.py+++ b/src/bindings/python/tests/test_runtime/test_model.py@@ -673,11 +673,8 @@ def test_serialize_rt_info(request, tmp_path):def test_serialize_node_rt_info_disable_fp16(request, tmp_path):- # Setting rt_info["precise_0"] = "" on a node from Python simulates- # disabling FP16 compression. During serialization, "precise_0" is- # converted into a DisablePrecisionConversion attribute so the flag- # persists in the IR. After deserialization the key becomes- # "DisablePrecisionConversion_0". This test verifies the round-trip.+ # "precise_0" is the legacy DisableFP16Compression RTTI key.+ # serialize.cpp converts it into DisablePrecisionConversion before serialization.core = Core()xml_path, bin_path = create_filenames_for_ir(request.node.name, tmp_path)@@ -685,8 +682,8 @@ def test_serialize_node_rt_info_disable_fp16(request, tmp_path):relu = ops.relu(param, name="relu_node")model = Model(relu, [param], "TestModel")- # Set the string-based rt_info that Python users would use- relu.get_rt_info()["precise_0"] = ""+ with pytest.warns(DeprecationWarning, match="precise_0"):+ relu.get_rt_info()["precise_0"] = ""assert "precise_0" in relu.get_rt_info()serialize(model, xml_path, bin_path)