Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
b4f11615
Unverified
Commit
b4f11615
authored
Sep 05, 2019
by
mvermeulen
Committed by
GitHub
Sep 05, 2019
Browse files
Merge pull request #352 from ROCmSoftwarePlatform/int8_quant_bugs
int8_quantization bug fix related to imagenet models
parents
debed772
daeb193f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
9 deletions
+51
-9
src/quantization.cpp
src/quantization.cpp
+7
-8
test/quantization.cpp
test/quantization.cpp
+44
-1
No files found.
src/quantization.cpp
View file @
b4f11615
...
@@ -258,14 +258,13 @@ static void ins_quantize_int8(program& prog,
...
@@ -258,14 +258,13 @@ static void ins_quantize_int8(program& prog,
{
{
// Current MIOpen convolution does not support alpha and beta,
// Current MIOpen convolution does not support alpha and beta,
// so we need a separate multiply to adjust the output
// so we need a separate multiply to adjust the output
auto
conv_op
=
any_cast
<
op
::
convolution
>
(
ins
->
get_operator
());
auto
conv_op
=
any_cast
<
op
::
convolution
>
(
ins
->
get_operator
());
auto
padding
=
conv_op
.
padding
;
auto
padding
=
conv_op
.
padding
;
auto
stride
=
conv_op
.
stride
;
auto
stride
=
conv_op
.
stride
;
auto
dilation
=
conv_op
.
dilation
;
auto
dilation
=
conv_op
.
dilation
;
auto
padding_mode
=
conv_op
.
padding_mode
;
auto
padding_mode
=
conv_op
.
padding_mode
;
auto
group
=
conv_op
.
group
;
auto
group
=
conv_op
.
group
;
auto
adjust_factor
=
auto
adjust_factor
=
1.0
f
/
(
ins_quant_params
[
0
].
first
*
ins_quant_params
[
1
].
first
);
std
::
round
(
1.0
f
/
(
ins_quant_params
[
0
].
first
*
ins_quant_params
[
1
].
first
));
auto
quant_conv
=
prog
.
insert_instruction
(
auto
quant_conv
=
prog
.
insert_instruction
(
ins
,
ins
,
...
...
test/quantization.cpp
View file @
b4f11615
...
@@ -896,7 +896,7 @@ TEST_CASE(target_copy)
...
@@ -896,7 +896,7 @@ TEST_CASE(target_copy)
}
}
}
}
TEST_CASE
(
int8_quantization
)
TEST_CASE
(
int8_quantization
_dot
)
{
{
auto
run_prog
=
[](
migraphx
::
program
p
,
auto
run_prog
=
[](
migraphx
::
program
p
,
const
migraphx
::
target
&
t
,
const
migraphx
::
target
&
t
,
...
@@ -958,4 +958,47 @@ TEST_CASE(int8_quantization)
...
@@ -958,4 +958,47 @@ TEST_CASE(int8_quantization)
}
}
}
}
TEST_CASE
(
int8_quantization_conv
)
{
auto
run_prog
=
[](
migraphx
::
program
p
,
const
migraphx
::
target
&
t
,
std
::
vector
<
float
>&
res
,
bool
b_quantize
=
false
)
{
if
(
b_quantize
)
{
std
::
vector
<
migraphx
::
program
::
parameter_map
>
cali_data
;
migraphx
::
quantize_int8
(
p
,
t
,
cali_data
);
}
p
.
compile
(
t
);
migraphx
::
program
::
parameter_map
m
;
auto
result
=
t
.
copy_from
(
p
.
eval
(
m
));
result
.
visit
([
&
](
auto
v
)
{
res
.
assign
(
v
.
begin
(),
v
.
end
());
});
};
auto
create_program
=
[]
{
migraphx
::
program
p
;
migraphx
::
shape
sx
{
migraphx
::
shape
::
float_type
,
{
4
,
2
,
2
,
2
}};
migraphx
::
shape
sw
{
migraphx
::
shape
::
float_type
,
{
4
,
2
,
2
,
2
}};
std
::
vector
<
float
>
v
(
sx
.
elements
(),
0.5
f
);
auto
input
=
p
.
add_literal
(
migraphx
::
literal
(
sx
,
v
));
auto
weights
=
p
.
add_literal
(
migraphx
::
literal
(
sw
,
v
));
p
.
add_instruction
(
migraphx
::
op
::
convolution
{},
input
,
weights
);
return
p
;
};
{
auto
p
=
create_program
();
std
::
vector
<
float
>
quant_result
;
migraphx
::
target
cpu_t
=
migraphx
::
cpu
::
target
{};
run_prog
(
p
,
cpu_t
,
quant_result
,
true
);
std
::
vector
<
float
>
no_quant_result
;
run_prog
(
p
,
cpu_t
,
no_quant_result
);
EXPECT
(
migraphx
::
verify_range
(
quant_result
,
no_quant_result
));
}
}
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