Checker error codes¶
When onnx.checker rejects a model, the ValidationError it raises carries a code: a stable identifier of the rule that failed. Code that reacts to particular failures should compare codes, not messages. Messages may be reworded and include model-specific names; codes do not change between releases.
import onnx
try:
onnx.checker.check_model(model)
except onnx.checker.ValidationError as e:
if e.code == "external-data-file-missing":
...
In C++, the code is ValidationError::code(), and the constants are in onnx::checker::error_code.
Not every rule has a code yet. Errors from rules without one have code set to None in Python and an empty code() in C++. Codes are added over time; once added, a code keeps its name and meaning.
Code |
Rule |
|---|---|
|
The model does not set |
|
The model’s |
|
Two |
|
A field the specification requires is not set. |
|
A field the specification requires to be non-empty is empty, such as a graph or initializer name. |
|
A tensor or type uses a data type that was introduced after the model’s |
|
A node uses a domain the model or function does not import, or a model with IR version 3 or later imports no opset. |
|
No operator schema exists for a node in a standard domain at the imported opset version, or in any domain when |
|
A node uses an operator that is deprecated at the imported opset version. |
|
A node does not match its operator schema: it has too few or too many inputs or outputs, an empty name for an input or output that must be set, or an attribute that is duplicated, unknown, missing, or of the wrong attribute type. The types of the inputs and outputs are not part of this check. |
|
A node uses a value that no earlier node, graph input, initializer or outer scope defines: either only a later node produces it, so the nodes are not topologically sorted, or nothing does. |
|
A value name is assigned more than once, for example by two nodes, two graph inputs or two initializers. |
|
A graph output is not produced inside the graph. |
|
An externally stored tensor also has inline data, lacks a |
|
An external data |
|
The file an external data |
|
An external data |