MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / run_index

Function run_index

imperative/python/test/helpers/utils.py:101–137  ·  view source on GitHub ↗
(index)

Source from the content-addressed store, hash-verified

99 return inp, outp
100
101 def run_index(index):
102 inp, outp = get_param(cases, index)
103 inp_tensor = [make_tensor(inpi, network) for inpi in inp]
104
105 if test_trace and not network:
106 copied_inp = inp_tensor.copy()
107 for symbolic in [False, True]:
108 traced_func = trace(symbolic=symbolic)(func)
109
110 for _ in range(3):
111 traced_results = traced_func(*copied_inp, **kwargs)
112 check_results(traced_results, outp)
113
114 dumped_func = trace(symbolic=True, capture_as_const=True)(func)
115 dumped_results = dumped_func(*copied_inp, **kwargs)
116 check_results(dumped_results, outp)
117
118 file = io.BytesIO()
119 dump_info = dumped_func.dump(file)
120 file.seek(0)
121
122 # arg_name has pattern arg_xxx, xxx is int value
123 def take_number(arg_name):
124 return int(arg_name.split("_")[-1])
125
126 input_names = dump_info[4]
127 inps_np = [i.numpy() for i in copied_inp]
128 input_names.sort(key=take_number)
129 inp_dict = dict(zip(input_names, inps_np))
130 infer_cg = cgtools.GraphInference(file)
131
132 # assume #outputs == 1
133 loaded_results = list(infer_cg.run(inp_dict=inp_dict).values())[0]
134 check_results(loaded_results, outp, check_shape=False) # scalar info lost
135
136 results = func(*inp_tensor, **kwargs)
137 check_results(results, outp, check_shape=(network is None))
138
139 if len(cases) == 0:
140 raise ValueError("should give one case at least")

Callers 1

opr_testFunction · 0.85

Calls 12

runMethod · 0.95
traceClass · 0.90
get_paramFunction · 0.85
make_tensorFunction · 0.85
check_resultsFunction · 0.85
listFunction · 0.85
valuesMethod · 0.80
funcFunction · 0.50
copyMethod · 0.45
dumpMethod · 0.45
seekMethod · 0.45
numpyMethod · 0.45

Tested by

no test coverage detected