Serialization
All the serialization and deserialization methods used by the TensorProcessor.
Flax
Flax serialization and deserialization utilities.
deserialize(data)
Convert safetensors format to flax tensors using safetensors.flax.load
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
bytes
|
Safetensors formatted data. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Array]
|
Dict[str, Array]: Flax tensors stored in a dictionary with their name as key. |
Source code in src/tensorshare/serialization/flax.py
serialize(tensors, metadata=None)
Convert flax tensors to safetensors format using safetensors.flax.save
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensors |
Dict[str, Array]
|
Flax 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
|
Returns:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
Tensors formatted with their metadata if any. |
Source code in src/tensorshare/serialization/flax.py
NumPy
NumPy serialization and deserialization utilities.
deserialize(data)
Convert safetensors format to numpy tensors using safetensors.numpy.load
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
bytes
|
Safetensors formatted data. |
required |
Returns:
Type | Description |
---|---|
Dict[str, ndarray]
|
Dict[str, np.ndarray]: Numpy tensors stored in a dictionary with their name as key. |
Source code in src/tensorshare/serialization/numpy.py
serialize(tensors, metadata=None)
Convert numpy tensors to safetensors format using safetensors.numpy.save
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensors |
Dict[str, ndarray]
|
Numpy 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
|
Returns:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
Tensors formatted with their metadata if any. |
Source code in src/tensorshare/serialization/numpy.py
PaddlePaddle
PaddlePaddle serialization and deserialization utilities
deserialize(data)
Convert safetensors format to paddle tensors using safetensors.paddle.load
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
bytes
|
Safetensors formatted data. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Tensor]
|
Dict[str, paddle.Tensor]: Paddle tensors stored in a dictionary with their name as key. |
Source code in src/tensorshare/serialization/paddle.py
serialize(tensors, metadata=None)
Convert paddle tensors to safetensors format using safetensors.paddle.save
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensors |
Dict[str, Tensor]
|
Paddle 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
|
Returns:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
Tensors formatted with their metadata if any. |
Source code in src/tensorshare/serialization/paddle.py
PyTorch
Torch serialization and deserialization utilities.
deserialize(data)
Convert safetensors format to torch tensors using safetensors.torch.load
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
bytes
|
Safetensors formatted data. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Tensor]
|
Dict[str, torch.Tensor]: Torch tensors stored in a dictionary with their name as key. |
Source code in src/tensorshare/serialization/torch.py
serialize(tensors, metadata=None)
Convert torch tensors to safetensors format using safetensors.torch.save
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensors |
Dict[str, Tensor]
|
Torch 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
|
Returns:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
Tensors formatted with their metadata if any. |
Source code in src/tensorshare/serialization/torch.py
TensorFlow
Created: 2023-08-20