Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:ONNX model

From ReverseEngineering.wiki
Format
Developer Linux Foundation (ONNX project)
Magic none (protobuf)
Extensions .onnx, .onnx_data (external tensor data)
License Apache-2.0
On this wiki Facts · Code · Notes · Topics

Open Neural Network Exchange model file (.onnx): a Protocol Buffers message of type ModelProto holding ir_version, opset_import, producer info and a GraphProto of nodes, initializers and value infos.

Layout

An .onnx file is a serialized ModelProto in the Format:Protocol Buffers wire format, defined in onnx/onnx.proto. There is no magic number. ModelProto fields (read from onnx.proto): ir_version = 1 (int64), producer_name = 2, producer_version = 3, domain = 4, model_version = 5, doc_string = 6, graph = 7 (GraphProto), opset_import = 8 (repeated OperatorSetIdProto: domain + version), metadata_props = 14 (StringStringEntryProto), training_info = 20.

So a file normally starts with byte 08 (field 1 varint) followed by the IR version, then often 12 (producer_name). Unverified as a rule: this start is typical of exporters but proto field order is not guaranteed.

Versions

Two independent numbers: ir_version (the file format, enum Version in onnx.proto: IR_VERSION 1 = 2017-10-10 ... 10 = 2024-03-25 (UINT4/INT4), 11 = 2025-05-12, 12 = 2025-08-26, 13 = 2025-11-06 (UINT2/INT2) in the pinned commit) and the opset per operator domain (opset_import; the empty or "ai.onnx" domain is the main operator set, "com.microsoft" is used by ONNX Runtime contrib ops). The runtime refuses models whose IR or opset is newer than it supports.

Tensors

TensorProto.DataType: FLOAT 1, UINT8 2, INT8 3, UINT16 4, INT16 5, INT32 6, INT64 7, STRING 8, BOOL 9, FLOAT16 10, DOUBLE 11, UINT32 12, UINT64 13, COMPLEX64 14, COMPLEX128 15, BFLOAT16 16, FLOAT8 variants 17-20, then 4-bit types from 21. Weights live in GraphProto.initializer, in raw_data, or in an external file referenced from the tensor (TensorProto.external_data is field 13, repeated StringStringEntryProto; onnx.proto at 88e38e2e18, lines 769-777, lists the keys: location (required, POSIX path relative to the model's directory), offset (optional, byte position as a decimal string, SHOULD be a multiple of 4096 for mmap), length (optional, byte count as a string) and checksum (optional, SHA1 of the file); data_location = 14 is set to EXTERNAL).

Reversing notes

A model is a data-flow graph: node op_type + inputs/outputs by name, so it can be dumped with any protobuf decoder using onnx.proto. The loader in an app is usually Library:ONNX Runtime. See Technique:Identifying machine-learning models in applications.

Related

Library:Protocol Buffers, Format:TensorFlow Lite model, Format:Core ML model

Code & repositories

  • https://github.com/onnx/onnx @ 88e38e2e18851621cc6343f5c685f19b75a98bfd · license: Apache-2.0 (read from LICENSE; GitHub's API was busy)
    onnx.proto (ModelProto, IR versions) and docs
    Tested on: source read, not run: read source · checked 2026-10-18