microsoft / onnxruntime

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
https://onnxruntime.ai
MIT License
14.49k stars 2.9k forks source link

RUNTIME_EXCEPTION : Non-zero status code returned while running Reshape node #20026

Open Priyanshu88 opened 7 months ago

Priyanshu88 commented 7 months ago

Describe the issue

onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Non-zero status code returned while running Reshape node. Name:'/Reshape_16_output_0_ReduceMax_Reshape' Status Message: /onnxruntime_src/onnxruntime/core/providers/cpu/tensor/reshape_helper.h:44 onnxruntime::ReshapeHelper::ReshapeHelper(const onnxruntime::TensorShape&, onnxruntime::TensorShapeVector&, bool) input_shape_size == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{0,1}, requested shape:{1}

Urgency

Yeah urgency

Target platform

OpenMMLab

Build script

I am using the below config to convert the rtmo model to onnx model with the help of mmdeploy https://github.com/open-mmlab/mmdeploy/blob/main/configs/mmpose/pose-detection_rtmo_onnxruntime_dynamic.py

onnx_config = dict(
    output_names=['dets', 'keypoints'],
    dynamic_axes={
        'input': {
            0: 'batch',
        },
        'dets': {
            0: 'batch',
        },
        'keypoints': {
            0: 'batch'
        }
    })

codebase_config = dict(
    post_processing=dict(
        score_threshold=0.05,
        iou_threshold=0.5,
        max_output_boxes_per_class=200,
        pre_top_k=2000,
        keep_top_k=50,
        background_label_id=-1,
    ))

Error / output

Full log describing the path

When keeping the batch size as 32, am getting below failure.

onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Non-zero status code returned while running Reshape node. Name:'/Reshape_16_output_0_ReduceMax_Reshape' Status Message: /onnxruntime_src/onnxruntime/core/providers/cpu/tensor/reshape_helper.h:44 onnxruntime::ReshapeHelper::ReshapeHelper(const onnxruntime::TensorShape&, onnxruntime::TensorShapeVector&, bool) input_shape_size == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{0,1}, requested shape:{1}

When keeping the batch size as 1, am getting below failure.

[ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Non-zero status code returned while running Reshape node. Name:'/Tile_output_0_ReduceMax_Reshape' Status Message: /onnxruntime_src/onnxruntime/core/providers/cpu/tensor/reshape_helper.h:44 onnxruntime::ReshapeHelper::ReshapeHelper(const onnxruntime::TensorShape&, onnxruntime::TensorShapeVector&, bool) input_shape_size == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{1,0,1}, requested shape:{1}

Visual Studio Version

No response

GCC / Compiler Version

No response

skottmckay commented 7 months ago

Reshape can only change the shape of the data. It does not create/destroy data.

In both cases the input to the Reshape node has no data as one of the dimensions is 0. So we can't 'reshape' no data to data with 1 element.

Most likely part of your model has some sort of selection logic, and nothing was selected, leading to a dimension with a value of 0.

It's also slightly unusual to be using Reshape with a target shape of {1}. Squeeze may be an alternative option as it would handle dims with a value of zero as it removes dimensions with a value of 1.

Priyanshu88 commented 7 months ago

Reshape can only change the shape of the data. It does not create/destroy data.

In both cases the input to the Reshape node has no data as one of the dimensions is 0. So we can't 'reshape' no data to data with 1 element.

Most likely part of your model has some sort of selection logic, and nothing was selected, leading to a dimension with a value of 0.

It's also slightly unusual to be using Reshape with a target shape of {1}. Squeeze may be an alternative option as it would handle dims with a value of zero as it removes dimensions with a value of 1.

But why is this different for two different batch sizes? Any possible solution will work that would handle my case of conversion, also did you take a look at onnx config specific to model and it's expected behavior ? let me know any modification if you can provide.

github-actions[bot] commented 6 months ago

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.