Dequantize tensor back to usable shape/dtype
(data, qtype, oshape, dtype=None)
| 28 | return torch.from_numpy(new).to(tensor.device, dtype=dtype) |
| 29 | |
| 30 | def dequantize(data, qtype, oshape, dtype=None): |
| 31 | """ |
| 32 | Dequantize tensor back to usable shape/dtype |
| 33 | """ |
| 34 | block_size, type_size = gguf.GGML_QUANT_SIZES[qtype] |
| 35 | dequantize_blocks = dequantize_functions[qtype] |
| 36 | |
| 37 | rows = data.reshape( |
| 38 | (-1, data.shape[-1]) |
| 39 | ).view(torch.uint8) |
| 40 | |
| 41 | n_blocks = rows.numel() // type_size |
| 42 | blocks = rows.reshape((n_blocks, type_size)) |
| 43 | blocks = dequantize_blocks(blocks, block_size, type_size, dtype) |
| 44 | return blocks.reshape(oshape) |
| 45 | |
| 46 | def to_uint32(x): |
| 47 | # no uint32 :( |