Commit f2d7787e by Lianmin Zheng Committed by Tianqi Chen

[AUTOTVM] Misc fix to document and style (#2035)

parent 8ad3bd56
...@@ -34,7 +34,7 @@ def get_network(name, batch_size, dtype='float32'): ...@@ -34,7 +34,7 @@ def get_network(name, batch_size, dtype='float32'):
elif name == 'mobilenet_v2': elif name == 'mobilenet_v2':
net, params = nnvm.testing.mobilenet_v2.get_workload(batch_size=batch_size, dtype=dtype) net, params = nnvm.testing.mobilenet_v2.get_workload(batch_size=batch_size, dtype=dtype)
elif name == 'inception_v3': elif name == 'inception_v3':
input_shape = (1, 3, 299, 299) input_shape = (batch_size, 3, 299, 299)
net, params = nnvm.testing.inception_v3.get_workload(batch_size=batch_size, dtype=dtype) net, params = nnvm.testing.inception_v3.get_workload(batch_size=batch_size, dtype=dtype)
elif "resnet" in name: elif "resnet" in name:
n_layer = int(name.split('-')[1]) n_layer = int(name.split('-')[1])
......
...@@ -124,13 +124,15 @@ TVM package ...@@ -124,13 +124,15 @@ TVM package
~~~~~~~~~~~ ~~~~~~~~~~~
The python package is located at `tvm/python` The python package is located at `tvm/python`
There are several ways to install the package: There are two ways to install the package:
1. Set the environment variable `PYTHONPATH` to tell python where to find Method 1
This method is **recommended for developers** who may change the codes.
Set the environment variable `PYTHONPATH` to tell python where to find
the library. For example, assume we cloned `tvm` on the home directory the library. For example, assume we cloned `tvm` on the home directory
`~`. then we can added the following line in `~/.bashrc`. `~`. then we can added the following line in `~/.bashrc`.
It is **recommended for developers** who may change the codes. The changes will be immediately reflected once you pull the code and rebuild the project (no need to call ``setup`` again)
The changes will be immediately reflected once you pulled the code and rebuild the project (no need to call ``setup`` again)
.. code:: bash .. code:: bash
...@@ -138,7 +140,8 @@ There are several ways to install the package: ...@@ -138,7 +140,8 @@ There are several ways to install the package:
export PYTHONPATH=$TVM_HOME/python:$TVM_HOME/topi/python:$TVM_HOME/nnvm/python:${PYTHONPATH} export PYTHONPATH=$TVM_HOME/python:$TVM_HOME/topi/python:$TVM_HOME/nnvm/python:${PYTHONPATH}
2. Install tvm python bindings by `setup.py`: Method 2
Install tvm python bindings by `setup.py`:
.. code:: bash .. code:: bash
......
...@@ -551,7 +551,9 @@ def check_remote(target, device_key, host=None, port=None, priority=100, timeout ...@@ -551,7 +551,9 @@ def check_remote(target, device_key, host=None, port=None, priority=100, timeout
""" """
def _check(): def _check():
remote = request_remote(device_key, host, port, priority) remote = request_remote(device_key, host, port, priority)
remote.context(str(target)) ctx = remote.context(str(target))
while not ctx.exist: # wait until we get an available device
pass
t = threading.Thread(target=_check,) t = threading.Thread(target=_check,)
t.start() t.start()
t.join(timeout) t.join(timeout)
......
...@@ -252,13 +252,13 @@ Usage: ...@@ -252,13 +252,13 @@ Usage:
This record executable module has three modes. This record executable module has three modes.
* Print log file in readable format * Print log file in readable format
e.g. python -m autotvm.record --mode read --i collect_conv.log --begin 0 --end 5 --ir --code e.g. python -m tvm.autotvm.record --mode read --i collect_conv.log --begin 0 --end 5 --ir --code
* Extract history best from a large log file * Extract history best from a large log file
e.g. python -m autotvm.record --mode pick --i collect.log e.g. python -m tvm.autotvm.record --mode pick --i collect.log
* Split a log file into separate files, each of which contains only a single wkl * Split a log file into separate files, each of which contains only a single wkl
e.g. python -m autotvm.record --mode split --i collect.log e.g. python -m tvm.autotvm.record --mode split --i collect.log
""" """
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
......
...@@ -292,17 +292,13 @@ class ApplyHistoryBest(DispatchContext): ...@@ -292,17 +292,13 @@ class ApplyHistoryBest(DispatchContext):
best_by_targetkey[key] = (inp, res) best_by_targetkey[key] = (inp, res)
# use model as key to build best map # use model as key to build best map
for opt in inp.target.options: key = (inp.target.model, inp.task.workload)
if opt.startswith("-model"): if key not in best_by_model:
model = opt[7:] best_by_model[key] = (inp, res)
key = (model, inp.task.workload) else:
if key not in best_by_model: _, other_res = best_by_model[key]
best_by_model[key] = (inp, res) if np.mean(other_res.costs) > np.mean(res.costs):
else: best_by_model[key] = (inp, res)
_, other_res = best_by_model[key]
if np.mean(other_res.costs) > np.mean(res.costs):
best_by_model[key] = (inp, res)
break
logger.debug("Finish loading %d records", counter) logger.debug("Finish loading %d records", counter)
...@@ -313,14 +309,11 @@ class ApplyHistoryBest(DispatchContext): ...@@ -313,14 +309,11 @@ class ApplyHistoryBest(DispatchContext):
" above the dispatcher call. So does other target. ") " above the dispatcher call. So does other target. ")
# first try matching by model # first try matching by model
for opt in target.options: key = (target.model, workload)
if opt.startswith("-model"): if key in self._best_user_defined:
model = opt[7:] return self._best_user_defined[key]
key = (model, workload) if key in self.best_by_model:
if key in self._best_user_defined: return self.best_by_model[key][0].config
return self._best_user_defined[key]
if key in self.best_by_model:
return self.best_by_model[key][0].config
# then try matching by target key # then try matching by target key
for k in target.keys: for k in target.keys:
...@@ -333,11 +326,9 @@ class ApplyHistoryBest(DispatchContext): ...@@ -333,11 +326,9 @@ class ApplyHistoryBest(DispatchContext):
return None return None
def update(self, target, workload, cfg): def update(self, target, workload, cfg):
for opt in target.options: model = target.model
if opt.startswith("-model"): key = (model, workload)
model = opt[7:] self._best_user_defined[key] = cfg
key = (model, workload)
self._best_user_defined[key] = cfg
for k in target.keys: for k in target.keys:
key = (k, workload) key = (k, workload)
......
"""Initializer of parameters.""" """Initializer of parameters."""
import numpy as np
import tvm import tvm
from tvm import relay from tvm import relay
import numpy as np
class Initializer(object): class Initializer(object):
"""The base class of an initializer.""" """The base class of an initializer."""
...@@ -103,7 +104,7 @@ class Xavier(Initializer): ...@@ -103,7 +104,7 @@ class Xavier(Initializer):
raise ValueError("Incorrect factor type") raise ValueError("Incorrect factor type")
# Hack for mobilenet, because there is less connectivity # Hack for mobilenet, because there is less connectivity
if "depthwise" in name: if "depthwise" in name:
factor = 3 * 3 factor = hw_scale
scale = np.sqrt(self.magnitude / factor) scale = np.sqrt(self.magnitude / factor)
if self.rnd_type == "uniform": if self.rnd_type == "uniform":
arr[:] = np.random.uniform(-scale, scale, size=arr.shape) arr[:] = np.random.uniform(-scale, scale, size=arr.shape)
......
...@@ -419,7 +419,7 @@ def intel_graphics(model='unknown', options=None): ...@@ -419,7 +419,7 @@ def intel_graphics(model='unknown', options=None):
return _api_internal._TargetCreate("opencl", *opts) return _api_internal._TargetCreate("opencl", *opts)
def opengl(options=None): def opengl(model='unknown', options=None):
"""Returns a OpenGL target. """Returns a OpenGL target.
Parameters Parameters
...@@ -427,8 +427,8 @@ def opengl(options=None): ...@@ -427,8 +427,8 @@ def opengl(options=None):
options : str or list of str options : str or list of str
Additional options Additional options
""" """
options = _merge_opts([], options) opts = _merge_opts(["-model=%s" % model], options)
return _api_internal._TargetCreate("opengl", *options) return _api_internal._TargetCreate("opengl", *opts)
def arm_cpu(model='unknown', options=None): def arm_cpu(model='unknown', options=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment