Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tutorial] Fix autotvm tutorial #4895

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions tutorials/autotvm/tune_conv2d_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
# Now return to python code. Import packages.

import logging
import os
import sys
import numpy as np

Expand Down Expand Up @@ -195,23 +196,27 @@ def conv2d_no_batching(N, H, W, CO, CI, KH, KW, stride, padding):
# Begin tuning, log records to file `conv2d.log`
# During tuning we will also try many invalid configs, so you are expected to
# see many error reports. As long as you can see non-zero GFLOPS, it is okay.
logdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../docs/tutorials/autotvm")
if not os.path.isdir(logdir):
os.makedirs(logdir)
logfile = os.path.join(logdir, "conv2d.log")
tuner = autotvm.tuner.XGBTuner(task)
tuner.tune(n_trial=20,
measure_option=measure_option,
callbacks=[autotvm.callback.log_to_file('conv2d.log')])
callbacks=[autotvm.callback.log_to_file(logfile)])

#########################################################################
# Finally we can inspect the best config from log file, check correctness,
# and measure running time.

# inspect the best config
dispatch_context = autotvm.apply_history_best("conv2d.log")
dispatch_context = autotvm.apply_history_best(logfile)
best_config = dispatch_context.query(task.target, task.workload)
print("\nBest config:")
print(best_config)

# apply history best from log file
with autotvm.apply_history_best('conv2d.log'):
with autotvm.apply_history_best(logfile):
with tvm.target.create("cuda"):
s, arg_bufs = conv2d_no_batching(N, H, W, CO, CI, KH, KW, strides, padding)
func = tvm.build(s, arg_bufs)
Expand Down
9 changes: 7 additions & 2 deletions tutorials/autotvm/tune_simple_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

import logging
import sys
import os

import numpy as np
import tvm
Expand Down Expand Up @@ -297,10 +298,14 @@ def matmul(N, L, M, dtype):

# Begin tuning with RandomTuner, log records to file `matmul.log`
# You can use alternatives like XGBTuner.
logdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../docs/tutorials/autotvm")
if not os.path.isdir(logdir):
os.makedirs(logdir)
logfile = os.path.join(logdir, "matmul.log")
tuner = autotvm.tuner.RandomTuner(task)
tuner.tune(n_trial=10,
measure_option=measure_option,
callbacks=[autotvm.callback.log_to_file('matmul.log')])
callbacks=[autotvm.callback.log_to_file(logfile)])

#########################################################################
# Finally we apply history best from the cache file and check its correctness.
Expand All @@ -310,7 +315,7 @@ def matmul(N, L, M, dtype):
# with the same argument.

# apply history best from log file
with autotvm.apply_history_best('matmul.log'):
with autotvm.apply_history_best(logfile):
with tvm.target.create("llvm"):
s, arg_bufs = matmul(N, L, M, 'float32')
func = tvm.build(s, arg_bufs)
Expand Down