def test_debug_graph_runtime(): if not tvm.testing.device_enabled("llvm"): print("Skip because llvm is not enabled") return mod, params = relay.testing.synthetic.get_workload() with relay.build_config(opt_level=3): complied_graph_lib = relay.build_module.build(mod, "llvm", params=params) data = np.random.uniform(-1, 1, size=input_shape(mod)).astype("float32") # raw api ctx = tvm.cpu() try: gmod = complied_graph_lib["debug_create"]("default", ctx) except: print("Skip because debug graph_runtime not enabled") return set_input = gmod["set_input"] run = gmod["run"] get_output = gmod["get_output"] set_input("data", tvm.nd.array(data)) run() out = get_output(0).asnumpy() tvm.testing.assert_allclose(out, verify(data), atol=1e-5) # debug graph runtime wrapper debug_g_mod = debug_runtime.GraphModuleDebug( complied_graph_lib["debug_create"]("default", ctx), [ctx], complied_graph_lib.get_json(), None, ) debug_g_mod.set_input("data", data) debug_g_mod.run() out = debug_g_mod.get_output(0).asnumpy() tvm.testing.assert_allclose(out, verify(data), atol=1e-5)
def eval_cpu(args, model_inst, compiled_model, samples): lowered = model_inst.lower_model(compiled_model) if args.use_debug_runtime: graph_mod = debug_runtime.GraphModuleDebug( lowered.module["debug_create"]("default", tvm.cpu(0)), [tvm.cpu(0)], lowered.get_json(), dump_root=f'{util.get_repo_root()}/debug/cpu') print('graph mod', graph_mod) else: graph_mod = tvm.contrib.graph_runtime.GraphModule(lowered["default"](tvm.cpu(0))) print('graph mod', lowered, graph_mod) graph_mod.set_input(**lowered.params) results = [] for i, sample in enumerate(samples): inputs = adapt_all_inputs( model_inst, sample, compiled_model.ir_mod[compiled_model.entry_point]) for key in inputs: if key in sample.inputs: graph_mod.set_input(key, inputs[key]) graph_mod.run() results.append(adapt_all_outputs(model_inst, graph_mod, sample)) _LOG.info('got prediction: %r', results[-1]) return results