Unpack a torch tensor into a Python dictionary. Parameters: - tensor_data: The torch tensor containing the packed data. Returns: A Python dictionary containing the unpacked data.
(tensor_data)
| 181 | |
| 182 | |
| 183 | def unpack_tensor_to_dict(tensor_data): |
| 184 | """ |
| 185 | Unpack a torch tensor into a Python dictionary. |
| 186 | |
| 187 | Parameters: |
| 188 | - tensor_data: The torch tensor containing the packed data. |
| 189 | |
| 190 | Returns: |
| 191 | A Python dictionary containing the unpacked data. |
| 192 | """ |
| 193 | json_bytes = bytes(tensor_data.cpu().numpy()) |
| 194 | json_str = json_bytes.decode("utf-8") |
| 195 | unpacked_dict = json.loads(json_str) |
| 196 | |
| 197 | return unpacked_dict |
| 198 | |
| 199 | |
| 200 | LINEAR_8BIT_WEIGHTS_FORMAT_MAPPING = {"row": 0, "col32": 1, "col_turing": 2, "col_ampere": 3} |