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
dc57c9c1
Commit
dc57c9c1
authored
Feb 16, 2019
by
Shucai Xiao
Browse files
add onnx test for the lstm operator.
parent
9d8cb8e6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
211 additions
and
69 deletions
+211
-69
test/onnx/onnx_lstm_bi.onnx
test/onnx/onnx_lstm_bi.onnx
+0
-0
test/onnx/onnx_lstm_forward.onnx
test/onnx/onnx_lstm_forward.onnx
+0
-0
test/onnx/onnx_lstm_reverse.onnx
test/onnx/onnx_lstm_reverse.onnx
+0
-0
test/onnx/onnx_rnn_test.cpp
test/onnx/onnx_rnn_test.cpp
+211
-69
No files found.
test/onnx/onnx_lstm_bi.onnx
0 → 100644
View file @
dc57c9c1
File added
test/onnx/onnx_lstm_forward.onnx
0 → 100644
View file @
dc57c9c1
File added
test/onnx/onnx_lstm_reverse.onnx
0 → 100644
View file @
dc57c9c1
File added
test/onnx/onnx_rnn_test.cpp
View file @
dc57c9c1
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#include <migraphx/onnx.hpp>
#include <migraphx/onnx.hpp>
#include "test.hpp"
#include "test.hpp"
TEST_CASE
(
rnn_test
)
TEST_CASE
(
rnn_test
_bidirectional
)
{
{
std
::
size_t
sl
=
5
;
// sequence len
std
::
size_t
sl
=
5
;
// sequence len
std
::
size_t
bs
=
3
;
// batch size
std
::
size_t
bs
=
3
;
// batch size
...
@@ -15,51 +15,63 @@ TEST_CASE(rnn_test)
...
@@ -15,51 +15,63 @@ TEST_CASE(rnn_test)
std
::
size_t
is
=
10
;
// input size
std
::
size_t
is
=
10
;
// input size
std
::
size_t
nd
=
2
;
// num directions
std
::
size_t
nd
=
2
;
// num directions
float
clip
=
0.0
f
;
float
clip
=
0.0
f
;
// bidirectional
migraphx
::
shape
seq_shape
{
migraphx
::
shape
::
float_type
,
{
sl
,
bs
,
is
}};
{
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
hs
,
is
}};
migraphx
::
program
p
;
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
hs
,
hs
}};
migraphx
::
shape
bias_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
2
*
hs
}};
auto
seq
=
migraphx
::
shape
sl_shape
{
migraphx
::
shape
::
int32_type
,
{
bs
}};
p
.
add_parameter
(
"seq"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
sl
,
bs
,
is
}});
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
bs
,
hs
}};
auto
w
=
p
.
add_parameter
(
"w"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
hs
,
is
}});
auto
r
=
p
.
add_parameter
(
"r"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
hs
,
hs
}});
migraphx
::
program
p
;
auto
bias
=
p
.
add_parameter
(
"bias"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
2
*
hs
}});
auto
seq
=
p
.
add_parameter
(
"seq"
,
seq_shape
);
auto
seq_len
=
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
p
.
add_parameter
(
"seq_len"
,
migraphx
::
shape
{
migraphx
::
shape
::
int32_type
,
{
bs
}});
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
ih
=
p
.
add_parameter
(
"h0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
bs
,
hs
}});
auto
bias
=
p
.
add_parameter
(
"bias"
,
bias_shape
);
auto
seq_len
=
p
.
add_parameter
(
"seq_len"
,
sl_shape
);
auto
out_hs
=
auto
ih
=
p
.
add_parameter
(
"h0"
,
ih_shape
);
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hs
,
{
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
sigmoid
{}},
auto
out_hs
=
migraphx
::
op
::
rnn_direction
::
bidirectional
,
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hs
,
clip
},
{
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
sigmoid
{}},
seq
,
migraphx
::
op
::
rnn_direction
::
bidirectional
,
w
,
clip
},
r
,
seq
,
bias
,
w
,
seq_len
,
r
,
ih
);
bias
,
p
.
add_instruction
(
migraphx
::
op
::
rnn_last_output
{},
out_hs
);
seq_len
,
auto
prog
=
migraphx
::
parse_onnx
(
"onnx_rnn_bi.onnx"
);
ih
);
p
.
add_instruction
(
migraphx
::
op
::
rnn_last_output
{},
out_hs
);
auto
prog
=
migraphx
::
parse_onnx
(
"onnx_rnn_bi.onnx"
);
EXPECT
(
p
==
prog
);
}
EXPECT
(
p
==
prog
);
TEST_CASE
(
rnn_test_one
)
}
{
std
::
size_t
sl
=
5
;
// sequence len
std
::
size_t
bs
=
3
;
// batch size
std
::
size_t
hs
=
20
;
// hidden size
std
::
size_t
is
=
10
;
// input size
std
::
size_t
nd
=
1
;
// num directions
float
clip
=
0.0
f
;
migraphx
::
shape
seq_shape
{
migraphx
::
shape
::
float_type
,
{
sl
,
bs
,
is
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
hs
,
is
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
hs
,
hs
}};
migraphx
::
shape
bias_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
2
*
hs
}};
migraphx
::
shape
sl_shape
{
migraphx
::
shape
::
int32_type
,
{
bs
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
bs
,
hs
}};
// forward
// forward
{
{
nd
=
1
;
migraphx
::
program
p
;
migraphx
::
program
p
;
auto
seq
=
p
.
add_parameter
(
"seq"
,
seq_shape
);
auto
seq
=
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
p
.
add_parameter
(
"seq"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
sl
,
bs
,
is
}});
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
hs
,
is
}});
auto
bias
=
p
.
add_parameter
(
"bias"
,
bias_shape
);
auto
r
=
p
.
add_parameter
(
"r"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
hs
,
hs
}});
auto
seq_len
=
p
.
add_parameter
(
"seq_len"
,
sl_shape
);
auto
bias
=
auto
ih
=
p
.
add_parameter
(
"h0"
,
ih_shape
);
p
.
add_parameter
(
"bias"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
2
*
hs
}});
auto
seq_len
=
p
.
add_parameter
(
"seq_len"
,
migraphx
::
shape
{
migraphx
::
shape
::
int32_type
,
{
bs
}});
auto
ih
=
p
.
add_parameter
(
"h0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
bs
,
hs
}});
auto
out_hs
=
auto
out_hs
=
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hs
,
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hs
,
...
@@ -80,19 +92,13 @@ TEST_CASE(rnn_test)
...
@@ -80,19 +92,13 @@ TEST_CASE(rnn_test)
// reverse
// reverse
{
{
nd
=
1
;
migraphx
::
program
p
;
migraphx
::
program
p
;
auto
seq
=
p
.
add_parameter
(
"seq"
,
seq_shape
);
auto
seq
=
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
p
.
add_parameter
(
"seq"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
sl
,
bs
,
is
}});
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
hs
,
is
}});
auto
bias
=
p
.
add_parameter
(
"bias"
,
bias_shape
);
auto
r
=
p
.
add_parameter
(
"r"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
hs
,
hs
}});
auto
seq_len
=
p
.
add_parameter
(
"seq_len"
,
sl_shape
);
auto
bias
=
auto
ih
=
p
.
add_parameter
(
"h0"
,
ih_shape
);
p
.
add_parameter
(
"bias"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
2
*
hs
}});
auto
seq_len
=
p
.
add_parameter
(
"seq_len"
,
migraphx
::
shape
{
migraphx
::
shape
::
int32_type
,
{
bs
}});
auto
ih
=
p
.
add_parameter
(
"h0"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
bs
,
hs
}});
auto
out_hs
=
auto
out_hs
=
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hs
,
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hs
,
{
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
sigmoid
{}},
{
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
sigmoid
{}},
...
@@ -112,15 +118,11 @@ TEST_CASE(rnn_test)
...
@@ -112,15 +118,11 @@ TEST_CASE(rnn_test)
// 3 argumments
// 3 argumments
{
{
nd
=
1
;
migraphx
::
program
p
;
migraphx
::
program
p
;
auto
seq
=
p
.
add_parameter
(
"seq"
,
seq_shape
);
auto
seq
=
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
p
.
add_parameter
(
"seq"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
sl
,
bs
,
is
}});
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
hs
,
is
}});
auto
r
=
p
.
add_parameter
(
"r"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
hs
,
hs
}});
auto
und
=
p
.
add_instruction
(
migraphx
::
op
::
undefined
{});
auto
und
=
p
.
add_instruction
(
migraphx
::
op
::
undefined
{});
auto
out_hs
=
auto
out_hs
=
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hs
,
p
.
add_instruction
(
migraphx
::
op
::
rnn
{
hs
,
{
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
sigmoid
{}},
{
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
sigmoid
{}},
...
@@ -140,17 +142,13 @@ TEST_CASE(rnn_test)
...
@@ -140,17 +142,13 @@ TEST_CASE(rnn_test)
// 5 argumments
// 5 argumments
{
{
nd
=
1
;
migraphx
::
program
p
;
migraphx
::
program
p
;
auto
seq
=
auto
seq
=
p
.
add_parameter
(
"seq"
,
seq_shape
);
p
.
add_parameter
(
"seq"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
sl
,
bs
,
is
}});
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
hs
,
is
}});
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
r
=
p
.
add_parameter
(
"r"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
hs
,
hs
}});
auto
bias
=
p
.
add_parameter
(
"bias"
,
bias_shape
);
auto
bias
=
auto
seq_len
=
p
.
add_parameter
(
"seq_len"
,
sl_shape
);
p
.
add_parameter
(
"bias"
,
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
2
*
hs
}});
auto
seq_len
=
p
.
add_parameter
(
"seq_len"
,
migraphx
::
shape
{
migraphx
::
shape
::
int32_type
,
{
bs
}});
auto
und
=
p
.
add_instruction
(
migraphx
::
op
::
undefined
{});
auto
und
=
p
.
add_instruction
(
migraphx
::
op
::
undefined
{});
auto
out_hs
=
auto
out_hs
=
...
@@ -594,4 +592,148 @@ TEST_CASE(gru_test_actv_funcs)
...
@@ -594,4 +592,148 @@ TEST_CASE(gru_test_actv_funcs)
}
}
}
}
TEST_CASE
(
lstm_forward
)
{
std
::
size_t
sl
=
5
;
// sequence len
std
::
size_t
bs
=
3
;
// batch size
std
::
size_t
hs
=
20
;
// hidden size
std
::
size_t
is
=
10
;
// input size
std
::
size_t
nd
=
1
;
// num directions
float
clip
=
0.0
f
;
int
input_forget
=
1
;
migraphx
::
shape
seq_shape
{
migraphx
::
shape
::
float_type
,
{
sl
,
bs
,
is
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
4
*
hs
,
is
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
4
*
hs
,
hs
}};
migraphx
::
shape
bias_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
8
*
hs
}};
migraphx
::
shape
sl_shape
{
migraphx
::
shape
::
int32_type
,
{
bs
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
bs
,
hs
}};
migraphx
::
shape
pph_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
3
*
hs
}};
{
migraphx
::
program
p
;
auto
seq
=
p
.
add_parameter
(
"seq"
,
seq_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
bias
=
p
.
add_parameter
(
"bias"
,
bias_shape
);
auto
seq_len
=
p
.
add_parameter
(
"seq_len"
,
sl_shape
);
auto
ih
=
p
.
add_parameter
(
"h0"
,
ih_shape
);
auto
ic
=
p
.
add_parameter
(
"c0"
,
ih_shape
);
auto
pph
=
p
.
add_parameter
(
"pph"
,
pph_shape
);
auto
out_hs
=
p
.
add_instruction
(
migraphx
::
op
::
lstm
{
hs
,
{
migraphx
::
op
::
sigmoid
{},
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
tanh
{}},
migraphx
::
op
::
rnn_direction
::
forward
,
clip
,
input_forget
},
seq
,
w
,
r
,
bias
,
seq_len
,
ih
,
ic
,
pph
);
p
.
add_instruction
(
migraphx
::
op
::
rnn_last_output
{},
out_hs
);
p
.
add_instruction
(
migraphx
::
op
::
lstm_last_cell_output
{},
out_hs
);
auto
prog
=
migraphx
::
parse_onnx
(
"onnx_lstm_forward.onnx"
);
EXPECT
(
p
==
prog
);
}
}
TEST_CASE
(
lstm_reverse
)
{
std
::
size_t
sl
=
5
;
// sequence len
std
::
size_t
bs
=
3
;
// batch size
std
::
size_t
hs
=
20
;
// hidden size
std
::
size_t
is
=
10
;
// input size
std
::
size_t
nd
=
1
;
// num directions
float
clip
=
0.0
f
;
int
input_forget
=
1
;
migraphx
::
shape
seq_shape
{
migraphx
::
shape
::
float_type
,
{
sl
,
bs
,
is
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
4
*
hs
,
is
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
4
*
hs
,
hs
}};
migraphx
::
shape
bias_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
8
*
hs
}};
migraphx
::
shape
sl_shape
{
migraphx
::
shape
::
int32_type
,
{
bs
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
bs
,
hs
}};
migraphx
::
shape
pph_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
3
*
hs
}};
{
migraphx
::
program
p
;
auto
seq
=
p
.
add_parameter
(
"seq"
,
seq_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
bias
=
p
.
add_parameter
(
"bias"
,
bias_shape
);
auto
seq_len
=
p
.
add_parameter
(
"seq_len"
,
sl_shape
);
auto
ih
=
p
.
add_parameter
(
"h0"
,
ih_shape
);
auto
ic
=
p
.
add_parameter
(
"c0"
,
ih_shape
);
auto
pph
=
p
.
add_parameter
(
"pph"
,
pph_shape
);
auto
out_hs
=
p
.
add_instruction
(
migraphx
::
op
::
lstm
{
hs
,
{
migraphx
::
op
::
sigmoid
{},
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
tanh
{}},
migraphx
::
op
::
rnn_direction
::
reverse
,
clip
,
input_forget
},
seq
,
w
,
r
,
bias
,
seq_len
,
ih
,
ic
,
pph
);
p
.
add_instruction
(
migraphx
::
op
::
rnn_last_output
{},
out_hs
);
p
.
add_instruction
(
migraphx
::
op
::
lstm_last_cell_output
{},
out_hs
);
auto
prog
=
migraphx
::
parse_onnx
(
"onnx_lstm_reverse.onnx"
);
EXPECT
(
p
==
prog
);
}
}
TEST_CASE
(
lstm_bidirectional
)
{
std
::
size_t
sl
=
5
;
// sequence len
std
::
size_t
bs
=
3
;
// batch size
std
::
size_t
hs
=
20
;
// hidden size
std
::
size_t
is
=
10
;
// input size
std
::
size_t
nd
=
2
;
// num directions
float
clip
=
0.0
f
;
int
input_forget
=
1
;
migraphx
::
shape
seq_shape
{
migraphx
::
shape
::
float_type
,
{
sl
,
bs
,
is
}};
migraphx
::
shape
w_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
4
*
hs
,
is
}};
migraphx
::
shape
r_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
4
*
hs
,
hs
}};
migraphx
::
shape
bias_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
8
*
hs
}};
migraphx
::
shape
sl_shape
{
migraphx
::
shape
::
int32_type
,
{
bs
}};
migraphx
::
shape
ih_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
bs
,
hs
}};
migraphx
::
shape
pph_shape
{
migraphx
::
shape
::
float_type
,
{
nd
,
3
*
hs
}};
{
migraphx
::
program
p
;
auto
seq
=
p
.
add_parameter
(
"seq"
,
seq_shape
);
auto
w
=
p
.
add_parameter
(
"w"
,
w_shape
);
auto
r
=
p
.
add_parameter
(
"r"
,
r_shape
);
auto
bias
=
p
.
add_parameter
(
"bias"
,
bias_shape
);
auto
seq_len
=
p
.
add_parameter
(
"seq_len"
,
sl_shape
);
auto
ih
=
p
.
add_parameter
(
"h0"
,
ih_shape
);
auto
ic
=
p
.
add_parameter
(
"c0"
,
ih_shape
);
auto
pph
=
p
.
add_parameter
(
"pph"
,
pph_shape
);
auto
out_hs
=
p
.
add_instruction
(
migraphx
::
op
::
lstm
{
hs
,
{
migraphx
::
op
::
sigmoid
{},
migraphx
::
op
::
tanh
{},
migraphx
::
op
::
tanh
{}},
migraphx
::
op
::
rnn_direction
::
bidirectional
,
clip
,
input_forget
},
seq
,
w
,
r
,
bias
,
seq_len
,
ih
,
ic
,
pph
);
p
.
add_instruction
(
migraphx
::
op
::
rnn_last_output
{},
out_hs
);
p
.
add_instruction
(
migraphx
::
op
::
lstm_last_cell_output
{},
out_hs
);
auto
prog
=
migraphx
::
parse_onnx
(
"onnx_lstm_bi.onnx"
);
EXPECT
(
p
==
prog
);
}
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
test
::
run
(
argc
,
argv
);
}
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