Thank you for the response! Yeah, I can share the code:
Following is the code for evaluate the Graph Runtime performance:

    def evaluate_graph_runtime(batch_size):
        mod, params, data_shape, out_shape = get_net(batch_size)
        with relay.build_config(opt_level=3):
            graph, lib, params = relay.build(mod, target=target, target_host = 
target, params=params)
        from tvm.contrib import graph_runtime
        m = graph_runtime.create(graph, lib, ctx)
        m.set_input(**params)
        input_shape = (batch_size, 1024)
        data_tvm = (np.random.uniform(size=input_shape)).astype(dtype)
        m.set_input('data', data_tvm)
        m.run()
        start_time = datetime.datetime.now()
        for i in range (100):
            m.set_input('data', data_tvm)
            m.run()
        end_time = datetime.datetime.now()
        tvm_time = end_time - start_time

Following is the code for evaluate the VM Runtime performance with "isany" to 
specify the dynamic shape or not:

    def evaluate_vm_runtime(batch_size, isany=False):
        batch_size_ = batch_size
        if isany:
            batch_size_ = relay.Any()
        mod, params, data_shape, out_shape = get_net(batch_size_)
        exe = compile(mod, target="llvm", params=params)
        vm = vm_rt.VirtualMachine(exe)
        vm.init(ctx)
        input_shape = (batch_size, 1024)
        data_tvm = 
tvm.nd.array((np.random.uniform(size=input_shape)).astype(dtype))
        input_list = [data_tvm]
        vm.run(input_list)
        start_time = datetime.datetime.now()
        for i in range(100):
            vm.run(input_list)
        end_time = datetime.datetime.now()
        tvm_time = end_time - start_time

To get the network, using the following code:

    def get_net(batch_size):
        input_shape = (batch_size, 1024)
        output_shape = (batch_size, 128)
        data = relay.var("data", shape=input_shape, dtype=dtype)
        dense0 = relay.testing.layers.dense_add_bias(data=data, units=512, 
name='fc0')
        dense1 = relay.testing.layers.dense_add_bias(data=dense0, units=256, 
name='fc1')
        dense2 = relay.testing.layers.dense_add_bias(data=dense1, units=128, 
name='fc2')
        func = relay.Function(relay.analysis.free_vars(dense2), dense2)
        mod, params = create_workload(func)
        return mod, params, input_shape, output_shape

Thank you!





---
[Visit 
Topic](https://discuss.tvm.ai/t/vm-the-performance-degradation-of-vm-runtime-and-dynamic-shape-support-compared-to-graph-runtime/6076/5)
 to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.tvm.ai/email/unsubscribe/72d1f4dcf9091d9364831f4f5a74f61801afccc0d7d6bf1301258d497ad445ac).

Reply via email to