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
e470f8ea
Commit
e470f8ea
authored
Nov 14, 2018
by
Wuwei Lin
Committed by
Tianqi Chen
Nov 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[RELAY] Fix type info after mutation in simplify inference (#2093)
parent
ba3ddcd7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
9 deletions
+24
-9
src/relay/pass/simplify_inference.cc
+21
-6
tests/python/relay/test_pass_simplify_inference.py
+3
-3
No files found.
src/relay/pass/simplify_inference.cc
View file @
e470f8ea
...
@@ -15,7 +15,8 @@ Expr BatchNormToInferUnpack(const Attrs attrs,
...
@@ -15,7 +15,8 @@ Expr BatchNormToInferUnpack(const Attrs attrs,
Expr
gamma
,
Expr
gamma
,
Expr
beta
,
Expr
beta
,
Expr
moving_mean
,
Expr
moving_mean
,
Expr
moving_var
)
{
Expr
moving_var
,
Type
tdata
)
{
const
auto
param
=
attrs
.
as
<
BatchNormAttrs
>
();
const
auto
param
=
attrs
.
as
<
BatchNormAttrs
>
();
Expr
epsilon
=
MakeConstantScalar
(
Float
(
32
),
static_cast
<
float
>
(
param
->
epsilon
));
Expr
epsilon
=
MakeConstantScalar
(
Float
(
32
),
static_cast
<
float
>
(
param
->
epsilon
));
Expr
var_add_eps
=
Add
(
moving_var
,
epsilon
);
Expr
var_add_eps
=
Add
(
moving_var
,
epsilon
);
...
@@ -32,9 +33,11 @@ Expr BatchNormToInferUnpack(const Attrs attrs,
...
@@ -32,9 +33,11 @@ Expr BatchNormToInferUnpack(const Attrs attrs,
}
}
int
axis
=
param
->
axis
;
int
axis
=
param
->
axis
;
const
auto
*
tdata
=
data
->
type_as
<
TensorTypeNode
>
();
auto
ttype
=
tdata
.
as
<
TensorTypeNode
>
();
scale
=
ExpandBiasToMatchAxis
(
scale
,
tdata
->
shape
.
size
(),
{
axis
});
CHECK
(
ttype
);
shift
=
ExpandBiasToMatchAxis
(
shift
,
tdata
->
shape
.
size
(),
{
axis
});
auto
ndim
=
ttype
->
shape
.
size
();
scale
=
ExpandBiasToMatchAxis
(
scale
,
ndim
,
{
axis
});
shift
=
ExpandBiasToMatchAxis
(
shift
,
ndim
,
{
axis
});
Expr
out
=
Multiply
(
data
,
scale
);
Expr
out
=
Multiply
(
data
,
scale
);
out
=
Add
(
out
,
shift
);
out
=
Add
(
out
,
shift
);
...
@@ -54,14 +57,26 @@ class InferenceSimplifier : public ExprMutator {
...
@@ -54,14 +57,26 @@ class InferenceSimplifier : public ExprMutator {
}
}
if
(
const
auto
*
call
=
new_n
->
tuple
.
as
<
CallNode
>
())
{
if
(
const
auto
*
call
=
new_n
->
tuple
.
as
<
CallNode
>
())
{
if
(
call
->
op
.
same_as
(
batch_norm
))
{
if
(
call
->
op
.
same_as
(
batch_norm
))
{
return
BatchNormToInferUnpack
(
call
->
attrs
,
return
BatchNormToInferUnpack
(
call
->
attrs
,
call
->
args
[
0
],
call
->
args
[
1
],
call
->
args
[
2
],
call
->
args
[
0
],
call
->
args
[
1
],
call
->
args
[
2
],
call
->
args
[
3
],
call
->
args
[
4
]
);
call
->
args
[
3
],
call
->
args
[
4
],
ty_map_
.
at
(
call
->
args
[
0
])
);
}
else
if
(
call
->
op
.
same_as
(
dropout
))
{
}
else
if
(
call
->
op
.
same_as
(
dropout
))
{
return
call
->
args
[
0
];
return
call
->
args
[
0
];
}
}
}
}
return
new_e
;
return
new_e
;
}
}
Expr
VisitExpr_
(
const
CallNode
*
n
)
{
static
const
Op
&
batch_norm
=
Op
::
Get
(
"nn.batch_norm"
);
auto
new_n
=
ExprMutator
::
VisitExpr_
(
n
);
if
(
n
->
op
.
same_as
(
batch_norm
))
{
ty_map_
[
new_n
.
as
<
CallNode
>
()
->
args
[
0
]]
=
n
->
args
[
0
]
->
checked_type
();
}
return
new_n
;
}
private
:
std
::
unordered_map
<
Expr
,
Type
,
NodeHash
,
NodeEqual
>
ty_map_
;
};
};
Expr
SimplifyInference
(
const
Expr
&
e
)
{
Expr
SimplifyInference
(
const
Expr
&
e
)
{
...
...
tests/python/relay/test_pass_simplify_inference.py
View file @
e470f8ea
...
@@ -30,12 +30,12 @@ def test_simplify_batchnorm():
...
@@ -30,12 +30,12 @@ def test_simplify_batchnorm():
y1
,
_
,
_
=
rly
.
nn
.
batch_norm
(
y1
+
rly
.
const
(
1
,
'float32'
),
y1
,
_
,
_
=
rly
.
nn
.
batch_norm
(
y1
+
rly
.
const
(
1
,
'float32'
),
gamma
,
beta
,
moving_mean
,
moving_var
,
epsilon
=
eps
,
axis
=
axis
)
gamma
,
beta
,
moving_mean
,
moving_var
,
epsilon
=
eps
,
axis
=
axis
)
y1
=
rly
.
nn
.
dropout
(
y1
)
y1
=
rly
.
nn
.
dropout
(
y1
)
y1
=
rly
.
ir_pass
.
infer_type
(
y1
)
y1
=
simplify_inference
(
y1
)
y2
=
simple_bn
(
y2
+
rly
.
const
(
1
,
'float32'
),
y2
=
simple_bn
(
y2
+
rly
.
const
(
1
,
'float32'
),
gamma
,
beta
,
moving_mean
,
moving_var
,
gamma
,
beta
,
moving_mean
,
moving_var
,
epsilon
=
eps
,
axis
=
axis
,
shape
=
ttype1
.
shape
)
epsilon
=
eps
,
axis
=
axis
,
shape
=
ttype1
.
shape
)
y1
=
rly
.
ir_pass
.
infer_type
(
y1
)
y1
=
simplify_inference
(
y1
)
assert
rly
.
ir_pass
.
graph_equal
(
y1
,
y2
)
assert
rly
.
ir_pass
.
graph_equal
(
y1
,
y2
)
check
(
2
,
1
,
1
)
check
(
2
,
1
,
1
)
...
...
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