fl_server_core.utils.torch_serialization ¶
Functions:
| Name | Description |
|---|---|
from_torch | Serialize a PyTorch object into bytes. |
from_torch_module | Serialize a PyTorch module into bytes. |
from_torch_module_or_tensor | Serialize a PyTorch module or tensor into bytes. |
from_torch_tensor | Serialize a PyTorch tensor into bytes. |
is_torchscript_instance | Check if an object is an instance of |
to_torch | Convert a serialized PyTorch object back into a PyTorch object. |
to_torch_module | Convert a serialized PyTorch module back into a PyTorch module. |
to_torch_module_or_tensor | Convert a serialized PyTorch module or tensor back into a PyTorch module or tensor. |
to_torch_tensor | Convert a serialized PyTorch tensor back into a PyTorch tensor. |
Attributes:
| Name | Type | Description |
|---|---|---|
T | |
Attributes¶
T module-attribute ¶
T = TypeVar('T')
- API Reference
fl_server_coreutilstorch_serialization Functionsto_torch
Classes¶
Functions¶
from_torch ¶
Serialize a PyTorch object into bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Any | The PyTorch object to serialize. | required |
| Additional arguments to pass to the | () | |
| Additional keyword arguments to pass to the | {} |
Returns:
| Name | Type | Description |
|---|---|---|
bytes | bytes | The serialized PyTorch object as bytes. |
Source code in fl_server_core/utils/torch_serialization.py
from_torch_module ¶
Serialize a PyTorch module into bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Module | The PyTorch module to serialize. | required |
| Additional arguments to pass to the | () | |
| Additional keyword arguments to pass to the | {} |
Returns:
| Name | Type | Description |
|---|---|---|
bytes | bytes | The serialized PyTorch module as bytes. |
Source code in fl_server_core/utils/torch_serialization.py
from_torch_module_or_tensor ¶
Serialize a PyTorch module or tensor into bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Module | Tensor | The PyTorch module or tensor to serialize. | required |
| Additional arguments to pass to the | () | |
| Additional keyword arguments to pass to the | {} |
Returns:
| Name | Type | Description |
|---|---|---|
bytes | bytes | The serialized PyTorch module or tensor as bytes. |
Source code in fl_server_core/utils/torch_serialization.py
from_torch_tensor ¶
Serialize a PyTorch tensor into bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Tensor | The PyTorch tensor to serialize. | required |
| Additional arguments to pass to the | () | |
| Additional keyword arguments to pass to the | {} |
Returns:
| Name | Type | Description |
|---|---|---|
bytes | bytes | The serialized PyTorch tensor as bytes. |
Source code in fl_server_core/utils/torch_serialization.py
is_torchscript_instance ¶
Check if an object is an instance of torch.jit.ScriptModule or torch.jit.ScriptFunction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Any | The object to check. | required |
Returns:
| Name | Type | Description |
|---|---|---|
bool | bool |
|
Source code in fl_server_core/utils/torch_serialization.py
to_torch ¶
Convert a serialized PyTorch object back into a PyTorch object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Any | The serialized PyTorch object. | required |
| Type[T] | Tuple[Type[T], ...] | The expected type or types of the PyTorch object. | required |
Returns:
| Name | Type | Description |
|---|---|---|
T | The deserialized PyTorch object. |
Raises:
| Type | Description |
|---|---|
TorchDeserializationException | If there is an error during deserialization or if the deserialized object is not of the expected type. |
Source code in fl_server_core/utils/torch_serialization.py
to_torch_module ¶
Convert a serialized PyTorch module back into a PyTorch module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Any | The serialized PyTorch module. | required |
Returns:
| Type | Description |
|---|---|
Module | torch.nn.Module: The deserialized PyTorch module. |
Raises:
| Type | Description |
|---|---|
TorchDeserializationException | If there is an error during deserialization or if the deserialized object is not a PyTorch module. |
Source code in fl_server_core/utils/torch_serialization.py
to_torch_module_or_tensor ¶
Convert a serialized PyTorch module or tensor back into a PyTorch module or tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Any | The serialized PyTorch module or tensor. | required |
Returns:
| Type | Description |
|---|---|
Module | Tensor | torch.nn.Module | torch.Tensor: The deserialized PyTorch module or tensor. |
Raises:
| Type | Description |
|---|---|
TorchDeserializationException | If there is an error during deserialization or if the deserialized object is not a PyTorch module or tensor. |
Source code in fl_server_core/utils/torch_serialization.py
to_torch_tensor ¶
Convert a serialized PyTorch tensor back into a PyTorch tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Any | The serialized PyTorch tensor. | required |
Returns:
| Type | Description |
|---|---|
Tensor | torch.Tensor: The deserialized PyTorch tensor. |
Raises:
| Type | Description |
|---|---|
TorchDeserializationException | If there is an error during deserialization or if the deserialized object is not a PyTorch tensor. |