[Auto-Tuning VTA solved] Using simulator to tune resnet18 on VTA successfully

Hi everyone, I am new to tvm, and I am going through the VTA tutorial Auto-tuning a convolutional network on VTA.
The example is run with some PYNQ boards. However, I want to run Auto TVM in simulation mode because of some reasons.

when I run python tune_relay_vta.py , it tells me Cannot connect to tracker :

So could I run it in fsim mode or tsim mode? What should I do?
I know that maybe I need to modify the code of “RPC Tacker” in the example code. Hope someone give could me some specific advice.
Thanks :pray:
By the way, I’m able to run the “deploy_classification.py” in the tutorial.

1 Like

Thanks to @jiang-haitian , the tvm source code needs two minor changes.

First, in TVM_ROOT/python/tvm/__init__.py:

# Add this code to enable vta fsim for autotvm
import vta.testing

Second, in TVM_ROOT/vta/tutorials/autotvm/tune_relay_vta.py:

tuning_option = {
    "log_filename": log_file,
    "tuner": "random",
    "n_trial": 1000,
    "early_stopping": None,
    "measure_option": autotvm.measure_option(
        builder=autotvm.LocalBuilder(),
        runner=autotvm.RPCRunner(
            env.TARGET,
            host=tracker_host,
            port=tracker_port,
            number=5,
            timeout=60,
            # set module_loader=None, if using sim mode
            # module_loader=vta.module_loader(),
            module_loader=None if env.TARGET in ["sim"] else vta.module_loader(),
        ),
    ),
}

With these changes, we can auto-tune a convnet on VTA without using a FPGA board. :100:
Anyway, this is only a temporary solution. Maybe there are better solutions, if we consider the overall structure of the tvm code.

Sorry, I got this problem when following like you do.

vllF.png) Could you give me some suggestions?

The error is “tvm has no attribute register_func”.
It seems that something else is wrong, please check your code, or could you show more infomation?
By the way, I used tvm-v0.8.0 (but it doesn’t matter right?) Good Luck :coffee:

I guess it is about circular import because you say that First, in TVM_ROOT/python/tvm/__init__.py:

# Add this code to enable vta fsim for autotvm
import vta.testing

I guess this is the reason for this error. Could you show more information? Because I think there are more things needed to be done than just you suggest doing thank you very much.

Hi, I just succeed in my enveronment (tvm-v0.8.0, ubuntu-18.04).
Have you imported vta.testiing in other python files?
Hope you can solve the problem.

I still face the problem about Cannot connect to tracker how do you solve that?

Could you show more codes? I think that parts need to be modified

Hi, there,

I can run tune_relay_vta.py with VTA simulator fsim in another way.

Please try the following steps (tvm version = v0.10.dev0).

Step 1.

eidt TVM_ROOT/vta/python/vta/exec/rpc_server.py: Line 42

def server_start():
    """VTA RPC server extension."""
    # pylint: disable=unused-variable
    curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
    proj_root = os.path.abspath(os.path.join(curr_path, "../../../../"))
    dll_path = find_libvta("libvta_fsim")[0]  # <== HERE!
    cfg_path = os.path.abspath(os.path.join(proj_root, "3rdparty/vta-hw/config/vta_config.json"))

Please check if there is the dynamic library file libvta_fsim.so in TVMROOT/build.

Step 2.

edit TVM_ROOT/vta/tutorials/autotvm/tune_relay_vta.py: Line 218

tuning_option = {
    "log_filename": log_file,
    "tuner": "random",
    "n_trial": 1000,
    "early_stopping": None,
    "measure_option": autotvm.measure_option(
        builder=autotvm.LocalBuilder(),
        runner=autotvm.RPCRunner(
            env.TARGET,
            host=tracker_host,
            port=tracker_port,
            number=5,
            timeout=60,
            module_loader=None  # <== HERE!

            # check_correctness=True, # TODO: re-enable when check_correctness works again.
        ),
    ),
}

, which same same as the way by denis above.

Step 3.

run tracker & server

python -m tvm.exec.rpc_tracker --host=0.0.0.0 --port=9190 &
python -m vta.exec.rpc_server --tracker=0.0.0.0:9190 --key=sim &

Use vta.exec.rpc_server not tvm.exec.rpc_server for RPC server because VTA modefiled rpc_server loads fsim module.

Step 4.

run the tuner script.

python TVM_ROOT/vta/tutorials/autotvm/tune_relay_vta.py

By the above steps, I’ve succeeded in running the tuner with fsim although lots of warning messages being produced like:

Warning: Trying to bind buffer to another one with lower alignment requirement  required_alignment=256, provided_alignment=128

I’ve not tried tsim, but maybe you can use libvta_tsim instead of libvta_fsim in Step 1. (Of cause, you have to build not only tvm with tsim option but also chisel codes in TVMROOT/3rdparty/vta-hw/hardware/chisel)

1 Like