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
74b947ed
"test/vscode:/vscode.git/clone" did not exist on "a6cdd6c734a9237cbf92198b852c95b748f09a6d"
Commit
74b947ed
authored
May 26, 2022
by
turneram
Browse files
Formatting
parent
6ca16d98
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
18 deletions
+18
-18
src/onnx/parse_attention.cpp
src/onnx/parse_attention.cpp
+3
-3
src/onnx/parse_layernorm.cpp
src/onnx/parse_layernorm.cpp
+15
-15
No files found.
src/onnx/parse_attention.cpp
View file @
74b947ed
...
...
@@ -28,9 +28,9 @@ struct parse_attention : op_parser<parse_attention>
num_heads
=
info
.
attributes
.
at
(
"num_heads"
).
i
();
// input shape: (batch_size, sequence_length, input_hidden_size)
auto
input_lens
=
input
->
get_shape
().
lens
();
auto
batch_size
=
input_lens
.
at
(
0
);
auto
sequence_length
=
input_lens
.
at
(
1
);
auto
input_lens
=
input
->
get_shape
().
lens
();
auto
batch_size
=
input_lens
.
at
(
0
);
auto
sequence_length
=
input_lens
.
at
(
1
);
// bias shape= (3 * hidden_size)
auto
bias_lens
=
bias
->
get_shape
().
lens
();
...
...
src/onnx/parse_layernorm.cpp
View file @
74b947ed
...
...
@@ -19,11 +19,11 @@ struct parse_layernorm : op_parser<parse_layernorm>
const
std
::
vector
<
instruction_ref
>&
args
)
const
{
// un-fuse layernorm op so migraphx can handle fusion instead
auto
x
=
args
.
front
();
auto
x_type
=
x
->
get_shape
().
type
();
auto
weights
=
args
.
at
(
1
);
auto
bias
=
args
.
at
(
2
);
auto
x
=
args
.
front
();
auto
x_type
=
x
->
get_shape
().
type
();
auto
weights
=
args
.
at
(
1
);
auto
bias
=
args
.
at
(
2
);
float
epsilon
=
1e-12
f
;
int64_t
axis
=
-
1
;
...
...
@@ -35,23 +35,23 @@ struct parse_layernorm : op_parser<parse_layernorm>
{
epsilon
=
parser
.
parse_value
(
info
.
attributes
.
at
(
"axis"
)).
at
<
int64_t
>
();
}
auto
epsilon_lit
=
info
.
add_literal
(
literal
{
shape
{
x_type
,
{
1
}},
{
epsilon
}});
auto
exponent
=
info
.
add_literal
(
literal
{
shape
{
x_type
,
{
1
}},
{
2.0
}});
auto
dims
=
x
->
get_shape
().
lens
();
auto
epsilon_lit
=
info
.
add_literal
(
literal
{
shape
{
x_type
,
{
1
}},
{
epsilon
}});
auto
exponent
=
info
.
add_literal
(
literal
{
shape
{
x_type
,
{
1
}},
{
2.0
}});
auto
dims
=
x
->
get_shape
().
lens
();
auto
mean
=
info
.
add_instruction
(
migraphx
::
make_op
(
"reduce_mean"
,
{{
"axes"
,
{
axis
}}}),
x
);
auto
mean_mbcast
=
info
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
dims
}}),
mean
);
auto
sub
=
info
.
add_instruction
(
migraphx
::
make_op
(
"sub"
),
x
,
mean_mbcast
);
auto
exponent_mbcast
=
info
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
dims
}}),
exponent
);
auto
sub
=
info
.
add_instruction
(
migraphx
::
make_op
(
"sub"
),
x
,
mean_mbcast
);
auto
exponent_mbcast
=
info
.
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
dims
}}),
exponent
);
auto
pow
=
info
.
add_instruction
(
migraphx
::
make_op
(
"pow"
),
sub
,
exponent_mbcast
);
auto
var
=
info
.
add_instruction
(
migraphx
::
make_op
(
"reduce_mean"
,
{{
"axes"
,
{
axis
}}}),
pow
);
auto
add_epsilon
=
info
.
add_broadcastable_binary_op
(
"add"
,
var
,
epsilon_lit
);
auto
sqrt
=
info
.
add_instruction
(
migraphx
::
make_op
(
"sqrt"
),
add_epsilon
);
auto
div
=
info
.
add_broadcastable_binary_op
(
"div"
,
sub
,
sqrt
);
auto
mul
=
info
.
add_broadcastable_binary_op
(
"mul"
,
div
,
weights
);
auto
sqrt
=
info
.
add_instruction
(
migraphx
::
make_op
(
"sqrt"
),
add_epsilon
);
auto
div
=
info
.
add_broadcastable_binary_op
(
"div"
,
sub
,
sqrt
);
auto
mul
=
info
.
add_broadcastable_binary_op
(
"mul"
,
div
,
weights
);
return
info
.
add_broadcastable_binary_op
(
"add"
,
mul
,
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