Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
66cd036e
Commit
66cd036e
authored
Feb 16, 2019
by
ziheng
Committed by
eqy
Feb 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Quantize] Skip for same input-output domain scale. (#2611)
parent
2ae3124f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
2 deletions
+8
-2
src/relay/pass/quantize.cc
+8
-2
No files found.
src/relay/pass/quantize.cc
View file @
66cd036e
...
@@ -198,14 +198,20 @@ Expr QuantizeRealize(const Call& ref_call,
...
@@ -198,14 +198,20 @@ Expr QuantizeRealize(const Call& ref_call,
// x * idom_scale = y * odom_scale
// x * idom_scale = y * odom_scale
// => y = x * idom_scale / odom_scale
// => y = x * idom_scale / odom_scale
if
(
const
auto
*
n
=
new_args
[
0
].
as
<
QRealizeIntExprNode
>
())
{
if
(
const
auto
*
n
=
new_args
[
0
].
as
<
QRealizeIntExprNode
>
())
{
// int32->int8
Expr
data
=
n
->
data
;
Expr
data
=
n
->
data
;
float
idom_scale_imm
=
GetScalarFromConstant
<
float
>
(
n
->
dom_scale
);
float
idom_scale_imm
=
GetScalarFromConstant
<
float
>
(
n
->
dom_scale
);
float
odom_scale_imm
=
GetScalarFromConstant
<
float
>
(
dom_scale
);
float
odom_scale_imm
=
GetScalarFromConstant
<
float
>
(
dom_scale
);
if
(
idom_scale_imm
==
odom_scale_imm
)
{
// same domain scale, only clip
data
=
Clip
(
data
,
clip_min_imm
,
clip_max_imm
);
return
QRealizeIntExprNode
::
make
(
data
,
dom_scale
,
n
->
dtype
);
}
float
shift_nbit
=
std
::
log2
(
odom_scale_imm
/
idom_scale_imm
);
float
shift_nbit
=
std
::
log2
(
odom_scale_imm
/
idom_scale_imm
);
// int32->int8
CHECK_GT
(
shift_nbit
,
0
);
CHECK_GT
(
shift_nbit
,
0
);
if
(
static_cast
<
int
>
(
shift_nbit
)
==
shift_nbit
)
{
if
(
static_cast
<
int
>
(
shift_nbit
)
==
shift_nbit
)
{
// use shift
// use
right
shift
if
(
cfg
->
round_for_shift
)
{
if
(
cfg
->
round_for_shift
)
{
float
round_bias
=
std
::
pow
(
2.0
,
shift_nbit
-
1
);
float
round_bias
=
std
::
pow
(
2.0
,
shift_nbit
-
1
);
data
=
Add
(
data
,
MakeConstantScalar
(
cfg
->
dtype_activation
,
static_cast
<
int
>
(
round_bias
)));
data
=
Add
(
data
,
MakeConstantScalar
(
cfg
->
dtype_activation
,
static_cast
<
int
>
(
round_bias
)));
...
...
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