Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
07fbe5c8
Unverified
Commit
07fbe5c8
authored
Jun 17, 2019
by
Tianqi Chen
Committed by
GitHub
Jun 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[RELAY][PASS] Enable decorating python class as Pass (#3364)
parent
133bb250
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
201 additions
and
36 deletions
+201
-36
3rdparty/dmlc-core
+1
-1
python/tvm/relay/__init__.py
+1
-0
python/tvm/relay/transform.py
+150
-35
tests/python/relay/test_pass_manager.py
+49
-0
No files found.
dmlc-core
@
fbe142b2
Subproject commit
3943914eed66470bd010df581e29e4dca4f7df6f
Subproject commit
fbe142b267a8edd1f1188fa2140d88f7ae308661
python/tvm/relay/__init__.py
View file @
07fbe5c8
...
...
@@ -101,6 +101,7 @@ const = expr.const
bind
=
expr
.
bind
module_pass
=
transform
.
module_pass
function_pass
=
transform
.
function_pass
alpha_equal
=
ir_pass
.
alpha_equal
# ExprFunctor
ExprFunctor
=
expr_functor
.
ExprFunctor
...
...
python/tvm/relay/transform.py
View file @
07fbe5c8
This diff is collapsed.
Click to expand it.
tests/python/relay/test_pass_manager.py
View file @
07fbe5c8
...
...
@@ -189,6 +189,29 @@ def test_module_pass():
test_pass_run
()
def
test_function_class_pass
():
@relay.transform.function_pass
(
opt_level
=
1
)
class
TestReplaceFunc
:
"""Simple test function to replace one argument to another."""
def
__init__
(
self
,
new_func
):
self
.
new_func
=
new_func
def
transform_function
(
self
,
func
,
mod
,
ctx
):
return
self
.
new_func
x
=
relay
.
var
(
"x"
,
shape
=
(
10
,
20
))
f1
=
relay
.
Function
([
x
],
x
)
f2
=
relay
.
Function
([
x
],
relay
.
log
(
x
))
fpass
=
TestReplaceFunc
(
f1
)
assert
fpass
.
info
.
opt_level
==
1
assert
fpass
.
info
.
name
==
"TestReplaceFunc"
mod
=
relay
.
Module
.
from_expr
(
f2
)
mod
=
fpass
(
mod
)
# wrap in expr
mod2
=
relay
.
Module
.
from_expr
(
f1
)
assert
relay
.
alpha_equal
(
mod
[
"main"
],
mod2
[
"main"
])
def
test_function_pass
():
shape
=
(
10
,
)
dtype
=
'float32'
...
...
@@ -259,6 +282,30 @@ def test_function_pass():
test_pass_run
()
def
test_module_class_pass
():
@relay.transform.module_pass
(
opt_level
=
1
)
class
TestPipeline
:
"""Simple test function to replace one argument to another."""
def
__init__
(
self
,
new_mod
,
replace
):
self
.
new_mod
=
new_mod
self
.
replace
=
replace
def
transform_module
(
self
,
mod
,
ctx
):
if
self
.
replace
:
return
self
.
new_mod
return
mod
x
=
relay
.
var
(
"x"
,
shape
=
(
10
,
20
))
m1
=
relay
.
Module
.
from_expr
(
relay
.
Function
([
x
],
x
))
m2
=
relay
.
Module
.
from_expr
(
relay
.
Function
([
x
],
relay
.
log
(
x
)))
fpass
=
TestPipeline
(
m2
,
replace
=
True
)
assert
fpass
.
info
.
name
==
"TestPipeline"
mod3
=
fpass
(
m1
)
assert
mod3
.
same_as
(
m2
)
mod4
=
TestPipeline
(
m2
,
replace
=
False
)(
m1
)
assert
mod4
.
same_as
(
m1
)
def
test_pass_info
():
info
=
relay
.
transform
.
PassInfo
(
opt_level
=
1
,
name
=
"xyz"
)
assert
info
.
opt_level
==
1
...
...
@@ -451,6 +498,8 @@ def test_sequential_with_scoping():
if
__name__
==
"__main__"
:
test_function_class_pass
()
test_module_class_pass
()
test_module_pass
()
test_function_pass
()
test_sequential_pass
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment