Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameters are optimized out even if it is a needed return value #13425

Open
ganler opened this issue Oct 25, 2022 · 0 comments
Open

Parameters are optimized out even if it is a needed return value #13425

ganler opened this issue Oct 25, 2022 · 0 comments
Labels
core runtime issues related to core runtime

Comments

@ganler
Copy link

ganler commented Oct 25, 2022

Describe the issue

The simplified model exported from PyTorch:

"""
graph torch_jit (
  %i0[FLOAT, 1x1x2x2]
) initializers (
  %/Cast_1_output_0[INT64, 8]
  %o2[FLOAT, 1]
) {
  %o0 = Pad[mode = 'reflect'](%i0, %/Cast_1_output_0)
  %o1 = Min(%o2, %i0)
  return %o0, %o1, %o2
}
"""

When running in ONNXRuntime with default optimization, the result o2 is missing where it returns None instead of an actual tensor. While disabling all ORT optimizations by setting ort.GraphOptimizationLevel.ORT_DISABLE_ALL gets this model correctly executed. So I think it might be due to some miss-/over-optimization in some graph passes.

To reproduce

import onnxruntime as ort
import onnx

import numpy as np

model = onnx.load("test.onnx")
onnx.checker.check_model(model, full_check=True)

x = np.array([[[[5.69269, 3.9831784], [5.8404264, 5.823447]]]], dtype=np.float32)

sess = ort.InferenceSession(
    model.SerializeToString(),
    providers=["CUDAExecutionProvider", "CPUExecutionProvider"],
)
results = sess.run(["o0", "o1", "o2"], {"i0": x})

print(f"{results[0] = }")
print(f"{results[1] = }")
print(f"{results[2] = }") # Results are incorrectly optimized out as `None`

assert results[2] is None

options = ort.SessionOptions()
options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_DISABLE_ALL
sess = ort.InferenceSession(
    model.SerializeToString(),
    sess_options=options,
    providers=["CUDAExecutionProvider", "CPUExecutionProvider"],
)
results = sess.run(["o0", "o1", "o2"], {"i0": x})

print(f"{results[0] = }")
print(f"{results[1] = }")
print(f"{results[2] = }")  # It works without optimization

assert results[2] is not None

The model "test.onnx" is attached: test.zip

Urgency

None. But it is very common to cache all intermediate outputs when using ONNXRuntime as a reference backend in testing (say in PyTorch and other ONNX supported engines).

Platform

Linux

OS Version

Ubuntu 22.04

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.14.0 (ort-nightly)

ONNX Runtime API

Python

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

@github-actions github-actions bot added ep:tvm issues related to TVM execution provider and removed ep:tvm issues related to TVM execution provider labels Oct 25, 2022
@faxu faxu added the core runtime issues related to core runtime label Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core runtime issues related to core runtime
Projects
None yet
Development

No branches or pull requests

2 participants