Skip to content

Commit 91907e8

Browse files
committed
Merge remote-tracking branch 'origin/main' into codex/tvm-skip-reporting
2 parents 31e1b8a + 7351b84 commit 91907e8

11 files changed

Lines changed: 132 additions & 199 deletions

File tree

README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@ SPDX-License-Identifier: Apache-2.0
88

99
This is a repository of the ONNX Backend Scoreboard which measures the compliance of ONNX backends with the standard.
1010

11-
## 🛠 Maintainer Wanted
12-
13-
We are currently **looking for a new maintainer** to help support and evolve the `backend-scoreboard` project.
14-
15-
If you're passionate about the ONNX standard or contributing to the open source machine learning ecosystem, we'd love to hear from you! This is a great opportunity to contribute to a widely used project and collaborate with the ONNX community.
16-
17-
**To express interest:**
18-
Please open an issue or comment on [this thread](https://github.com/onnx/backend-scoreboard/issues) and let us know about your interest and background.
19-
20-
2111
### :chart_with_upwards_trend: [Check out the scoreboard page](https://onnx.ai/backend-scoreboard/)
2212

2313
- To add another backend to the scoreboard please follow [these instructions](ADD-BACKEND.md).

backends/emx_onnx_cgen/backend.py

Lines changed: 0 additions & 164 deletions
This file was deleted.

backends/tvm/backend.py

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
"""ONNX backend wrapper for Apache TVM (Relay frontend)."""
3+
"""ONNX backend wrapper for Apache TVM (Relay frontend, native ops only)."""
44

5+
import logging
56
import multiprocessing as mp
7+
import sys
68

79
import numpy as np
810
from onnx.backend.base import Backend, BackendRep
911
from onnx.backend.test.runner import BackendIsNotSupposedToImplementIt
1012

13+
logging.basicConfig(level=logging.WARNING)
14+
logger = logging.getLogger(__name__)
15+
16+
17+
def _native_ops_only(model):
18+
"""Return ops in the model that have no native TVM Relay converter.
19+
20+
Uses TVM's internal converter map to detect ops that would silently fall
21+
back to the ONNX reference runtime instead of being compiled natively.
22+
Returns an empty list when the check cannot be performed.
23+
"""
24+
try:
25+
from tvm.relay.frontend.onnx import _get_convert_map
26+
27+
opset = max(
28+
(x.version for x in model.opset_import if x.domain == ""),
29+
default=1,
30+
)
31+
convert_map = _get_convert_map(opset)
32+
unsupported = {n.op_type for n in model.graph.node if n.op_type not in convert_map}
33+
return sorted(unsupported)
34+
except (ImportError, AttributeError):
35+
return []
36+
1137

1238
def _tvm_worker(model_bytes, inputs, input_names, output_count, result_queue):
1339
"""Compile and run an ONNX model via TVM Relay in an isolated subprocess."""
@@ -18,6 +44,14 @@ def _tvm_worker(model_bytes, inputs, input_names, output_count, result_queue):
1844

1945
model = onnx.ModelProto()
2046
model.ParseFromString(model_bytes)
47+
48+
unsupported = _native_ops_only(model)
49+
if unsupported:
50+
msg = f"no native TVM converter for: {unsupported}"
51+
print(f"[tvm] SKIP {msg}", file=sys.stderr, flush=True)
52+
result_queue.put(("error", msg))
53+
return
54+
2155
shape_dict = {
2256
name: np.asarray(inp).shape
2357
for name, inp in zip(input_names, inputs, strict=True)
@@ -33,7 +67,10 @@ def _tvm_worker(model_bytes, inputs, input_names, output_count, result_queue):
3367
outputs = [module.get_output(i).numpy() for i in range(output_count)]
3468
result_queue.put(("ok", outputs))
3569
except (tvm.TVMError, RuntimeError, ValueError, TypeError, OSError) as e:
36-
result_queue.put(("error", str(e)))
70+
ops = sorted({n.op_type for n in model.graph.node})
71+
msg = f"ops={ops} error={type(e).__name__}: {e}"
72+
print(f"[tvm] SKIP {msg}", file=sys.stderr, flush=True)
73+
result_queue.put(("error", msg))
3774

3875

3976
class TVMBackendRep(BackendRep):
@@ -58,13 +95,16 @@ def run(self, inputs, **kwargs):
5895
if p.is_alive():
5996
p.terminate()
6097
p.join()
61-
raise BackendIsNotSupposedToImplementIt("tvm process timed out")
98+
msg = "tvm process timed out"
99+
logger.warning(msg)
100+
raise BackendIsNotSupposedToImplementIt(msg)
62101
if p.exitcode != 0:
63-
raise BackendIsNotSupposedToImplementIt(
64-
f"tvm process crashed (exit code {p.exitcode})"
65-
)
102+
msg = f"tvm process crashed (exit code {p.exitcode})"
103+
logger.warning(msg)
104+
raise BackendIsNotSupposedToImplementIt(msg)
66105
status, result = q.get_nowait()
67106
if status == "error":
107+
logger.warning("tvm skip: %s", result)
68108
raise BackendIsNotSupposedToImplementIt(result)
69109
return result
70110

runtimes/emx-onnx-cgen/stable/Dockerfile

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
1-
FROM ubuntu:22.04
1+
FROM ubuntu:24.04
22

33
# Disable interactive installation mode
44
ENV DEBIAN_FRONTEND=noninteractive
5+
ENV PIP_BREAK_SYSTEM_PACKAGES=1
6+
ENV CC=gcc-14
57

68
# Install Python, gcc and locales dependencies
9+
# emx-onnx-cgen needs a compiler with C23 _BitInt(N) support. Ubuntu 24.04's
10+
# default gcc-13 does not provide it on this target, so install and prefer gcc-14.
711
RUN apt-get update && apt-get install -y \
812
python3 \
913
python3-dev \
1014
python3-pip \
11-
gcc \
15+
gcc-14 \
16+
g++-14 \
1217
locales && \
13-
apt-get clean autoclean && apt-get autoremove -y && \
14-
pip3 install --upgrade pip setuptools wheel
18+
apt-get clean autoclean && apt-get autoremove -y
19+
20+
RUN ln -sf /usr/bin/gcc-14 /usr/bin/gcc && \
21+
ln -sf /usr/bin/g++-14 /usr/bin/g++
1522

1623
# Copy local directories
1724
COPY ./test /root/test
1825
COPY ./setup /root/setup
19-
COPY ./backends/emx_onnx_cgen/backend.py /root/emx_backend.py
2026

2127
# Install test report dependencies
2228
RUN pip3 install --no-cache-dir -r /root/setup/requirements_report.txt
2329

2430
############## ONNX Backend dependencies ###########
25-
ENV ONNX_BACKEND="emx_backend"
26-
ENV PYTHONPATH="/root"
31+
ENV ONNX_BACKEND="emx_onnx_cgen.onnx_backend"
2732

2833
# Set locale which is required for StringNormalizer
2934
RUN locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8
3035

31-
# Install emx-onnx-cgen and onnx
36+
# Install emx-onnx-cgen backend and onnx
3237
RUN pip3 install \
3338
onnx \
3439
emx-onnx-cgen
3540
####################################################
3641

37-
RUN useradd -m -u 1000 runner && chown -R runner:runner /root
42+
RUN useradd -m runner && chown -R runner:runner /root
3843
USER runner
3944
WORKDIR /root
4045

test/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,28 @@
1515
import json
1616
import os
1717

18+
import pytest
19+
1820
from datetime import datetime
1921

2022

2123
# Keys for values to save in report (matched with terminalreporter.stats)
2224
REPORT_KEYS = ["passed", "failed", "skipped"]
2325

26+
# Ops seen across ALL collected test items (populated before -k deselection)
27+
_suite_ops: set = set()
28+
29+
30+
@pytest.hookimpl(tryfirst=True)
31+
def pytest_collection_modifyitems(session, config, items): # noqa: ARG001
32+
"""Collect all op names from onnx_coverage marks before -k deselection."""
33+
for item in items:
34+
for mark in item.iter_markers("onnx_coverage"):
35+
proto = mark.args[0] if mark.args else None
36+
if proto is not None and hasattr(proto, "graph"):
37+
for node in proto.graph.node:
38+
_suite_ops.add(node.op_type)
39+
2440

2541
def pytest_addoption(parser):
2642
"""Pytest hook function."""
@@ -116,6 +132,7 @@ def _prepare_summary(report, package_versions=None):
116132

117133
summary = {"date": report.get("date", datetime.now().strftime("%m/%d/%Y %H:%M:%S"))}
118134
summary["versions"] = package_versions
135+
summary["total_ops"] = len(_suite_ops)
119136
for key in report.keys():
120137
if isinstance(report.get(key), list):
121138
summary[key] = len(report.get(key))

0 commit comments

Comments
 (0)