{"id":15654982,"url":"https://github.com/sdpython/onnx-extended","last_synced_at":"2025-10-11T17:40:47.307Z","repository":{"id":152476315,"uuid":"618794416","full_name":"sdpython/onnx-extended","owner":"sdpython","description":"New operators for the ReferenceEvaluator, new kernels for onnxruntime, CPU, CUDA","archived":false,"fork":false,"pushed_at":"2025-03-17T11:52:21.000Z","size":2313,"stargazers_count":32,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-09T23:18:41.216Z","etag":null,"topics":["cuda","machine-learning","onnx","onnxruntime","python"],"latest_commit_sha":null,"homepage":"https://sdpython.github.io/doc/onnx-extended/dev/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sdpython.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOGS.rst","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-25T11:24:53.000Z","updated_at":"2025-03-17T11:52:26.000Z","dependencies_parsed_at":"2024-01-27T12:59:49.259Z","dependency_job_id":"256c1dd8-9ae6-4e54-add3-4efde1a06175","html_url":"https://github.com/sdpython/onnx-extended","commit_stats":{"total_commits":209,"total_committers":4,"mean_commits":52.25,"dds":"0.18181818181818177","last_synced_commit":"87d76642a3e14e3ef14d1d76be27d211dae8f42a"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdpython%2Fonnx-extended","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdpython%2Fonnx-extended/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdpython%2Fonnx-extended/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sdpython%2Fonnx-extended/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sdpython","download_url":"https://codeload.github.com/sdpython/onnx-extended/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125592,"owners_count":21051771,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cuda","machine-learning","onnx","onnxruntime","python"],"created_at":"2024-10-03T12:55:18.325Z","updated_at":"2025-10-11T17:40:42.275Z","avatar_url":"https://github.com/sdpython.png","language":"Python","readme":"\n.. image:: https://github.com/sdpython/onnx-extended/raw/main/_doc/_static/logo.png\n    :width: 120\n\nonnx-extended: extensions for onnx and onnxruntime\n==================================================\n\n.. image:: https://dev.azure.com/xavierdupre3/onnx-extended/_apis/build/status/sdpython.onnx-extended\n    :target: https://dev.azure.com/xavierdupre3/onnx-extended/\n.. image:: https://badge.fury.io/py/onnx-extended.svg\n    :target: http://badge.fury.io/py/onnx-extended\n.. image:: http://img.shields.io/github/issues/sdpython/onnx-extended.png\n    :alt: GitHub Issues\n    :target: https://github.com/sdpython/onnx-extended/issues\n.. image:: https://img.shields.io/badge/license-MIT-blue.svg\n    :alt: MIT License\n    :target: https://opensource.org/license/MIT/\n.. image:: https://img.shields.io/github/repo-size/sdpython/onnx-extended\n    :target: https://github.com/sdpython/onnx-extended/\n    :alt: size\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/psf/black\n\n**onnx-extended** extends the list of supported operators in onnx\nreference implementation and `onnxruntime\n\u003chttps://github.com/microsoft/onnxruntime\u003e`_,\nor implements faster versions in C++.\nDocumentation `onnx-extended\n\u003chttps://sdpython.github.io/doc/onnx-extended/dev/\u003e`_.\nSource are available on `github/onnx-extended\n\u003chttps://github.com/sdpython/onnx-extended/\u003e`_.\n\nUse a C++ implementation of existing operators\n++++++++++++++++++++++++++++++++++++++++++++++\n\n.. code-block:: python\n\n    import timeit\n    import numpy as np\n    from onnx import TensorProto\n    from onnx.helper import (\n        make_graph,\n        make_model,\n        make_node,\n        make_opsetid,\n        make_tensor_value_info,\n    )\n    from onnx.reference import ReferenceEvaluator\n    from onnxruntime import InferenceSession\n    from onnx_extended.ext_test_case import measure_time\n    from onnx_extended.reference import CReferenceEvaluator\n\n\n    X = make_tensor_value_info(\"X\", TensorProto.FLOAT, [None, None, None, None])\n    Y = make_tensor_value_info(\"Y\", TensorProto.FLOAT, [None, None, None, None])\n    B = make_tensor_value_info(\"B\", TensorProto.FLOAT, [None, None, None, None])\n    W = make_tensor_value_info(\"W\", TensorProto.FLOAT, [None, None, None, None])\n    node = make_node(\n        \"Conv\",\n        [\"X\", \"W\", \"B\"],\n        [\"Y\"],\n        pads=[1, 1, 1, 1],\n        dilations=[1, 1],\n        strides=[2, 2],\n    )\n    graph = make_graph([node], \"g\", [X, W, B], [Y])\n    onnx_model = make_model(graph, opset_imports=[make_opsetid(\"\", 16)])\n\n    sH, sW = 64, 64\n    X = np.arange(sW * sH).reshape((1, 1, sH, sW)).astype(np.float32)\n    W = np.ones((1, 1, 3, 3), dtype=np.float32)\n    B = np.array([[[[0]]]], dtype=np.float32)\n\n    sess1 = ReferenceEvaluator(onnx_model)\n    sess2 = CReferenceEvaluator(onnx_model)  # 100 times faster\n\n    expected = sess1.run(None, {\"X\": X, \"W\": W, \"B\": B})[0]\n    got = sess2.run(None, {\"X\": X, \"W\": W, \"B\": B})[0]\n    diff = np.abs(expected - got).max()\n    print(f\"difference: {diff}\")\n\n    f1 = lambda: sess1.run(None, {\"X\": X, \"W\": W, \"B\": B})[0]\n    f2 = lambda: sess2.run(None, {\"X\": X, \"W\": W, \"B\": B})[0]\n    print(\"onnx:\", timeit.timeit(f1, globals=globals(), number=5))\n    print(\"onnx-extended:\", timeit.timeit(f2, globals=globals(), number=5))\n\n::\n\n    difference: 0.0\n    onnx: 0.024006774998269975\n    onnx-extended: 0.0002316169993719086\n\nBuild with CUDA, openmp, eigen, onnxruntime\n+++++++++++++++++++++++++++++++++++++++++++\n\nThe package also contains some dummy examples on how to\nbuild with C++ functions (`pybind11 \u003chttps://github.com/pybind/pybind11\u003e`_,\n`cython \u003chttps://cython.org/\u003e`_),\nwith `openmp \u003chttps://www.openmp.org/\u003e`_,\n`eigen \u003chttps://eigen.tuxfamily.org/index.php\u003e`_\nwith or without CUDA. It also shows how to create a custom operator\nfor *onnxruntime* in C++.\n\nThe version released on `pypi/onnx-extended \u003chttps://pypi.org/project/onnx-extended/\u003e`_\nonly works on CPU. It needs to be manually built to enable\nthe code using CUDA. The build will automatically link with CUDA if it is found.\nIf not, some extensions might not be available.\n\n::\n\n    python setup.py build_ext --inplace\n    # pip install -e .\n\nIt is possible to use a specific version of CUDA:\n\n::\n\n    python setup.py build_ext --inplace --cuda-version=12.6\n    # or (not working yet)\n    # pip install -e . --config-settings=\"--cuda-version=12.6\"\n    # pip install -e . --global-option=\"--cuda-version=12.6\"\n    export USE_CUDA=12.6\n    pip install -e .\n\n`NVTX \u003chttps://github.com/NVIDIA/NVTX\u003e`_\ncan be enabled with the following command:\n\n::\n\n    python setup.py build_ext --inplace --use_nvtx 1\n    # or (not working yet)\n    # pip install -e . --config-settings=\"--use_nvtx=1\"\n    pip install -e . --global-option \"--use_nvtx=1\"\n\nExperimental cython binding for onnxruntime\n+++++++++++++++++++++++++++++++++++++++++++\n\nThe python onnxruntime package relies on pybind11 to expose\nits functionalities. *onnx-extended* tries to build a cython wrapper\naround the C/C++ API of onnxruntime. cython relies on python C API\nand is faster than pybind11. This different may be significant when\nonnxruntime is used on small graphs and tensors.\n\nCustom kernels for onnxruntime\n++++++++++++++++++++++++++++++\n\nonnxruntime provides an API to add custom implementation\nfor existing or new onnx operators. An example for CPU.\n\n::\n\n    from onnxruntime import InferenceSession, SessionOptions\n    from onnx_extended.ortops.optim.cpu import get_ort_ext_libs\n\n    r = get_ort_ext_libs()\n    opts = SessionOptions()\n    if r is not None:\n        opts.register_custom_ops_library(r[0])\n\n    sess_cus = InferenceSession(\n        onx_modified.SerializeToString(), opts, providers=[\"CPUExecutionProvider\"]\n    )\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsdpython%2Fonnx-extended","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsdpython%2Fonnx-extended","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsdpython%2Fonnx-extended/lists"}