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
a457df8a
Commit
a457df8a
authored
Dec 26, 2019
by
masahi
Committed by
Wuwei Lin
Dec 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Quantization, Calibrate] Fix context creation when current_target is explicity set (#4582)
parent
e0cf9e31
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
python/tvm/relay/quantize/_calibrate.py
+9
-2
tests/python/relay/test_pass_auto_quantize.py
+24
-0
No files found.
python/tvm/relay/quantize/_calibrate.py
View file @
a457df8a
...
...
@@ -53,11 +53,18 @@ def collect_stats(mod, dataset):
logging
.
info
(
"collecting statistics for calibration..."
)
func
=
mod
[
'main'
]
func
=
_quantize
.
CreateStatsCollector
(
func
)
target
=
tvm
.
target
.
current_target
()
or
'llvm'
if
tvm
.
target
.
current_target
():
target
=
tvm
.
target
.
current_target
()
ctx
=
tvm
.
context
(
target
.
target_name
)
else
:
target
=
'llvm'
ctx
=
tvm
.
context
(
target
)
with
_transform
.
build_config
(
opt_level
=
3
):
graph
,
lib
,
params
=
_build_module
.
build
(
func
,
target
=
target
)
outputs
=
[]
runtime
=
graph_runtime
.
create
(
graph
,
lib
,
tvm
.
context
(
target
)
)
runtime
=
graph_runtime
.
create
(
graph
,
lib
,
ctx
)
runtime
.
set_input
(
**
params
)
num_outputs
=
runtime
.
get_num_outputs
()
...
...
tests/python/relay/test_pass_auto_quantize.py
View file @
a457df8a
...
...
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import
numpy
as
np
import
tvm
from
tvm
import
relay
from
tvm.relay
import
testing
...
...
@@ -45,5 +46,28 @@ def test_mul_rewrite():
quantize_and_build
(
act
*
pool
)
def
get_calibration_dataset
(
input_name
):
dataset
=
[]
for
i
in
range
(
5
):
data
=
np
.
random
.
uniform
(
size
=
(
1
,
3
,
224
,
224
))
dataset
.
append
({
input_name
:
data
})
return
dataset
def
test_calibrate_target
(
create_target
=
False
):
mod
,
params
=
testing
.
resnet
.
get_workload
(
num_layers
=
18
)
dataset
=
get_calibration_dataset
(
"data"
)
with
relay
.
quantize
.
qconfig
(
calibrate_mode
=
"kl_divergence"
):
if
create_target
:
with
tvm
.
target
.
create
(
"llvm"
):
relay
.
quantize
.
quantize
(
mod
,
params
,
dataset
)
else
:
# current_target = None
relay
.
quantize
.
quantize
(
mod
,
params
,
dataset
)
if
__name__
==
"__main__"
:
test_mul_rewrite
()
test_calibrate_target
(
False
)
test_calibrate_target
(
True
)
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