#32998·onnxruntime

[Plugin EP] Graph assignment API returns no subgraphs for an executed Add

Author: edgchen1Created Sep 30, 2026Updated Sep 30, 2026
Labelsplatform:webep:WebGPU

Describe the issue

With session.record_ep_graph_assignment_info=1, InferenceSession.get_provider_graph_assignment_info() (Session_GetEpGraphAssignmentInfo in the C API) returns an empty list for a single-Add model using the released onnxruntime-ep-webgpu plugin package.

CPU fallback is disabled. Inference produces the correct output, and profiling confirms the Add executes on WebGpuExecutionProvider. A CPU-only session reports the same node's assignment correctly.

This issue is reproducible with the WebGPU plugin EP but not necessarily WebGPU EP-specific.

Expected Behavior

One subgraph containing the Add node, assigned to WebGpuExecutionProvider.

To reproduce

Run the repro_webgpu_ep_assignment.py script on a supported platform and device. The script generates its own float32 Add model (opset 7), inputs, and expected output; no ORT checkout or test harness is needed. It obtains the released plugin library and EP name from the onnxruntime_ep_webgpu Python module.

powershell
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install numpy==2.5.3 onnx==1.23.0 onnxruntime==1.24.4 onnxruntime-ep-webgpu==0.4.0
.\.venv\Scripts\python.exe -I repro_webgpu_ep_assignment.py

Observed: CPU reports one assigned node; WebGPU reports zero subgraphs despite executing Add correctly. The script prints the package and plugin details, then prints BUG REPRODUCED and exits 1. Setup or execution failures exit 2. Use --adapter-index N to select a different physical adapter from Dawn's enumeration.

repro_webgpu_ep_assignment.py

python
"""Reproduce missing WebGPU EP assignment records using public Python APIs.

Requires numpy, onnx, onnxruntime, and the onnxruntime-ep-webgpu package.

Run from anywhere (including an ORT checkout) with isolated Python imports:
    python -I repro_webgpu_ep_assignment.py

Exit codes: 0 = assignment reported correctly (or CPU-only control passed),
1 = assignment-reporting bug reproduced, 2 = prerequisite/execution failure.
"""

import argparse
import hashlib
import importlib.metadata
import json
import platform
import sys
import tempfile
from pathlib import Path

try:
    import numpy as np
    import onnx

    import onnxruntime as ort
    import onnxruntime_ep_webgpu as webgpu_ep
except ImportError as error:
    print(
        f"SETUP ERROR: {error}. Install numpy, onnx, onnxruntime, and onnxruntime-ep-webgpu; "
        "use python -I inside a checkout.",
        file=sys.stderr,
    )
    sys.exit(2)


def make_model():
    graph = onnx.helper.make_graph(
        [onnx.helper.make_node("Add", ["A", "B"], ["C"], name="repro_add")],
        "webgpu_assignment_repro",
        [
            onnx.helper.make_tensor_value_info("A", onnx.TensorProto.FLOAT, [3, 1]),
            onnx.helper.make_tensor_value_info("B", onnx.TensorProto.FLOAT, [3]),
        ],
        [onnx.helper.make_tensor_value_info("C", onnx.TensorProto.FLOAT, [3, 3])],
    )
    model = onnx.helper.make_model(graph, opset_imports=[onnx.helper.make_opsetid("", 7)], ir_version=10)
    onnx.checker.check_model(model)
    return model.SerializeToString()


def run_session(model, directory, device=None, provider_options=None):
    target = "CPUExecutionProvider" if device is None else webgpu_ep.get_ep_name()
    options = ort.SessionOptions()
    options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_DISABLE_ALL
    options.add_session_config_entry("session.record_ep_graph_assignment_info", "1")
    options.enable_profiling = True
    options.profile_file_prefix = str(directory / target)
    if device is not None:
        options.add_session_config_entry("session.disable_cpu_ep_fallback", "1")
        options.add_provider_for_devices([device], provider_options or {})

    session = ort.InferenceSession(
        model,
        sess_options=options,
        providers=["CPUExecutionProvider"] if device is None else [],
        enable_fallback=False,
    )
    session.disable_fallback()
    subgraphs = [
        {
            "ep": subgraph.ep_name,
            "nodes": [
                {"name": node.name, "domain": node.domain, "op_type": node.op_type} for node in subgraph.get_nodes()
            ],
        }
        for subgraph in session.get_provider_graph_assignment_info()
    ]
    feeds = {
        "A": np.array([[3], [2], [1]], dtype=np.float32),
        "B": np.array([1, 2, 3], dtype=np.float32),
    }
    try:
        (actual,) = session.run(["C"], feeds)
    finally:
        profile_path = Path(session.end_profiling())
    expected = np.array([[4, 5, 6], [3, 4, 5], [2, 3, 4]], dtype=np.float32)
    if actual.dtype != expected.dtype or actual.shape != expected.shape or not np.array_equal(actual, expected):
        raise RuntimeError(f"{target}: unexpected output: {actual!r}")

    events = json.loads(profile_path.read_text(encoding="utf-8"))
    kernels = [
        {"name": event["name"], "ep": event["args"]["provider"], "op_type": event["args"].get("op_name")}
        for event in events
        if event.get("cat") == "Node" and "provider" in event.get("args", {})
    ]
    report = {
        "target": target,
        "subgraph_count": len(subgraphs),
        "assigned_node_count": sum(len(subgraph["nodes"]) for subgraph in subgraphs),
        "assignments": subgraphs,
        "executed_kernels": kernels,
        "output_matches": True,
    }
    print(json.dumps(report, indent=2), flush=True)
    if len(kernels) != 1 or kernels[0]["ep"] != target or kernels[0]["op_type"] != "Add":
        raise RuntimeError(f"{target}: profiling did not prove execution of exactly one Add on the requested EP")

    expected_assignments = [{"ep": target, "nodes": [{"name": "repro_add", "domain": "", "op_type": "Add"}]}]
    return subgraphs == expected_assignments


def main():
    parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument("--cpu-only", action="store_true", help="Validate only the CPU control, not the WebGPU bug")
    parser.add_argument(
        "--adapter-index",
        type=int,
        default=0,
        help="Index in Dawn's physical adapter enumeration (default: 0)",
    )
    args = parser.parse_args()
    if args.adapter_index < 0:
        parser.error("--adapter-index must be nonnegative")
    if not hasattr(ort.InferenceSession, "get_provider_graph_assignment_info"):
        raise RuntimeError("This ORT Python package does not expose get_provider_graph_assignment_info()")

    print(
        json.dumps(
            {
                "python": sys.version,
                "platform": platform.platform(),
                "ort": ort.__version__,
                "ort_path": ort.__file__,
                "webgpu_ep_package": importlib.metadata.version("onnxruntime-ep-webgpu"),
                "webgpu_ep_package_path": webgpu_ep.__file__,
            }
        )
    )
    model = make_model()
    with tempfile.TemporaryDirectory(prefix="ort-assignment-repro-") as temporary:
        directory = Path(temporary)
        if not run_session(model, directory):
            raise RuntimeError("CPU control failed: the API did not report exactly one CPU Add")
        if args.cpu_only:
            print("CPU CONTROL PASSED; WebGPU was not tested.")
            return 0

        if not hasattr(ort, "register_execution_provider_library") or not hasattr(
            ort.SessionOptions, "add_provider_for_devices"
        ):
            raise RuntimeError("This ORT Python package does not expose the required plugin APIs")
        plugin = Path(webgpu_ep.get_library_path()).resolve(strict=True)
        print(
            json.dumps(
                {
                    "plugin": str(plugin),
                    "plugin_sha256": hashlib.sha256(plugin.read_bytes()).hexdigest(),
                    "plugin_ep_name": webgpu_ep.get_ep_name(),
                }
            )
        )
        registration = "webgpu-assignment-repro"
        ort.register_execution_provider_library(registration, str(plugin))
        devices = [device for device in ort.get_ep_devices() if device.ep_name == webgpu_ep.get_ep_name()]
        if not devices:
            raise RuntimeError(f"No {webgpu_ep.get_ep_name()} device was found")
        device = devices[0]
        print(
            json.dumps(
                {
                    "ep": device.ep_name,
                    "ep_vendor": device.ep_vendor,
                    "ep_metadata": device.ep_metadata,
                    "device_vendor_id": device.device.vendor_id,
                    "device_id": device.device.device_id,
                    "device_metadata": device.device.metadata,
                },
                indent=2,
            )
        )
        reported_correctly = run_session(model, directory, device, {"adapterIndex": str(args.adapter_index)})
        del device, devices
        ort.unregister_execution_provider_library(registration)

    if not reported_correctly:
        print("BUG REPRODUCED: WebGPU executed Add correctly, but the assignment API did not report it exactly once.")
        return 1
    print("BUG NOT REPRODUCED: WebGPU executed Add and the assignment API reported it exactly once.")
    return 0


if __name__ == "__main__":
    try:
        sys.exit(main())
    except Exception as error:
        print(f"SETUP/EXECUTION ERROR (not a confirmed reproduction): {error}", file=sys.stderr)
        sys.exit(2)

Urgency

No response

Platform

Windows

OS Version

Windows 11

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

onnxruntime 1.24.4 from PyPI.

ONNX Runtime API

Python

Architecture

X64

Execution Provider

Other / Unknown

Execution Provider Library Version

onnxruntime-ep-webgpu 0.4.0 from PyPI.