Skip to content

Commit

Permalink
[Relay] Change Default "opt_level" of Sequantial from 2 to 0 (#8634)
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnson9009 authored Aug 4, 2021
1 parent 9dfcb22 commit b9204cd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/tvm/ir/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class Sequential(Pass):
The list of passes that the sequential pass is dependent on.
"""

def __init__(self, passes=None, opt_level=2, name="sequential", required=None):
def __init__(self, passes=None, opt_level=0, name="sequential", required=None):
passes = passes if passes else []
if not isinstance(passes, (list, tuple)):
raise TypeError("passes must be a list of Pass objects.")
Expand Down
2 changes: 1 addition & 1 deletion src/ir/transform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ Sequential::Sequential(tvm::Array<Pass> passes, PassInfo pass_info) {
Sequential::Sequential(tvm::Array<Pass> passes, String name) {
auto n = make_object<SequentialNode>();
n->passes = std::move(passes);
PassInfo pass_info = PassInfo(2, std::move(name), {});
PassInfo pass_info = PassInfo(0, std::move(name), {});
n->pass_info = std::move(pass_info);
data_ = std::move(n);
}
Expand Down
28 changes: 28 additions & 0 deletions tests/python/relay/test_pass_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,34 @@ def expected():
assert tvm.ir.structural_equal(zz, zexpected)


def test_nested_sequential_with_scoping():
def before():
x = relay.var("x", shape=(1, 16, 16, 16), dtype="float32")
w = relay.var("w", shape=(32, 16, 3, 3), dtype="float32")
y = relay.nn.conv2d(x, w, padding=(1, 1))
y = relay.reshape(y, newshape=(1, 16, -1))
y = relay.reshape(y, newshape=(4, 8, -1, 16))
y = relay.reverse_reshape(y, newshape=(32, 0, -1))
return tvm.IRModule.from_expr(y)

def expected():
x = relay.var("x", shape=(1, 16, 16, 16), dtype="float32")
w = relay.var("w", shape=(32, 16, 3, 3), dtype="float32")
y = relay.nn.conv2d(x, w, padding=(1, 1))
y = relay.reshape(y, newshape=(32, 16, 16))
return tvm.IRModule.from_expr(y)

z = before()
passes = [
tvm.transform.Sequential([relay.transform.SimplifyExpr()]),
]
with tvm.transform.PassContext(opt_level=1):
zz = tvm.transform.Sequential(passes)(z)

expected = relay.transform.InferType()(expected())
assert tvm.ir.structural_equal(zz, expected)


def test_print_ir(capfd):
shape = (1, 2, 3)
tp = relay.TensorType(shape, "float32")
Expand Down

0 comments on commit b9204cd

Please sign in to comment.