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
e33de246
Unverified
Commit
e33de246
authored
Feb 07, 2020
by
Cody Yu
Committed by
GitHub
Feb 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Doc][AutoTVM] Fix bugs that override n_trials (#4842)
parent
0186ca49
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
48 deletions
+59
-48
tutorials/autotvm/tune_relay_arm.py
+5
-4
tutorials/autotvm/tune_relay_cuda.py
+5
-4
tutorials/autotvm/tune_relay_mobile_gpu.py
+5
-4
vta/tutorials/autotvm/tune_relay_vta.py
+44
-36
No files found.
tutorials/autotvm/tune_relay_arm.py
View file @
e33de246
...
...
@@ -299,13 +299,14 @@ def tune_tasks(tasks,
tuner_obj
.
load_history
(
autotvm
.
record
.
load_from_file
(
tmp_log_file
))
# do tuning
n
_trial
=
min
(
n_trial
,
len
(
tsk
.
config_space
))
tuner_obj
.
tune
(
n_trial
=
n
_trial
,
tsk
_trial
=
min
(
n_trial
,
len
(
tsk
.
config_space
))
tuner_obj
.
tune
(
n_trial
=
tsk
_trial
,
early_stopping
=
early_stopping
,
measure_option
=
measure_option
,
callbacks
=
[
autotvm
.
callback
.
progress_bar
(
n_trial
,
prefix
=
prefix
),
autotvm
.
callback
.
log_to_file
(
tmp_log_file
)])
autotvm
.
callback
.
progress_bar
(
tsk_trial
,
prefix
=
prefix
),
autotvm
.
callback
.
log_to_file
(
tmp_log_file
)
])
# pick best records to a cache file
autotvm
.
record
.
pick_best
(
tmp_log_file
,
log_filename
)
...
...
tutorials/autotvm/tune_relay_cuda.py
View file @
e33de246
...
...
@@ -201,13 +201,14 @@ def tune_tasks(tasks,
tuner_obj
.
load_history
(
autotvm
.
record
.
load_from_file
(
tmp_log_file
))
# do tuning
n
_trial
=
min
(
n_trial
,
len
(
tsk
.
config_space
))
tuner_obj
.
tune
(
n_trial
=
n
_trial
,
tsk
_trial
=
min
(
n_trial
,
len
(
tsk
.
config_space
))
tuner_obj
.
tune
(
n_trial
=
tsk
_trial
,
early_stopping
=
early_stopping
,
measure_option
=
measure_option
,
callbacks
=
[
autotvm
.
callback
.
progress_bar
(
n_trial
,
prefix
=
prefix
),
autotvm
.
callback
.
log_to_file
(
tmp_log_file
)])
autotvm
.
callback
.
progress_bar
(
tsk_trial
,
prefix
=
prefix
),
autotvm
.
callback
.
log_to_file
(
tmp_log_file
)
])
# pick best records to a cache file
autotvm
.
record
.
pick_best
(
tmp_log_file
,
log_filename
)
...
...
tutorials/autotvm/tune_relay_mobile_gpu.py
View file @
e33de246
...
...
@@ -283,13 +283,14 @@ def tune_tasks(tasks,
tuner_obj
.
load_history
(
autotvm
.
record
.
load_from_file
(
tmp_log_file
))
# do tuning
n
_trial
=
min
(
n_trial
,
len
(
tsk
.
config_space
))
tuner_obj
.
tune
(
n_trial
=
n
_trial
,
tsk
_trial
=
min
(
n_trial
,
len
(
tsk
.
config_space
))
tuner_obj
.
tune
(
n_trial
=
tsk
_trial
,
early_stopping
=
early_stopping
,
measure_option
=
measure_option
,
callbacks
=
[
autotvm
.
callback
.
progress_bar
(
n_trial
,
prefix
=
prefix
),
autotvm
.
callback
.
log_to_file
(
tmp_log_file
)])
autotvm
.
callback
.
progress_bar
(
tsk_trial
,
prefix
=
prefix
),
autotvm
.
callback
.
log_to_file
(
tmp_log_file
)
])
# pick best records to a cache file
autotvm
.
record
.
pick_best
(
tmp_log_file
,
log_filename
)
...
...
vta/tutorials/autotvm/tune_relay_vta.py
View file @
e33de246
...
...
@@ -74,6 +74,7 @@ from vta.top import graph_pack
# ---------------
# Perform vta-specific compilation with Relay from a Gluon model
def
compile_network
(
env
,
target
,
model
,
start_pack
,
stop_pack
):
# Populate the shape and data type dictionary
...
...
@@ -91,20 +92,18 @@ def compile_network(env, target, model, start_pack, stop_pack):
# Perform quantization in Relay
# Note: We set opt_level to 3 in order to fold batch norm
with
relay
.
build_config
(
opt_level
=
3
):
with
relay
.
quantize
.
qconfig
(
global_scale
=
8.0
,
skip_conv_layers
=
[
0
]):
with
relay
.
quantize
.
qconfig
(
global_scale
=
8.0
,
skip_conv_layers
=
[
0
]):
mod
=
relay
.
quantize
.
quantize
(
mod
,
params
=
params
)
# Perform graph packing and constant folding for VTA target
if
target
.
device_name
==
"vta"
:
assert
env
.
BLOCK_IN
==
env
.
BLOCK_OUT
relay_prog
=
graph_pack
(
mod
[
"main"
],
env
.
BATCH
,
env
.
BLOCK_OUT
,
env
.
WGT_WIDTH
,
start_name
=
start_pack
,
stop_name
=
stop_pack
)
relay_prog
=
graph_pack
(
mod
[
"main"
],
env
.
BATCH
,
env
.
BLOCK_OUT
,
env
.
WGT_WIDTH
,
start_name
=
start_pack
,
stop_name
=
stop_pack
)
return
relay_prog
,
params
...
...
@@ -195,8 +194,8 @@ target = env.target if device == "vta" else env.target_vta_cpu
# to start and end the graph packing relay pass: in other words
# where to start and finish offloading to VTA.
network
=
"resnet18_v1"
start_pack
=
"nn.max_pool2d"
stop_pack
=
"nn.global_avg_pool2d"
start_pack
=
"nn.max_pool2d"
stop_pack
=
"nn.global_avg_pool2d"
# Tuning option
log_file
=
"
%
s.
%
s.log"
%
(
device
,
network
)
...
...
@@ -209,12 +208,12 @@ tuning_option = {
'measure_option'
:
autotvm
.
measure_option
(
builder
=
autotvm
.
LocalBuilder
(),
runner
=
autotvm
.
RPCRunner
(
env
.
TARGET
,
host
=
tracker_host
,
port
=
tracker_por
t
,
number
=
5
,
timeout
=
60
,
check_correctness
=
True
),
runner
=
autotvm
.
RPCRunner
(
env
.
TARGET
,
host
=
tracker_hos
t
,
port
=
tracker_port
,
number
=
5
,
timeout
=
60
,
check_correctness
=
True
),
),
}
...
...
@@ -240,6 +239,7 @@ tuning_option = {
# Given that the tuning will be done on Pynq FPGA boards, make sure that
# the ```TARGET`` entry in the ``vta_config.json`` file is set to ``pynq``.
# You can skip the implementation of this function for this tutorial.
def
tune_tasks
(
tasks
,
measure_option
,
...
...
@@ -255,7 +255,7 @@ def tune_tasks(tasks,
os
.
remove
(
tmp_log_file
)
for
i
,
tsk
in
enumerate
(
reversed
(
tasks
)):
prefix
=
"[Task
%2
d/
%2
d] "
%
(
i
+
1
,
len
(
tasks
))
prefix
=
"[Task
%2
d/
%2
d] "
%
(
i
+
1
,
len
(
tasks
))
# create tuner
if
tuner
==
'xgb'
or
tuner
==
'xgb-rank'
:
...
...
@@ -276,23 +276,24 @@ def tune_tasks(tasks,
tuner_obj
.
load_history
(
autotvm
.
record
.
load_from_file
(
tmp_log_file
))
# do tuning
n
_trial
=
min
(
n_trial
,
len
(
tsk
.
config_space
))
tuner_obj
.
tune
(
n_trial
=
n
_trial
,
tsk
_trial
=
min
(
n_trial
,
len
(
tsk
.
config_space
))
tuner_obj
.
tune
(
n_trial
=
tsk
_trial
,
early_stopping
=
early_stopping
,
measure_option
=
measure_option
,
callbacks
=
[
autotvm
.
callback
.
progress_bar
(
n_trial
,
prefix
=
prefix
),
autotvm
.
callback
.
log_to_file
(
tmp_log_file
)])
autotvm
.
callback
.
progress_bar
(
tsk_trial
,
prefix
=
prefix
),
autotvm
.
callback
.
log_to_file
(
tmp_log_file
)
])
# pick best records to a cache file
autotvm
.
record
.
pick_best
(
tmp_log_file
,
log_filename
)
os
.
remove
(
tmp_log_file
)
########################################################################
# Register VTA-specific tuning tasks
def
register_vta_tuning_tasks
():
from
tvm.autotvm.task.topi_integration
import
TaskExtractEnv
,
deserialize_args
...
...
@@ -330,11 +331,15 @@ def register_vta_tuning_tasks():
########################################################################
# Finally, we launch tuning jobs and evaluate the end-to-end performance.
def
tune_and_evaluate
(
tuning_opt
):
if
env
.
TARGET
!=
"sim"
:
# Get remote from fleet node
remote
=
autotvm
.
measure
.
request_remote
(
env
.
TARGET
,
tracker_host
,
tracker_port
,
timeout
=
10000
)
remote
=
autotvm
.
measure
.
request_remote
(
env
.
TARGET
,
tracker_host
,
tracker_port
,
timeout
=
10000
)
# Reconfigure the JIT runtime and FPGA.
vta
.
reconfig_runtime
(
remote
)
vta
.
program_fpga
(
remote
,
bitstream
=
None
)
...
...
@@ -351,7 +356,7 @@ def tune_and_evaluate(tuning_opt):
mod
=
relay
.
Module
.
from_expr
(
relay_prog
)
tasks
=
autotvm
.
task
.
extract_from_program
(
mod
,
params
=
params
,
ops
=
(
tvm
.
relay
.
op
.
nn
.
conv2d
,),
ops
=
(
tvm
.
relay
.
op
.
nn
.
conv2d
,
),
target
=
target
,
target_host
=
env
.
target_host
)
...
...
@@ -361,17 +366,16 @@ def tune_and_evaluate(tuning_opt):
for
tsk
in
tasks
:
inp
=
tsk
.
args
[
0
][
1
]
wgt
=
tsk
.
args
[
1
][
1
]
batch
=
inp
[
0
]
*
inp
[
4
]
in_filter
=
inp
[
1
]
*
inp
[
5
]
out_filter
=
wgt
[
0
]
*
wgt
[
4
]
batch
=
inp
[
0
]
*
inp
[
4
]
in_filter
=
inp
[
1
]
*
inp
[
5
]
out_filter
=
wgt
[
0
]
*
wgt
[
4
]
height
,
width
=
inp
[
2
],
inp
[
3
]
hkernel
,
wkernel
=
wgt
[
2
],
wgt
[
3
]
hstride
,
wstride
=
tsk
.
args
[
2
][
0
],
tsk
.
args
[
2
][
1
]
hpad
,
wpad
=
tsk
.
args
[
3
][
0
],
tsk
.
args
[
3
][
1
]
print
(
"({}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {})"
.
format
(
batch
,
height
,
width
,
in_filter
,
out_filter
,
hkernel
,
wkernel
,
hpad
,
wpad
,
hstride
,
wstride
))
batch
,
height
,
width
,
in_filter
,
out_filter
,
hkernel
,
wkernel
,
hpad
,
wpad
,
hstride
,
wstride
))
# We do not run the tuning in our webpage server since it takes too long.
# Comment the following line to run it by yourself.
...
...
@@ -387,14 +391,17 @@ def tune_and_evaluate(tuning_opt):
print
(
"Compile..."
)
with
relay
.
build_config
(
opt_level
=
3
,
disabled_pass
=
{
"AlterOpLayout"
}):
if
target
.
device_name
!=
"vta"
:
graph
,
lib
,
params
=
relay
.
build
(
relay_prog
,
target
=
target
,
params
=
params
,
target_host
=
env
.
target_host
)
graph
,
lib
,
params
=
relay
.
build
(
relay_prog
,
target
=
target
,
params
=
params
,
target_host
=
env
.
target_host
)
else
:
with
vta
.
build_config
():
graph
,
lib
,
params
=
relay
.
build
(
relay_prog
,
target
=
target
,
params
=
params
,
target_host
=
env
.
target_host
)
relay_prog
,
target
=
target
,
params
=
params
,
target_host
=
env
.
target_host
)
# Export library
print
(
"Upload..."
)
...
...
@@ -421,6 +428,7 @@ def tune_and_evaluate(tuning_opt):
print
(
"Mean inference time (std dev):
%.2
f ms (
%.2
f ms)"
%
(
np
.
mean
(
prof_res
),
np
.
std
(
prof_res
)))
# Run the tuning and evaluate the results
tune_and_evaluate
(
tuning_option
)
...
...
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