It is recommended that you run tuning by yourself if you have your customized network or devices.
Please follow the tutorial for
-[NVIDIA GPU](https://docs.tvm.ai/tutorials/autotvm/tune_nnvm_cuda.html),
-[ARM CPU](https://docs.tvm.ai/tutorials/autotvm/tune_nnvm_arm.html),
-[Mobile GPU](https://docs.tvm.ai/tutorials/autotvm/tune_nnvm_mobile_gpu.html).
+[NVIDIA GPU](https://docs.tvm.ai/tutorials/autotvm/tune_conv2d_cuda.html),
+[ARM CPU](https://docs.tvm.ai/tutorials/autotvm/tune_relay_arm.html),
+[Mobile GPU](https://docs.tvm.ai/tutorials/autotvm/tune_relay_mobile_gpu.html).
### NVIDIA GPU
2. Register devices to the tracker
* For Linux device
- * Build tvm runtime on your device [Help](https://docs.tvm.ai/tutorials/nnvm/deploy_model_on_rasp.html#build-tvm-runtime-on-device)
+ * Build tvm runtime on your device [Help](https://docs.tvm.ai/tutorials/frontend/deploy_model_on_rasp.html#build-tvm-runtime-on-device)
* Register your device to tracker by
```bash
python3 -m tvm.exec.rpc_server --tracker=[HOST_IP]:9190 --key=[DEVICE_KEY]
import tvm
from tvm.contrib.util import tempdir
import tvm.contrib.graph_runtime as runtime
-import nnvm.compiler
-import nnvm.testing
+from tvm import relay
from util import get_network, print_progress
net, params, input_shape, output_shape = get_network(network, batch_size=1)
print_progress("%-20s building..." % network)
- with nnvm.compiler.build_config(opt_level=3):
- graph, lib, params = nnvm.compiler.build(
- net, target=target, target_host=target_host,
- shape={'data': input_shape}, params=params, dtype=dtype)
+ with relay.build_config(opt_level=3):
+ graph, lib, params = relay.build(
+ net, target=target, target_host=target_host, params=params)
tmp = tempdir()
if 'android' in str(target):
parser.add_argument("--network", type=str, choices=
['resnet-18', 'resnet-34', 'resnet-50',
'vgg-16', 'vgg-19', 'densenet-121', 'inception_v3',
- 'mobilenet', 'mobilenet_v2', 'squeezenet_v1.0', 'squeezenet_v1.1'],
+ 'mobilenet', 'squeezenet_v1.0', 'squeezenet_v1.1'],
help='The name of neural network')
parser.add_argument("--model", type=str, choices=
['rk3399', 'mate10', 'mate10pro', 'p20', 'p20pro',
import numpy as np
import tvm
-from tvm.contrib.util import tempdir
import tvm.contrib.graph_runtime as runtime
-import nnvm.compiler
-import nnvm.testing
+from tvm import relay
from util import get_network
def benchmark(network, target):
net, params, input_shape, output_shape = get_network(network, batch_size=1)
- with nnvm.compiler.build_config(opt_level=3):
- graph, lib, params = nnvm.compiler.build(
- net, target=target, shape={'data': input_shape}, params=params, dtype=dtype)
+ with relay.build_config(opt_level=3):
+ graph, lib, params = relay.build(net, target=target, params=params)
# create runtime
ctx = tvm.context(str(target), 0)
parser.add_argument("--network", type=str, choices=
['resnet-18', 'resnet-34', 'resnet-50',
'vgg-16', 'vgg-19', 'densenet-121', 'inception_v3',
- 'mobilenet', 'mobilenet_v2', 'squeezenet_v1.0', 'squeezenet_v1.1'],
+ 'mobilenet', 'squeezenet_v1.0', 'squeezenet_v1.1'],
help='The name of neural network')
parser.add_argument("--model", type=str,
choices=['1080ti', 'titanx', 'tx2', 'gfx900'], default='1080ti',
import tvm
from tvm.contrib.util import tempdir
import tvm.contrib.graph_runtime as runtime
-import nnvm.compiler
-import nnvm.testing
+from tvm import relay
from util import get_network, print_progress
net, params, input_shape, output_shape = get_network(network, batch_size=1, dtype=dtype)
print_progress("%-20s building..." % network)
- with nnvm.compiler.build_config(opt_level=3):
- graph, lib, params = nnvm.compiler.build(
- net, target=target, target_host=target_host,
- shape={'data': input_shape}, params=params, dtype=dtype)
+ with relay.build_config(opt_level=3):
+ graph, lib, params = relay.build(
+ net, target=target, target_host=target_host, params=params)
tmp = tempdir()
if 'android' in str(target) or 'android' in str(target_host):
parser.add_argument("--network", type=str, choices=
['resnet-18', 'resnet-34', 'resnet-50',
'vgg-16', 'vgg-19', 'densenet-121', 'inception_v3',
- 'mobilenet', 'mobilenet_v2', 'squeezenet_v1.0', 'squeezenet_v1.1'],
+ 'mobilenet', 'squeezenet_v1.0', 'squeezenet_v1.1'],
help='The name of neural network')
parser.add_argument("--model", type=str, choices=
['rk3399'], default='rk3399',
"""Utility for benchmark"""
import sys
-import nnvm
+from tvm import relay
+from tvm.relay import testing
def get_network(name, batch_size, dtype='float32'):
"""Get the symbol definition and random weight of a network
output_shape = (batch_size, 1000)
if name == 'mobilenet':
- net, params = nnvm.testing.mobilenet.get_workload(batch_size=batch_size, dtype=dtype)
- elif name == 'mobilenet_v2':
- net, params = nnvm.testing.mobilenet_v2.get_workload(batch_size=batch_size, dtype=dtype)
+ net, params = testing.mobilenet.get_workload(batch_size=batch_size, dtype=dtype)
elif name == 'inception_v3':
input_shape = (batch_size, 3, 299, 299)
- net, params = nnvm.testing.inception_v3.get_workload(batch_size=batch_size, dtype=dtype)
+ net, params = testing.inception_v3.get_workload(batch_size=batch_size, dtype=dtype)
elif "resnet" in name:
n_layer = int(name.split('-')[1])
- net, params = nnvm.testing.resnet.get_workload(num_layers=n_layer, batch_size=batch_size, dtype=dtype)
+ net, params = testing.resnet.get_workload(num_layers=n_layer, batch_size=batch_size, dtype=dtype)
elif "vgg" in name:
n_layer = int(name.split('-')[1])
- net, params = nnvm.testing.vgg.get_workload(num_layers=n_layer, batch_size=batch_size, dtype=dtype)
+ net, params = testing.vgg.get_workload(num_layers=n_layer, batch_size=batch_size, dtype=dtype)
elif "densenet" in name:
n_layer = int(name.split('-')[1])
- net, params = nnvm.testing.densenet.get_workload(num_layers=n_layer, batch_size=batch_size, dtype=dtype)
+ net, params = testing.densenet.get_workload(densenet_size=n_layer, batch_size=batch_size, dtype=dtype)
elif "squeezenet" in name:
version = name.split("_v")[1]
- net, params = nnvm.testing.squeezenet.get_workload(batch_size=batch_size, version=version, dtype=dtype)
- elif name == 'custom':
- # an example for custom network
- from nnvm.testing import utils
- net = nnvm.sym.Variable('data')
- net = nnvm.sym.conv2d(net, channels=4, kernel_size=(3,3), padding=(1,1))
- net = nnvm.sym.flatten(net)
- net = nnvm.sym.dense(net, units=1000)
- net, params = utils.create_workload(net, batch_size, (3, 224, 224), dtype=dtype)
+ net, params = testing.squeezenet.get_workload(batch_size=batch_size, version=version, dtype=dtype)
elif name == 'mxnet':
# an example for mxnet model
from mxnet.gluon.model_zoo.vision import get_model
block = get_model('resnet18_v1', pretrained=True)
- net, params = nnvm.frontend.from_mxnet(block)
- net = nnvm.sym.softmax(net)
+ net, params = relay.frontend.from_mxnet(block, shape={'data': input_shape}, dtype=dtype)
+ net = net["main"]
+ net = relay.Function(net.params, relay.nn.softmax(net.body), None, net.type_params, net.attrs)
+ net = relay.Module.from_expr(net)
else:
raise ValueError("Unsupported network: " + name)