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