TensorShare
Bases: BaseModel
Base model for tensor sharing.
Source code in src/tensorshare/schema.py
size_as_str: str
property
Return size as a string in human readable format.
from_dict(tensors, metadata=None, backend=None)
classmethod
Create a TensorShare object from a dictionary of tensors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensors |
Dict[str, Union[Array, ndarray, Tensor, Tensor, Tensor]]
|
Tensors stored in a dictionary with their name as key. |
required |
metadata |
Optional[Dict[str, str]]
|
Metadata to add to the safetensors file. Defaults to None. |
None
|
backend |
Optional[Union[str, Backend]]
|
Backend to use for the conversion. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
TypeError
|
If tensors is not a dictionary. |
TypeError
|
If backend is not a string or an instance of Backend enum. |
ValueError
|
If backend is not supported. |
ValueError
|
If tensors is empty. |
Returns:
Name | Type | Description |
---|---|---|
TensorShare |
TensorShare
|
A TensorShare object. |
Source code in src/tensorshare/schema.py
to_tensors(backend)
Convert a TensorShare object to a dictionary of tensors in the specified backend.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backend |
Union[str, Backend]
|
Backend to use for the conversion. |
required |
Raises:
Type | Description |
---|---|
TypeError
|
If backend is not a string or an instance of Backend enum. |
ValueError
|
If backend is not supported. |
Returns:
Type | Description |
---|---|
Dict[str, Union['Array', 'np.ndarray', 'paddle.Tensor', 'tf.Tensor', 'torch.Tensor']]
|
Dict[str, Union[Array, np.ndarray, paddle.Tensor, tf.Tensor, torch.Tensor]]: Tensors stored in a dictionary with their name as key in the specified backend. |
Source code in src/tensorshare/schema.py
Created: 2023-08-20