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
43cc89bf
Commit
43cc89bf
authored
Aug 06, 2019
by
Haichen Shen
Committed by
Zhi
Aug 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Bugfix] Fix the issue that function pass modifies original module (#3712)
* fix * fix interpreter
parent
3b287c4d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
5 deletions
+34
-5
python/tvm/relay/backend/interpreter.py
+2
-2
src/relay/pass/pass_manager.cc
+2
-3
tests/python/relay/test_pass_fuse_ops.py
+30
-0
No files found.
python/tvm/relay/backend/interpreter.py
View file @
43cc89bf
...
...
@@ -269,7 +269,6 @@ class Interpreter(Executor):
self
.
mod
=
mod
self
.
ctx
=
ctx
self
.
target
=
target
self
.
_intrp
=
_backend
.
CreateInterpreter
(
mod
,
ctx
,
target
)
def
optimize
(
self
):
"""Optimize functions in a module.
...
...
@@ -313,5 +312,6 @@ class Interpreter(Executor):
mod
=
self
.
optimize
()
opt_expr
=
Call
(
mod
[
"main"
],
relay_args
)
return
self
.
_intrp
(
opt_expr
)
_intrp
=
_backend
.
CreateInterpreter
(
mod
,
self
.
ctx
,
self
.
target
)
return
_intrp
(
opt_expr
)
return
_interp_wrapper
src/relay/pass/pass_manager.cc
View file @
43cc89bf
...
...
@@ -314,11 +314,10 @@ Module FunctionPassNode::operator()(const Module& mod,
<<
" with opt level: "
<<
pass_info
->
opt_level
;
Module
updated_mod
=
mod
;
// Execute the pass function and return a new module.
Module
updated_mod
=
ModuleNode
::
make
(
mod
->
functions
,
mod
->
type_definitions
);
std
::
vector
<
std
::
pair
<
GlobalVar
,
Function
>
>
updates
;
auto
original
=
mod
->
functions
;
for
(
const
auto
&
it
:
original
)
{
for
(
const
auto
&
it
:
updated_mod
->
functions
)
{
auto
updated_func
=
SkipFunction
(
it
.
second
)
?
it
.
second
:
pass_func
(
it
.
second
,
updated_mod
,
pass_ctx
);
...
...
tests/python/relay/test_pass_fuse_ops.py
View file @
43cc89bf
...
...
@@ -512,6 +512,35 @@ def test_fuse_parallel_injective():
assert
relay
.
analysis
.
alpha_equal
(
zz
,
after
)
def
test_immutable
():
"""Verify the fusion pass won't change original module."""
def
before
():
x
=
relay
.
var
(
"x"
,
shape
=
(
10
,
20
))
y
=
relay
.
add
(
x
,
relay
.
const
(
1
,
"float32"
))
z
=
relay
.
exp
(
y
)
w
=
relay
.
squeeze
(
z
)
mod
=
relay
.
module
.
Module
()
mod
[
"main"
]
=
relay
.
Function
([
x
],
w
)
return
mod
def
expected
():
x
=
relay
.
var
(
"p"
,
shape
=
(
10
,
20
))
y
=
relay
.
add
(
x
,
relay
.
const
(
1
,
"float32"
))
z
=
relay
.
exp
(
y
)
w
=
relay
.
squeeze
(
z
)
f1
=
relay
.
Function
([
x
],
w
)
x
=
relay
.
var
(
"x"
,
shape
=
(
10
,
20
))
y
=
relay
.
Call
(
f1
,
[
x
])
mod
=
relay
.
module
.
Module
()
mod
[
"main"
]
=
relay
.
Function
([
x
],
y
)
return
mod
mod
=
before
()
new_mod
=
transform
.
FuseOps
(
fuse_opt_level
=
2
)(
mod
)
assert
relay
.
analysis
.
alpha_equal
(
mod
,
before
())
assert
relay
.
analysis
.
alpha_equal
(
new_mod
,
expected
())
if
__name__
==
"__main__"
:
test_fuse_simple
()
test_conv2d_fuse
()
...
...
@@ -525,3 +554,4 @@ if __name__ == "__main__":
test_tuple_consecutive
()
test_inception_like
()
test_fuse_parallel_injective
()
test_immutable
()
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