Skip to content

[Bug]: Constant folding pass fails during compilation with convert->constant_fold error #33446

@dutZ1855

Description

@dutZ1855

OpenVINO Version

2026.0.0.dev20251223

Operating System

Ubuntu 20.04 (LTS)

Device used for inference

CPU

Framework

None

Model used

No response

Issue description

For the following model,

Image

OpenVINO compilation fails during the constant folding optimization pass with the error: Check 'convert->constant_fold(replacements, convert->input_values())' failed at src/core/src/pass/constant_folding.cpp:70.

The model works correctly in ONNXRuntime but crashes in OpenVINO during compilation when the constant folding pass attempts to process a Convert node.

Step-by-step reproduction

Download the model and run the following code to obtain the results.

model.zip

from __future__ import annotations

import argparse
import pickle
import sys
import traceback
from pathlib import Path
from typing import Any, Dict


def _load_oracle_inputs(oracle_path: Path) -> Dict[str, Any]:
    with oracle_path.open("rb") as f:
        obj = pickle.load(f)
    if isinstance(obj, dict) and "input" in obj and isinstance(obj["input"], dict):
        return obj["input"]
    if isinstance(obj, dict):
        return obj
    raise TypeError(f"Unsupported oracle.pkl format: {type(obj)}")


def main() -> int:
    ap = argparse.ArgumentParser()
    ap.add_argument("--model", type=Path, default=Path(__file__).with_name("model.onnx"))
    ap.add_argument("--oracle", type=Path, default=Path(__file__).with_name("oracle.pkl"))
    ap.add_argument("--device", type=str, default="CPU")
    args = ap.parse_args()

    model_path = args.model.resolve()
    oracle_path = args.oracle.resolve()
    print(f"model:  {model_path}")
    print(f"oracle: {oracle_path}")
    feed = _load_oracle_inputs(oracle_path)

    # ORT
    print("\n== ORT ==")
    try:
        import onnxruntime as ort

        sess = ort.InferenceSession(str(model_path), providers=["CUDAExecutionProvider"])
        print("ORT inputs:", [(i.name, i.type, i.shape) for i in sess.get_inputs()])
        print("ORT outputs:", [(o.name, o.type, o.shape) for o in sess.get_outputs()])
        outs = sess.run(None, feed)
        for oinfo, val in zip(sess.get_outputs(), outs):
            print(f"{oinfo.name}: {val.dtype} {val.shape} {val}")
    except Exception:
        print("ORT failed unexpectedly (full traceback):", file=sys.stderr)
        print(traceback.format_exc(), file=sys.stderr)
        return 2

    print("\n== OpenVINO ==")
    try:
        import numpy as np
        import openvino as ov

        core = ov.Core()
        print(f"OpenVINO version: {getattr(ov, '__version__', 'unknown')}")
        print(f"Compile device: {args.device}")
        compiled = core.compile_model(str(model_path), args.device)
        print("compile_model: OK (unexpected for this bug)")
        req = compiled.create_infer_request()
        for inp in compiled.inputs:
            name = inp.get_any_name()
            req.set_tensor(name, ov.Tensor(np.asarray(feed[name])))
        res = req.infer()
        print("inference: OK (unexpected)")
        for out in compiled.outputs:
            name = out.get_any_name()
            arr = np.asarray(res[name])
            print(f"{name}: {arr.dtype} {arr.shape} {arr}")
        return 1
    except Exception:
        print("OpenVINO failed as expected (full traceback):", file=sys.stderr)
        print(traceback.format_exc(), file=sys.stderr)
        return 0


if __name__ == "__main__":
    raise SystemExit(main())

Relevant log output

== ORT ==
ORT inputs: [('v0_0', 'tensor(float16)', [1, 55, 1])]
ORT outputs: [('v2_0', 'tensor(float16)', [1, 56, 1]), ('v15_0', 'tensor(float16)', [1, 55, 1]), ('v10_0', 'tensor(float16)', [2, 55, 1]), ('v8_0', 'tensor(float16)', [1, 55, 2]), ('v6_0', 'tensor(float16)', [2, 55, 1]), ('v14_0', 'tensor(float16)', [1, 1, 1]), ('v1_0', 'tensor(float16)', [1, 56, 2])]
v2_0: float16 (1, 56, 1) [[[3.152]
  [5.44 ]
  [4.234]
  [3.271]
  [5.09 ]
  [5.36 ]
  [4.965]
....

== OpenVINO ==
OpenVINO version: 2026.0.0-20706-0a5eedc91d7
Compile device: CPU
OpenVINO failed as expected (full traceback):
Traceback (most recent call last):
  File "/home/user/DLCompilers/openvino/model_6_10/run_compare_ort_ov.py", line 60, in main
    compiled = core.compile_model(str(model_path), args.device)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/anaconda3/envs/openvino_env/lib/python3.11/site-packages/openvino/_ov_api.py", line 646, in compile_model
    super().compile_model(model, device_name, {} if config is None else config),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Exception from src/inference/src/cpp/core.cpp:136:
Exception from src/inference/src/dev/plugin.cpp:58:
Check 'convert->constant_fold(replacements, convert->input_values())' failed at src/core/src/pass/constant_folding.cpp:70

Issue submission checklist

  • I'm reporting an issue. It's not a question.
  • I checked the problem with the documentation, FAQ, open issues, Stack Overflow, etc., and have not found a solution.
  • There is reproducer code and related data files such as images, videos, models, etc.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions