Loosed Top.K K input tensor condition#28676
Open
damdoo01-arm wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.