Hey Everyone,
I am new to TVM and I am trying to optimise and deploy yolov5s on the Jetson Nano. when I try to run the optimization directly on the Jetson Nano it works without any problems but when I try to run the tuning via RPC then it fails as for all tasks AutoTVM could not find any valid schedulers.
The content of file /tmp/tvm_tuning_errors_xxxxx.log
looks like follow:
and my code is as follows:
import os import numpy as np import tvm import onnx from tvm import autotvm from tvm import relay import tvm.relay.testing from tvm.autotvm.tuner import XGBTuner, GATuner, RandomTuner, GridSearchTuner from tvm.contrib.utils import tempdir import tvm.contrib.graph_runtime as runtime from PIL import Image import cv2 from tvm.contrib import graph_executor import timeit import sys
network = “Yolo-v5-nano” # name of the output file log_file = “%s.log” % network dtype = ‘float32’ device_key=“nano”
def get_model(model, shape): “”" this function takes care of translating the model to relay""" mod, params = relay.frontend.from_onnx(model, shape) return mod, params, shape
model = onnx.load(“best.onnx”)
input_name = “images” shape_dict = {input_name: (1, 3, 640, 640)} # select input shape of the data
target = tvm.target.Target(“nvidia/jetson-nano”, host=“llvm -mtriple=aarch64-linux-gnu”)
tuning_option = { ‘log_filename’: log_file,
'tuner': 'xgb', 'n_trial': 500, 'early_stopping': 100, 'measure_option': autotvm.measure_option( builder=autotvm.LocalBuilder(timeout=10), runner=autotvm.RPCRunner( 'nano', # change the device key to your key '0.0.0.0', 9190, number=20, repeat=3, timeout=4, min_repeat_ms=150, ), ), "tuning_records": "%s.json" % network,
}
tuner = tuning_option[“tuner”]
log_filename = tuning_option[“log_filename”]
mod, params, input_shape = get_model(model, shape_dict) tasks = autotvm.task.extract_from_program(mod[“main”], target=target, params=params,)
tmp_log_file = log_filename + “.tmp” if os.path.exists(tmp_log_file): os.remove(tmp_log_file)
open(tmp_log_file, ‘w’).close()
for i, tsk in enumerate(reversed(tasks)): prefix = "[Task %2d/%2d] " % (i+1, len(tasks))
# create tuner if tuner == 'xgb' or tuner == 'xgb-rank': tuner_obj = XGBTuner(tsk, feature_type='knob', loss_type='rank') elif tuner == 'ga': tuner_obj = GATuner(tsk, pop_size=100) elif tuner == 'random': tuner_obj = RandomTuner(tsk) elif tuner == 'gridsearch': tuner_obj = GridSearchTuner(tsk) else: raise ValueError("Invalid tuner: " + tuner) # do tuning tuner_obj.tune(n_trial=min(tuning_option["n_trial"], len(tsk.config_space)), early_stopping=tuning_option["early_stopping"], measure_option=tuning_option["measure_option"], callbacks=[ autotvm.callback.progress_bar( tuning_option["n_trial"], prefix=prefix), autotvm.callback.log_to_file(tmp_log_file)])
autotvm.record.pick_best(tmp_log_file, log_filename) os.remove(tmp_log_file)
I don’t understand why the tuning works perfectly fine when it’s directly done on the nano yet there are these errors when the tuning is done via RPC. can anyone help? thanks!