torch_to_nnef.tensor
torch_to_nnef.tensor
NamedTensor
OffloadedTensor
OffloadedTensor(elem, device, offload_dir: Path, name: str, offloaded_tensor_type: T.Type[torch.Tensor], force_gc_collect: bool = False)
Bases: OpaqueTensor
Tensor subclass that maintains data on disk.
It hold an virtual internal memory storage (permanent) and a temporary instantiation at each operation accessing it on targeted device.
Warning
we recommend to version of PyTorch > 1.12 for best compatibility.
is_meta
property
Whether the tensor is on the meta device.
Always False as the tensor is (off|re)loaded from disk.
from_original_tensor
classmethod
from_original_tensor(tensor: torch.Tensor, name: str, offload_dir: T.Optional[Path] = None, suffix_log_msg: str = '')
Take a torch.Tensor or OpaqueTensor and offload it to disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor |
Tensor
|
the torch.Tensor or torch_to_nnef.tensor.OpaqueTensor to dump on disk |
required |
name |
str
|
the name of the tensor that will be used to create the filename store on disk |
required |
offload_dir |
Optional[Path]
|
The directory where this file will be stored (temporarly) |
None
|
suffix_log_msg |
str
|
Added message log suffix for context |
''
|
update_values
Replace offloaded tensor by new 'values' tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
Tensor
|
The tensor that will replace it on disk assertion are made to ensure same shape, dtype as prior |
required |
strict_shape |
bool
|
if True (default) the shape of the new tensor must be the same as the prior one |
True
|
strict_dtype |
bool
|
if True (default) the dtype of the new tensor must be the same as the prior one |
True
|
OpaqueTensorRef
Bases: Tensor
Allow to pass through 'tracing'.
QScalePerGroupF16
QTensor
QTensor(fp_tensor: torch.Tensor, qscheme: QScheme, dequant_to_dtype=torch.float32, u8_compressors: T.Optional[T.List[U8Compressor]] = None)
Bases: OpaqueTensor
Common interface for all Compressed storage.
QTensorTractScaleOnly
Bases: QTensorTract
Tract data format it serializes to: Q4_0.
apply_name_to_tensor_in_module
Transform torch.Tensor or Parameters into NamedTensor.
This is applied at export time of torch_to_nnef
Just before doing any tracing and allow to keep
variable naming identical to PyTorch one
This consistent naming unlock subsequent manipulations such as LORA applications @ inference or such.