MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / UnquantizedTensor

Class UnquantizedTensor

convert.py:477–501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

475
476
477class 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
504def load_unquantized(lazy_tensor: LazyTensor, expected_dtype: Any = None, convert: bool = False) -> NDArray:

Callers 6

astypeMethod · 0.70
permute_partMethod · 0.70
partMethod · 0.70
permuteMethod · 0.70
loadFunction · 0.70
loadMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected