webnn-graph

Reference: ONNX → WebNN Lowering

This reference explains how webnn-graph lowers ONNX graphs into the WebNN DSL.

Key concepts up front

Why simplification is mandatory

Two-phase lowering

1) Prepare the ONNX graph for static lowering

2) Lower the ONNX graph to WebNN DSL

Flow at a glance

flowchart LR
    A["ONNX model (may have symbolic dims)"]
    B["Shape overrides (--override-dim) + constant folding (--optimize)"]
    C["Static shape inference"]
    D["Constant folding: Shape/Gather/Concat/etc"]
    E["Op mapping (OpRegistry)"]
    F["WebNN DSL (.webnn)"]
    G["Weights sidecars (.weights + .manifest.json)"]

    A --> B --> C --> D --> E --> F
    D --> G

How dynamic constructs are handled

Before/after examples for common tricky patterns

Operator mapping (ONNX → WebNN)

Unsupported ops (or ops with remaining dynamism) fail fast with an explicit “unsupported operator” or “WebNN requires static …” message to keep the pipeline predictable.

End-to-end recipe (anchor example: all-MiniLM-L6-v2-webnn)

1) Convert with overrides + folding: