Skip to content

Shape of Gather output is wrong making it unusable as K input to TopK operator #29072

Description

@arnej27959

Describe the issue

After upgrading from onnxruntime 1.23 to 1.26 one of our customers models fails to load with this error:

Load model from topk_repro.onnx failed:Node (/TopK) Op (TopK) [ShapeInferenceError] K input must be a one-dimensional tensor of size 1.

As far as I can tell this happens because there's a "Gather" operation that should give the required shape as input, but doesn't. I've reduced the model to just a toy example; the "Gather" operation here should be no-op but clearly its output type isn't as expected.

topk.py

To reproduce

on both Mac and Linux I can reproduce the problem with the attached script:

python3.14 -m venv ~/onnxruntime-env
source ~/onnxruntime-env/bin/activate
pip install onnx onnxruntime==1.26.0
python topk.py

Urgency

No response

Platform

Linux

OS Version

AlmaLinux 10.2

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

v1.26.0

ONNX Runtime API

Python

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

Metadata

Metadata

Assignees

Labels

regressionissues that demonstrate a regression in ORT functionality and need to be addressed immediately

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions