Huggingface
zenml.integrations.huggingface
Initialization of the Huggingface integration.
Attributes
HUGGINGFACE = 'huggingface'
module-attribute
HUGGINGFACE_MODEL_DEPLOYER_FLAVOR = 'huggingface'
module-attribute
HUGGINGFACE_SERVICE_ARTIFACT = 'hf_deployment_service'
module-attribute
Classes
Flavor
Class for ZenML Flavors.
Attributes
config_class: Type[StackComponentConfig]
abstractmethod
property
Returns StackComponentConfig
config class.
Returns:
Type | Description |
---|---|
Type[StackComponentConfig]
|
The config class. |
config_schema: Dict[str, Any]
property
The config schema for a flavor.
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
The config schema. |
docs_url: Optional[str]
property
A url to point at docs explaining this flavor.
Returns:
Type | Description |
---|---|
Optional[str]
|
A flavor docs url. |
implementation_class: Type[StackComponent]
abstractmethod
property
Implementation class for this flavor.
Returns:
Type | Description |
---|---|
Type[StackComponent]
|
The implementation class for this flavor. |
logo_url: Optional[str]
property
A url to represent the flavor in the dashboard.
Returns:
Type | Description |
---|---|
Optional[str]
|
The flavor logo. |
name: str
abstractmethod
property
The flavor name.
Returns:
Type | Description |
---|---|
str
|
The flavor name. |
sdk_docs_url: Optional[str]
property
A url to point at SDK docs explaining this flavor.
Returns:
Type | Description |
---|---|
Optional[str]
|
A flavor SDK docs url. |
service_connector_requirements: Optional[ServiceConnectorRequirements]
property
Service connector resource requirements for service connectors.
Specifies resource requirements that are used to filter the available service connector types that are compatible with this flavor.
Returns:
Type | Description |
---|---|
Optional[ServiceConnectorRequirements]
|
Requirements for compatible service connectors, if a service |
Optional[ServiceConnectorRequirements]
|
connector is required for this flavor. |
type: StackComponentType
abstractmethod
property
Functions
from_model(flavor_model: FlavorResponse) -> Flavor
classmethod
Loads a flavor from a model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flavor_model
|
FlavorResponse
|
The model to load from. |
required |
Raises:
Type | Description |
---|---|
CustomFlavorImportError
|
If the custom flavor can't be imported. |
ImportError
|
If the flavor can't be imported. |
Returns:
Type | Description |
---|---|
Flavor
|
The loaded flavor. |
Source code in src/zenml/stack/flavor.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
generate_default_docs_url() -> str
Generate the doc urls for all inbuilt and integration flavors.
Note that this method is not going to be useful for custom flavors, which do not have any docs in the main zenml docs.
Returns:
Type | Description |
---|---|
str
|
The complete url to the zenml documentation |
Source code in src/zenml/stack/flavor.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
generate_default_sdk_docs_url() -> str
Generate SDK docs url for a flavor.
Returns:
Type | Description |
---|---|
str
|
The complete url to the zenml SDK docs |
Source code in src/zenml/stack/flavor.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
to_model(integration: Optional[str] = None, is_custom: bool = True) -> FlavorRequest
Converts a flavor to a model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
integration
|
Optional[str]
|
The integration to use for the model. |
None
|
is_custom
|
bool
|
Whether the flavor is a custom flavor. |
True
|
Returns:
Type | Description |
---|---|
FlavorRequest
|
The model. |
Source code in src/zenml/stack/flavor.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
HuggingfaceIntegration
Bases: Integration
Definition of Huggingface integration for ZenML.
Functions
activate() -> None
classmethod
Activates the integration.
Source code in src/zenml/integrations/huggingface/__init__.py
33 34 35 36 37 |
|
flavors() -> List[Type[Flavor]]
classmethod
Declare the stack component flavors for the Huggingface integration.
Returns:
Type | Description |
---|---|
List[Type[Flavor]]
|
List of stack component flavors for this integration. |
Source code in src/zenml/integrations/huggingface/__init__.py
66 67 68 69 70 71 72 73 74 75 76 77 |
|
get_requirements(target_os: Optional[str] = None, python_version: Optional[str] = None) -> List[str]
classmethod
Defines platform specific requirements for the integration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_os
|
Optional[str]
|
The target operating system. |
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/huggingface/__init__.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
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 |
|
Modules
flavors
Hugging Face integration flavors.
Classes
HuggingFaceBaseConfig
Bases: BaseModel
Hugging Face Inference Endpoint configuration.
HuggingFaceModelDeployerConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseModelDeployerConfig
, HuggingFaceBaseConfig
Configuration for the Hugging Face model deployer.
Attributes:
Name | Type | Description |
---|---|---|
token |
Optional[str]
|
Hugging Face token used for authentication |
namespace |
str
|
Hugging Face namespace used to list endpoints |
Source code in src/zenml/stack/stack_component.py
61 62 63 64 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 |
|
HuggingFaceModelDeployerFlavor
Bases: BaseModelDeployerFlavor
Hugging Face Endpoint model deployer flavor.
config_class: Type[HuggingFaceModelDeployerConfig]
property
Returns HuggingFaceModelDeployerConfig
config class.
Returns:
Type | Description |
---|---|
Type[HuggingFaceModelDeployerConfig]
|
The config class. |
docs_url: Optional[str]
property
A url to point at docs explaining this flavor.
Returns:
Type | Description |
---|---|
Optional[str]
|
A flavor docs url. |
implementation_class: Type[HuggingFaceModelDeployer]
property
Implementation class for this flavor.
Returns:
Type | Description |
---|---|
Type[HuggingFaceModelDeployer]
|
The implementation class. |
logo_url: str
property
A url to represent the flavor in the dashboard.
Returns:
Type | Description |
---|---|
str
|
The flavor logo. |
name: str
property
Name of the flavor.
Returns:
Type | Description |
---|---|
str
|
The name of the flavor. |
sdk_docs_url: Optional[str]
property
A url to point at SDK docs explaining this flavor.
Returns:
Type | Description |
---|---|
Optional[str]
|
A flavor SDK docs url. |
Modules
huggingface_model_deployer_flavor
Hugging Face model deployer flavor.
HuggingFaceBaseConfig
Bases: BaseModel
Hugging Face Inference Endpoint configuration.
HuggingFaceModelDeployerConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseModelDeployerConfig
, HuggingFaceBaseConfig
Configuration for the Hugging Face model deployer.
Attributes:
Name | Type | Description |
---|---|---|
token |
Optional[str]
|
Hugging Face token used for authentication |
namespace |
str
|
Hugging Face namespace used to list endpoints |
Source code in src/zenml/stack/stack_component.py
61 62 63 64 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 |
|
HuggingFaceModelDeployerFlavor
Bases: BaseModelDeployerFlavor
Hugging Face Endpoint model deployer flavor.
config_class: Type[HuggingFaceModelDeployerConfig]
property
Returns HuggingFaceModelDeployerConfig
config class.
Returns:
Type | Description |
---|---|
Type[HuggingFaceModelDeployerConfig]
|
The config class. |
docs_url: Optional[str]
property
A url to point at docs explaining this flavor.
Returns:
Type | Description |
---|---|
Optional[str]
|
A flavor docs url. |
implementation_class: Type[HuggingFaceModelDeployer]
property
Implementation class for this flavor.
Returns:
Type | Description |
---|---|
Type[HuggingFaceModelDeployer]
|
The implementation class. |
logo_url: str
property
A url to represent the flavor in the dashboard.
Returns:
Type | Description |
---|---|
str
|
The flavor logo. |
name: str
property
Name of the flavor.
Returns:
Type | Description |
---|---|
str
|
The name of the flavor. |
sdk_docs_url: Optional[str]
property
A url to point at SDK docs explaining this flavor.
Returns:
Type | Description |
---|---|
Optional[str]
|
A flavor SDK docs url. |
materializers
Initialization of Huggingface materializers.
Classes
Modules
huggingface_datasets_materializer
Implementation of the Huggingface datasets materializer.
HFDatasetMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Materializer to read data to and from huggingface datasets.
Source code in src/zenml/materializers/base_materializer.py
125 126 127 128 129 130 131 132 133 134 135 |
|
extract_metadata(ds: Union[Dataset, DatasetDict]) -> Dict[str, MetadataType]
Extract metadata from the given Dataset
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Union[Dataset, DatasetDict]
|
The |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
The extracted metadata as a dictionary. |
Raises:
Type | Description |
---|---|
ValueError
|
If the given object is not a |
Source code in src/zenml/integrations/huggingface/materializers/huggingface_datasets_materializer.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
load(data_type: Union[Type[Dataset], Type[DatasetDict]]) -> Union[Dataset, DatasetDict]
Reads Dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Union[Type[Dataset], Type[DatasetDict]]
|
The type of the dataset to read. |
required |
Returns:
Type | Description |
---|---|
Union[Dataset, DatasetDict]
|
The dataset read from the specified dir. |
Source code in src/zenml/integrations/huggingface/materializers/huggingface_datasets_materializer.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
save(ds: Union[Dataset, DatasetDict]) -> None
Writes a Dataset to the specified dir.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Union[Dataset, DatasetDict]
|
The Dataset to write. |
required |
Source code in src/zenml/integrations/huggingface/materializers/huggingface_datasets_materializer.py
97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
save_visualizations(ds: Union[Dataset, DatasetDict]) -> Dict[str, VisualizationType]
Save visualizations for the dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Union[Dataset, DatasetDict]
|
The Dataset or DatasetDict to visualize. |
required |
Returns:
Type | Description |
---|---|
Dict[str, VisualizationType]
|
A dictionary mapping visualization paths to their types. |
Raises:
Type | Description |
---|---|
ValueError
|
If the given object is not a |
Source code in src/zenml/integrations/huggingface/materializers/huggingface_datasets_materializer.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
extract_repo_name(checksum_str: str) -> Optional[str]
Extracts the repo name from the checksum string.
An example of a checksum_str is: "hf://datasets/nyu-mll/glue@bcdcba79d07bc864c1c254ccfcedcce55bcc9a8c/mrpc/train-00000-of-00001.parquet" and the expected output is "nyu-mll/glue".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
checksum_str
|
str
|
The checksum_str to extract the repo name from. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Optional[str]
|
The extracted repo name. |
Source code in src/zenml/integrations/huggingface/materializers/huggingface_datasets_materializer.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
huggingface_pt_model_materializer
Implementation of the Huggingface PyTorch model materializer.
HFPTModelMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Materializer to read torch model to and from huggingface pretrained model.
Source code in src/zenml/materializers/base_materializer.py
125 126 127 128 129 130 131 132 133 134 135 |
|
extract_metadata(model: PreTrainedModel) -> Dict[str, MetadataType]
Extract metadata from the given PreTrainedModel
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
PreTrainedModel
|
The |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
The extracted metadata as a dictionary. |
Source code in src/zenml/integrations/huggingface/materializers/huggingface_pt_model_materializer.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
load(data_type: Type[PreTrainedModel]) -> PreTrainedModel
Reads HFModel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[PreTrainedModel]
|
The type of the model to read. |
required |
Returns:
Type | Description |
---|---|
PreTrainedModel
|
The model read from the specified dir. |
Source code in src/zenml/integrations/huggingface/materializers/huggingface_pt_model_materializer.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
save(model: PreTrainedModel) -> None
Writes a Model to the specified dir.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
PreTrainedModel
|
The Torch Model to write. |
required |
Source code in src/zenml/integrations/huggingface/materializers/huggingface_pt_model_materializer.py
60 61 62 63 64 65 66 67 68 69 70 71 |
|
huggingface_t5_materializer
Implementation of the Huggingface t5 materializer.
HFT5Materializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Base class for huggingface t5 models.
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]) -> Union[T5ForConditionalGeneration, T5Tokenizer, T5TokenizerFast]
Reads a T5ForConditionalGeneration model or T5Tokenizer from a serialized zip file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
A T5ForConditionalGeneration or T5Tokenizer type. |
required |
Returns:
Type | Description |
---|---|
Union[T5ForConditionalGeneration, T5Tokenizer, T5TokenizerFast]
|
A T5ForConditionalGeneration or T5Tokenizer object. |
Raises:
Type | Description |
---|---|
ValueError
|
Unsupported data type used |
Source code in src/zenml/integrations/huggingface/materializers/huggingface_t5_materializer.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
save(obj: Union[T5ForConditionalGeneration, T5Tokenizer, T5TokenizerFast]) -> None
Creates a serialization for a T5ForConditionalGeneration model or T5Tokenizer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Union[T5ForConditionalGeneration, T5Tokenizer, T5TokenizerFast]
|
A T5ForConditionalGeneration model or T5Tokenizer. |
required |
Source code in src/zenml/integrations/huggingface/materializers/huggingface_t5_materializer.py
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 |
|
huggingface_tf_model_materializer
Implementation of the Huggingface TF model materializer.
HFTFModelMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Materializer to read Tensorflow model to and from huggingface pretrained model.
Source code in src/zenml/materializers/base_materializer.py
125 126 127 128 129 130 131 132 133 134 135 |
|
extract_metadata(model: TFPreTrainedModel) -> Dict[str, MetadataType]
Extract metadata from the given PreTrainedModel
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
TFPreTrainedModel
|
The |
required |
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
The extracted metadata as a dictionary. |
Source code in src/zenml/integrations/huggingface/materializers/huggingface_tf_model_materializer.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
load(data_type: Type[TFPreTrainedModel]) -> TFPreTrainedModel
Reads HFModel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[TFPreTrainedModel]
|
The type of the model to read. |
required |
Returns:
Type | Description |
---|---|
TFPreTrainedModel
|
The model read from the specified dir. |
Source code in src/zenml/integrations/huggingface/materializers/huggingface_tf_model_materializer.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
save(model: TFPreTrainedModel) -> None
Writes a Model to the specified dir.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
TFPreTrainedModel
|
The TF Model to write. |
required |
Source code in src/zenml/integrations/huggingface/materializers/huggingface_tf_model_materializer.py
60 61 62 63 64 65 66 67 68 69 70 71 |
|
huggingface_tokenizer_materializer
Implementation of the Huggingface tokenizer materializer.
HFTokenizerMaterializer(uri: str, artifact_store: Optional[BaseArtifactStore] = None)
Bases: BaseMaterializer
Materializer to read tokenizer to and from huggingface tokenizer.
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]) -> PreTrainedTokenizerBase
Reads Tokenizer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_type
|
Type[Any]
|
The type of the tokenizer to read. |
required |
Returns:
Type | Description |
---|---|
PreTrainedTokenizerBase
|
The tokenizer read from the specified dir. |
Source code in src/zenml/integrations/huggingface/materializers/huggingface_tokenizer_materializer.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
save(tokenizer: Type[Any]) -> None
Writes a Tokenizer to the specified dir.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tokenizer
|
Type[Any]
|
The HFTokenizer to write. |
required |
Source code in src/zenml/integrations/huggingface/materializers/huggingface_tokenizer_materializer.py
54 55 56 57 58 59 60 61 62 63 64 65 |
|
model_deployers
Initialization of the Hugging Face model deployers.
Classes
HuggingFaceModelDeployer(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, labels: Optional[Dict[str, Any]] = None, connector_requirements: Optional[ServiceConnectorRequirements] = None, connector: Optional[UUID] = None, connector_resource_id: Optional[str] = None, *args: Any, **kwargs: Any)
Bases: BaseModelDeployer
Hugging Face endpoint model deployer.
Source code in src/zenml/stack/stack_component.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
config: HuggingFaceModelDeployerConfig
property
Config class for the Hugging Face Model deployer settings class.
Returns:
Type | Description |
---|---|
HuggingFaceModelDeployerConfig
|
The configuration. |
validator: Optional[StackValidator]
property
Validates the stack.
Returns:
Type | Description |
---|---|
Optional[StackValidator]
|
A validator that checks that the stack contains a remote artifact |
Optional[StackValidator]
|
store. |
get_model_server_info(service_instance: HuggingFaceDeploymentService) -> Dict[str, Optional[str]]
staticmethod
Return implementation specific information that might be relevant to the user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service_instance
|
HuggingFaceDeploymentService
|
Instance of a HuggingFaceDeploymentService |
required |
Returns:
Type | Description |
---|---|
Dict[str, Optional[str]]
|
Model server information. |
Source code in src/zenml/integrations/huggingface/model_deployers/huggingface_model_deployer.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
perform_delete_model(service: BaseService, timeout: int = DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT, force: bool = False) -> None
Method to delete all configuration of a model server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service
|
BaseService
|
The service to delete. |
required |
timeout
|
int
|
Timeout in seconds to wait for the service to stop. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
force
|
bool
|
If True, force the service to stop. |
False
|
Source code in src/zenml/integrations/huggingface/model_deployers/huggingface_model_deployer.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
perform_deploy_model(id: UUID, config: ServiceConfig, timeout: int = DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT) -> BaseService
Create a new Hugging Face deployment service or update an existing one.
This should serve the supplied model and deployment configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
UUID
|
the UUID of the model to be deployed with Hugging Face. |
required |
config
|
ServiceConfig
|
the configuration of the model to be deployed with Hugging Face. |
required |
timeout
|
int
|
the timeout in seconds to wait for the Hugging Face endpoint to be provisioned and successfully started or updated. If set to 0, the method will return immediately after the Hugging Face server is provisioned, without waiting for it to fully start. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
Returns:
Type | Description |
---|---|
BaseService
|
The ZenML Hugging Face deployment service object that can be used to |
BaseService
|
interact with the remote Hugging Face inference endpoint server. |
Source code in src/zenml/integrations/huggingface/model_deployers/huggingface_model_deployer.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
perform_start_model(service: BaseService, timeout: int = DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT) -> BaseService
Method to start a model server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service
|
BaseService
|
The service to start. |
required |
timeout
|
int
|
Timeout in seconds to wait for the service to start. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
Returns:
Type | Description |
---|---|
BaseService
|
The started service. |
Source code in src/zenml/integrations/huggingface/model_deployers/huggingface_model_deployer.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
perform_stop_model(service: BaseService, timeout: int = DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT, force: bool = False) -> BaseService
Method to stop a model server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service
|
BaseService
|
The service to stop. |
required |
timeout
|
int
|
Timeout in seconds to wait for the service to stop. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
force
|
bool
|
If True, force the service to stop. |
False
|
Returns:
Type | Description |
---|---|
BaseService
|
The stopped service. |
Source code in src/zenml/integrations/huggingface/model_deployers/huggingface_model_deployer.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
Modules
huggingface_model_deployer
Implementation of the Hugging Face Model Deployer.
HuggingFaceModelDeployer(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, labels: Optional[Dict[str, Any]] = None, connector_requirements: Optional[ServiceConnectorRequirements] = None, connector: Optional[UUID] = None, connector_resource_id: Optional[str] = None, *args: Any, **kwargs: Any)
Bases: BaseModelDeployer
Hugging Face endpoint model deployer.
Source code in src/zenml/stack/stack_component.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
config: HuggingFaceModelDeployerConfig
property
Config class for the Hugging Face Model deployer settings class.
Returns:
Type | Description |
---|---|
HuggingFaceModelDeployerConfig
|
The configuration. |
validator: Optional[StackValidator]
property
Validates the stack.
Returns:
Type | Description |
---|---|
Optional[StackValidator]
|
A validator that checks that the stack contains a remote artifact |
Optional[StackValidator]
|
store. |
get_model_server_info(service_instance: HuggingFaceDeploymentService) -> Dict[str, Optional[str]]
staticmethod
Return implementation specific information that might be relevant to the user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service_instance
|
HuggingFaceDeploymentService
|
Instance of a HuggingFaceDeploymentService |
required |
Returns:
Type | Description |
---|---|
Dict[str, Optional[str]]
|
Model server information. |
Source code in src/zenml/integrations/huggingface/model_deployers/huggingface_model_deployer.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
perform_delete_model(service: BaseService, timeout: int = DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT, force: bool = False) -> None
Method to delete all configuration of a model server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service
|
BaseService
|
The service to delete. |
required |
timeout
|
int
|
Timeout in seconds to wait for the service to stop. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
force
|
bool
|
If True, force the service to stop. |
False
|
Source code in src/zenml/integrations/huggingface/model_deployers/huggingface_model_deployer.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
perform_deploy_model(id: UUID, config: ServiceConfig, timeout: int = DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT) -> BaseService
Create a new Hugging Face deployment service or update an existing one.
This should serve the supplied model and deployment configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
UUID
|
the UUID of the model to be deployed with Hugging Face. |
required |
config
|
ServiceConfig
|
the configuration of the model to be deployed with Hugging Face. |
required |
timeout
|
int
|
the timeout in seconds to wait for the Hugging Face endpoint to be provisioned and successfully started or updated. If set to 0, the method will return immediately after the Hugging Face server is provisioned, without waiting for it to fully start. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
Returns:
Type | Description |
---|---|
BaseService
|
The ZenML Hugging Face deployment service object that can be used to |
BaseService
|
interact with the remote Hugging Face inference endpoint server. |
Source code in src/zenml/integrations/huggingface/model_deployers/huggingface_model_deployer.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
perform_start_model(service: BaseService, timeout: int = DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT) -> BaseService
Method to start a model server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service
|
BaseService
|
The service to start. |
required |
timeout
|
int
|
Timeout in seconds to wait for the service to start. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
Returns:
Type | Description |
---|---|
BaseService
|
The started service. |
Source code in src/zenml/integrations/huggingface/model_deployers/huggingface_model_deployer.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
|
perform_stop_model(service: BaseService, timeout: int = DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT, force: bool = False) -> BaseService
Method to stop a model server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service
|
BaseService
|
The service to stop. |
required |
timeout
|
int
|
Timeout in seconds to wait for the service to stop. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
force
|
bool
|
If True, force the service to stop. |
False
|
Returns:
Type | Description |
---|---|
BaseService
|
The stopped service. |
Source code in src/zenml/integrations/huggingface/model_deployers/huggingface_model_deployer.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
services
Initialization of the Hugging Face Service.
Classes
Modules
huggingface_deployment
Implementation of the Hugging Face Deployment service.
HuggingFaceDeploymentService(config: HuggingFaceServiceConfig, **attrs: Any)
Bases: BaseDeploymentService
Hugging Face model deployment service.
Attributes:
Name | Type | Description |
---|---|---|
SERVICE_TYPE |
a service type descriptor with information describing the Hugging Face deployment service class |
|
config |
HuggingFaceServiceConfig
|
service configuration |
Initialize the Hugging Face deployment service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
HuggingFaceServiceConfig
|
service configuration |
required |
attrs
|
Any
|
additional attributes to set on the service |
{}
|
Source code in src/zenml/integrations/huggingface/services/huggingface_deployment.py
74 75 76 77 78 79 80 81 |
|
hf_endpoint: InferenceEndpoint
property
Get the deployed Hugging Face inference endpoint.
Returns:
Type | Description |
---|---|
InferenceEndpoint
|
Huggingface inference endpoint. |
inference_client: InferenceClient
property
Get the Hugging Face InferenceClient from Inference Endpoint.
Returns:
Type | Description |
---|---|
InferenceClient
|
Hugging Face inference client. |
prediction_url: Optional[str]
property
The prediction URI exposed by the prediction service.
Returns:
Type | Description |
---|---|
Optional[str]
|
The prediction URI exposed by the prediction service, or None if |
Optional[str]
|
the service is not yet ready. |
check_status() -> Tuple[ServiceState, str]
Check the current operational state of the Hugging Face deployment.
Returns:
Type | Description |
---|---|
ServiceState
|
The operational state of the Hugging Face deployment and a message |
str
|
providing additional information about that state (e.g. a |
Tuple[ServiceState, str]
|
description of the error, if one is encountered). |
Source code in src/zenml/integrations/huggingface/services/huggingface_deployment.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
|
deprovision(force: bool = False) -> None
Deprovision the remote Hugging Face deployment instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
if True, the remote deployment instance will be forcefully deprovisioned. |
False
|
Source code in src/zenml/integrations/huggingface/services/huggingface_deployment.py
268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
get_logs(follow: bool = False, tail: Optional[int] = None) -> Generator[str, bool, None]
Retrieve the service logs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
follow
|
bool
|
if True, the logs will be streamed as they are written |
False
|
tail
|
Optional[int]
|
only retrieve the last NUM lines of log output. |
None
|
Returns:
Type | Description |
---|---|
None
|
A generator that can be accessed to get the service logs. |
Source code in src/zenml/integrations/huggingface/services/huggingface_deployment.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
|
get_token() -> str
Get the Hugging Face token.
Raises:
Type | Description |
---|---|
ValueError
|
If token not found. |
Returns:
Type | Description |
---|---|
str
|
Hugging Face token. |
Source code in src/zenml/integrations/huggingface/services/huggingface_deployment.py
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 |
|
predict(data: Any, max_new_tokens: int) -> Any
Make a prediction using the service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Any
|
input data |
required |
max_new_tokens
|
int
|
Number of new tokens to generate |
required |
Returns:
Type | Description |
---|---|
Any
|
The prediction result. |
Raises:
Type | Description |
---|---|
Exception
|
if the service is not running |
NotImplementedError
|
if task is not supported. |
Source code in src/zenml/integrations/huggingface/services/huggingface_deployment.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
provision() -> None
Provision or update remote Hugging Face deployment instance.
Raises:
Type | Description |
---|---|
Exception
|
If any unexpected error while creating inference endpoint. |
Source code in src/zenml/integrations/huggingface/services/huggingface_deployment.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
HuggingFaceServiceConfig(**data: Any)
Bases: HuggingFaceBaseConfig
, ServiceConfig
Hugging Face service configurations.
Source code in src/zenml/services/service.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
HuggingFaceServiceStatus
steps
Initialization for Hugging Face model deployer step.
Functions
Modules
accelerate_runner
Step function to run any ZenML step using Accelerate.
run_with_accelerate(step_function_top_level: Optional[BaseStep] = None, **accelerate_launch_kwargs: Any) -> Union[Callable[[BaseStep], BaseStep], BaseStep]
Run a function with accelerate.
Accelerate package: https://huggingface.co/docs/accelerate/en/index Example: ```python from zenml import step, pipeline from zenml.integrations.hugginface.steps import run_with_accelerate
@run_with_accelerate(num_processes=4, multi_gpu=True)
@step
def training_step(some_param: int, ...):
# your training code is below
...
@pipeline
def training_pipeline(some_param: int, ...):
training_step(some_param, ...)
```
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step_function_top_level
|
Optional[BaseStep]
|
The step function to run with accelerate [optional].
Used in functional calls like |
None
|
accelerate_launch_kwargs
|
Any
|
A dictionary of arguments to pass along to the
|
{}
|
Returns:
Source code in src/zenml/integrations/huggingface/steps/accelerate_runner.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
huggingface_deployer
Implementation of the Hugging Face Deployer step.
huggingface_model_deployer_step(service_config: HuggingFaceServiceConfig, deploy_decision: bool = True, timeout: int = DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT) -> HuggingFaceDeploymentService
Hugging Face model deployer pipeline step.
This step can be used in a pipeline to implement continuous deployment with Hugging Face Inference Endpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service_config
|
HuggingFaceServiceConfig
|
Hugging Face deployment service configuration. |
required |
deploy_decision
|
bool
|
whether to deploy the model or not |
True
|
timeout
|
int
|
the timeout in seconds to wait for the deployment to start |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
Returns:
Type | Description |
---|---|
HuggingFaceDeploymentService
|
Huggingface deployment service |
Source code in src/zenml/integrations/huggingface/steps/huggingface_deployer.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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 |
|