Huggingface
zenml.integrations.huggingface
Initialization of the Huggingface integration.
Attributes
HUGGINGFACE = 'huggingface'
module-attribute
HUGGINGFACE_DEPLOYER_FLAVOR = '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 261 262 263 264 | |
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
34 35 36 37 38 | |
flavors() -> List[Type[Flavor]]
classmethod
Declare the stack component flavors for the Hugging Face integration.
Returns:
| Type | Description |
|---|---|
List[Type[Flavor]]
|
List of stack component flavors for this integration. |
Source code in src/zenml/integrations/huggingface/__init__.py
67 68 69 70 71 72 73 74 75 76 77 78 79 | |
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
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 | |
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
140 141 142 | |
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
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 | |
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
144 145 146 147 148 149 150 151 | |
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
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
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
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
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
153 154 155 156 157 158 159 160 | |
Modules
deployers
Hugging Face deployers.
Classes
HuggingFaceDeployer(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, environment: Optional[Dict[str, str]] = None, secrets: Optional[List[UUID]] = None, 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: ContainerizedDeployer
Deployer that runs deployments as Hugging Face Spaces.
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 386 387 388 389 390 391 392 393 | |
config: HuggingFaceDeployerConfig
property
Returns the HuggingFaceDeployerConfig config.
Returns:
| Type | Description |
|---|---|
HuggingFaceDeployerConfig
|
The configuration. |
settings_class: Optional[Type[BaseSettings]]
property
Settings class for the Hugging Face deployer.
Returns:
| Type | Description |
|---|---|
Optional[Type[BaseSettings]]
|
The settings class. |
validator: Optional[StackValidator]
property
Validates the stack.
Returns:
| Type | Description |
|---|---|
Optional[StackValidator]
|
A validator that checks required stack components. |
do_deprovision_deployment(deployment: DeploymentResponse, timeout: int) -> Optional[DeploymentOperationalState]
Deprovision a Huggingface Space deployment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deployment
|
DeploymentResponse
|
The deployment to stop. |
required |
timeout
|
int
|
Maximum time to wait for deprovision (unused - deletion is immediate). |
required |
Returns:
| Type | Description |
|---|---|
Optional[DeploymentOperationalState]
|
None, indicating immediate deletion completed. |
Raises:
| Type | Description |
|---|---|
DeploymentNotFoundError
|
If the Space ID is not in metadata. |
DeploymentDeprovisionError
|
If deletion fails. |
Source code in src/zenml/integrations/huggingface/deployers/huggingface_deployer.py
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 | |
do_get_deployment_state(deployment: DeploymentResponse) -> DeploymentOperationalState
Get information about a Huggingface Space deployment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deployment
|
DeploymentResponse
|
The deployment to inspect. |
required |
Returns:
| Type | Description |
|---|---|
DeploymentOperationalState
|
Operational state of the deployment. |
Raises:
| Type | Description |
|---|---|
DeploymentNotFoundError
|
If the Space is not found. |
Source code in src/zenml/integrations/huggingface/deployers/huggingface_deployer.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
do_get_deployment_state_logs(deployment: DeploymentResponse, follow: bool = False, tail: Optional[int] = None) -> Generator[str, bool, None]
Get logs from a Huggingface Space deployment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deployment
|
DeploymentResponse
|
The deployment to read logs for. |
required |
follow
|
bool
|
Stream logs if True (not supported). |
False
|
tail
|
Optional[int]
|
Return only last N lines if set (not supported). |
None
|
Raises:
| Type | Description |
|---|---|
DeploymentLogsNotFoundError
|
Always, as logs are not available via API. |
Source code in src/zenml/integrations/huggingface/deployers/huggingface_deployer.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | |
do_provision_deployment(deployment: DeploymentResponse, stack: Stack, environment: Dict[str, str], secrets: Dict[str, str], timeout: int) -> DeploymentOperationalState
Provision a Huggingface Space deployment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deployment
|
DeploymentResponse
|
The deployment to run. |
required |
stack
|
Stack
|
The active stack. |
required |
environment
|
Dict[str, str]
|
Environment variables for the app. |
required |
secrets
|
Dict[str, str]
|
Secret environment variables for the app. |
required |
timeout
|
int
|
Maximum time to wait for deployment (unused). |
required |
Returns:
| Type | Description |
|---|---|
DeploymentOperationalState
|
Operational state of the provisioned deployment. |
Raises:
| Type | Description |
|---|---|
DeploymentProvisionError
|
If the deployment cannot be provisioned. |
Source code in src/zenml/integrations/huggingface/deployers/huggingface_deployer.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 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 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 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 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
Modules
huggingface_deployer
Implementation of the ZenML Hugging Face deployer.
HuggingFaceDeployer(name: str, id: UUID, config: StackComponentConfig, flavor: str, type: StackComponentType, user: Optional[UUID], created: datetime, updated: datetime, environment: Optional[Dict[str, str]] = None, secrets: Optional[List[UUID]] = None, 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: ContainerizedDeployer
Deployer that runs deployments as Hugging Face Spaces.
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 386 387 388 389 390 391 392 393 | |
config: HuggingFaceDeployerConfig
property
Returns the HuggingFaceDeployerConfig config.
Returns:
| Type | Description |
|---|---|
HuggingFaceDeployerConfig
|
The configuration. |
settings_class: Optional[Type[BaseSettings]]
property
Settings class for the Hugging Face deployer.
Returns:
| Type | Description |
|---|---|
Optional[Type[BaseSettings]]
|
The settings class. |
validator: Optional[StackValidator]
property
Validates the stack.
Returns:
| Type | Description |
|---|---|
Optional[StackValidator]
|
A validator that checks required stack components. |
do_deprovision_deployment(deployment: DeploymentResponse, timeout: int) -> Optional[DeploymentOperationalState]
Deprovision a Huggingface Space deployment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deployment
|
DeploymentResponse
|
The deployment to stop. |
required |
timeout
|
int
|
Maximum time to wait for deprovision (unused - deletion is immediate). |
required |
Returns:
| Type | Description |
|---|---|
Optional[DeploymentOperationalState]
|
None, indicating immediate deletion completed. |
Raises:
| Type | Description |
|---|---|
DeploymentNotFoundError
|
If the Space ID is not in metadata. |
DeploymentDeprovisionError
|
If deletion fails. |
Source code in src/zenml/integrations/huggingface/deployers/huggingface_deployer.py
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 | |
do_get_deployment_state(deployment: DeploymentResponse) -> DeploymentOperationalState
Get information about a Huggingface Space deployment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deployment
|
DeploymentResponse
|
The deployment to inspect. |
required |
Returns:
| Type | Description |
|---|---|
DeploymentOperationalState
|
Operational state of the deployment. |
Raises:
| Type | Description |
|---|---|
DeploymentNotFoundError
|
If the Space is not found. |
Source code in src/zenml/integrations/huggingface/deployers/huggingface_deployer.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
do_get_deployment_state_logs(deployment: DeploymentResponse, follow: bool = False, tail: Optional[int] = None) -> Generator[str, bool, None]
Get logs from a Huggingface Space deployment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deployment
|
DeploymentResponse
|
The deployment to read logs for. |
required |
follow
|
bool
|
Stream logs if True (not supported). |
False
|
tail
|
Optional[int]
|
Return only last N lines if set (not supported). |
None
|
Raises:
| Type | Description |
|---|---|
DeploymentLogsNotFoundError
|
Always, as logs are not available via API. |
Source code in src/zenml/integrations/huggingface/deployers/huggingface_deployer.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | |
do_provision_deployment(deployment: DeploymentResponse, stack: Stack, environment: Dict[str, str], secrets: Dict[str, str], timeout: int) -> DeploymentOperationalState
Provision a Huggingface Space deployment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deployment
|
DeploymentResponse
|
The deployment to run. |
required |
stack
|
Stack
|
The active stack. |
required |
environment
|
Dict[str, str]
|
Environment variables for the app. |
required |
secrets
|
Dict[str, str]
|
Secret environment variables for the app. |
required |
timeout
|
int
|
Maximum time to wait for deployment (unused). |
required |
Returns:
| Type | Description |
|---|---|
DeploymentOperationalState
|
Operational state of the provisioned deployment. |
Raises:
| Type | Description |
|---|---|
DeploymentProvisionError
|
If the deployment cannot be provisioned. |
Source code in src/zenml/integrations/huggingface/deployers/huggingface_deployer.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 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 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 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 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
flavors
Hugging Face integration flavors.
Classes
HuggingFaceBaseConfig
Bases: BaseModel
Hugging Face Inference Endpoint configuration.
HuggingFaceDeployerConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseDeployerConfig, HuggingFaceDeployerSettings
Configuration for the Hugging Face deployer.
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 | |
HuggingFaceDeployerFlavor
Bases: BaseDeployerFlavor
Flavor for the Hugging Face deployer.
config_class: Type[BaseDeployerConfig]
property
Returns HuggingFaceDeployerConfig config class.
Returns:
| Type | Description |
|---|---|
Type[BaseDeployerConfig]
|
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[HuggingFaceDeployer]
property
Implementation class for this flavor.
Returns:
| Type | Description |
|---|---|
Type[HuggingFaceDeployer]
|
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 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 this flavor.
Returns:
| Type | Description |
|---|---|
Optional[ServiceConnectorRequirements]
|
Service connector resource requirements. |
HuggingFaceDeployerSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseDeployerSettings
Hugging Face deployer settings.
Attributes:
| Name | Type | Description |
|---|---|---|
space_hardware |
Optional[str]
|
Hardware tier for the Space (e.g., 'cpu-basic', 't4-small') |
space_storage |
Optional[str]
|
Persistent storage tier (e.g., 'small', 'medium', 'large') |
private |
bool
|
Whether to create a private Space (default: True for security) |
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 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 | |
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_deployer_flavor
Huggingface deployer flavor.
HuggingFaceDeployerConfig(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseDeployerConfig, HuggingFaceDeployerSettings
Configuration for the Hugging Face deployer.
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 | |
HuggingFaceDeployerFlavor
Bases: BaseDeployerFlavor
Flavor for the Hugging Face deployer.
config_class: Type[BaseDeployerConfig]
property
Returns HuggingFaceDeployerConfig config class.
Returns:
| Type | Description |
|---|---|
Type[BaseDeployerConfig]
|
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[HuggingFaceDeployer]
property
Implementation class for this flavor.
Returns:
| Type | Description |
|---|---|
Type[HuggingFaceDeployer]
|
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 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 this flavor.
Returns:
| Type | Description |
|---|---|
Optional[ServiceConnectorRequirements]
|
Service connector resource requirements. |
HuggingFaceDeployerSettings(warn_about_plain_text_secrets: bool = False, **kwargs: Any)
Bases: BaseDeployerSettings
Hugging Face deployer settings.
Attributes:
| Name | Type | Description |
|---|---|---|
space_hardware |
Optional[str]
|
Hardware tier for the Space (e.g., 'cpu-basic', 't4-small') |
space_storage |
Optional[str]
|
Persistent storage tier (e.g., 'small', 'medium', 'large') |
private |
bool
|
Whether to create a private Space (default: True for security) |
Source code in src/zenml/config/secret_reference_mixin.py
30 31 32 33 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 | |
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, environment: Optional[Dict[str, str]] = None, secrets: Optional[List[UUID]] = None, 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 386 387 388 389 390 391 392 393 | |
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, environment: Optional[Dict[str, str]] = None, secrets: Optional[List[UUID]] = None, 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 386 387 388 389 390 391 392 393 | |
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:
| Type | Description |
|---|---|
Union[Callable[[BaseStep], BaseStep], BaseStep]
|
The accelerate-enabled version of the step. |
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 | |