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
aa49e851
Commit
aa49e851
authored
Nov 01, 2019
by
Wuwei Lin
Committed by
Zhi
Nov 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Relay][Pass] Avoid FoldConstant folding some ops (#4245)
* [Relay][Pass] Avoid FoldConstant folding some ops * rename
parent
cd717dea
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
src/relay/pass/fold_constant.cc
+6
-0
tests/python/relay/test_pass_fold_constant.py
+16
-0
No files found.
src/relay/pass/fold_constant.cc
View file @
aa49e851
...
...
@@ -102,6 +102,9 @@ class ConstantFolder : public ExprMutator {
Expr
VisitExpr_
(
const
CallNode
*
call
)
final
{
static
auto
op_stateful
=
Op
::
GetAttr
<
TOpIsStateful
>
(
"TOpIsStateful"
);
std
::
unordered_set
<
std
::
string
>
skip_list
{
"zeros_like"
,
"ones_like"
,
"full_like"
,
"full"
};
auto
origin_args
=
call
->
args
;
Expr
res
=
ExprMutator
::
VisitExpr_
(
call
);
call
=
res
.
as
<
CallNode
>
();
...
...
@@ -111,6 +114,9 @@ class ConstantFolder : public ExprMutator {
if
(
call
->
args
.
size
()
==
0
)
return
res
;
const
OpNode
*
op
=
call
->
op
.
as
<
OpNode
>
();
if
(
op
==
nullptr
)
return
res
;
if
(
skip_list
.
count
(
op
->
name
))
{
return
res
;
}
// skip stateful ops.
if
(
op_stateful
.
get
(
GetRef
<
Op
>
(
op
),
false
))
return
res
;
// Try to evaluate shape_of op
...
...
tests/python/relay/test_pass_fold_constant.py
View file @
aa49e851
...
...
@@ -146,9 +146,25 @@ def test_fold_shape_of():
assert
relay
.
analysis
.
graph_equal
(
zz
,
zexpected
)
def
test_fold_full
():
c_shape
=
(
8
,
9
,
10
)
def
before
():
dtype
=
'float32'
return
relay
.
full
(
relay
.
const
(
1.0
,
dtype
),
c_shape
,
dtype
=
dtype
)
def
expected
():
# expect no changes
return
before
()
zz
=
run_opt_pass
(
before
(),
transform
.
FoldConstant
())
zexpected
=
run_opt_pass
(
expected
(),
transform
.
InferType
())
assert
relay
.
analysis
.
graph_equal
(
zz
,
zexpected
)
if
__name__
==
"__main__"
:
test_fold_const
()
test_fold_let
()
test_fold_tuple
()
test_fold_concat
()
test_fold_shape_of
()
test_fold_full
()
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