MCPcopy Index your code
hub / github.com/microsoft/BitNet / LazyTensor

Class LazyTensor

utils/convert.py:831–853  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

829
830@dataclass
831class LazyTensor:
832 _load: Callable[[], Tensor]
833 shape: list[int]
834 data_type: DataType
835 description: str
836
837 def load(self) -> Tensor:
838 ret = self._load()
839 # Should be okay if it maps to the same numpy type?
840 assert ret.data_type == self.data_type or (self.data_type.dtype == ret.data_type.dtype), \
841 (self.data_type, ret.data_type, self.description)
842 return ret
843
844 def astype(self, data_type: DataType) -> LazyTensor:
845 self.validate_conversion_to(data_type)
846
847 def load() -> Tensor:
848 return self.load().astype(data_type)
849 return LazyTensor(load, self.shape, data_type, f'convert({data_type}) {self.description}')
850
851 def validate_conversion_to(self, data_type: DataType) -> None:
852 if data_type != self.data_type and data_type.name not in self.data_type.valid_conversions:
853 raise ValueError(f'Cannot validate conversion from {self.data_type} to {data_type}.')
854
855
856LazyModel: TypeAlias = 'dict[str, LazyTensor]'

Callers 6

astypeMethod · 0.70
convertFunction · 0.70
permute_lazyFunction · 0.70
permute_part_lazyFunction · 0.70
part_lazyFunction · 0.70
pack_experts_lazyFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected