From 8f6500be4335f4918f4009064c03d819b1d289eb Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Fri, 25 Apr 2025 11:33:36 -0700 Subject: [PATCH 01/13] Add modules --- docs/_templates/classtemplate.rst | 2 +- docs/_templates/functiontemplate.rst | 12 ++++++++++++ docs/api/index.md | 8 ++++++++ docs/api/optimizer.md | 14 ++++++++++++++ docs/api/rewriter.md | 19 +++++++++++++++++++ docs/api/tools.md | 19 ------------------- docs/api/version_converter.md | 10 ++++++++++ docs/intermediate_representation/ir_api.md | 10 ++++++---- 8 files changed, 70 insertions(+), 24 deletions(-) create mode 100644 docs/_templates/functiontemplate.rst create mode 100644 docs/api/optimizer.md create mode 100644 docs/api/rewriter.md delete mode 100644 docs/api/tools.md create mode 100644 docs/api/version_converter.md diff --git a/docs/_templates/classtemplate.rst b/docs/_templates/classtemplate.rst index cd1a21dede..24441c7513 100644 --- a/docs/_templates/classtemplate.rst +++ b/docs/_templates/classtemplate.rst @@ -7,8 +7,8 @@ .. autoclass:: {{ name }} :members: + :inherited-members: .. autogenerated from docs/_templates/classtemplate.rst - note it does not have :inherited-members: diff --git a/docs/_templates/functiontemplate.rst b/docs/_templates/functiontemplate.rst new file mode 100644 index 0000000000..f41fb0d764 --- /dev/null +++ b/docs/_templates/functiontemplate.rst @@ -0,0 +1,12 @@ +.. role:: hidden + :class: hidden-section +.. currentmodule:: {{ module }} + + +{{ name | underline}} + +.. autofunction:: {{ name }} + + +.. + autogenerated from docs/_templates/functiontemplate.rst diff --git a/docs/api/index.md b/docs/api/index.md index 9ae7651003..2ffd17ae24 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -9,6 +9,14 @@ converter values ``` +## Model transformation + +```{toctree} +optimizer +rewriter +version_converter +``` + ## Tests and Tools ```{toctree} diff --git a/docs/api/optimizer.md b/docs/api/optimizer.md new file mode 100644 index 0000000000..29c6cb3224 --- /dev/null +++ b/docs/api/optimizer.md @@ -0,0 +1,14 @@ +# onnxscript.optimizer + +```{eval-rst} +.. currentmodule:: onnxscript +.. autosummary:: + :toctree: generated + :template: functiontemplate.rst + + optimizer.optimize + optimizer.inline + optimizer.basic_constant_propagation + optimizer.fold_constants + optimizer.remove_unused_nodes +``` diff --git a/docs/api/rewriter.md b/docs/api/rewriter.md new file mode 100644 index 0000000000..811f5d6eb1 --- /dev/null +++ b/docs/api/rewriter.md @@ -0,0 +1,19 @@ +# onnxscript.rewriter + +```{eval-rst} +.. currentmodule:: onnxscript +.. autosummary:: + :toctree: generated + :template: functiontemplate.rst + + rewriter.pattern + rewriter.rewrite +``` + +```{eval-rst} +.. autosummary:: + :toctree: generated + :template: classtemplate.rst + + rewriter.RewritePass +``` diff --git a/docs/api/tools.md b/docs/api/tools.md deleted file mode 100644 index 9f565d613c..0000000000 --- a/docs/api/tools.md +++ /dev/null @@ -1,19 +0,0 @@ -# Tools - -## Transformers Models - -```{eval-rst} -.. autofunction:: onnxscript.tools.transformers_models.get_model_and_inputs -``` - -```{eval-rst} -.. autofunction:: onnxscript.tools.transformers_models.phi.get_phi_model_from_config -``` - -```{eval-rst} -.. autofunction:: onnxscript.tools.transformers_models.phi3.get_phi3_model_from_config -``` - -```{eval-rst} -.. autofunction:: onnxscript.tools.transformers_models.llama.get_llama_model_from_config -``` diff --git a/docs/api/version_converter.md b/docs/api/version_converter.md new file mode 100644 index 0000000000..4bc0c4cdee --- /dev/null +++ b/docs/api/version_converter.md @@ -0,0 +1,10 @@ +# onnxscript.version_converter + +```{eval-rst} +.. currentmodule:: onnxscript +.. autosummary:: + :toctree: generated + :template: functiontemplate.rst + + version_converter.convert_version +``` diff --git a/docs/intermediate_representation/ir_api.md b/docs/intermediate_representation/ir_api.md index 0ae18f7453..02d856a81d 100644 --- a/docs/intermediate_representation/ir_api.md +++ b/docs/intermediate_representation/ir_api.md @@ -1,16 +1,15 @@ -# onnxscript.ir +# IR APIs ```{eval-rst} .. automodule::onnxscript.ir ``` -## IR objects +## Classes ```{eval-rst} .. currentmodule:: onnxscript .. autosummary:: :toctree: generated - :nosignatures: :template: classtemplate.rst ir.Model @@ -33,12 +32,15 @@ ir.StringTensor ``` +## Functions + + + ## Enums ```{eval-rst} .. autosummary:: :toctree: generated - :nosignatures: :template: classtemplate.rst ir.DataType From a95023ac995457e403bf5538340e2efac5bac7fb Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Fri, 25 Apr 2025 12:17:16 -0700 Subject: [PATCH 02/13] Update --- docs/api/optimizer.md | 4 ++ docs/api/rewriter.md | 4 ++ docs/api/version_converter.md | 4 ++ docs/intermediate_representation/index.md | 2 + docs/intermediate_representation/ir_api.md | 22 ++++++++--- docs/intermediate_representation/ir_passes.md | 38 +++++++++++++++++++ .../ir_passes_common.md | 24 ++++++++++++ 7 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 docs/intermediate_representation/ir_passes.md create mode 100644 docs/intermediate_representation/ir_passes_common.md diff --git a/docs/api/optimizer.md b/docs/api/optimizer.md index 29c6cb3224..040f007ebc 100644 --- a/docs/api/optimizer.md +++ b/docs/api/optimizer.md @@ -1,7 +1,11 @@ # onnxscript.optimizer ```{eval-rst} +.. automodule::onnxscript.optimizer .. currentmodule:: onnxscript +``` + +```{eval-rst} .. autosummary:: :toctree: generated :template: functiontemplate.rst diff --git a/docs/api/rewriter.md b/docs/api/rewriter.md index 811f5d6eb1..05ec3e6cfe 100644 --- a/docs/api/rewriter.md +++ b/docs/api/rewriter.md @@ -1,7 +1,11 @@ # onnxscript.rewriter ```{eval-rst} +.. automodule::onnxscript.rewriter .. currentmodule:: onnxscript +``` + +```{eval-rst} .. autosummary:: :toctree: generated :template: functiontemplate.rst diff --git a/docs/api/version_converter.md b/docs/api/version_converter.md index 4bc0c4cdee..8fb636edaa 100644 --- a/docs/api/version_converter.md +++ b/docs/api/version_converter.md @@ -1,7 +1,11 @@ # onnxscript.version_converter ```{eval-rst} +.. automodule::onnxscript.version_converter .. currentmodule:: onnxscript +``` + +```{eval-rst} .. autosummary:: :toctree: generated :template: functiontemplate.rst diff --git a/docs/intermediate_representation/index.md b/docs/intermediate_representation/index.md index 0088d5ebeb..be28005f4e 100644 --- a/docs/intermediate_representation/index.md +++ b/docs/intermediate_representation/index.md @@ -20,5 +20,7 @@ An in-memory IR that supports the full ONNX spec, designed for graph constructio getting_started tensors ir_api +ir_passes +ir_passes_common generated ``` diff --git a/docs/intermediate_representation/ir_api.md b/docs/intermediate_representation/ir_api.md index 02d856a81d..edbb105347 100644 --- a/docs/intermediate_representation/ir_api.md +++ b/docs/intermediate_representation/ir_api.md @@ -2,16 +2,32 @@ ```{eval-rst} .. automodule::onnxscript.ir +.. currentmodule:: onnxscript +``` + +## Functions and constructors + +```{eval-rst} +.. autosummary:: + :toctree: generated + :template: classtemplate.rst + + ir.load + ir.save + ir.from_proto + ir.to_proto + ir.tensor + ir.node ``` ## Classes ```{eval-rst} -.. currentmodule:: onnxscript .. autosummary:: :toctree: generated :template: classtemplate.rst + ir.TensorProtocol ir.Model ir.Graph ir.GraphView @@ -32,10 +48,6 @@ ir.StringTensor ``` -## Functions - - - ## Enums ```{eval-rst} diff --git a/docs/intermediate_representation/ir_passes.md b/docs/intermediate_representation/ir_passes.md new file mode 100644 index 0000000000..63957414a7 --- /dev/null +++ b/docs/intermediate_representation/ir_passes.md @@ -0,0 +1,38 @@ +# ir.passes + +```{eval-rst} +.. automodule::onnxscript.ir.passes +.. currentmodule:: onnxscript +``` + +## Use built-in passes + +Common, reusable passes are implemented in {py:module}`ir.passes.common `. You can use {py:class}`ir.passes.Sequential ` to chain passes or use {py:class}`ir.passes.PassManager ` which supports early stopping if no changes are made. + +## Pass infrastructure + +Inherent {py:class}`ir.passes.InPlacePass ` or {py:class}`ir.passes.FunctionalPass ` to define a pass. You will need to implement the `call` method which returns a {py:class}`ir.passes.PassResult `. + +Alternatively, inherent the base class `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 + + ir.passes.PassBase + ir.passes.InPlacePass + ir.passes.FunctionalPass + ir.passes.Sequential + ir.passes.PassResult + ir.passes.PassManager +``` + +## Errors + +```{eval-rst} +.. autoclass:: ir.passes.InvariantError +.. autoclass:: ir.passes.PreconditionError +.. autoclass:: ir.passes.PostconditionError +.. autoclass:: ir.passes.PassError +``` diff --git a/docs/intermediate_representation/ir_passes_common.md b/docs/intermediate_representation/ir_passes_common.md new file mode 100644 index 0000000000..20bf0876c6 --- /dev/null +++ b/docs/intermediate_representation/ir_passes_common.md @@ -0,0 +1,24 @@ +# ir.passes.common + +```{eval-rst} +.. currentmodule:: onnxscript +``` + +## Common passes + + +```{eval-rst} +.. autosummary:: + :toctree: generated + :template: classtemplate.rst + + ir.passes.common.unused_removal.RemoveUnusedNodesPass + ir.passes.common.unused_removal.RemoveUnusedFunctionsPass + ir.passes.common.unused_removal.RemoveUnusedNodesPass + ir.passes.common.inliner.InlinePass + ir.passes.common.topological_sort.TopologicalSortPass + ir.passes.common.constant_manipulation.LiftConstantsToInitializersPass + ir.passes.common.shape_inference.ShapeInferencePass + ir.passes.common.onnx_checker.CheckerPass + ir.passes.common.clear_metadata_and_docstring.ClearMetadataAndDocStringPass +``` From 9396d19a73ef7a107974379a80f1856500b61df3 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Fri, 25 Apr 2025 12:19:10 -0700 Subject: [PATCH 03/13] Create --- docs/intermediate_representation/ir_convenience.md | 0 docs/intermediate_representation/ir_external_data.md | 0 docs/intermediate_representation/ir_serde.md | 0 docs/intermediate_representation/ir_tape.md | 0 docs/intermediate_representation/ir_traversal.md | 0 5 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 docs/intermediate_representation/ir_convenience.md create mode 100644 docs/intermediate_representation/ir_external_data.md create mode 100644 docs/intermediate_representation/ir_serde.md create mode 100644 docs/intermediate_representation/ir_tape.md create mode 100644 docs/intermediate_representation/ir_traversal.md diff --git a/docs/intermediate_representation/ir_convenience.md b/docs/intermediate_representation/ir_convenience.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/intermediate_representation/ir_external_data.md b/docs/intermediate_representation/ir_external_data.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/intermediate_representation/ir_serde.md b/docs/intermediate_representation/ir_serde.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/intermediate_representation/ir_tape.md b/docs/intermediate_representation/ir_tape.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/docs/intermediate_representation/ir_traversal.md b/docs/intermediate_representation/ir_traversal.md new file mode 100644 index 0000000000..e69de29bb2 From d57e9211aba4ee0a18a27c37eafbc2dc31b56621 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Fri, 25 Apr 2025 12:27:11 -0700 Subject: [PATCH 04/13] tape --- .../ir_external_data.md | 20 +++++++++++++++++++ docs/intermediate_representation/ir_serde.md | 0 docs/intermediate_representation/ir_tape.md | 18 +++++++++++++++++ 3 files changed, 38 insertions(+) delete mode 100644 docs/intermediate_representation/ir_serde.md diff --git a/docs/intermediate_representation/ir_external_data.md b/docs/intermediate_representation/ir_external_data.md index e69de29bb2..c70d52f649 100644 --- a/docs/intermediate_representation/ir_external_data.md +++ b/docs/intermediate_representation/ir_external_data.md @@ -0,0 +1,20 @@ +# ir.external_data + +```{eval-rst} +.. automodule::onnxscript.ir.passes +.. currentmodule:: onnxscript +``` + +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:: ir.external_data.load_to_model +.. autofunction:: ir.external_data.unload_from_model +.. autofunction:: ir.external_data.convert_tensors_to_external +.. autofunction:: ir.external_data.convert_tensors_from_external +.. autofunction:: ir.external_data.set_base_dir +``` + + diff --git a/docs/intermediate_representation/ir_serde.md b/docs/intermediate_representation/ir_serde.md deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/docs/intermediate_representation/ir_tape.md b/docs/intermediate_representation/ir_tape.md index e69de29bb2..ed8bd9b245 100644 --- a/docs/intermediate_representation/ir_tape.md +++ b/docs/intermediate_representation/ir_tape.md @@ -0,0 +1,18 @@ +# ir.tape + +```{eval-rst} +.. automodule:: onnxscript.ir.tape +.. currentmodule:: onnxscript +``` + +The `ir.tape` module provides utilities for recording nodes and initializers to construct computational graphs or functions. + +## The `Tape` class + +The `Tape` class is a recorder that collects nodes and initializers created during the construction of a graph or function. It supports creating nodes with single or multiple outputs and registering initializers. + +```{eval-rst} +.. autoclass:: ir.tape.Tape + :members: + :undoc-members: +``` From a8a61511689934ce42b4246d85dbd31268efd358 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Fri, 25 Apr 2025 12:31:11 -0700 Subject: [PATCH 05/13] Rename --- docs/intermediate_representation/index.md | 3 --- .../{ir_api.md => ir_api/index.md} | 12 ++++++++++++ .../{ => ir_api}/ir_convenience.md | 0 .../{ => ir_api}/ir_external_data.md | 0 .../{ => ir_api}/ir_passes.md | 0 .../{ => ir_api}/ir_passes_common.md | 0 .../{ => ir_api}/ir_tape.md | 0 .../ir_api/ir_traversal.md | 12 ++++++++++++ docs/intermediate_representation/ir_traversal.md | 0 9 files changed, 24 insertions(+), 3 deletions(-) rename docs/intermediate_representation/{ir_api.md => ir_api/index.md} (87%) rename docs/intermediate_representation/{ => ir_api}/ir_convenience.md (100%) rename docs/intermediate_representation/{ => ir_api}/ir_external_data.md (100%) rename docs/intermediate_representation/{ => ir_api}/ir_passes.md (100%) rename docs/intermediate_representation/{ => ir_api}/ir_passes_common.md (100%) rename docs/intermediate_representation/{ => ir_api}/ir_tape.md (100%) create mode 100644 docs/intermediate_representation/ir_api/ir_traversal.md delete mode 100644 docs/intermediate_representation/ir_traversal.md diff --git a/docs/intermediate_representation/index.md b/docs/intermediate_representation/index.md index be28005f4e..596049ff00 100644 --- a/docs/intermediate_representation/index.md +++ b/docs/intermediate_representation/index.md @@ -20,7 +20,4 @@ An in-memory IR that supports the full ONNX spec, designed for graph constructio getting_started tensors ir_api -ir_passes -ir_passes_common -generated ``` diff --git a/docs/intermediate_representation/ir_api.md b/docs/intermediate_representation/ir_api/index.md similarity index 87% rename from docs/intermediate_representation/ir_api.md rename to docs/intermediate_representation/ir_api/index.md index edbb105347..b81de59989 100644 --- a/docs/intermediate_representation/ir_api.md +++ b/docs/intermediate_representation/ir_api/index.md @@ -58,3 +58,15 @@ ir.DataType ir.AttributeType ``` + +```{toctree} +:maxdepth: 1 + +ir_convenience +ir_external_data +ir_passes +ir_passes_common +ir_traversal +ir_tape +generated +``` diff --git a/docs/intermediate_representation/ir_convenience.md b/docs/intermediate_representation/ir_api/ir_convenience.md similarity index 100% rename from docs/intermediate_representation/ir_convenience.md rename to docs/intermediate_representation/ir_api/ir_convenience.md diff --git a/docs/intermediate_representation/ir_external_data.md b/docs/intermediate_representation/ir_api/ir_external_data.md similarity index 100% rename from docs/intermediate_representation/ir_external_data.md rename to docs/intermediate_representation/ir_api/ir_external_data.md diff --git a/docs/intermediate_representation/ir_passes.md b/docs/intermediate_representation/ir_api/ir_passes.md similarity index 100% rename from docs/intermediate_representation/ir_passes.md rename to docs/intermediate_representation/ir_api/ir_passes.md diff --git a/docs/intermediate_representation/ir_passes_common.md b/docs/intermediate_representation/ir_api/ir_passes_common.md similarity index 100% rename from docs/intermediate_representation/ir_passes_common.md rename to docs/intermediate_representation/ir_api/ir_passes_common.md diff --git a/docs/intermediate_representation/ir_tape.md b/docs/intermediate_representation/ir_api/ir_tape.md similarity index 100% rename from docs/intermediate_representation/ir_tape.md rename to docs/intermediate_representation/ir_api/ir_tape.md diff --git a/docs/intermediate_representation/ir_api/ir_traversal.md b/docs/intermediate_representation/ir_api/ir_traversal.md new file mode 100644 index 0000000000..e58188fa13 --- /dev/null +++ b/docs/intermediate_representation/ir_api/ir_traversal.md @@ -0,0 +1,12 @@ +# ir.traversal + +```{eval-rst} +.. automodule:: onnxscript.ir.traversal +.. currentmodule:: onnxscript +``` + +```{eval-rst} +.. autoclass:: ir.traversal.RecursiveGraphIterator + :members: + :undoc-members: +``` diff --git a/docs/intermediate_representation/ir_traversal.md b/docs/intermediate_representation/ir_traversal.md deleted file mode 100644 index e69de29bb2..0000000000 From f361305cf694f731abfd39eb1f52ca221fb5acfd Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Fri, 25 Apr 2025 12:32:58 -0700 Subject: [PATCH 06/13] con --- .../ir_api/ir_convenience.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/intermediate_representation/ir_api/ir_convenience.md b/docs/intermediate_representation/ir_api/ir_convenience.md index e69de29bb2..d8cb232d08 100644 --- a/docs/intermediate_representation/ir_api/ir_convenience.md +++ b/docs/intermediate_representation/ir_api/ir_convenience.md @@ -0,0 +1,15 @@ +# ir.convenience + +```{eval-rst} +.. automodule::onnxscript.ir.passes +.. currentmodule:: onnxscript +``` + + +```{eval-rst} +.. autofunction:: convert_attribute +.. autofunction:: cconvert_attributes +.. autofunction:: creplace_all_uses_with +.. autofunction:: creplace_nodes_and_values +.. autofunction:: ccreate_value_mapping +``` From b4544de5ba72177da51e09e7ea3b7766845e5e4f Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Fri, 25 Apr 2025 12:34:40 -0700 Subject: [PATCH 07/13] name --- docs/intermediate_representation/ir_api/ir_convenience.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/intermediate_representation/ir_api/ir_convenience.md b/docs/intermediate_representation/ir_api/ir_convenience.md index d8cb232d08..71bd97a32f 100644 --- a/docs/intermediate_representation/ir_api/ir_convenience.md +++ b/docs/intermediate_representation/ir_api/ir_convenience.md @@ -8,8 +8,8 @@ ```{eval-rst} .. autofunction:: convert_attribute -.. autofunction:: cconvert_attributes -.. autofunction:: creplace_all_uses_with -.. autofunction:: creplace_nodes_and_values -.. autofunction:: ccreate_value_mapping +.. autofunction:: convert_attributes +.. autofunction:: replace_all_uses_with +.. autofunction:: replace_nodes_and_values +.. autofunction:: create_value_mapping ``` From 8b478cbdffbc0acdd2bf64845ec1a5106d1ea6e6 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Fri, 25 Apr 2025 13:35:53 -0700 Subject: [PATCH 08/13] Update --- .gitignore | 2 +- docs/api/index.md | 1 + docs/index.md | 2 +- .../getting_started.ipynb | 0 docs/{intermediate_representation => ir}/index.md | 2 +- .../ir_api/index.md => ir/ir_api/core.md} | 12 ------------ docs/ir/ir_api/index.md | 14 ++++++++++++++ .../ir_api/ir_convenience.md | 4 ++-- .../ir_api/ir_external_data.md | 14 +++++++------- .../ir_api/ir_passes.md | 0 .../ir_api/ir_passes_common.md | 0 .../ir_api/ir_tape.md | 0 .../ir_api/ir_traversal.md | 0 .../{intermediate_representation => ir}/tensors.md | 0 onnxscript/ir/_convenience/__init__.py | 2 +- onnxscript/ir/_core.py | 2 +- onnxscript/ir/_io.py | 4 ++-- onnxscript/ir/external_data.py | 4 ++-- 18 files changed, 33 insertions(+), 30 deletions(-) rename docs/{intermediate_representation => ir}/getting_started.ipynb (100%) rename docs/{intermediate_representation => ir}/index.md (98%) rename docs/{intermediate_representation/ir_api/index.md => ir/ir_api/core.md} (87%) create mode 100644 docs/ir/ir_api/index.md rename docs/{intermediate_representation => ir}/ir_api/ir_convenience.md (74%) rename docs/{intermediate_representation => ir}/ir_api/ir_external_data.md (55%) rename docs/{intermediate_representation => ir}/ir_api/ir_passes.md (100%) rename docs/{intermediate_representation => ir}/ir_api/ir_passes_common.md (100%) rename docs/{intermediate_representation => ir}/ir_api/ir_tape.md (100%) rename docs/{intermediate_representation => ir}/ir_api/ir_traversal.md (100%) rename docs/{intermediate_representation => ir}/tensors.md (100%) diff --git a/.gitignore b/.gitignore index cd616c1321..23ce89a464 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/docs/api/index.md b/docs/api/index.md index 2ffd17ae24..8c878896b7 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -15,6 +15,7 @@ values optimizer rewriter version_converter +generated ``` ## Tests and Tools diff --git a/docs/index.md b/docs/index.md index 3cd5e3db30..4dd0472706 100644 --- a/docs/index.md +++ b/docs/index.md @@ -103,7 +103,7 @@ result = MatmulAdd(x, wt, bias) Overview tutorial/index api/index -intermediate_representation/index +ir/index auto_examples/index articles/index ``` diff --git a/docs/intermediate_representation/getting_started.ipynb b/docs/ir/getting_started.ipynb similarity index 100% rename from docs/intermediate_representation/getting_started.ipynb rename to docs/ir/getting_started.ipynb diff --git a/docs/intermediate_representation/index.md b/docs/ir/index.md similarity index 98% rename from docs/intermediate_representation/index.md rename to docs/ir/index.md index 596049ff00..807dbddb51 100644 --- a/docs/intermediate_representation/index.md +++ b/docs/ir/index.md @@ -19,5 +19,5 @@ An in-memory IR that supports the full ONNX spec, designed for graph constructio getting_started tensors -ir_api +ir_api/index ``` diff --git a/docs/intermediate_representation/ir_api/index.md b/docs/ir/ir_api/core.md similarity index 87% rename from docs/intermediate_representation/ir_api/index.md rename to docs/ir/ir_api/core.md index b81de59989..edbb105347 100644 --- a/docs/intermediate_representation/ir_api/index.md +++ b/docs/ir/ir_api/core.md @@ -58,15 +58,3 @@ ir.DataType ir.AttributeType ``` - -```{toctree} -:maxdepth: 1 - -ir_convenience -ir_external_data -ir_passes -ir_passes_common -ir_traversal -ir_tape -generated -``` diff --git a/docs/ir/ir_api/index.md b/docs/ir/ir_api/index.md new file mode 100644 index 0000000000..e4ab922f34 --- /dev/null +++ b/docs/ir/ir_api/index.md @@ -0,0 +1,14 @@ +# IR API + +```{toctree} +:maxdepth: 1 + +core +ir_convenience +ir_external_data +ir_passes +ir_passes_common +ir_traversal +ir_tape +generated +``` diff --git a/docs/intermediate_representation/ir_api/ir_convenience.md b/docs/ir/ir_api/ir_convenience.md similarity index 74% rename from docs/intermediate_representation/ir_api/ir_convenience.md rename to docs/ir/ir_api/ir_convenience.md index 71bd97a32f..77f09bfe81 100644 --- a/docs/intermediate_representation/ir_api/ir_convenience.md +++ b/docs/ir/ir_api/ir_convenience.md @@ -1,8 +1,8 @@ # ir.convenience ```{eval-rst} -.. automodule::onnxscript.ir.passes -.. currentmodule:: onnxscript +.. automodule::onnxscript.ir.convenience +.. currentmodule:: onnxscript.ir.convenience ``` diff --git a/docs/intermediate_representation/ir_api/ir_external_data.md b/docs/ir/ir_api/ir_external_data.md similarity index 55% rename from docs/intermediate_representation/ir_api/ir_external_data.md rename to docs/ir/ir_api/ir_external_data.md index c70d52f649..faf34514f1 100644 --- a/docs/intermediate_representation/ir_api/ir_external_data.md +++ b/docs/ir/ir_api/ir_external_data.md @@ -1,8 +1,8 @@ # ir.external_data ```{eval-rst} -.. automodule::onnxscript.ir.passes -.. currentmodule:: onnxscript +.. 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. @@ -10,11 +10,11 @@ The `ir.external_data` module provides utilities for handling external data in O ## Functions ```{eval-rst} -.. autofunction:: ir.external_data.load_to_model -.. autofunction:: ir.external_data.unload_from_model -.. autofunction:: ir.external_data.convert_tensors_to_external -.. autofunction:: ir.external_data.convert_tensors_from_external -.. autofunction:: ir.external_data.set_base_dir +.. autofunction:: load_to_model +.. autofunction:: unload_from_model +.. autofunction:: convert_tensors_to_external +.. autofunction:: convert_tensors_from_external +.. autofunction:: set_base_dir ``` diff --git a/docs/intermediate_representation/ir_api/ir_passes.md b/docs/ir/ir_api/ir_passes.md similarity index 100% rename from docs/intermediate_representation/ir_api/ir_passes.md rename to docs/ir/ir_api/ir_passes.md diff --git a/docs/intermediate_representation/ir_api/ir_passes_common.md b/docs/ir/ir_api/ir_passes_common.md similarity index 100% rename from docs/intermediate_representation/ir_api/ir_passes_common.md rename to docs/ir/ir_api/ir_passes_common.md diff --git a/docs/intermediate_representation/ir_api/ir_tape.md b/docs/ir/ir_api/ir_tape.md similarity index 100% rename from docs/intermediate_representation/ir_api/ir_tape.md rename to docs/ir/ir_api/ir_tape.md diff --git a/docs/intermediate_representation/ir_api/ir_traversal.md b/docs/ir/ir_api/ir_traversal.md similarity index 100% rename from docs/intermediate_representation/ir_api/ir_traversal.md rename to docs/ir/ir_api/ir_traversal.md diff --git a/docs/intermediate_representation/tensors.md b/docs/ir/tensors.md similarity index 100% rename from docs/intermediate_representation/tensors.md rename to docs/ir/tensors.md diff --git a/onnxscript/ir/_convenience/__init__.py b/onnxscript/ir/_convenience/__init__.py index 8da5c5b8d2..0addc9da2f 100644 --- a/onnxscript/ir/_convenience/__init__.py +++ b/onnxscript/ir/_convenience/__init__.py @@ -107,7 +107,7 @@ def convert_attribute( A ``Attr`` object. Raises: - ValueError: If :param:`attr` is ``None`` and :param:`attr_type` is not provided. + ValueError: If ``attr`` is ``None`` and ``attr_type`` is not provided. TypeError: If the type of the attribute is not supported. """ if attr is None: diff --git a/onnxscript/ir/_core.py b/onnxscript/ir/_core.py index aa10098cbd..58dad2e6bb 100644 --- a/onnxscript/ir/_core.py +++ b/onnxscript/ir/_core.py @@ -333,7 +333,7 @@ def __init__( value: The backing data of the tensor. It can be a numpy array compatible object or a DLPack compatible object. When the dtype is not one of the numpy native dtypes, the value needs to be ``uint8`` for 4-bit and 8-bit data types, and ``uint16`` for bfloat16 - when the value is a numpy array; :param:`dtype` must be specified in this case. + when the value is a numpy array; ``dtype`` must be specified in this case. dtype: The data type of the tensor. It can be None only when value is a numpy array. Users are responsible for making sure the dtype matches the value when value is not a numpy array. shape: The shape of the tensor. If None, the shape is obtained from the value. diff --git a/onnxscript/ir/_io.py b/onnxscript/ir/_io.py index 0d07992901..a83cfdbd9d 100644 --- a/onnxscript/ir/_io.py +++ b/onnxscript/ir/_io.py @@ -47,7 +47,7 @@ def save( """Save an ONNX model to a file. The model remains unchanged after the call. If any existing external tensor - references the provided :param:`external_data` path, it will be invalidated + references the provided ``external_data`` path, it will be invalidated after the external data is overwritten. To obtain a valid model, use :func:`load` to load the newly saved model, or provide a different external data path that is not currently referenced by any tensors in the model. @@ -64,7 +64,7 @@ def save( with the same external information; if the tensor is not external, it will be serialized in the ONNX Proto message. size_threshold_bytes: Save to external data if the tensor size in bytes is larger than this threshold. - Effective only when :param:`external_data` is set. + Effective only when ``external_data`` is set. Raises: ValueError: If the external data path is an absolute path. diff --git a/onnxscript/ir/external_data.py b/onnxscript/ir/external_data.py index 87524899fd..4ca9ca5036 100644 --- a/onnxscript/ir/external_data.py +++ b/onnxscript/ir/external_data.py @@ -341,7 +341,7 @@ def unload_from_model( and not make any other modifications to the model. If any existing external tensor - references the provided :param:`external_data` path, it will be invalidated + references the provided ``external_data`` path, it will be invalidated after the external data is overwritten. To obtain a valid model, use :func:`load` to load the newly saved model, or provide a different external data path that is not currently referenced by any tensors in the model. @@ -354,7 +354,7 @@ def unload_from_model( size_threshold_bytes: Save to external data if the tensor size in bytes is larger than this threshold. Returns: - An ir.Model with all initializer data equal or above :param:`size_threshold_bytes` + An ir.Model with all initializer data equal or above ``size_threshold_bytes`` converted to external tensors. """ # In-memory or external tensors, if equal to or above the threshold, should be converted to or re-saved as external tensors From eba9aceb1ac901d608d06fa29ad5835a15fd4de6 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Fri, 25 Apr 2025 13:55:16 -0700 Subject: [PATCH 09/13] reorder --- docs/_templates/classtemplate.rst | 3 +-- docs/_templates/classtemplate_inherited.rst | 15 +++++++++++++++ docs/api/index.md | 4 +--- docs/ir/ir_api/core.md | 15 +++++++++------ docs/ir/ir_api/index.md | 3 +-- docs/ir/ir_api/ir_passes.md | 11 ++++++----- docs/ir/ir_api/ir_tape.md | 4 ++-- docs/ir/ir_api/ir_traversal.md | 4 ++-- 8 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 docs/_templates/classtemplate_inherited.rst diff --git a/docs/_templates/classtemplate.rst b/docs/_templates/classtemplate.rst index 24441c7513..c36b2ad1da 100644 --- a/docs/_templates/classtemplate.rst +++ b/docs/_templates/classtemplate.rst @@ -7,8 +7,7 @@ .. autoclass:: {{ name }} :members: - :inherited-members: - + :undoc-members: .. autogenerated from docs/_templates/classtemplate.rst diff --git a/docs/_templates/classtemplate_inherited.rst b/docs/_templates/classtemplate_inherited.rst new file mode 100644 index 0000000000..9c1548fd2e --- /dev/null +++ b/docs/_templates/classtemplate_inherited.rst @@ -0,0 +1,15 @@ +.. role:: hidden + :class: hidden-section +.. currentmodule:: {{ module }} + + +{{ name | underline}} + +.. autoclass:: {{ name }} + :members: + :undoc-members: + :inherited-members: + + +.. + autogenerated from docs/_templates/classtemplate.rst diff --git a/docs/api/index.md b/docs/api/index.md index 8c878896b7..3138592d6a 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -15,12 +15,10 @@ values optimizer rewriter version_converter -generated ``` -## Tests and Tools +## Testing ```{toctree} testing -tools ``` diff --git a/docs/ir/ir_api/core.md b/docs/ir/ir_api/core.md index edbb105347..c612bb13c9 100644 --- a/docs/ir/ir_api/core.md +++ b/docs/ir/ir_api/core.md @@ -1,4 +1,4 @@ -# IR APIs +# onnxscript.ir ```{eval-rst} .. automodule::onnxscript.ir @@ -10,7 +10,8 @@ ```{eval-rst} .. autosummary:: :toctree: generated - :template: classtemplate.rst + :template: functiontemplate.rst + :nosignatures: ir.load ir.save @@ -25,15 +26,16 @@ ```{eval-rst} .. autosummary:: :toctree: generated - :template: classtemplate.rst + :template: classtemplate_inherited.rst + :nosignatures: ir.TensorProtocol - ir.Model + ir.Value + ir.Node ir.Graph + ir.Model ir.GraphView ir.Function - ir.Node - ir.Value ir.Attr ir.RefAttr ir.Shape @@ -54,6 +56,7 @@ .. autosummary:: :toctree: generated :template: classtemplate.rst + :nosignatures: ir.DataType ir.AttributeType diff --git a/docs/ir/ir_api/index.md b/docs/ir/ir_api/index.md index e4ab922f34..c8ed762621 100644 --- a/docs/ir/ir_api/index.md +++ b/docs/ir/ir_api/index.md @@ -1,4 +1,4 @@ -# IR API +# IR APIs ```{toctree} :maxdepth: 1 @@ -10,5 +10,4 @@ ir_passes ir_passes_common ir_traversal ir_tape -generated ``` diff --git a/docs/ir/ir_api/ir_passes.md b/docs/ir/ir_api/ir_passes.md index 63957414a7..10d9d14e9c 100644 --- a/docs/ir/ir_api/ir_passes.md +++ b/docs/ir/ir_api/ir_passes.md @@ -7,7 +7,7 @@ ## Use built-in passes -Common, reusable passes are implemented in {py:module}`ir.passes.common `. You can use {py:class}`ir.passes.Sequential ` to chain passes or use {py:class}`ir.passes.PassManager ` which supports early stopping if no changes are made. +Common, reusable passes are implemented in `ir.passes.common`. You can use {py:class}`ir.passes.Sequential ` to chain passes or use {py:class}`ir.passes.PassManager ` which supports early stopping if no changes are made. ## Pass infrastructure @@ -19,6 +19,7 @@ Alternatively, inherent the base class `ir.passes.PassBase Date: Fri, 25 Apr 2025 14:07:32 -0700 Subject: [PATCH 10/13] Fix --- docs/ir/ir_api/ir_passes_common.md | 5 +++-- onnxscript/ir/_tape.py | 1 + onnxscript/ir/passes/common/__init__.py | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 onnxscript/ir/passes/common/__init__.py diff --git a/docs/ir/ir_api/ir_passes_common.md b/docs/ir/ir_api/ir_passes_common.md index 20bf0876c6..695dc21950 100644 --- a/docs/ir/ir_api/ir_passes_common.md +++ b/docs/ir/ir_api/ir_passes_common.md @@ -4,17 +4,18 @@ .. currentmodule:: onnxscript ``` -## Common passes +## Built-in passes ```{eval-rst} .. autosummary:: :toctree: generated :template: classtemplate.rst + :nosignatures: ir.passes.common.unused_removal.RemoveUnusedNodesPass ir.passes.common.unused_removal.RemoveUnusedFunctionsPass - ir.passes.common.unused_removal.RemoveUnusedNodesPass + ir.passes.common.unused_removal.RemoveUnusedOpsetsPass ir.passes.common.inliner.InlinePass ir.passes.common.topological_sort.TopologicalSortPass ir.passes.common.constant_manipulation.LiftConstantsToInitializersPass diff --git a/onnxscript/ir/_tape.py b/onnxscript/ir/_tape.py index 0a63118d4f..340142df3d 100644 --- a/onnxscript/ir/_tape.py +++ b/onnxscript/ir/_tape.py @@ -26,6 +26,7 @@ class Tape: that they can be used for creating a graph. Example:: + from onnxscript import ir tape = ir.tape.Tape() diff --git a/onnxscript/ir/passes/common/__init__.py b/onnxscript/ir/passes/common/__init__.py new file mode 100644 index 0000000000..59e481eb93 --- /dev/null +++ b/onnxscript/ir/passes/common/__init__.py @@ -0,0 +1,2 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. From fa44004a5203318e18f4dc9bd19e0565dbbeaa9f Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Fri, 25 Apr 2025 14:14:56 -0700 Subject: [PATCH 11/13] update --- docs/_templates/classtemplate.rst | 1 + docs/_templates/classtemplate_inherited.rst | 1 + docs/ir/ir_api/ir_passes.md | 8 ++++---- docs/ir/ir_api/ir_traversal.md | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/_templates/classtemplate.rst b/docs/_templates/classtemplate.rst index c36b2ad1da..24a5ac1803 100644 --- a/docs/_templates/classtemplate.rst +++ b/docs/_templates/classtemplate.rst @@ -8,6 +8,7 @@ .. autoclass:: {{ name }} :members: :undoc-members: + :member-order: bysource .. autogenerated from docs/_templates/classtemplate.rst diff --git a/docs/_templates/classtemplate_inherited.rst b/docs/_templates/classtemplate_inherited.rst index 9c1548fd2e..07c84a9068 100644 --- a/docs/_templates/classtemplate_inherited.rst +++ b/docs/_templates/classtemplate_inherited.rst @@ -9,6 +9,7 @@ :members: :undoc-members: :inherited-members: + :member-order: bysource .. diff --git a/docs/ir/ir_api/ir_passes.md b/docs/ir/ir_api/ir_passes.md index 10d9d14e9c..ba759a0aee 100644 --- a/docs/ir/ir_api/ir_passes.md +++ b/docs/ir/ir_api/ir_passes.md @@ -32,8 +32,8 @@ Alternatively, inherent the base class `ir.passes.PassBase Date: Fri, 25 Apr 2025 14:36:36 -0700 Subject: [PATCH 12/13] update --- docs/api/index.md | 7 +++++++ docs/api/optimizer.md | 1 + docs/api/rewriter.md | 5 ++++- docs/api/rewriter_pattern.md | 39 +++++++++++++++++++++++++++++++++++ docs/api/version_converter.md | 14 +++++++++++++ 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 docs/api/rewriter_pattern.md diff --git a/docs/api/index.md b/docs/api/index.md index 3138592d6a..a6dd4bd59b 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -3,6 +3,8 @@ ## Author Models ```{toctree} +:maxdepth: 1 + decorator opsets converter @@ -12,13 +14,18 @@ values ## Model transformation ```{toctree} +:maxdepth: 1 + optimizer rewriter +rewriter_pattern version_converter ``` ## Testing ```{toctree} +:maxdepth: 1 + testing ``` diff --git a/docs/api/optimizer.md b/docs/api/optimizer.md index 040f007ebc..90de403099 100644 --- a/docs/api/optimizer.md +++ b/docs/api/optimizer.md @@ -9,6 +9,7 @@ .. autosummary:: :toctree: generated :template: functiontemplate.rst + :nosignatures: optimizer.optimize optimizer.inline diff --git a/docs/api/rewriter.md b/docs/api/rewriter.md index 05ec3e6cfe..8ff015844b 100644 --- a/docs/api/rewriter.md +++ b/docs/api/rewriter.md @@ -9,15 +9,18 @@ .. autosummary:: :toctree: generated :template: functiontemplate.rst + :nosignatures: - rewriter.pattern rewriter.rewrite ``` +## IR passes + ```{eval-rst} .. autosummary:: :toctree: generated :template: classtemplate.rst + :nosignatures: rewriter.RewritePass ``` diff --git a/docs/api/rewriter_pattern.md b/docs/api/rewriter_pattern.md new file mode 100644 index 0000000000..a3f1dcbe4b --- /dev/null +++ b/docs/api/rewriter_pattern.md @@ -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 +``` diff --git a/docs/api/version_converter.md b/docs/api/version_converter.md index 8fb636edaa..0478efbf5a 100644 --- a/docs/api/version_converter.md +++ b/docs/api/version_converter.md @@ -5,10 +5,24 @@ .. 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 +``` From 629b712d46324846919b25176f99388225e62105 Mon Sep 17 00:00:00 2001 From: Justin Chu Date: Fri, 25 Apr 2025 14:39:53 -0700 Subject: [PATCH 13/13] init --- onnxscript/ir/passes/common/__init__.py | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/onnxscript/ir/passes/common/__init__.py b/onnxscript/ir/passes/common/__init__.py index 59e481eb93..c211572fd4 100644 --- a/onnxscript/ir/passes/common/__init__.py +++ b/onnxscript/ir/passes/common/__init__.py @@ -1,2 +1,32 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. + +__all__ = [ + "clear_metadata_and_docstring", + "constant_manipulation", + "inliner", + "onnx_checker", + "shape_inference", + "topological_sort", + "unused_removal", +] + +from onnxscript.ir.passes.common import ( + clear_metadata_and_docstring, + constant_manipulation, + inliner, + onnx_checker, + shape_inference, + topological_sort, + unused_removal, +) + + +def __set_module() -> None: + """Set the module of all functions in this module to this public module.""" + global_dict = globals() + for name in __all__: + global_dict[name].__module__ = __name__ + + +__set_module()