(tensor, dtype=None)
| 599 | |
| 600 | |
| 601 | def dequantize_tensor(tensor, dtype=None): |
| 602 | qtype = getattr(tensor, "gguf_type", None) |
| 603 | oshape = getattr(tensor, "orig_shape", tensor.data.shape) |
| 604 | |
| 605 | if qtype in TORCH_COMPATIBLE_QTYPES: |
| 606 | return tensor.to(dtype) |
| 607 | else: |
| 608 | if dequantize_c is not None: |
| 609 | return dequantize_c(tensor).to(dtype) |
| 610 | elif qtype in dequantize_functions: |
| 611 | return dequantize(tensor.to_torch().data, qtype, oshape, dtype=dtype).to(dtype) |
| 612 | else: |
| 613 | # this is incredibly slow |
| 614 | logger.warning(f"Falling back to numpy dequant for qtype: {qtype}") |
| 615 | new = gguf.quants.dequantize(tensor.cpu().numpy(), qtype) |
| 616 | return torch.from_numpy(new).to(tensor.device, dtype=dtype) |
| 617 | |
| 618 | |
| 619 | def dequantize(data, qtype, oshape, dtype=None): |
nothing calls this directly
no test coverage detected