Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Dupre <[email protected]>
  • Loading branch information
xadupre committed Jun 27, 2024
2 parents ab552a5 + be00339 commit 12dd1a0
Show file tree
Hide file tree
Showing 251 changed files with 6,631 additions and 1,376 deletions.
30 changes: 25 additions & 5 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,32 @@ jobs:
with:
name: Error reports (${{ matrix.name }}-${{ matrix.os }})
path: error_reports
- name: Upload IR profiling results
if: matrix.name == 'py311' || matrix.name == 'py311-onnx-weekly'
uses: actions/upload-artifact@v3

dort:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
transformers: ["4.37.2", "4.41.2"]
torch: ["release", "nightly"]
python_version: ["3.11"]
nox-tag: ["test-dort"]
name:
- dort
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python_version }}
uses: actions/setup-python@v5
with:
name: IR profiling results
path: tests/ir/serde_test_profiles
python-version: ${{ matrix.python_version }}
- name: Install nox
run: python -m pip install nox
- name: Pull Test Data
run: git lfs pull
- run: |
nox -t ${{ matrix.nox-tag }} --forcecolor -- ${{ matrix.torch }} ${{ matrix.transformers }}
name: Run tests
build_docs:
strategy:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ coverage.xml
cover/
test-output.xml
dump_*/*
*.sarif

# Sphinx documentation
docs/_build/
Expand Down Expand Up @@ -94,6 +95,8 @@ dmypy.json

# Generated files
*.onnx
*.csv
*.xlsx
!testdata/**/*.onnx
*.onnxlib
**/onnx_backend_test_code/**
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ models using a subset of Python. ONNX Script is:
Note however that ONNX Script does **not** intend to support the entirety
of the Python language.

Website: [https://onnxscript.ai/](https://onnxscript.ai/)

## Design Overview

ONNX Script provides a few major capabilities for authoring and debugging
Expand Down
9 changes: 9 additions & 0 deletions docs/api/index.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
# API

## Author Models

```{toctree}
decorator
opsets
converter
values
```

## Tests and Tools

```{toctree}
testing
tools
```
6 changes: 6 additions & 0 deletions docs/api/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Testing

```{eval-rst}
.. automodule:: onnxscript.testing
:members:
```
19 changes: 19 additions & 0 deletions docs/api/tools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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
```
8 changes: 6 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Configuration file for the Sphinx documentation builder.
# To run the documentation: python -m sphinx docs dist/html
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Configuration file for the Sphinx documentation builder.
To run the documentation: python -m sphinx docs dist/html
"""

import os
import re
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/01_plot_selu.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
Generating a FunctionProto
==========================
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/02_plot_square_loss.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
Generating a ModelProto
=======================
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/03_export_lib.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
Generating a LibProto
=====================
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/04_plot_eager_mode_evaluation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
Eager mode evaluation
=====================
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/05_plot_model_props.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
ModelProto Properties
=====================
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/06_plot_model_local_funs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
Model Local Functions
=====================
Expand Down
11 changes: 2 additions & 9 deletions docs/intermediate_representation/getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,12 @@
"metadata": {},
"outputs": [],
"source": [
"import pathlib\n",
"\n",
"import onnx\n",
"\n",
"from onnxscript import ir\n",
"\n",
"# Load the model as onnx.ModelProto\n",
"model_proto = onnx.load(\n",
" pathlib.Path(ir.__file__).parent.parent.parent\n",
" / \"testdata\"\n",
" / \"dort_models\"\n",
" / \"llama_forward.onnx\"\n",
")\n",
"model_proto = onnx.load(\"../../testdata/dort_models/llama_forward.onnx\")\n",
"\n",
"# Create an IR object from the model\n",
"model = ir.serde.deserialize_model(model_proto)"
Expand Down Expand Up @@ -1479,7 +1472,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
4 changes: 1 addition & 3 deletions docs/test/test_documentation_examples.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# --------------------------------------------------------------------------

import os
import subprocess
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/dropout.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/firstdim.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/forloop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/forwhileloop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/hardmax_end_to_end.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import onnx

# We use ONNX opset 15 to define the function below.
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/leaky_relu.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/leaky_relu_attr_promoted.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/omitted_input.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
4 changes: 3 additions & 1 deletion docs/tutorial/examples/outerscope_redef_error.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import graph, script
from onnxscript import opset15 as op

Expand All @@ -13,7 +15,7 @@ def Sum(sum_in, next):
return sum_out, sum_out

g = op.Constant(value=1)
all_sum, cumulative_sum = op.Scan(0, X, body=Sum, num_scan_inputs=1)
_all_sum, cumulative_sum = op.Scan(0, X, body=Sum, num_scan_inputs=1)
return cumulative_sum

except Exception as e:
Expand Down
4 changes: 3 additions & 1 deletion docs/tutorial/examples/scanloop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import graph, script
from onnxscript import opset15 as op

Expand All @@ -9,5 +11,5 @@ def Sum(sum_in, next):
sum_out = sum_in + next
return sum_out, sum_out

all_sum, cumulative_sum = op.Scan(0, X, body=Sum, num_scan_inputs=1)
_all_sum, cumulative_sum = op.Scan(0, X, body=Sum, num_scan_inputs=1)
return cumulative_sum
2 changes: 2 additions & 0 deletions docs/tutorial/examples/softplus.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# We use ONNX opset 15 to define the function below.
from onnxscript import opset15 as op
from onnxscript import script
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/tensor_attr.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnx import TensorProto, helper

from onnxscript import opset15 as op
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/tensor_attr2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnx import TensorProto, helper

from onnxscript import opset15 as op
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/tensor_attr_short.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/whileloop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnx import TensorProto
from onnx.helper import make_tensor

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/rewriter/examples/broadcast_matmul.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Onnx Pattern Rewriting with match condition parameter.
This script shows how to define a rewriting rule based on patterns while
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/rewriter/examples/erfgelu.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Onnx Pattern Rewriting.
This script shows how to define a rewriting rule based on patterns.
Expand Down
6 changes: 4 additions & 2 deletions docs/update_readme.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Script to update end-to-end example in README.md.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Script to update end-to-end example in README.md."""

updated_readme = []
with open("README.md", encoding="utf-8") as f:
Expand All @@ -12,7 +14,7 @@
with open(
"docs/tutorial/examples/hardmax_end_to_end.py", encoding="utf-8"
) as example_f:
example_code = example_f.readlines()
example_code = example_f.readlines()[2:] # Skip the copyright header
updated_readme += example_code
if line == "```\n" and in_stub:
updated_readme.append(line)
Expand Down
6 changes: 5 additions & 1 deletion examples/pattern_rewriting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Onnx Pattern Rewriting.
This script shows how to define a rewriting rule based on patterns.
Expand Down Expand Up @@ -74,7 +76,9 @@ def rotary_match_pattern(op, x, pos_ids, axis):

matmul = op.MatMul(pos_ids, cast)
transpose = op.Transpose(matmul)
output, length = op.ConcatTraining(transpose, transpose, domain="com.microsoft", outputs=2)
output, _length = op.ConcatTraining(
transpose, transpose, domain="com.microsoft", outputs=2
)

sin = op.Sin(output)
cast1 = op.Cast(sin, to=onnx.TensorProto.FLOAT)
Expand Down
Loading

0 comments on commit 12dd1a0

Please sign in to comment.