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
5447f39c
Commit
5447f39c
authored
Aug 08, 2019
by
Shucai Xiao
Browse files
fixed a bug in the int8 quantization function
parent
965ac6fc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
4 deletions
+25
-4
src/quantization.cpp
src/quantization.cpp
+25
-4
No files found.
src/quantization.cpp
View file @
5447f39c
...
@@ -301,10 +301,14 @@ void quantize_int8(program& prog,
...
@@ -301,10 +301,14 @@ void quantize_int8(program& prog,
else
else
{
{
auto
q_dot
=
prog
.
insert_instruction
(
ins
,
op
::
quant_dot
{
1
,
0
},
converted_inputs
);
auto
q_dot
=
prog
.
insert_instruction
(
ins
,
op
::
quant_dot
{
1
,
0
},
converted_inputs
);
auto
f_dot
=
prog
.
insert_instruction
(
ins
,
op
::
convert
{
shape
::
float_type
},
q_dot
);
auto
c_shape
=
q_dot
->
get_shape
();
std
::
vector
<
float
>
vec_alpha
(
c_shape
.
elements
(),
new_alpha
);
auto
l_alpha
=
prog
.
add_literal
(
literal
({
shape
::
float_type
,
c_shape
.
lens
()},
vec_alpha
));
if
(
inputs
.
size
()
==
3
and
dot_op
.
beta
!=
0.0
f
)
if
(
inputs
.
size
()
==
3
and
dot_op
.
beta
!=
0.0
f
)
{
{
auto
alpha_ab
=
prog
.
insert_instruction
(
ins
,
op
::
convert
{
orig_type
},
q_dot
);
auto
alpha_ab
=
prog
.
insert_instruction
(
ins
,
op
::
mul
{},
l_alpha
,
f_dot
);
auto
c_shape
=
q_dot
->
get_shape
();
std
::
vector
<
float
>
vec_beta
(
c_shape
.
elements
(),
dot_op
.
beta
);
std
::
vector
<
float
>
vec_beta
(
c_shape
.
elements
(),
dot_op
.
beta
);
auto
l_beta
=
auto
l_beta
=
prog
.
add_literal
(
literal
({
shape
::
float_type
,
c_shape
.
lens
()},
vec_beta
));
prog
.
add_literal
(
literal
({
shape
::
float_type
,
c_shape
.
lens
()},
vec_beta
));
...
@@ -320,11 +324,28 @@ void quantize_int8(program& prog,
...
@@ -320,11 +324,28 @@ void quantize_int8(program& prog,
{
{
beta_c
=
prog
.
insert_instruction
(
ins
,
op
::
mul
{},
l_beta
,
inputs
.
back
());
beta_c
=
prog
.
insert_instruction
(
ins
,
op
::
mul
{},
l_beta
,
inputs
.
back
());
}
}
if
(
orig_type
==
shape
::
float_type
)
{
prog
.
replace_instruction
(
ins
,
op
::
add
{},
alpha_ab
,
beta_c
);
prog
.
replace_instruction
(
ins
,
op
::
add
{},
alpha_ab
,
beta_c
);
}
}
else
else
{
{
prog
.
replace_instruction
(
ins
,
op
::
convert
{
orig_type
},
q_dot
);
auto
f_res
=
prog
.
insert_instruction
(
ins
,
op
::
add
{},
alpha_ab
,
beta_c
);
prog
.
replace_instruction
(
ins
,
op
::
convert
{
orig_type
},
f_res
);
}
}
else
{
if
(
orig_type
==
shape
::
float_type
)
{
prog
.
replace_instruction
(
ins
,
op
::
mul
{},
l_alpha
,
f_dot
);
}
else
{
auto
alpha_ab
=
prog
.
insert_instruction
(
ins
,
op
::
mul
{},
l_alpha
,
f_dot
);
prog
.
replace_instruction
(
ins
,
op
::
convert
{
orig_type
},
alpha_ab
);
}
}
}
}
}
}
}
...
...
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