(
dest_path: str,
input_list_filename: str,
inputs=None,
prefix_input_filename: str = "",
)
| 888 | |
| 889 | |
| 890 | def generate_inputs( |
| 891 | dest_path: str, |
| 892 | input_list_filename: str, |
| 893 | inputs=None, |
| 894 | prefix_input_filename: str = "", |
| 895 | ): |
| 896 | |
| 897 | input_list_file = None |
| 898 | input_files = [] |
| 899 | |
| 900 | def prepare_input_file(tensor, fd, index, sub_index): |
| 901 | # transform torch.Tensor to raw file |
| 902 | input_file_name = f"{prefix_input_filename}_input_{index}_{sub_index}.raw" |
| 903 | input_file_path = f"{dest_path}/{input_file_name}" |
| 904 | if not isinstance(tensor, torch.Tensor): |
| 905 | tensor = torch.tensor(tensor) |
| 906 | tensor.detach().numpy().tofile(input_file_path) |
| 907 | input_files.append(input_file_path) |
| 908 | # prepare input_list |
| 909 | if sub_index > 0: |
| 910 | fd.write(" ") |
| 911 | fd.write(input_file_name) |
| 912 | |
| 913 | # Prepare input data |
| 914 | if inputs is not None: |
| 915 | input_list_file = f"{dest_path}/{input_list_filename}" |
| 916 | |
| 917 | with open(input_list_file, "w") as f: |
| 918 | for idx, data in enumerate(inputs): |
| 919 | sub_index = 0 |
| 920 | for d in data: |
| 921 | if isinstance(d, (list, tuple)): |
| 922 | for sub_d in d: |
| 923 | prepare_input_file(sub_d, f, idx, sub_index) |
| 924 | sub_index += 1 |
| 925 | else: |
| 926 | prepare_input_file(d, f, idx, sub_index) |
| 927 | sub_index += 1 |
| 928 | |
| 929 | f.write("\n") |
| 930 | |
| 931 | return input_list_file, input_files |
| 932 | |
| 933 | |
| 934 | def _qat_train(ori_model, captured_model, quantizer, dataset): |
no test coverage detected