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
2629e8f1
Commit
2629e8f1
authored
Feb 17, 2022
by
Shucai Xiao
Browse files
Merge branch 'develop' of github.com:ROCmSoftwarePlatform/AMDMIGraphX into parse_dynamic_shape
parents
dfbfd078
7fce121e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
144 additions
and
22 deletions
+144
-22
examples/nlp/python_bert_squad/requirements_bertsquad.txt
examples/nlp/python_bert_squad/requirements_bertsquad.txt
+1
-1
src/include/migraphx/op/unsqueeze.hpp
src/include/migraphx/op/unsqueeze.hpp
+15
-5
test/op_shape_test.cpp
test/op_shape_test.cpp
+49
-0
test/ref_ops_nonstd_shape_test.cpp
test/ref_ops_nonstd_shape_test.cpp
+79
-16
No files found.
examples/nlp/python_bert_squad/requirements_bertsquad.txt
View file @
2629e8f1
tensorflow==2.5.
2
tensorflow==2.5.
3
onnxruntime
tokenizers
\ No newline at end of file
src/include/migraphx/op/unsqueeze.hpp
100755 → 100644
View file @
2629e8f1
...
...
@@ -37,11 +37,11 @@ struct unsqueeze
std
::
string
name
()
const
{
return
"unsqueeze"
;
}
shape
normalize_compute_shape
(
std
::
vector
<
shape
>
inputs
)
const
{
check_shapes
{
inputs
,
*
this
}.
has
(
1
)
.
standard_or_scalar
()
;
check_shapes
{
inputs
,
*
this
}.
has
(
1
);
auto
input_shape
=
inputs
[
0
];
auto
type
=
input_shape
.
type
();
auto
old_lens
=
input_shape
.
lens
();
auto
old_strides
=
input_shape
.
strides
();
if
(
input_shape
.
scalar
())
{
if
(
old_lens
.
size
()
==
1
and
old_lens
.
front
()
==
1
)
...
...
@@ -53,19 +53,29 @@ struct unsqueeze
std
::
size_t
new_size
=
old_lens
.
size
()
+
axes
.
size
();
std
::
vector
<
std
::
size_t
>
new_lens
(
new_size
);
std
::
vector
<
std
::
size_t
>
new_strides
(
new_size
);
std
::
size_t
p
=
0
;
for
(
std
::
size_t
i
=
0
;
i
<
new_size
;
i
++
)
for
(
auto
i
:
range
(
new_size
)
)
{
if
(
std
::
find
(
axes
.
begin
(),
axes
.
end
(),
i
)
!=
axes
.
end
())
{
new_lens
[
i
]
=
1
;
if
(
p
==
0
)
// unsqueeze on the first axes
{
new_strides
[
i
]
=
old_lens
[
0
]
*
old_strides
[
0
];
}
else
// unsqueeze on middle or last axes
{
new_strides
[
i
]
=
(
p
<
old_strides
.
size
())
?
old_strides
[
p
-
1
]
:
1
;
}
}
else
{
new_lens
[
i
]
=
old_lens
[
p
++
];
new_lens
[
i
]
=
old_lens
[
p
];
new_strides
[
i
]
=
old_strides
[
p
++
];
}
}
return
shape
{
type
,
new_lens
};
return
shape
{
type
,
new_lens
,
new_strides
};
}
argument
compute
(
shape
output_shape
,
std
::
vector
<
argument
>
args
)
const
{
...
...
test/op_shape_test.cpp
View file @
2629e8f1
...
...
@@ -1513,6 +1513,55 @@ TEST_CASE(test_unsqueeze_scalar_tensor2)
throws_shape
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
-
2
}}}),
s
);
}
TEST_CASE
(
test_unsqueeze_transpose
)
{
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
4
,
4
,
3
},
{
12
,
1
,
4
}};
migraphx
::
shape
s2
{
migraphx
::
shape
::
float_type
,
{
4
,
4
,
1
,
3
},
{
12
,
1
,
1
,
4
}};
expect_shape
(
s2
,
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}}}),
s1
);
}
TEST_CASE
(
test_unsqueeze_multibroadcast
)
{
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
},
{
0
,
1
,
0
}};
migraphx
::
shape
s2
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
1
,
4
},
{
0
,
1
,
1
,
0
}};
expect_shape
(
s2
,
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}}}),
s1
);
}
TEST_CASE
(
test_unsqueeze_slice
)
{
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
},
{
108
,
36
,
1
}};
migraphx
::
shape
s2
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
1
,
4
},
{
108
,
36
,
36
,
1
}};
expect_shape
(
s2
,
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}}}),
s1
);
}
TEST_CASE
(
test_unsqueeze_axis_zero
)
{
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
}};
migraphx
::
shape
s2
{
migraphx
::
shape
::
float_type
,
{
1
,
2
,
3
,
4
}};
expect_shape
(
s2
,
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
0
}}}),
s1
);
}
TEST_CASE
(
test_unsqueeze_axis_last
)
{
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
}};
migraphx
::
shape
s2
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
,
1
}};
expect_shape
(
s2
,
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
-
1
}}}),
s1
);
}
TEST_CASE
(
test_unsqueeze_multiple_axes_1
)
{
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
}};
migraphx
::
shape
s2
{
migraphx
::
shape
::
float_type
,
{
1
,
2
,
3
,
4
,
1
}};
expect_shape
(
s2
,
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
0
,
-
1
}}}),
s1
);
}
TEST_CASE
(
test_unsqueeze_multiple_axes_2
)
{
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
}};
migraphx
::
shape
s2
{
migraphx
::
shape
::
float_type
,
{
1
,
1
,
2
,
3
,
4
}};
expect_shape
(
s2
,
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
0
,
1
}}}),
s1
);
}
TEST_CASE
(
transpose_shape
)
{
migraphx
::
shape
input
{
migraphx
::
shape
::
float_type
,
{
2
,
2
}};
...
...
test/ref_ops_nonstd_shape_test.cpp
View file @
2629e8f1
...
...
@@ -57,14 +57,15 @@ TEST_CASE(squeeze_transpose_test)
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
1
,
2
,
3
,
0
,
4
}}}),
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"squeeze"
),
l0_trans
);
auto
p_uncompiled
=
p
;
// contiguous is required to read the values in standard shaped order
auto
*
mm_uncompiled
=
p_uncompiled
.
get_main_module
();
mm_uncompiled
->
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
std
::
prev
(
mm_uncompiled
->
end
()));
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
// contiguous is required to read the values in standard shaped order
auto
tr_op
=
migraphx
::
make_op
(
"contiguous"
);
auto
std_expected_result
=
tr_op
.
compute
(
result
.
get_shape
(),
{
expected_result
});
EXPECT
(
result
.
get_shape
()
==
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
3
}});
EXPECT
(
result
==
std_
expected_result
);
EXPECT
(
result
==
expected_result
);
}
TEST_CASE
(
squeeze_multibroadcast_test
)
...
...
@@ -76,14 +77,15 @@ TEST_CASE(squeeze_multibroadcast_test)
auto
l0_brcst
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
4
,
1
,
3
,
4
,
3
}}}),
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"squeeze"
),
l0_brcst
);
auto
p_uncompiled
=
p
;
auto
p_uncompiled
=
p
;
auto
*
mm_uncompiled
=
p_uncompiled
.
get_main_module
();
mm_uncompiled
->
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
std
::
prev
(
mm_uncompiled
->
end
()));
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
auto
tr_op
=
migraphx
::
make_op
(
"contiguous"
);
auto
std_expected_result
=
tr_op
.
compute
(
result
.
get_shape
(),
{
expected_result
});
auto
result
=
p
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
EXPECT
(
result
.
get_shape
()
==
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
4
,
3
,
4
,
3
}});
EXPECT
(
result
==
std_
expected_result
);
EXPECT
(
result
==
expected_result
);
}
TEST_CASE
(
squeeze_slice_test
)
...
...
@@ -95,14 +97,75 @@ TEST_CASE(squeeze_slice_test)
auto
l0_slice
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
2
}},
{
"starts"
,
{
2
}},
{
"ends"
,
{
3
}}}),
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"squeeze"
),
l0_slice
);
auto
p_uncompiled
=
p
;
auto
p_uncompiled
=
p
;
auto
*
mm_uncompiled
=
p_uncompiled
.
get_main_module
();
mm_uncompiled
->
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
std
::
prev
(
mm_uncompiled
->
end
()));
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
auto
tr_op
=
migraphx
::
make_op
(
"contiguous"
);
auto
std_expected_result
=
tr_op
.
compute
(
result
.
get_shape
(),
{
expected_result
});
auto
result
=
p
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
EXPECT
(
result
.
get_shape
()
==
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
3
}});
EXPECT
(
result
==
std_expected_result
);
EXPECT
(
result
==
expected_result
);
}
TEST_CASE
(
unsqueeze_transpose_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
4
,
3
,
3
}};
auto
l0
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
s1
));
auto
l0_trans
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"transpose"
,
{{
"permutation"
,
{
2
,
0
,
1
}}}),
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}}}),
l0_trans
);
auto
p_uncompiled
=
p
;
auto
*
mm_uncompiled
=
p_uncompiled
.
get_main_module
();
mm_uncompiled
->
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
std
::
prev
(
mm_uncompiled
->
end
()));
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
EXPECT
(
result
.
get_shape
()
==
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
3
,
4
,
1
,
3
}});
EXPECT
(
result
==
expected_result
);
}
TEST_CASE
(
unsqueeze_multibroadcast_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
4
,
1
,
3
}};
auto
l0
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
s1
));
auto
l0_brcst
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"multibroadcast"
,
{{
"out_lens"
,
{
4
,
4
,
3
,
3
}}}),
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
2
}}}),
l0_brcst
);
auto
p_uncompiled
=
p
;
auto
*
mm_uncompiled
=
p_uncompiled
.
get_main_module
();
mm_uncompiled
->
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
std
::
prev
(
mm_uncompiled
->
end
()));
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
EXPECT
(
result
.
get_shape
()
==
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
4
,
4
,
1
,
3
,
3
}});
EXPECT
(
result
==
expected_result
);
}
TEST_CASE
(
unsqueeze_slice_test
)
{
migraphx
::
program
p
;
auto
*
mm
=
p
.
get_main_module
();
migraphx
::
shape
s1
{
migraphx
::
shape
::
float_type
,
{
2
,
3
,
4
,
4
}};
auto
l0
=
mm
->
add_literal
(
migraphx
::
generate_literal
(
s1
));
auto
l0_slice
=
mm
->
add_instruction
(
migraphx
::
make_op
(
"slice"
,
{{
"axes"
,
{
3
}},
{
"starts"
,
{
2
}},
{
"ends"
,
{
3
}}}),
l0
);
mm
->
add_instruction
(
migraphx
::
make_op
(
"unsqueeze"
,
{{
"axes"
,
{
1
}}}),
l0_slice
);
auto
p_uncompiled
=
p
;
auto
*
mm_uncompiled
=
p_uncompiled
.
get_main_module
();
mm_uncompiled
->
add_instruction
(
migraphx
::
make_op
(
"contiguous"
),
std
::
prev
(
mm_uncompiled
->
end
()));
p
.
compile
(
migraphx
::
ref
::
target
{});
auto
result
=
p
.
eval
({}).
back
();
auto
expected_result
=
p_uncompiled
.
eval
({}).
back
();
EXPECT
(
result
.
get_shape
()
==
migraphx
::
shape
{
migraphx
::
shape
::
float_type
,
{
2
,
1
,
3
,
4
,
1
}});
EXPECT
(
result
==
expected_result
);
}
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