microsoft / microsoft/onnxruntime

Optimizer Throws Runtime Error on String Constant Node

Open
#17,392 3 comments 0 reactions 1 assignee Claimed by @skottmckay View on GitHub
Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 11h
Merged PRs (30d)
184

Description

### Describe the issue

When trying to load a simple model which only consists of a constant node, the optimizer throws a runtime error saying "string tensor can not use pre-allocated buffer".

Here's the full error message:
```
onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Exception during initialization: /path/to/onnxruntime/core/optimizer/optimizer_execution_frame.cc:78 onnxruntime::OptimizerExecutionFrame::Info::Info(const std::vector &, const onnxruntime::InitializedTensorSet &, const onnxruntime::Path &, const onnxruntime::IExecutionProvider &, const std::function &) [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : string tensor can not use pre-allocated buffer
```

### To reproduce

Here's a short Python Script to reproduce the issue:
```python
from onnx.checker import check_model
from onnx.helper import make_graph, make_model, make_node, make_tensor_value_info
from onnx.reference.reference_evaluator import ReferenceEvaluator
from onnxruntime import InferenceSession

# Write output shape
Y = make_tensor_value_info("Y", elem_type=8, shape=(1,))

# Make constant and Identity nodes
node_constant = make_node("Constant", [], ["C"], value_strings=["a"])
node_identity = make_node("Identity", ["C"], ["Y"])

# Build the grapg
graph = make_graph(
[node_constant, node_identity], name="Constant", inputs=[], outputs=[Y]
)

# Generate and check the model
onnx_model = make_model(graph)
check_model(onnx_model)

# It runs on onnx.reference
print(ReferenceEvaluator(onnx_model).run(output_names=["Y"], feed_inputs={}))

# Loading the model errors
InferenceSession(onnx_model.SerializeToString())
```

### Urgency

_No response_

### Platform

Mac

### OS Version

Mac OS Ventura, 13.4.1 (c) (22F770820d)

### ONNX Runtime Installation

Released Package

### ONNX Runtime Version or Commit ID

1.15.1

### ONNX Runtime API

Python

### Architecture

X64

### Execution Provider

Default CPU

### Execution Provider Library Version

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.