MCPcopy Create free account
hub / github.com/Pints-AI/1.5-Pints / LazyTensor

Class LazyTensor

tokenizer/convert/convert.py:645–667  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

643
644@dataclass
645class LazyTensor:
646 _load: Callable[[], Tensor]
647 shape: list[int]
648 data_type: DataType
649 description: str
650
651 def load(self) -> Tensor:
652 ret = self._load()
653 # Should be okay if it maps to the same numpy type?
654 assert ret.data_type == self.data_type or (self.data_type.dtype == ret.data_type.dtype), \
655 (self.data_type, ret.data_type, self.description)
656 return ret
657
658 def astype(self, data_type: DataType) -> LazyTensor:
659 self.validate_conversion_to(data_type)
660
661 def load() -> Tensor:
662 return self.load().astype(data_type)
663 return LazyTensor(load, self.shape, data_type, f'convert({data_type}) {self.description}')
664
665 def validate_conversion_to(self, data_type: DataType) -> None:
666 if data_type != self.data_type and data_type.name not in self.data_type.valid_conversions:
667 raise ValueError(f'Cannot validate conversion from {self.data_type} to {data_type}.')
668
669
670LazyModel: TypeAlias = 'dict[str, LazyTensor]'

Callers 6

astypeMethod · 0.85
convertFunction · 0.85
permute_lazyFunction · 0.85
permute_part_lazyFunction · 0.85
part_lazyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected