Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
5b709a1c
Commit
5b709a1c
authored
Aug 24, 2018
by
Paul
Browse files
Fix bias shape
parent
1be2883d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
9 deletions
+10
-9
src/fwd_conv_batchnorm_rewrite.cpp
src/fwd_conv_batchnorm_rewrite.cpp
+10
-9
No files found.
src/fwd_conv_batchnorm_rewrite.cpp
View file @
5b709a1c
...
@@ -34,12 +34,10 @@ void fwd_conv_batchnorm_rewrite::apply(program& p) const
...
@@ -34,12 +34,10 @@ void fwd_conv_batchnorm_rewrite::apply(program& p) const
const
auto
&
weights
=
conv_ins
->
arguments
[
1
]
->
get_literal
();
const
auto
&
weights
=
conv_ins
->
arguments
[
1
]
->
get_literal
();
// Get convolution op
// Get convolution op
auto
conv_op
=
conv_ins
->
op
;
auto
conv_op
=
conv_ins
->
op
;
auto
out_channels
=
weights
.
get_shape
().
lens
()[
0
];
auto
weights_lens
=
weights
.
get_shape
().
lens
();
auto
in_channels
=
weights
.
get_shape
().
lens
()[
1
];
auto
conv_lens
=
conv_ins
->
get_shape
().
lens
();
auto
height
=
weights
.
get_shape
().
lens
()[
2
];
auto
width
=
weights
.
get_shape
().
lens
()[
3
];
argument
new_weights
{
weights
.
get_shape
()};
argument
new_weights
{
weights
.
get_shape
()};
argument
new_bias
{
bias
.
get_shape
()};
argument
new_bias
{
conv_ins
->
get_shape
()};
visit_all
(
weights
,
gamma
,
bias
,
mean
,
variance
,
new_weights
,
new_bias
)(
visit_all
(
weights
,
gamma
,
bias
,
mean
,
variance
,
new_weights
,
new_bias
)(
[
&
](
auto
weights2
,
[
&
](
auto
weights2
,
auto
gamma2
,
auto
gamma2
,
...
@@ -48,17 +46,20 @@ void fwd_conv_batchnorm_rewrite::apply(program& p) const
...
@@ -48,17 +46,20 @@ void fwd_conv_batchnorm_rewrite::apply(program& p) const
auto
variance2
,
auto
variance2
,
auto
new_weights2
,
auto
new_weights2
,
auto
new_bias2
)
{
auto
new_bias2
)
{
dfor
(
out_channels
,
in_channels
,
h
eight
,
width
)(
dfor
(
weights_lens
[
0
],
weights_lens
[
1
]
,
w
eight
s_lens
[
2
],
weights_lens
[
3
]
)(
[
&
](
std
::
size_t
k
,
std
::
size_t
c
,
std
::
size_t
h
,
std
::
size_t
w
)
{
[
&
](
std
::
size_t
k
,
std
::
size_t
c
,
std
::
size_t
h
,
std
::
size_t
w
)
{
new_weights2
(
k
,
c
,
h
,
w
)
=
new_weights2
(
k
,
c
,
h
,
w
)
=
gamma2
(
k
)
/
std
::
sqrt
(
variance2
(
k
)
+
epsilon
)
*
weights2
(
k
,
c
,
h
,
w
);
gamma2
(
k
)
/
std
::
sqrt
(
variance2
(
k
)
+
epsilon
)
*
weights2
(
k
,
c
,
h
,
w
);
new_bias2
(
k
,
c
,
h
,
w
)
=
});
bias2
(
k
)
-
(
mean2
(
k
)
/
std
::
sqrt
(
variance2
(
k
)
+
epsilon
));
dfor
(
conv_lens
[
0
],
conv_lens
[
1
],
conv_lens
[
2
],
conv_lens
[
3
])(
[
&
](
std
::
size_t
n
,
std
::
size_t
c
,
std
::
size_t
h
,
std
::
size_t
w
)
{
new_bias2
(
n
,
c
,
h
,
w
)
=
bias2
(
c
)
-
(
mean2
(
c
)
/
std
::
sqrt
(
variance2
(
c
)
+
epsilon
));
});
});
});
});
// Replace convolution instruction with updated weights
// Replace convolution instruction with updated weights
auto
l_weights
=
p
.
add_literal
({
weights
.
get_shape
(),
new_weights
.
data
()});
auto
l_weights
=
p
.
add_literal
({
weights
.
get_shape
(),
new_weights
.
data
()});
auto
l_bias
=
p
.
add_literal
({
bias
.
get_shape
(),
new_bias
.
data
()});
auto
l_bias
=
p
.
add_literal
({
new_
bias
.
get_shape
(),
new_bias
.
data
()});
auto
c
=
p
.
replace_instruction
(
conv_ins
,
conv_op
,
{
conv_ins
->
arguments
[
0
],
l_weights
});
auto
c
=
p
.
replace_instruction
(
conv_ins
,
conv_op
,
{
conv_ins
->
arguments
[
0
],
l_weights
});
p
.
replace_instruction
(
ins
,
add
{},
{
c
,
l_bias
});
p
.
replace_instruction
(
ins
,
add
{},
{
c
,
l_bias
});
}
}
...
...
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