Pytorch
zenml.integrations.pytorch
Initialization of the PyTorch integration.
Attributes
PYTORCH = 'pytorch'
module-attribute
Classes
Integration
Base class for integration in ZenML.
Functions
activate() -> None
classmethod
Abstract method to activate the integration.
Source code in src/zenml/integrations/integration.py
175 176 177 |
|
check_installation() -> bool
classmethod
Method to check whether the required packages are installed.
Returns:
Type | Description |
---|---|
bool
|
True if all required packages are installed, False otherwise. |
Source code in src/zenml/integrations/integration.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
flavors() -> List[Type[Flavor]]
classmethod
Abstract method to declare new stack component flavors.
Returns:
Type | Description |
---|---|
List[Type[Flavor]]
|
A list of new stack component flavors. |
Source code in src/zenml/integrations/integration.py
179 180 181 182 183 184 185 186 |
|
get_requirements(target_os: Optional[str] = None, python_version: Optional[str] = None) -> List[str]
classmethod
Method to get the requirements for the integration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_os
|
Optional[str]
|
The target operating system to get the requirements for. |
None
|
python_version
|
Optional[str]
|
The Python version to use for the requirements. |
None
|
Returns:
Type | Description |
---|---|
List[str]
|
A list of requirements. |
Source code in src/zenml/integrations/integration.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
get_uninstall_requirements(target_os: Optional[str] = None) -> List[str]
classmethod
Method to get the uninstall requirements for the integration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_os
|
Optional[str]
|
The target operating system to get the requirements for. |
None
|
Returns:
Type | Description |
---|---|
List[str]
|
A list of requirements. |
Source code in src/zenml/integrations/integration.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
plugin_flavors() -> List[Type[BasePluginFlavor]]
classmethod
Abstract method to declare new plugin flavors.
Returns:
Type | Description |
---|---|
List[Type[BasePluginFlavor]]
|
A list of new plugin flavors. |
Source code in src/zenml/integrations/integration.py
188 189 190 191 192 193 194 195 |
|
PytorchIntegration
Bases: Integration
Definition of PyTorch integration for ZenML.
Functions
activate() -> None
classmethod
Activates the integration.
Source code in src/zenml/integrations/pytorch/__init__.py
28 29 30 31 |
|
Modules
materializers
Initialization of the PyTorch Materializer.
Classes
Modules
base_pytorch_materializer
Implementation of the PyTorch DataLoader materializer.
BasePyTorchMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Base class for PyTorch materializers.
Source code in src/zenml/materializers/base_materializer.py
125 126 127 128 129 130 131 132 133 134 135 |
|
load(data_type: Type[Any]) -> Any
Uses torch.load
to load a PyTorch object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
The type of the object to load. |
required |
Returns:
Type | Description |
---|---|
Any
|
The loaded PyTorch object. |
Source code in src/zenml/integrations/pytorch/materializers/base_pytorch_materializer.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
save(obj: Any) -> None
Uses torch.save
to save a PyTorch object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The PyTorch object to save. |
required |
Source code in src/zenml/integrations/pytorch/materializers/base_pytorch_materializer.py
49 50 51 52 53 54 55 56 57 58 59 |
|
pytorch_dataloader_materializer
Implementation of the PyTorch DataLoader materializer.
PyTorchDataLoaderMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BasePyTorchMaterializer
Materializer to read/write PyTorch dataloaders and datasets.
Source code in src/zenml/materializers/base_materializer.py
125 126 127 128 129 130 131 132 133 134 135 |
|
extract_metadata(dataloader: Any) -> Dict[str, MetadataType]
Extract metadata from the given dataloader or dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataloader
|
Any
|
The dataloader or dataset to extract metadata from. |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
The extracted metadata as a dictionary. |
Source code in src/zenml/integrations/pytorch/materializers/pytorch_dataloader_materializer.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
pytorch_module_materializer
Implementation of the PyTorch Module materializer.
PyTorchModuleMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BasePyTorchMaterializer
Materializer to read/write Pytorch models.
Inspired by the guide: https://pytorch.org/tutorials/beginner/saving_loading_models.html
Source code in src/zenml/materializers/base_materializer.py
125 126 127 128 129 130 131 132 133 134 135 |
|
extract_metadata(model: Module) -> Dict[str, MetadataType]
Extract metadata from the given Model
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Module
|
The |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
The extracted metadata as a dictionary. |
Source code in src/zenml/integrations/pytorch/materializers/pytorch_module_materializer.py
69 70 71 72 73 74 75 76 77 78 |
|
save(model: Module) -> None
Writes a PyTorch model, as a model and a checkpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Module
|
A torch.nn.Module or a dict to pass into model.save |
required |
Source code in src/zenml/integrations/pytorch/materializers/pytorch_module_materializer.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
utils
PyTorch utils.
Functions
count_module_params(module: torch.nn.Module) -> Dict[str, int]
Get the total and trainable parameters of a module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module
|
Module
|
The module to get the parameters of. |
required |
Returns:
Type | Description |
---|---|
Dict[str, int]
|
A dictionary with the total and trainable parameters. |
Source code in src/zenml/integrations/pytorch/utils.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|