import { parseOnnx } from '@wetron/onnx';

function parseOnnx(bytes: Uint8Array): ModelGraph;

What is parsed

  • All graph nodes with op type, domain, inputs, outputs, and attributes
  • Graph inputs and outputs with shape and dtype from value_info
  • Initializers - weight tensor shapes and dtypes in ModelGraph.initializers, plus inline bytes via ModelGraph.weights.source.get(name) when weights.kind === "available"
  • Opset imports - graph.opsets: ReadonlyMap<string, number> (domain -> version; "" = ai.onnx)
  • Tensor shapes from value_info entries in the graph proto
  • If, Loop, and Scan subgraphs are inlined with prefixed names (<parent>/<attrName>/...) up to a depth of 4

ONNX-specific fields

node.domain is set for non-standard domains (e.g. com.microsoft, ai.onnx.ml). It is absent for standard ai.onnx operators.

graph.opsets is only set by the ONNX parser. Pass it to NodePropertyPanel via opsets={graph?.opsets} to show opset versions in the node header.

Notes

  • Inline initializer bytes use weights.kind === "available"; the parser indexes them but does not decode until requested. See Weights for decodeWeight, decodeFirstN, and computeStats.
  • Initializers with data_location = EXTERNAL set { kind: "external", format: "onnx" }. Load them via loadOnnxExternalWeightsFromUrl(modelBytes, baseUrl) from @wetron/onnx - see Weights.
  • The parser uses protobufjs - not a hand-rolled binary reader.