Skip to content

Commit 738c869

Browse files
committed
Merge with main
Signed-off-by: Ganesan Ramalingam <grama@microsoft.com>
2 parents 1ae7270 + 79afb87 commit 738c869

File tree

75 files changed

+2348
-2021
lines changed

Some content is hidden

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

75 files changed

+2348
-2021
lines changed

.lintrunner.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ exclude_patterns = [
5757
'onnxscript/rewriter/onnxruntime/transformers/multihead_attention.py', # FIXME
5858
'onnxscript/tools/function_unittest_producer.py', # FIXME
5959
'onnxscript/rewriter/onnxruntime/transformers/layernorm.py', # FIXME
60-
'onnxscript/rewriter/generic_pattern.py', # FIXME
6160
]
6261
command = [
6362
'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.2

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"packaging",
4343
"protobuf",
4444
)
45-
ONNX_IR = "onnx_ir==0.1.7"
45+
ONNX_IR = "onnx_ir==0.1.9"
4646
ONNX_IR_MAIN = "git+https://github.com/onnx/ir-py.git@main#egg=onnx_ir"
4747

4848

onnxscript/function_libs/torch_lib/ops/common.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# mypy: disable-error-code="misc,arg-type,type-arg,valid-type,assignment,return-value"
66
from __future__ import annotations
77

8+
from collections.abc import Sequence
9+
810
import numpy.typing as npt
911
import onnx
1012

@@ -78,3 +80,22 @@ def constant(
7880
A constant node.
7981
"""
8082
return op.Constant(value=ir.tensor(array, dtype=ir.DataType(dtype)))
83+
84+
85+
def merge_dims(dims: Sequence[int | INT64]) -> INT64:
86+
"""Concatenate dimensions into a single value."""
87+
88+
if not dims:
89+
return op.Constant(value_ints=ir.AttrInt64s("value_ints", []))
90+
91+
neg_one_1d = op.Constant(value_ints=ir.AttrInt64s("value_ints", [-1]))
92+
93+
result_dims = [
94+
op.Constant(value_ints=[d]) if isinstance(d, int) else op.Reshape(d, neg_one_1d)
95+
for d in dims
96+
]
97+
98+
# Set the output type to INT64 so op.Concat can be used
99+
for dim in result_dims:
100+
dim.dtype = ir.DataType.INT64
101+
return op.Concat(*result_dims, axis=0)

0 commit comments

Comments
 (0)