Skip to content

Commit b8aae85

Browse files
authored
Merge pull request #1 from crypto-a/main
Rebase
2 parents d2da96e + 1f84cc7 commit b8aae85

120 files changed

Lines changed: 7297 additions & 3812 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ jobs:
4141

4242
steps:
4343
- name: Checkout repository
44-
uses: actions/checkout@v5
44+
uses: actions/checkout@v6
4545

4646
# Initializes the CodeQL tools for scanning.
4747
- name: Initialize CodeQL
48-
uses: github/codeql-action/init@v3
48+
uses: github/codeql-action/init@v4
4949
with:
5050
languages: ${{ matrix.language }}
5151
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -59,7 +59,7 @@ jobs:
5959
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
6060
# If this step fails, then you should remove it and run the build manually (see below)
6161
- name: Autobuild
62-
uses: github/codeql-action/autobuild@v3
62+
uses: github/codeql-action/autobuild@v4
6363

6464
# ℹ️ Command-line programs to run using the OS shell.
6565
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -72,4 +72,4 @@ jobs:
7272
# ./location_of_script_within_repo/buildscript.sh
7373

7474
- name: Perform CodeQL Analysis
75-
uses: github/codeql-action/analyze@v3
75+
uses: github/codeql-action/analyze@v4

.github/workflows/lint.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
pull-requests: write
2121

2222
steps:
23-
- uses: actions/checkout@v5
23+
- uses: actions/checkout@v6
2424
- name: misspell # Check spelling
2525
uses: reviewdog/action-misspell@v1
2626
with:
@@ -43,9 +43,9 @@ jobs:
4343
permissions:
4444
security-events: write
4545
steps:
46-
- uses: actions/checkout@v5
46+
- uses: actions/checkout@v6
4747
- name: Setup Python
48-
uses: actions/setup-python@v5
48+
uses: actions/setup-python@v6
4949
with:
5050
# Version range or exact version of Python to use, using SemVer's version range syntax. Reads from .python-version if unset.
5151
python-version: "3.10"
@@ -78,7 +78,7 @@ jobs:
7878
# To toggle linter comments in the files page, press `i` on the keyboard
7979
if: always()
8080
continue-on-error: true
81-
uses: github/codeql-action/upload-sarif@v3
81+
uses: github/codeql-action/upload-sarif@v4
8282
with:
8383
# Path to SARIF file relative to the root of the repository
8484
sarif_file: lintrunner.sarif

.github/workflows/main.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ jobs:
5757
nox-tag: test-onnx-ir-git
5858
runs-on: ${{ matrix.os }}
5959
steps:
60-
- uses: actions/checkout@v5
60+
- uses: actions/checkout@v6
6161
- name: Setup Python ${{ matrix.python-version }}
62-
uses: actions/setup-python@v5
62+
uses: actions/setup-python@v6
6363
with:
6464
python-version: ${{ matrix.python-version }}
6565
- name: Install nox
@@ -83,7 +83,7 @@ jobs:
8383
token: ${{ secrets.CODECOV_TOKEN }}
8484
- name: Upload torchlib error reports
8585
if: always()
86-
uses: actions/upload-artifact@v4
86+
uses: actions/upload-artifact@v5
8787
with:
8888
name: Error reports (${{ matrix.name }}-${{ matrix.os }})
8989
path: error_reports
@@ -95,9 +95,9 @@ jobs:
9595
os: [ubuntu-latest, windows-latest]
9696
runs-on: ${{ matrix.os }}
9797
steps:
98-
- uses: actions/checkout@v5
98+
- uses: actions/checkout@v6
9999
- name: Setup Python
100-
uses: actions/setup-python@v5
100+
uses: actions/setup-python@v6
101101
with:
102102
python-version: "3.10"
103103
cache: pip
@@ -119,9 +119,9 @@ jobs:
119119
update_readme:
120120
runs-on: ubuntu-latest
121121
steps:
122-
- uses: actions/checkout@v5
122+
- uses: actions/checkout@v6
123123
- name: Setup Python
124-
uses: actions/setup-python@v5
124+
uses: actions/setup-python@v6
125125
- name: Update readme
126126
run: |
127127
python docs/update_readme.py

.github/workflows/pages.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ jobs:
2525
runs-on: ubuntu-latest
2626
steps:
2727
- name: Checkout
28-
uses: actions/checkout@v5
28+
uses: actions/checkout@v6
2929
- name: Setup Pages
3030
uses: actions/configure-pages@v4
3131
- name: Setup Python
32-
uses: actions/setup-python@v5
32+
uses: actions/setup-python@v6
3333
with:
3434
python-version: "3.10"
35-
- uses: actions/checkout@v5
35+
- uses: actions/checkout@v6
3636
- name: Install dependencies
3737
run: |
3838
python -m pip install --upgrade pip setuptools wheel

.lintrunner.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ include_patterns = [
3939
exclude_patterns = [
4040
'tests/**', # Skip linting test files for speed
4141
# FIXME: Fix typing annotations in these files
42+
'examples/custom_op_expansion.py',
4243
'onnxscript/converter_test.py',
4344
'onnxscript/converter.py',
4445
'onnxscript/evaluator_test.py',
@@ -57,7 +58,6 @@ exclude_patterns = [
5758
'onnxscript/rewriter/onnxruntime/transformers/multihead_attention.py', # FIXME
5859
'onnxscript/tools/function_unittest_producer.py', # FIXME
5960
'onnxscript/rewriter/onnxruntime/transformers/layernorm.py', # FIXME
60-
'onnxscript/rewriter/generic_pattern.py', # FIXME
6161
]
6262
command = [
6363
'python',

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.1
1+
0.5.7

docs/api/optimizer.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@
1515
optimizer.inline
1616
optimizer.basic_constant_propagation
1717
optimizer.fold_constants
18-
optimizer.remove_unused_nodes
1918
```

examples/custom_op_expansion.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
# ruff: noqa
4+
5+
"""A utility and an example showing how onnxscript functions can be used to define function expansions
6+
and be used with the inliner to replace calls to the custom function with an expanded subgraph.
7+
This is useful to perform certain classes of graph surgery easily.
8+
"""
9+
10+
import onnx
11+
12+
import onnxscript
13+
import onnxscript.utils.replace as replace
14+
15+
script = onnxscript.script
16+
FLOAT = onnxscript.FLOAT
17+
op = onnxscript.values.opset22
18+
local = onnxscript.values.Opset("local", 1)
19+
20+
21+
# Example Model: Actual models can come from ModelBuilder or Exporter or any other source.
22+
# Models can contain calls to custom operations (from a custom domain like 'local' here or
23+
# even "com.microsoft" etc.)
24+
@script()
25+
def model_script(X: FLOAT["N"], Y: FLOAT["N"]) -> FLOAT["N"]:
26+
DoubleX = op.Add(X, X)
27+
YSquare = op.Mul(Y, Y)
28+
# Example call to a custom operation
29+
Temp1 = local.CustomOp1(DoubleX, YSquare)
30+
# Another call to a custom operation with an attribute
31+
Temp2 = local.CustomOp2(Temp1, alp=0.9)
32+
return Temp2
33+
34+
35+
# Define expansions for custom operations as onnxscript functions
36+
@script(opset=local)
37+
def CustomOp1(X: FLOAT["N"], Y: FLOAT["N"]) -> FLOAT["N"]:
38+
Temp1 = op.Sub(X, Y)
39+
return op.Div(Temp1, X)
40+
41+
42+
@script(opset=local)
43+
def CustomOp2(X: FLOAT["N"], alp: float) -> FLOAT["N"]:
44+
Temp2 = op.Elu(X, alpha=alp)
45+
return op.Mul(Temp2, Temp2)
46+
47+
48+
# Now, we can replace the custom operations in the model with their expansions:
49+
50+
functions = [CustomOp1.to_function_proto(), CustomOp2.to_function_proto()]
51+
52+
model = model_script.to_model_proto()
53+
54+
print("Original Model with custom operations:")
55+
print(onnx.printer.to_text(model))
56+
57+
58+
updated_model = replace.replace_functions(model, functions)
59+
60+
print("\nUpdated Model after replacing custom operations with their expansions:")
61+
print(onnx.printer.to_text(updated_model))

examples/pattern_rewriting.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,3 @@ def rotary_apply_pattern(op, x, pos_ids, axis):
141141
rule = pattern.RewriteRule(rotary_match_pattern, rotary_apply_pattern, verbose=10)
142142

143143
rule.apply_to_model(ir_model)
144-
145-
# TODO(rama): Update the following, the trace-printed looks different now.
146-
147-
######################################
148-
# The logs shows every time the algorithm rejected a pattern.
149-
# We can see the following:
150-
#
151-
# ::
152-
#
153-
# [OnnxGenericPattern.match] NONE - line: 673:onnxscript.rewriter.generic_pattern, op_type=Cast
154-
# --hint--: BACKWARD: different node types
155-
# --pattern
156-
# ConcatTraining(transpose, transpose) -> (output, length)
157-
# -- model
158-
# ConcatTrainingBad(_onx_transpose0, _onx_transpose0) -> (_onx_concattraining0, _onx_concattraining1)
159-
# iteration=1
160-
# --marked-- #2
161-
# Cast(_onx_cos0) ~ Cast(cos) [140186194226496-140186194222320]
162-
# Cos(_onx_concattraining0) ~ Cos(output) [140186194230816-140186194223472]
163-
# len(stacked)=0:[]
164-
#
165-
# Line 673 in file `generic_pattern.py`, the match was rejected.
166-
# It says while comparing two nodes in the backward direction,
167-
# node types do not match.
168-
# It also says that two nodes were actually matched.

noxfile.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313

1414
COMMON_TEST_DEPENDENCIES = (
15-
"beartype==0.17.2",
1615
"expecttest==0.1.6",
1716
"hypothesis",
1817
"numpy",
@@ -30,9 +29,9 @@
3029
"ml-dtypes",
3130
)
3231
ONNX = "onnx==1.17"
33-
ONNX_RUNTIME = "onnxruntime==1.20.1"
34-
PYTORCH = "torch==2.5.1"
35-
TORCHVISON = "torchvision==0.20.1"
32+
ONNX_RUNTIME = "onnxruntime==1.23.0"
33+
PYTORCH = "torch==2.7.1"
34+
TORCHVISON = "torchvision==0.22.1"
3635
TRANSFORMERS = "transformers==4.37.2"
3736
ONNX_RUNTIME_NIGHTLY_DEPENDENCIES = (
3837
"flatbuffers",
@@ -42,7 +41,7 @@
4241
"packaging",
4342
"protobuf",
4443
)
45-
ONNX_IR = "onnx_ir==0.1.7"
44+
ONNX_IR = "onnx_ir==0.1.12"
4645
ONNX_IR_MAIN = "git+https://github.com/onnx/ir-py.git@main#egg=onnx_ir"
4746

4847

0 commit comments

Comments
 (0)