Name | spox JSON |
Version |
0.12.1
JSON |
| download |
home_page | None |
Summary | A framework for constructing ONNX computational graphs. |
upload_time | 2024-06-18 10:54:17 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8.0 |
license | None |
keywords |
machine-learning
onnx
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Spox
[](https://github.com/Quantco/spox/actions/workflows/ci.yml)
[](https://spox.readthedocs.io/en/latest/?badge=latest)
Spox makes it easy to construct [ONNX](https://github.com/onnx/onnx/) models through clean and idiomatic Python code.
## Why use Spox?
A common application of ONNX is converting models from various frameworks. This requires replicating their runtime behaviour with ONNX operators.
In the past this has been a major challenge.
Based on our experience, we designed Spox from the ground up to make the process of writing converters (and ONNX models in general) as easy as possible.
Spox's features include:
- Eager operator validation and type inference
- Errors with Python tracebacks to offending operators
- First-class support for subgraphs (control flow)
- A lean and predictable API
## Installation
Spox releases are available on PyPI:
```bash
pip install spox
```
There is also a package available on conda-forge:
```bash
conda install spox
```
## Quick start
In Spox, you primarily interact with `Var` objects - **variables** - which are placeholders for runtime values.
The initial `Var` objects, which represent the _arguments_ of a model (the model inputs in ONNX nomenclature), are created with an explicit type using the `argument(Type) -> Var` function. The possible types include `Tensor`, `Sequence`, and `Optional`.
All further `Var` objects are created by calling functions which take existing `Var` objects as inputs and produce new `Var` objects as outputs. Spox determines the `Var.type` for these eagerly to allow validation.
Spox provides such functions for all operators in the standard. They are grouped by domain and version in the `spox.opset` submodule.
The final `onnx.ModelProto` object is built by passing input and output `Var`s for the model to the `spox.build` function.
Below is an example for defining an ONNX graph which computes the [geometric mean](https://en.wikipedia.org/wiki/Geometric_mean) of two inputs.
Make sure to consult the Spox [documentation](https://spox.readthedocs.io/en/latest) to find more details and tutorials.
```python
import onnx
from spox import argument, build, Tensor, Var
# Import operators from the ai.onnx domain at version 17
from spox.opset.ai.onnx import v17 as op
def geometric_mean(x: Var, y: Var) -> Var:
# use the standard Sqrt and Mul
return op.sqrt(op.mul(x, y))
# Create typed model inputs. Each tensor is of rank 1
# and has the runtime-determined length 'N'.
a = argument(Tensor(float, ('N',)))
b = argument(Tensor(float, ('N',)))
# Perform operations on `Var`s
c = geometric_mean(a, b)
# Build an `onnx.ModelProto` for the given inputs and outputs.
model: onnx.ModelProto = build(inputs={'a': a, 'b': b}, outputs={'c': c})
```
## Credits
Original designed and developed by [@jbachurski](https://github.com/jbachurski) with the supervision of [@cbourjau](https://github.com/cbourjau).
Raw data
{
"_id": null,
"home_page": null,
"name": "spox",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8.0",
"maintainer_email": "Jakub Bachurski <kbachurski@gmail.com>, Christian Bourjau <christian.bourjau@quantco.com>",
"keywords": "machine-learning, onnx",
"author": null,
"author_email": "Jakub Bachurski <kbachurski@gmail.com>, Christian Bourjau <christian.bourjau@quantco.com>",
"download_url": "https://files.pythonhosted.org/packages/51/e5/a4d19a7b4ad65ecf7a97cea54f597b13215a1455f3a28ba3c4fc4d4a9849/spox-0.12.1.tar.gz",
"platform": null,
"description": "# Spox\n\n[](https://github.com/Quantco/spox/actions/workflows/ci.yml)\n[](https://spox.readthedocs.io/en/latest/?badge=latest)\n\nSpox makes it easy to construct [ONNX](https://github.com/onnx/onnx/) models through clean and idiomatic Python code.\n\n## Why use Spox?\n\nA common application of ONNX is converting models from various frameworks. This requires replicating their runtime behaviour with ONNX operators.\nIn the past this has been a major challenge.\nBased on our experience, we designed Spox from the ground up to make the process of writing converters (and ONNX models in general) as easy as possible.\n\nSpox's features include:\n\n- Eager operator validation and type inference\n- Errors with Python tracebacks to offending operators\n- First-class support for subgraphs (control flow)\n- A lean and predictable API\n\n## Installation\n\nSpox releases are available on PyPI:\n\n```bash\npip install spox\n```\n\nThere is also a package available on conda-forge:\n\n```bash\nconda install spox\n```\n\n## Quick start\n\nIn Spox, you primarily interact with `Var` objects - **variables** - which are placeholders for runtime values.\nThe initial `Var` objects, which represent the _arguments_ of a model (the model inputs in ONNX nomenclature), are created with an explicit type using the `argument(Type) -> Var` function. The possible types include `Tensor`, `Sequence`, and `Optional`.\nAll further `Var` objects are created by calling functions which take existing `Var` objects as inputs and produce new `Var` objects as outputs. Spox determines the `Var.type` for these eagerly to allow validation.\nSpox provides such functions for all operators in the standard. They are grouped by domain and version in the `spox.opset` submodule.\n\nThe final `onnx.ModelProto` object is built by passing input and output `Var`s for the model to the `spox.build` function.\n\nBelow is an example for defining an ONNX graph which computes the [geometric mean](https://en.wikipedia.org/wiki/Geometric_mean) of two inputs.\nMake sure to consult the Spox [documentation](https://spox.readthedocs.io/en/latest) to find more details and tutorials.\n\n```python\nimport onnx\n\nfrom spox import argument, build, Tensor, Var\n# Import operators from the ai.onnx domain at version 17\nfrom spox.opset.ai.onnx import v17 as op\n\ndef geometric_mean(x: Var, y: Var) -> Var:\n # use the standard Sqrt and Mul\n return op.sqrt(op.mul(x, y))\n\n# Create typed model inputs. Each tensor is of rank 1\n# and has the runtime-determined length 'N'.\na = argument(Tensor(float, ('N',)))\nb = argument(Tensor(float, ('N',)))\n\n# Perform operations on `Var`s\nc = geometric_mean(a, b)\n\n# Build an `onnx.ModelProto` for the given inputs and outputs.\nmodel: onnx.ModelProto = build(inputs={'a': a, 'b': b}, outputs={'c': c})\n```\n\n## Credits\n\nOriginal designed and developed by [@jbachurski](https://github.com/jbachurski) with the supervision of [@cbourjau](https://github.com/cbourjau).\n",
"bugtrack_url": null,
"license": null,
"summary": "A framework for constructing ONNX computational graphs.",
"version": "0.12.1",
"project_urls": {
"Source": "https://github.com/quantco/spox"
},
"split_keywords": [
"machine-learning",
" onnx"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "41254c08b87db6a56e77d6d7763302668d3cecb51575e5ffdfc8f2a8d634fea0",
"md5": "94c12ae56800666e1604cc56401de445",
"sha256": "0efc136ed6786417d1b447c8bff614c297f7bb5bee13f5b94d460b7d21abfa6b"
},
"downloads": -1,
"filename": "spox-0.12.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "94c12ae56800666e1604cc56401de445",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8.0",
"size": 236511,
"upload_time": "2024-06-18T10:54:13",
"upload_time_iso_8601": "2024-06-18T10:54:13.742062Z",
"url": "https://files.pythonhosted.org/packages/41/25/4c08b87db6a56e77d6d7763302668d3cecb51575e5ffdfc8f2a8d634fea0/spox-0.12.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "51e5a4d19a7b4ad65ecf7a97cea54f597b13215a1455f3a28ba3c4fc4d4a9849",
"md5": "d16f32b43a9c871328bf6a544b3ad568",
"sha256": "11ac288e8f36b192927a7713337b840289f844345f41a247e4ae6579d89050bb"
},
"downloads": -1,
"filename": "spox-0.12.1.tar.gz",
"has_sig": false,
"md5_digest": "d16f32b43a9c871328bf6a544b3ad568",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8.0",
"size": 350050,
"upload_time": "2024-06-18T10:54:17",
"upload_time_iso_8601": "2024-06-18T10:54:17.663442Z",
"url": "https://files.pythonhosted.org/packages/51/e5/a4d19a7b4ad65ecf7a97cea54f597b13215a1455f3a28ba3c4fc4d4a9849/spox-0.12.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-18 10:54:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "quantco",
"github_project": "spox",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "spox"
}