Introduction
ONNX (Open Neural Network Exchange) is an open format for trained neural networks, announced by Facebook and Microsoft in September 2017 and now run by the ONNX project. An ONNX file holds the whole network, both its graph of operations and its weights, so a model trained in one framework can run in another program or on another device. It is widely used to move models from PyTorch into ONNX Runtime and onto phones and embedded hardware.
A model is usually named .onnx; the same message is sometimes saved as
.pb. It is one ModelProto message from the project’s
schema, onnx.proto, stored as a
Protocol Buffers message with no header
of its own. Every new IR version of the
format has only added messages, fields and data types, so all of them are one
format; a change to existing fields would make a separate one.
An .onnx or .pb file dropped on any page of this site opens
in the explorer, which shows the IR version, the operator sets, the program that
wrote the model, the graph’s inputs and outputs, every node and the operators used,
and every initialiser with its type, shape and size. It reads only the parts it
shows, so a model of a gigabyte opens in under a second.
Structure
The file is one ModelProto. Its main fields, in the order of the PyTorch export shown below:
0ir_version field 1, the version of the format2 bytes…producer_name, producer_version fields 2 and 3, the program that wrote itvaries…graph field 7, the GraphProto: nodes, inputs and outputs, and the initialiser tensors that hold the weightsnearly all of the file…opset_import field 8, the operator sets the model uses, with their versionsa few bytes each
The start of a 1 GB model exported from PyTorch, examined for this site:
| Bytes | Field | Value |
|---|---|---|
08 08 | ir_version | 8 |
12 07 70 79 74 6F 72 63 68 | producer_name | pytorch |
1A 05 32 2E 38 2E 30 | producer_version | 2.8.0 |
3A E7 D5 D7 FD 03 | graph | 1,068,886,759 bytes follow: the graph, nearly the whole file |
The opset_import, four bytes, comes after the graph at the very end of
the file. A Protocol Buffers message must be smaller than 2 GiB, so larger models keep
their weights in external files beside the
model, which refers to them by name.
Versions
The ir_version field gives the version of the format; the operator
sets have versions of their own, in opset_import. IR versions 1 to 3
appeared in October and November 2017, and ONNX 1.0, the first release, used IR 3.
Since then each new IR version has come with an ONNX release: IR 13, dated 6 November
2025, with ONNX 1.20, and IR 14 with ONNX 1.23, whose schema still dates it “TBD”. The
full list is on IR versions.
Telling it apart
The file has no signature. The explorer takes it as Protocol Buffers when the name
ends .onnx, .pb or .binpb, the first field reads
cleanly and the first 512 bytes are not all printable text. After the ONNX tensor and
sequence parsers turn it down, the parser for this format checks:
- every field number is one of ModelProto’s (1 to 8, 14, 20, 25 and 26), each with the wire type its type is stored with;
ir_versionis present and from 1 to 64 (14 is the newest known);- there is a
graph; - there is at least one
opset_importwhen the IR version is 3 or later; - the nested messages follow their own schemas, down to the first 20,000 fields, with every node naming an operator and every tensor’s values fitting its shape;
- strings declared
stringare valid UTF-8 (checked up to 4 KB).
Every .onnx file examined for this site, up to 64 MB, passed with no
issue. The field numbers come from onnx 1.23. A later version of the schema that adds
a field is still this format, but the parser turns such a file down until it learns
the field, and the file is then shown as a message without a schema.
Not described
Known, not yet covered
- Reference and viewer: the
com.microsoftoperators of ONNX Runtime and other vendor domains. Microsoft documents its contrib operators, but these pages treat them as out of scope (see operators). The viewer names the domain and shows the operator and its attributes as written, without meanings. - Reference and viewer: ONNX’s text syntax for models, used in its tests and documentation, is not described and not read.
Variants
- ONNX tensor (TensorProto) – one tensor, as in ONNX’s test data
- ONNX sequence or optional value – a list of tensors, or a value that may be absent
- ONNX model (ModelProto) – a whole model: graph, operators and weights
- TensorFlow SavedModel (saved_model.pb) – meta graphs, signatures and functions
- TensorFlow GraphDef (frozen graph) – nodes, with the weights as constants
- Protocol Buffers message – any message, read without its schema
Links
Software
- ONNX Runtime – Microsoft’s engine for running ONNX models (Windows, macOS, Linux, Android, iOS, web)
- Netron – viewer that draws the network and lists its weights (Windows, macOS, Linux, web)
- PyTorch – machine learning framework that exports models to ONNX (Windows, macOS, Linux)
Developers
- onnx – package for loading, checking and editing models (Python)
- ONNX Runtime – inference library (C, C++, C#, Java, Python, JavaScript)
Reference
- ONNX documentation – the operator list and the intermediate representation
- onnx.proto – the Protocol Buffers schema of an ONNX file
- ONNX versioning – IR versions, operator set versions and the releases that brought them
- Encoding – the Protocol Buffers wire format