Skip to content

List expected types in operator type-mismatch error message#29214

Open
ArsalanShakil wants to merge 1 commit into
microsoft:mainfrom
ArsalanShakil:improve-type-mismatch-error
Open

List expected types in operator type-mismatch error message#29214
ArsalanShakil wants to merge 1 commit into
microsoft:mainfrom
ArsalanShakil:improve-type-mismatch-error

Conversation

@ArsalanShakil

Copy link
Copy Markdown
Contributor

Description

When a node input has a type that is not among the operator's permitted types, Graph::InferAndVerifyTypeMatch reports only the offending type. For example:

This is an invalid model. Type Error: Type 'tensor(int64)' of input parameter (X) of operator (Sin) in node (node_1) is invalid.

This does not tell the user which types are actually valid, so they have to go look up the operator spec to understand the error.

This change appends the operator's permitted types to the existing message:

This is an invalid model. Type Error: Type 'tensor(int64)' of input parameter (X) of operator (Sin) in node (node_1) is invalid. Expected one of the following types: tensor(double), tensor(float), tensor(float16).

The permitted types are sorted so the message is deterministic. The existing text is preserved unchanged and only appended to, so callers that match on the current substring (for example the quantization Python tests) are unaffected.

A unit test in graph_test.cc builds a graph that feeds an int64 input to Sin (a float-only operator) and asserts that the resolve error lists the expected types.

Motivation and Context

Fixes #4429. The original report and a maintainer both noted it would be helpful for the error message to indicate the expected types, not just the offending one.

When a node input has a type that is not among the operator's permitted
types, the resolve-time error reported only the offending type, which
made it hard to know which types were valid. This was raised in microsoft#4429.

Append the operator's permitted types (sorted for a deterministic
message) to the existing 'Type Error' message. The existing text is
preserved, so callers that match on the current substring are
unaffected. Adds a graph test covering the new message.
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.

Display all input types on type error

1 participant