Skip to content

Loosed Top.K K input tensor condition#28676

Open
damdoo01-arm wants to merge 1 commit into
microsoft:mainfrom
damdoo01-arm:topK_loosen_condition
Open

Loosed Top.K K input tensor condition#28676
damdoo01-arm wants to merge 1 commit into
microsoft:mainfrom
damdoo01-arm:topK_loosen_condition

Conversation

@damdoo01-arm
Copy link
Copy Markdown
Contributor

Changes

Loosened TopK K handling so opset 10+ accepts any single-element int64 tensor, including scalar tensors produced by dynamic shape paths.
Patched bundled ONNX TopK shape inference to validate K by element count instead of requiring rank-1 {1}, while preserving errors for empty/multi-element and negative values.
Added a local rvq_decoder_v1.onnx smoke test and a committed minimal Shape -> Gather -> TopK regression.

Motivation
Additional functionality to pre-compute the K value in the Top.K layer results in model load failures in an OEM model.
Latest ORT successfully follows Shape -> Gather and computes the K value before runtime (none of this happens in 1.19.2). The issue is that it stores that result internally as a scalar TensorProto. Later, when TopK asks for its K input during shape inference, latest ORT converts that scalar into a TensorProto with no dimensions. That scalar TensorProto reaches ONNX TopK shape inference, which expects K to be a rank-1 tensor of size 1. So latest ORT fails at load time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant