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
e93c3a10
"...diffusion/python_stable_diffusion_21/requirements.txt" did not exist on "5ba656a325387a73ea62192f893b9674cf1679d0"
Commit
e93c3a10
authored
Oct 18, 2023
by
lakhinderwalia
Browse files
quantize tie half to even
parent
94bda243
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
4 deletions
+44
-4
src/include/migraphx/op/quantizelinear.hpp
src/include/migraphx/op/quantizelinear.hpp
+4
-3
src/include/migraphx/op/round.hpp
src/include/migraphx/op/round.hpp
+1
-1
test/onnx/gen_onnx.py
test/onnx/gen_onnx.py
+18
-0
test/onnx/verify_onnx.cpp
test/onnx/verify_onnx.cpp
+21
-0
No files found.
src/include/migraphx/op/quantizelinear.hpp
View file @
e93c3a10
...
@@ -63,8 +63,9 @@ struct quantizelinear
...
@@ -63,8 +63,9 @@ struct quantizelinear
argument
compute
(
const
shape
&
output_shape
,
std
::
vector
<
argument
>
args
)
const
argument
compute
(
const
shape
&
output_shape
,
std
::
vector
<
argument
>
args
)
const
{
{
auto
x
=
args
.
at
(
0
);
auto
round_even
=
[](
auto
v
)
{
return
v
-
remainder
(
v
,
1.0
);
};
auto
y_scale
=
args
.
at
(
1
);
auto
x
=
args
.
at
(
0
);
auto
y_scale
=
args
.
at
(
1
);
std
::
vector
<
int8_t
>
zeros
(
output_shape
.
bytes
(),
0
);
std
::
vector
<
int8_t
>
zeros
(
output_shape
.
bytes
(),
0
);
argument
y_zero_point
{
output_shape
,
zeros
.
data
()};
argument
y_zero_point
{
output_shape
,
zeros
.
data
()};
if
(
args
.
size
()
==
3
)
if
(
args
.
size
()
==
3
)
...
@@ -79,7 +80,7 @@ struct quantizelinear
...
@@ -79,7 +80,7 @@ struct quantizelinear
auto
min_value
=
std
::
numeric_limits
<
quant_type
>::
min
();
auto
min_value
=
std
::
numeric_limits
<
quant_type
>::
min
();
auto
max_value
=
std
::
numeric_limits
<
quant_type
>::
max
();
auto
max_value
=
std
::
numeric_limits
<
quant_type
>::
max
();
par_for
(
output_shape
.
elements
(),
[
&
](
auto
i
)
{
par_for
(
output_shape
.
elements
(),
[
&
](
auto
i
)
{
int64_t
quantized
=
static_cast
<
int64_t
>
(
std
::
round
(
input
[
i
]
/
scales
[
i
]))
+
int64_t
quantized
=
static_cast
<
int64_t
>
(
round
_even
(
input
[
i
]
/
scales
[
i
]))
+
static_cast
<
int64_t
>
(
zero_pts
[
i
]);
static_cast
<
int64_t
>
(
zero_pts
[
i
]);
output
[
i
]
=
std
::
max
(
static_cast
<
int64_t
>
(
min_value
),
output
[
i
]
=
std
::
max
(
static_cast
<
int64_t
>
(
min_value
),
std
::
min
(
static_cast
<
int64_t
>
(
max_value
),
quantized
));
std
::
min
(
static_cast
<
int64_t
>
(
max_value
),
quantized
));
...
...
src/include/migraphx/op/round.hpp
View file @
e93c3a10
...
@@ -35,7 +35,7 @@ struct round : unary<round>
...
@@ -35,7 +35,7 @@ struct round : unary<round>
{
{
auto
apply
()
const
auto
apply
()
const
{
{
return
[](
auto
x
)
{
return
std
::
round
(
x
);
};
return
[](
auto
v
)
{
return
v
-
remainder
(
v
,
1.0
);
};
}
}
};
};
...
...
test/onnx/gen_onnx.py
View file @
e93c3a10
...
@@ -5495,6 +5495,24 @@ def prelu_brcst_test():
...
@@ -5495,6 +5495,24 @@ def prelu_brcst_test():
return
([
node
],
[
arg0
,
arg1
],
[
arg_out
])
return
([
node
],
[
arg0
,
arg1
],
[
arg_out
])
@
onnx_test
()
def
qlinear_test
():
x
=
helper
.
make_tensor_value_info
(
'X'
,
TensorProto
.
FLOAT
,
[
6
])
sc_y
=
helper
.
make_tensor
(
'y_scale'
,
TensorProto
.
FLOAT
,
[],
[
2
])
zero_pt_y
=
helper
.
make_tensor
(
'y_zero_point'
,
TensorProto
.
UINT8
,
[],
[
128
])
y
=
helper
.
make_tensor_value_info
(
'Y'
,
TensorProto
.
UINT8
,
[
6
])
node
=
onnx
.
helper
.
make_node
(
'QuantizeLinear'
,
inputs
=
[
'X'
],
outputs
=
[
'Y'
],
)
return
([
node
],
[
x
],
[
y
],
[
sc_y
,
zero_pt_y
])
@
onnx_test
()
@
onnx_test
()
def
qlinearadd_test
():
def
qlinearadd_test
():
a
=
helper
.
make_tensor_value_info
(
'A'
,
TensorProto
.
UINT8
,
[
64
])
a
=
helper
.
make_tensor_value_info
(
'A'
,
TensorProto
.
UINT8
,
[
64
])
...
...
test/onnx/verify_onnx.cpp
View file @
e93c3a10
...
@@ -1344,6 +1344,27 @@ TEST_CASE(nonzero_test)
...
@@ -1344,6 +1344,27 @@ TEST_CASE(nonzero_test)
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
result_vector
,
gold
));
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
result_vector
,
gold
));
}
}
TEST_CASE
(
qlinear_test
)
{
// https://xadupre.github.io/draft/onnx/onnx_doc_folder/onnx__QuantizeLinear.html
migraphx
::
program
p
=
migraphx
::
parse_onnx
(
"qlinear_test.onnx"
);
p
.
compile
(
migraphx
::
make_target
(
"ref"
));
migraphx
::
shape
x
{
migraphx
::
shape
::
float_type
,
{
6
}};
std
::
vector
<
float
>
data_x
=
{
0
,
2
,
3
,
1000
,
-
254
,
-
1000
};
migraphx
::
parameter_map
pp
;
pp
[
"X"
]
=
migraphx
::
argument
(
x
,
data_x
.
data
());
auto
result
=
p
.
eval
(
pp
).
back
();
std
::
vector
<
uint8_t
>
result_vector
;
result
.
visit
([
&
](
auto
output
)
{
result_vector
.
assign
(
output
.
begin
(),
output
.
end
());
});
std
::
vector
<
uint8_t
>
gold
=
{
128
,
129
,
130
,
255
,
1
,
0
};
EXPECT
(
migraphx
::
verify
::
verify_rms_range
(
result_vector
,
gold
));
}
TEST_CASE
(
qlinearadd_test
)
TEST_CASE
(
qlinearadd_test
)
{
{
// github.com/microsoft/onnxruntime/blob/main/docs/ContribOperators.md#com.microsoft.QLinearAdd
// github.com/microsoft/onnxruntime/blob/main/docs/ContribOperators.md#com.microsoft.QLinearAdd
...
...
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