| 475 | |
| 476 | |
| 477 | class UnquantizedTensor(Tensor): |
| 478 | def __init__(self, ndarray: NDArray) -> None: |
| 479 | assert isinstance(ndarray, np.ndarray) |
| 480 | self.ndarray = ndarray |
| 481 | self.data_type = NUMPY_TYPE_TO_DATA_TYPE[ndarray.dtype] |
| 482 | |
| 483 | def astype(self, data_type: DataType) -> Tensor: |
| 484 | dtype = data_type.dtype |
| 485 | if self.data_type == DT_BF16: |
| 486 | self.ndarray = bf16_to_fp32(self.ndarray) |
| 487 | return UnquantizedTensor(self.ndarray.astype(dtype)) |
| 488 | |
| 489 | def to_ggml(self) -> UnquantizedTensor: |
| 490 | return self |
| 491 | |
| 492 | def permute_part(self, n_part: int, n_head: int, n_head_kv: int) -> UnquantizedTensor: |
| 493 | r = self.ndarray.shape[0] // 3 |
| 494 | return UnquantizedTensor(permute(self.ndarray[r * n_part : r * n_part + r, ...], n_head, n_head_kv)) |
| 495 | |
| 496 | def part(self, n_part: int) -> UnquantizedTensor: |
| 497 | r = self.ndarray.shape[0] // 3 |
| 498 | return UnquantizedTensor(self.ndarray[r * n_part : r * n_part + r, ...]) |
| 499 | |
| 500 | def permute(self, n_head: int, n_head_kv: int) -> UnquantizedTensor: |
| 501 | return UnquantizedTensor(permute(self.ndarray, n_head, n_head_kv)) |
| 502 | |
| 503 | |
| 504 | def load_unquantized(lazy_tensor: LazyTensor, expected_dtype: Any = None, convert: bool = False) -> NDArray: |