{
  "schemaVersion": "1.0",
  "canonicalPage": "https://fileformat.co/ext/onnx",
  "inspectorUrl": "https://fileformat.co/inspect",
  "spec": {
    "slug": "onnx",
    "extension": ".onnx",
    "aliases": [],
    "name": "ONNX (Open Neural Network Exchange)",
    "shortName": "ONNX",
    "category": "ai-ml",
    "tier": 2,
    "summary": "Cross-framework Protocol Buffers computation graph and weight format used by ONNX Runtime, TensorRT, and CoreML converters.",
    "technicalNotes": "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).",
    "mimeTypes": [
      "application/onnx",
      "application/octet-stream"
    ],
    "identifiers": {
      "specUrl": "https://onnx.ai/onnx/repo-docs/IR.html"
    },
    "binarySignature": {
      "endianness": "little",
      "magicBytes": [
        {
          "offset": 0,
          "hex": "08",
          "description": "Protobuf field #1 (ir_version) varint wire tag"
        }
      ],
      "containerFamily": null,
      "headerLayout": [
        {
          "offset": "0x00",
          "byteOffset": 0,
          "byteLength": 1,
          "lengthLabel": "1 B",
          "dataType": "uint8",
          "fieldName": "ir_version_tag",
          "description": "Protobuf tag 0x08 (field 1, varint)"
        },
        {
          "offset": "0x01",
          "byteOffset": 1,
          "byteLength": 1,
          "lengthLabel": "1-2 B",
          "dataType": "varint",
          "fieldName": "ir_version",
          "description": "ONNX IR specification version"
        },
        {
          "offset": "0x02+",
          "byteOffset": 2,
          "byteLength": 12,
          "lengthLabel": "var",
          "dataType": "protobuf",
          "fieldName": "producer_and_graph",
          "description": "Producer name, opset_import, and GraphProto"
        }
      ]
    },
    "securityProfile": {
      "riskLevel": "medium",
      "allowsArbitraryCodeOrMacros": false,
      "xxeRisk": false,
      "polyglotPrependRisk": false,
      "pickleDeserializationRisk": false,
      "uploadValidationNotes": "Audit external_data tensor file paths inside TensorProto to block arbitrary local file read (LFI / path traversal) when loading untrusted ONNX models."
    },
    "codeSnippets": {
      "python": "import sys\nwith open(sys.argv[1], \"rb\") as f:\n    b = f.read(32)\n    assert b[0] == 0x08, \"Expected ModelProto.ir_version tag 0x08\"\n    print(f\"ONNX ModelProto IR version={b[1]}\")",
      "typescript": "export async function probeOnnxIr(file: File) {\n  const b = new Uint8Array(await file.slice(0, 8).arrayBuffer());\n  return { validTag: b[0] === 0x08, irVersion: b[1] };\n}",
      "rust": "use std::{fs::File, io::Read};\nfn main() -> std::io::Result<()> {\n    let mut b = [0u8; 4];\n    File::open(std::env::args().nth(1).expect(\"usage: <prog> <file>\"))?.read_exact(&mut b)?;\n    println!(\"ONNX tag=0x{:02x} ir_v={}\", b[0], b[1]);\n    Ok(())\n}",
      "go": "package main\nimport (\"fmt\"; \"io\"; \"os\")\nfunc main() {\n    f, err := os.Open(os.Args[1])\n    if err != nil {\n        fmt.Fprintln(os.Stderr, \"open:\", err)\n        os.Exit(1)\n    }\n    defer f.Close()\n    b := make([]byte, 4)\n    if _, err := io.ReadFull(f, b); err != nil {\n        fmt.Fprintln(os.Stderr, \"read:\", err)\n        os.Exit(1)\n    }\n    fmt.Printf(\"ONNX ir_version=%d\\n\", b[1])\n}"
    },
    "relatedFormats": [
      "safetensors",
      "gguf",
      "pt"
    ],
    "verifiedAt": "2026-11-14T16:09:03Z"
  },
  "samples": [
    {
      "id": "onnx-minimal",
      "filename": "minimal-linear.onnx",
      "variant": "minimal",
      "title": "Minimal ONNX IR v9 Linear+ReLU Graph",
      "description": "Real ONNX ModelProto (ir_version=9, opset=21) verified by onnx.checker.check_model — MatMul + Relu.",
      "localPath": "/fixtures/v1/onnx/minimal-linear.onnx",
      "cdnUrl": "https://fileformat.co/fixtures/v1/onnx/minimal-linear.onnx",
      "sizeBytes": 319,
      "sha256": "aa4e82d69b4579c1a7bfbf12228776f121238825abb64a45e937d4e1299a33fb",
      "expectValid": true
    },
    {
      "id": "onnx-realistic",
      "filename": "mlp-classifier.onnx",
      "variant": "realistic",
      "title": "Realistic MLP Classifier ONNX Graph",
      "description": "onnx.helper-built MLP with float32 TensorProto initializers, Gelu activation — passes onnx.checker.",
      "localPath": "/fixtures/v1/onnx/mlp-classifier.onnx",
      "cdnUrl": "https://fileformat.co/fixtures/v1/onnx/mlp-classifier.onnx",
      "sizeBytes": 702,
      "sha256": "bc52092748c786119aa203b36f61a706a5f40a426b9626ed0469552d9566ff4e",
      "expectValid": true
    },
    {
      "id": "onnx-edge-case",
      "filename": "truncated-protobuf.onnx",
      "variant": "edge-case",
      "title": "Truncated ONNX Protobuf Stream",
      "description": "ModelProto wire frame truncated mid-GraphProto — ModelProto.ParseFromString must raise DecodeError.",
      "localPath": "/fixtures/v1/onnx/truncated-protobuf.onnx",
      "cdnUrl": "https://fileformat.co/fixtures/v1/onnx/truncated-protobuf.onnx",
      "sizeBytes": 56,
      "sha256": "d4db86720670b6fb423cba89dae6fd0d3dc7a92624f836148e6fc29a590b06f4",
      "expectValid": false,
      "edgeCaseTag": "Truncated Protobuf Frame"
    }
  ]
}