ONNX (Open Neural Network Exchange)
Cross-framework Protocol Buffers computation graph and weight format used by ONNX Runtime, TensorRT, and CoreML converters.
Encoded as a Protobuf v2/v3 ModelProto message. Field 1 (ir_version) is typically serialized first as tag 0x08 followed by a varint IR version (e.g., 7..10).
Drop any .onnx file (even 100 GB+) to inspect locally
Reads tiny File.slice() header/footer pages in a sandboxed Web Worker · 0 Bytes Uploaded
.onnx Magic Bytes & Header Offset Map
Protobuf field #1 (ir_version) varint wire tag
| Byte Offset | Length | Data Type | Field Name | Engineering Description |
|---|---|---|---|---|
| 0x00 | 1 B | uint8 | ir_version_tag | Protobuf tag 0x08 (field 1, varint) |
| 0x01 | 1-2 B | varint | ir_version | ONNX IR specification version |
| 0x02+ | var | protobuf | producer_and_graph | Producer name, opset_import, and GraphProto |
.onnx Security & Polyglot Risk Matrix
Audit external_data tensor file paths inside TensorProto to block arbitrary local file read (LFI / path traversal) when loading untrusted ONNX models.
Read .onnx Header & Metadata Without Heavy Dependencies
import sys
with open(sys.argv[1], "rb") as f:
b = f.read(32)
assert b[0] == 0x08, "Expected ModelProto.ir_version tag 0x08"
print(f"ONNX ModelProto IR version={b[1]}")Deterministic .onnx Sample Files & Edge Cases
minimal-linear.onnx
Real ONNX ModelProto (ir_version=9, opset=21) verified by onnx.checker.check_model — MatMul + Relu.
curl -fsSL https://fileformat.co/fixtures/v1/onnx/minimal-linear.onnx -o minimal-linear.onnx \
&& echo "aa4e82d69b4579c1a7bfbf12228776f121238825abb64a45e937d4e1299a33fb minimal-linear.onnx" | shasum -a 256 -cmlp-classifier.onnx
onnx.helper-built MLP with float32 TensorProto initializers, Gelu activation — passes onnx.checker.
curl -fsSL https://fileformat.co/fixtures/v1/onnx/mlp-classifier.onnx -o mlp-classifier.onnx \
&& echo "bc52092748c786119aa203b36f61a706a5f40a426b9626ed0469552d9566ff4e mlp-classifier.onnx" | shasum -a 256 -ctruncated-protobuf.onnx
ModelProto wire frame truncated mid-GraphProto — ModelProto.ParseFromString must raise DecodeError.
curl -fsSL https://fileformat.co/fixtures/v1/onnx/truncated-protobuf.onnx -o truncated-protobuf.onnx \
&& echo "d4db86720670b6fb423cba89dae6fd0d3dc7a92624f836148e6fc29a590b06f4 truncated-protobuf.onnx" | shasum -a 256 -cRelated Specifications & Alternatives
Hugging Face's memory-safe, zero-copy tensor serialization format designed to replace Pickle-based PyTorch checkpoints without arbitrary code execution risks.
Self-contained binary model weight format for llama.cpp and local LLM inference engines, storing architecture KV metadata, BPE vocabulary, and quantized tensor blocks in a single mmap-ready file.
Default PyTorch `torch.save()` archive wrapping a Python Pickle instruction stream (`data.pkl`) alongside raw tensor storage files inside a ZIP container.