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
65016b65
Commit
65016b65
authored
Oct 11, 2018
by
Steven S. Lyubomirsky
Committed by
Tianqi Chen
Oct 11, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Relay] Alpha equality tests for Relay exprs (#1871)
parent
1eedc945
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
1 deletions
+45
-1
python/tvm/relay/expr.py
+1
-1
src/relay/pass/alpha_eq.cc
+44
-0
tests/python/relay/test_pass_alpha_equal.py
+0
-0
No files found.
python/tvm/relay/expr.py
View file @
65016b65
...
@@ -112,7 +112,7 @@ class Call(Expr):
...
@@ -112,7 +112,7 @@ class Call(Expr):
class
Let
(
Expr
):
class
Let
(
Expr
):
"""A variable bindings in Relay, see tvm/relay/expr.h for more details."""
"""A variable bindings in Relay, see tvm/relay/expr.h for more details."""
def
__init__
(
self
,
var
,
value
,
body
,
value_type
):
def
__init__
(
self
,
var
,
value
,
body
,
value_type
=
None
):
self
.
__init_handle_by_constructor__
(
self
.
__init_handle_by_constructor__
(
_make
.
Let
,
var
,
value
,
body
,
value_type
)
_make
.
Let
,
var
,
value
,
body
,
value_type
)
...
...
src/relay/pass/alpha_eq.cc
View file @
65016b65
...
@@ -268,10 +268,27 @@ struct AlphaEq : ExprFunctor<void(const Expr&, const Expr&)> {
...
@@ -268,10 +268,27 @@ struct AlphaEq : ExprFunctor<void(const Expr&, const Expr&)> {
return
;
return
;
}
}
if
(
func1
->
type_params
.
size
()
!=
func2
->
type_params
.
size
())
{
equal
=
false
;
return
;
}
for
(
size_t
i
=
0U
;
i
<
func1
->
params
.
size
();
i
++
)
{
for
(
size_t
i
=
0U
;
i
<
func1
->
params
.
size
();
i
++
)
{
this
->
VisitExpr
(
func1
->
params
[
i
],
func2
->
params
[
i
]);
this
->
VisitExpr
(
func1
->
params
[
i
],
func2
->
params
[
i
]);
}
}
for
(
size_t
i
=
0U
;
i
<
func1
->
type_params
.
size
();
i
++
)
{
equal
=
equal
&&
AlphaEqual
(
func1
->
type_params
[
i
],
func2
->
type_params
[
i
]);
if
(
!
equal
)
{
return
;
}
}
equal
=
equal
&&
AlphaEqual
(
func1
->
ret_type
,
func2
->
ret_type
);
if
(
!
equal
)
{
return
;
}
this
->
VisitExpr
(
func1
->
body
,
func2
->
body
);
this
->
VisitExpr
(
func1
->
body
,
func2
->
body
);
}
else
{
}
else
{
equal
=
false
;
equal
=
false
;
...
@@ -287,10 +304,27 @@ struct AlphaEq : ExprFunctor<void(const Expr&, const Expr&)> {
...
@@ -287,10 +304,27 @@ struct AlphaEq : ExprFunctor<void(const Expr&, const Expr&)> {
return
;
return
;
}
}
if
(
op
->
type_args
.
size
()
!=
call
->
type_args
.
size
())
{
equal
=
false
;
return
;
}
// checking attrs by pointer equality for now
equal
=
equal
&&
(
op
->
attrs
==
call
->
attrs
);
if
(
!
equal
)
{
return
;
}
for
(
size_t
i
=
0U
;
i
<
op
->
args
.
size
();
i
++
)
{
for
(
size_t
i
=
0U
;
i
<
op
->
args
.
size
();
i
++
)
{
this
->
VisitExpr
(
op
->
args
[
i
],
call
->
args
[
i
]);
this
->
VisitExpr
(
op
->
args
[
i
],
call
->
args
[
i
]);
}
}
for
(
size_t
i
=
0U
;
i
<
op
->
type_args
.
size
();
i
++
)
{
equal
=
equal
&&
AlphaEqual
(
op
->
type_args
[
i
],
call
->
type_args
[
i
]);
if
(
!
equal
)
{
return
;
}
}
}
else
{
}
else
{
equal
=
false
;
equal
=
false
;
}
}
...
@@ -301,6 +335,16 @@ struct AlphaEq : ExprFunctor<void(const Expr&, const Expr&)> {
...
@@ -301,6 +335,16 @@ struct AlphaEq : ExprFunctor<void(const Expr&, const Expr&)> {
eq_map
.
Set
(
op
->
var
,
let
->
var
);
eq_map
.
Set
(
op
->
var
,
let
->
var
);
this
->
VisitExpr
(
op
->
value
,
let
->
value
);
this
->
VisitExpr
(
op
->
value
,
let
->
value
);
this
->
VisitExpr
(
op
->
body
,
let
->
body
);
this
->
VisitExpr
(
op
->
body
,
let
->
body
);
// value_type should match as well (including nulls)
if
(
op
->
value_type
.
defined
()
!=
let
->
value_type
.
defined
())
{
equal
=
false
;
return
;
}
if
(
op
->
value_type
.
defined
())
{
equal
=
equal
&&
AlphaEqual
(
op
->
value_type
,
let
->
value_type
);
}
}
else
{
}
else
{
equal
=
false
;
equal
=
false
;
}
}
...
...
tests/python/relay/test_pass_alpha_equal.py
View file @
65016b65
This diff is collapsed.
Click to expand it.
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