7def _dump_npy_included_json(output_dir: str, json_content: dict):
8 """
9 Dump json and npy files to output_dir
10 """
11
12 if not os.path.exists(output_dir):
13 os.makedirs(output_dir)
14
15
16 _index = 0
17 _index_to_value = dict()
18
19
20 for tensor_name, qparam in json_content.items():
21 assert type(tensor_name) == str
22 assert type(qparam) == dict
23 for field, value in qparam.items():
24 if isinstance(value, np.ndarray):
25 npy_name = str(_index) + '.npy'
26
27
28 np.save(os.path.join(output_dir, npy_name), value)
29
30
31 json_content[tensor_name][field] = npy_name
32
33
34 _index_to_value[_index] = tensor_name + "_" + field
35 _index += 1
36
37
38 with open(os.path.join(output_dir, 'qparam.json'), 'w') as f:
39 json.dump(json_content, f, indent=2)
40
41