From bfd7bc1f61621ccb9f6365f09b00195dbabdeb6d Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Thu, 24 Apr 2025 14:33:36 -0700 Subject: [PATCH 1/5] Update documentation --- docs/_templates/classtemplate.rst | 14 ++++++++ docs/intermediate_representation/ir_api.md | 41 +++++++++++++++++++--- 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 docs/_templates/classtemplate.rst diff --git a/docs/_templates/classtemplate.rst b/docs/_templates/classtemplate.rst new file mode 100644 index 0000000000..cd1a21dede --- /dev/null +++ b/docs/_templates/classtemplate.rst @@ -0,0 +1,14 @@ +.. role:: hidden + :class: hidden-section +.. currentmodule:: {{ module }} + + +{{ name | underline}} + +.. autoclass:: {{ name }} + :members: + + +.. + autogenerated from docs/_templates/classtemplate.rst + note it does not have :inherited-members: diff --git a/docs/intermediate_representation/ir_api.md b/docs/intermediate_representation/ir_api.md index 2d1d8ebcb6..ad396e3c14 100644 --- a/docs/intermediate_representation/ir_api.md +++ b/docs/intermediate_representation/ir_api.md @@ -1,9 +1,42 @@ # onnxscript.ir - +```{eval-rst} +.. automodule::onnxscript.ir +``` + +## IR objects + +```{eval-rst} +.. autosummary:: + :toctree: generated + :nosignatures: + :template: classtemplate.rst + + Model + Graph + GraphView + Function + Node + Value + Usage + Attr + RefAttr + Shape + SymbolicDim + TypeAndShape + TensorType + SparseTensorType + SequenceType + OptionalType + Tensor + ExternalTensor + StringTensor +``` + +## Enums ```{eval-rst} -.. automodule:: onnxscript.ir - :members: - :undoc-members: +.. autosummary:: + DataType + AttributeType ``` From 13ba35cadb694da1ee8def915b7e5d81d2ea6c52 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Thu, 24 Apr 2025 14:45:51 -0700 Subject: [PATCH 2/5] Update docs --- .gitignore | 1 + docs/intermediate_representation/ir_api.md | 3 +-- docs/intermediate_representation/tensors.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 9e6f1a45cc..cd616c1321 100644 --- a/.gitignore +++ b/.gitignore @@ -100,6 +100,7 @@ dmypy.json *.onnxlib **/onnx_backend_test_code/** docs/auto_examples/* +docs/intermediate_representation/generated/* tests/export/* tests/models/testoutputs/* tests/mylib.onnxlib diff --git a/docs/intermediate_representation/ir_api.md b/docs/intermediate_representation/ir_api.md index ad396e3c14..f997d59a92 100644 --- a/docs/intermediate_representation/ir_api.md +++ b/docs/intermediate_representation/ir_api.md @@ -18,7 +18,6 @@ Function Node Value - Usage Attr RefAttr Shape @@ -38,5 +37,5 @@ ```{eval-rst} .. autosummary:: DataType - AttributeType + AttrType ``` diff --git a/docs/intermediate_representation/tensors.md b/docs/intermediate_representation/tensors.md index 5cd12a2eca..7b46ac2094 100644 --- a/docs/intermediate_representation/tensors.md +++ b/docs/intermediate_representation/tensors.md @@ -167,7 +167,7 @@ The following example shows how to create a `FLOAT8E4M3FN` tensor, transform its print("tensor.numpy():", tensor.numpy()) # [0.00195312 0.00585938] # Compute - times_100 = tensor.numpy() * 100 + times_100 = tensor.numpy() * np.array(100, dtype=tensor.numpy().dtype) print("times_100:", times_100) # Create a new tensor out of the new value; dtype must be specified From 472236e0572797b62c6343b022e473850fe57fb7 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Thu, 24 Apr 2025 14:58:36 -0700 Subject: [PATCH 3/5] update --- docs/intermediate_representation/index.md | 1 + docs/intermediate_representation/ir_api.md | 49 ++++++++++++---------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/docs/intermediate_representation/index.md b/docs/intermediate_representation/index.md index ec6878e69b..7459a0c443 100644 --- a/docs/intermediate_representation/index.md +++ b/docs/intermediate_representation/index.md @@ -6,4 +6,5 @@ getting_started tensors ir_api +generated ``` diff --git a/docs/intermediate_representation/ir_api.md b/docs/intermediate_representation/ir_api.md index f997d59a92..5c2e6271ff 100644 --- a/docs/intermediate_representation/ir_api.md +++ b/docs/intermediate_representation/ir_api.md @@ -2,7 +2,13 @@ ```{eval-rst} .. automodule::onnxscript.ir -``` + +.. contents:: onnxscript.ir + :depth: 2 + :local: + :backlinks: top + +.. currentmodule:: onnxscript ## IR objects @@ -12,30 +18,29 @@ :nosignatures: :template: classtemplate.rst - Model - Graph - GraphView - Function - Node - Value - Attr - RefAttr - Shape - SymbolicDim - TypeAndShape - TensorType - SparseTensorType - SequenceType - OptionalType - Tensor - ExternalTensor - StringTensor + ir.Model + ir.Graph + ir.GraphView + ir.Function + ir.Node + ir.Value + ir.Attr + ir.RefAttr + ir.Shape + ir.SymbolicDim + ir.TypeAndShape + ir.TensorType + ir.SparseTensorType + ir.SequenceType + ir.OptionalType + ir.Tensor + ir.ExternalTensor + ir.StringTensor ``` ## Enums ```{eval-rst} -.. autosummary:: - DataType - AttrType +.. autoclass:: onnxscript.ir.DataType +.. autoclass:: onnxscript.ir.AttrType ``` From 649c04e4e70ad918f7dbd7ebcb7c68e21ee043bc Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Thu, 24 Apr 2025 15:34:32 -0700 Subject: [PATCH 4/5] Update --- docs/intermediate_representation/ir_api.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/intermediate_representation/ir_api.md b/docs/intermediate_representation/ir_api.md index 5c2e6271ff..0ae18f7453 100644 --- a/docs/intermediate_representation/ir_api.md +++ b/docs/intermediate_representation/ir_api.md @@ -2,17 +2,12 @@ ```{eval-rst} .. automodule::onnxscript.ir - -.. contents:: onnxscript.ir - :depth: 2 - :local: - :backlinks: top - -.. currentmodule:: onnxscript +``` ## IR objects ```{eval-rst} +.. currentmodule:: onnxscript .. autosummary:: :toctree: generated :nosignatures: @@ -41,6 +36,11 @@ ## Enums ```{eval-rst} -.. autoclass:: onnxscript.ir.DataType -.. autoclass:: onnxscript.ir.AttrType +.. autosummary:: + :toctree: generated + :nosignatures: + :template: classtemplate.rst + + ir.DataType + ir.AttributeType ``` From 9cca3e932a61cffe1dba48302e810f1543a363e9 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Thu, 24 Apr 2025 15:40:40 -0700 Subject: [PATCH 5/5] index --- docs/intermediate_representation/index.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/intermediate_representation/index.md b/docs/intermediate_representation/index.md index 7459a0c443..0088d5ebeb 100644 --- a/docs/intermediate_representation/index.md +++ b/docs/intermediate_representation/index.md @@ -1,5 +1,19 @@ # ONNX IR +An in-memory IR that supports the full ONNX spec, designed for graph construction, analysis and transformation. + +## Features ✨ + +- Full ONNX spec support: all valid models representable by ONNX protobuf, and a subset of invalid models (so you can load and fix them). +- Low memory footprint: mmap'ed external tensors; unified interface for ONNX TensorProto, Numpy arrays and PyTorch Tensors etc. No tensor size limitation. Zero copies. +- Straightforward access patterns: Access value information and traverse the graph topology at ease. +- Robust mutation: Create as many iterators as you like on the graph while mutating it. +- Speed: Performant graph manipulation, serialization/deserialization to Protobuf. +- Pythonic and familiar APIs: Classes define Pythonic apis and still map to ONNX protobuf concepts in an intuitive way. +- No protobuf dependency: The IR does not require protobuf once the model is converted to the IR representation, decoupling from the serialization format. + +## Get started + ```{toctree} :maxdepth: 1