Skip to content

Improvement to IR docs 2/n #2229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ dmypy.json
*.onnxlib
**/onnx_backend_test_code/**
docs/auto_examples/*
docs/intermediate_representation/generated/*
docs/**/generated/*
tests/export/*
tests/models/testoutputs/*
tests/mylib.onnxlib
Expand Down
4 changes: 2 additions & 2 deletions docs/_templates/classtemplate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

.. autoclass:: {{ name }}
:members:

:undoc-members:
:member-order: bysource

..
autogenerated from docs/_templates/classtemplate.rst
note it does not have :inherited-members:
16 changes: 16 additions & 0 deletions docs/_templates/classtemplate_inherited.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.. role:: hidden
:class: hidden-section
.. currentmodule:: {{ module }}


{{ name | underline}}

.. autoclass:: {{ name }}
:members:
:undoc-members:
:inherited-members:
:member-order: bysource


..
autogenerated from docs/_templates/classtemplate.rst
12 changes: 12 additions & 0 deletions docs/_templates/functiontemplate.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.. role:: hidden
:class: hidden-section
.. currentmodule:: {{ module }}


{{ name | underline}}

.. autofunction:: {{ name }}


..
autogenerated from docs/_templates/functiontemplate.rst
18 changes: 16 additions & 2 deletions docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@
## Author Models

```{toctree}
:maxdepth: 1

decorator
opsets
converter
values
```

## Tests and Tools
## Model transformation

```{toctree}
:maxdepth: 1

optimizer
rewriter
rewriter_pattern
version_converter
```

## Testing

```{toctree}
:maxdepth: 1

testing
tools
```
19 changes: 19 additions & 0 deletions docs/api/optimizer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# onnxscript.optimizer

```{eval-rst}
.. automodule::onnxscript.optimizer
.. currentmodule:: onnxscript
```

```{eval-rst}
.. autosummary::
:toctree: generated
:template: functiontemplate.rst
:nosignatures:

optimizer.optimize
optimizer.inline
optimizer.basic_constant_propagation
optimizer.fold_constants
optimizer.remove_unused_nodes
```
26 changes: 26 additions & 0 deletions docs/api/rewriter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# onnxscript.rewriter

```{eval-rst}
.. automodule::onnxscript.rewriter
.. currentmodule:: onnxscript
```

```{eval-rst}
.. autosummary::
:toctree: generated
:template: functiontemplate.rst
:nosignatures:

rewriter.rewrite
```

## IR passes

```{eval-rst}
.. autosummary::
:toctree: generated
:template: classtemplate.rst
:nosignatures:

rewriter.RewritePass
```
39 changes: 39 additions & 0 deletions docs/api/rewriter_pattern.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# onnxscript.rewriter.pattern

```{eval-rst}
.. automodule::onnxscript.rewriter.pattern
.. currentmodule:: onnxscript
```

```{eval-rst}
.. autosummary::
:toctree: generated
:template: classtemplate.rst
:nosignatures:

rewriter.pattern.Pattern
rewriter.pattern.StringPattern
rewriter.pattern.StringConstantPattern
rewriter.pattern.PrefixPattern
rewriter.pattern.AttrPattern
rewriter.pattern.AttrConstantPattern
rewriter.pattern.OpsetPatternBuilder
rewriter.pattern.OpPatternBuilder
rewriter.pattern.MatchResult
rewriter.pattern.ValuePattern
rewriter.pattern.NodePattern
rewriter.pattern.NodeOutputPattern
rewriter.pattern.AnyValue
rewriter.pattern.Constant
rewriter.pattern.GraphPattern
rewriter.pattern.ReplacementSubgraph
rewriter.pattern.ReplacementPatternFunction
rewriter.pattern.PatternMatcher
rewriter.pattern.SimplePatternMatcher
rewriter.pattern.RewriteRule
rewriter.pattern.RewriteRuleAsClass
rewriter.pattern.RewriteRuleSet
rewriter.pattern.MatchStatus
rewriter.pattern.MatchInfo
rewriter.pattern.MatchingTracer
```
19 changes: 0 additions & 19 deletions docs/api/tools.md

This file was deleted.

28 changes: 28 additions & 0 deletions docs/api/version_converter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# onnxscript.version_converter

```{eval-rst}
.. automodule::onnxscript.version_converter
.. currentmodule:: onnxscript
```

## Functions

```{eval-rst}
.. autosummary::
:toctree: generated
:template: functiontemplate.rst
:nosignatures:

version_converter.convert_version
```

## IR passes

```{eval-rst}
.. autosummary::
:toctree: generated
:template: classtemplate.rst
:nosignatures:

version_converter.ConvertVersionPass
```
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ result = MatmulAdd(x, wt, bias)
Overview <self>
tutorial/index
api/index
intermediate_representation/index
ir/index
auto_examples/index
articles/index
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ An in-memory IR that supports the full ONNX spec, designed for graph constructio

getting_started
tensors
ir_api
generated
ir_api/index
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,40 @@

```{eval-rst}
.. automodule::onnxscript.ir
.. currentmodule:: onnxscript
```

## IR objects
## Functions and constructors

```{eval-rst}
.. currentmodule:: onnxscript
.. autosummary::
:toctree: generated
:template: functiontemplate.rst
:nosignatures:
:template: classtemplate.rst

ir.Model
ir.load
ir.save
ir.from_proto
ir.to_proto
ir.tensor
ir.node
```

## Classes

```{eval-rst}
.. autosummary::
:toctree: generated
:template: classtemplate_inherited.rst
:nosignatures:

ir.TensorProtocol
ir.Value
ir.Node
ir.Graph
ir.Model
ir.GraphView
ir.Function
ir.Node
ir.Value
ir.Attr
ir.RefAttr
ir.Shape
Expand All @@ -38,8 +55,8 @@
```{eval-rst}
.. autosummary::
:toctree: generated
:nosignatures:
:template: classtemplate.rst
:nosignatures:

ir.DataType
ir.AttributeType
Expand Down
13 changes: 13 additions & 0 deletions docs/ir/ir_api/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# IR APIs

```{toctree}
:maxdepth: 1

core
ir_convenience
ir_external_data
ir_passes
ir_passes_common
ir_traversal
ir_tape
```
15 changes: 15 additions & 0 deletions docs/ir/ir_api/ir_convenience.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ir.convenience

```{eval-rst}
.. automodule::onnxscript.ir.convenience
.. currentmodule:: onnxscript.ir.convenience
```


```{eval-rst}
.. autofunction:: convert_attribute
.. autofunction:: convert_attributes
.. autofunction:: replace_all_uses_with
.. autofunction:: replace_nodes_and_values
.. autofunction:: create_value_mapping
```
20 changes: 20 additions & 0 deletions docs/ir/ir_api/ir_external_data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ir.external_data

```{eval-rst}
.. automodule::onnxscript.ir.external_data
.. currentmodule:: onnxscript.ir.external_data
```

The `ir.external_data` module provides utilities for handling external data in ONNX models. It enables the conversion of tensors to and from external data files, allowing for efficient storage and manipulation of large tensor data. This is particularly useful for models with large initializers that exceed memory constraints.

## Functions

```{eval-rst}
.. autofunction:: load_to_model
.. autofunction:: unload_from_model
.. autofunction:: convert_tensors_to_external
.. autofunction:: convert_tensors_from_external
.. autofunction:: set_base_dir
```

<!-- TODO: Create examples -->
39 changes: 39 additions & 0 deletions docs/ir/ir_api/ir_passes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ir.passes

```{eval-rst}
.. automodule::onnxscript.ir.passes
.. currentmodule:: onnxscript
```

## Use built-in passes

Common, reusable passes are implemented in `ir.passes.common`. You can use {py:class}`ir.passes.Sequential <onnxscript.ir.passes.Sequential>` to chain passes or use {py:class}`ir.passes.PassManager <onnxscript.ir.passes.PassManager>` which supports early stopping if no changes are made.

## Pass infrastructure

Inherent {py:class}`ir.passes.InPlacePass <onnxscript.ir.passes.InPlacePass>` or {py:class}`ir.passes.FunctionalPass <onnxscript.ir.passes.FunctionalPass>` to define a pass. You will need to implement the `call` method which returns a {py:class}`ir.passes.PassResult <onnxscript.ir.passes.PassResult>`.

Alternatively, inherent the base class `ir.passes.PassBase <onnxscript.ir.passes.PassBase>` and override the two properties `changes_input` and `in_place` to set properties of the pass.

```{eval-rst}
.. autosummary::
:toctree: generated
:template: classtemplate.rst
:nosignatures:

ir.passes.PassBase
ir.passes.InPlacePass
ir.passes.FunctionalPass
ir.passes.Sequential
ir.passes.PassResult
ir.passes.PassManager
```

## Errors

```{eval-rst}
.. autoexception:: onnxscript.ir.passes.InvariantError
.. autoexception:: onnxscript.ir.passes.PreconditionError
.. autoexception:: onnxscript.ir.passes.PostconditionError
.. autoexception:: onnxscript.ir.passes.PassError
```
Loading
Loading