(io_info, tensors, logger, checking_output=False)
| 111 | |
| 112 | |
| 113 | def get_tensor(io_info, tensors, logger, checking_output=False): |
| 114 | # check if enough tensors have been given |
| 115 | if len(tensors) != len(io_info): |
| 116 | logger.error( |
| 117 | "given tensor numbers mismatch, " |
| 118 | f"expected {len(io_info)} but got {len(tensors)}" |
| 119 | ) |
| 120 | if checking_output: |
| 121 | logger.error( |
| 122 | "output tensors failed to generate, " |
| 123 | "please check executor_runner logs." |
| 124 | ) |
| 125 | exit(-1) |
| 126 | |
| 127 | return [get_ones_tensor(t, logger) for t in io_info] |
| 128 | |
| 129 | # list of tensors to be returned |
| 130 | ret_tensors = [] |
| 131 | for i, info in enumerate(io_info): |
| 132 | if list(tensors[i].shape) != info["shape"]: |
| 133 | logger.error( |
| 134 | f"tensor '{info['name']}' shape mismatch: " |
| 135 | f"users > {tensors[i].shape} - " |
| 136 | f"required > {info['shape']}" |
| 137 | ) |
| 138 | ret_tensors.append(get_ones_tensor(info, logger)) |
| 139 | continue |
| 140 | |
| 141 | ret_tensors.append( |
| 142 | tensors[i] |
| 143 | if tensors[i].dtype == eval(info["dtype"]) |
| 144 | else |
| 145 | # try quant / dequant for given tensor if possible |
| 146 | ret_tensors.append(get_tensor_with_encoding(tensors[i], info, logger)) |
| 147 | ) |
| 148 | return [ret_tensors] |
| 149 | |
| 150 | |
| 151 | def to_context_binary( |
no test coverage detected