{"record":{"id":"deb42b7af0b4539e","repo":"mlflow/mlflow","slug":"value-for-key-key-in-onnx-session-options-should-deb42b","errorCode":null,"errorMessage":"Value for key {key} in onnx_session_options should be 0, 1, 2, or 99, not {value}","messagePattern":"Value for key (.+?) in onnx_session_options should be 0, 1, 2, or 99, not (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mlflow/utils/model_utils.py","lineNumber":379,"sourceCode":"                raise ValueError(\n                    f\"Key {key} in onnx_session_options is not a valid \"\n                    \"ONNX Runtime session options key\"\n                )\n            elif key == \"extra_session_config\" and not isinstance(value, dict):\n                raise TypeError(\n                    f\"Value for key {key} in onnx_session_options should be a dict, \"\n                    \"not {type(value)}\"\n                )\n            elif key == \"execution_mode\" and value.upper() not in [\n                \"PARALLEL\",\n                \"SEQUENTIAL\",\n            ]:\n                raise ValueError(\n                    f\"Value for key {key} in onnx_session_options should be \"\n                    f\"'parallel' or 'sequential', not {value}\"\n                )\n            elif key == \"graph_optimization_level\" and value not in [0, 1, 2, 99]:\n                raise ValueError(\n                    f\"Value for key {key} in onnx_session_options should be 0, 1, 2, or 99, \"\n                    f\"not {value}\"\n                )\n            elif key in [\"intra_op_num_threads\", \"intra_op_num_threads\"] and value < 0:\n                raise ValueError(\n                    f\"Value for key {key} in onnx_session_options should be >= 0, not {value}\"\n                )\n\n\ndef _get_overridden_pyfunc_model_config(\n    pyfunc_config: dict[str, Any], load_config: dict[str, Any], logger\n) -> dict[str, Any]:\n    \"\"\"\n    Updates the inference configuration according to the model's configuration and the overrides.\n    Only arguments already present in the inference configuration can be updated. The environment\n    variable ``MLFLOW_PYFUNC_INFERENCE_CONFIG`` can also be used to provide additional inference\n    configuration.\n    \"\"\"","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/utils/model_utils.py#L361-L397","documentation":"When `graph_optimization_level` is provided in `onnx_session_options`, MLflow restricts it to the integers 0, 1, 2, or 99, which map to ORT's ORT_DISABLE_ALL, ORT_ENABLE_BASIC, ORT_ENABLE_EXTENDED, and ORT_ENABLE_ALL levels. Any other value (e.g. 3, strings, floats) raises this ValueError.","triggerScenarios":"`save_model(..., onnx_session_options={'graph_optimization_level': 3})` or passing the string 'ORT_ENABLE_ALL' instead of the integer 99.","commonSituations":"Copying a value from onnxruntime's GraphOptimizationLevel enum (0/1/2/99) but using a level like 3; passing a string level name rather than the integer.","solutions":["Use one of the allowed integers: 0, 1, 2, or 99","Replace a string like 'ORT_ENABLE_ALL' with the equivalent integer 99","Remove the key to accept the runtime default optimization level"],"exampleFix":"// before\nonnx_session_options={'graph_optimization_level': 'ORT_ENABLE_ALL'}\n// after\nonnx_session_options={'graph_optimization_level': 99}","handlingStrategy":"validation","validationCode":"lvl = opts.get('graph_optimization_level')\nif lvl is not None and lvl not in (0, 1, 2, 99):\n    raise ValueError(f'Invalid graph_optimization_level: {lvl}')","typeGuard":"def is_valid_opt_level(v) -> bool:\n    return v is None or (isinstance(v, int) and v in (0, 1, 2, 99))","tryCatchPattern":"try:\n    mlflow.onnx.save_model(model, path, onnx_session_options=opts)\nexcept ValueError as e:\n    if 'graph_optimization_level' in str(e):\n        opts['graph_optimization_level'] = 99\n    raise","preventionTips":["Map ORT_ENABLE_ALL/BASIC/EXTENDED strings to 99/1/2 before passing","Only use integers 0, 1, 2, 99","Document the allowed values next to your model-saving helper"],"tags":["onnx","validation","configuration"],"backgroundTag":"invalid-enum-value","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}