Model Deployers
Model deployers are stack components responsible for online model serving.
Online serving is the process of hosting and loading machine-learning models as part of a managed web service and providing access to the models through an API endpoint like HTTP or GRPC. Once deployed, you can send inference requests to the model through the web service's API and receive fast, low-latency responses.
Add a model deployer to your ZenML stack to be able to implement continuous model deployment pipelines that train models and continuously deploy them to a model prediction web service.
When present in a stack, the model deployer also acts as a registry for models that are served with ZenML. You can use the model deployer to list all models that are currently deployed for online inference or filtered according to a particular pipeline run or step, or to suspend, resume or delete an external model server managed through ZenML.
BaseModelDeployer
Bases: StackComponent
, ABC
Base class for all ZenML model deployers.
The model deployer serves three major purposes:
-
It contains all the stack related configuration attributes required to interact with the remote model serving tool, service or platform (e.g. hostnames, URLs, references to credentials, other client related configuration parameters).
-
It implements the continuous deployment logic necessary to deploy models in a way that updates an existing model server that is already serving a previous version of the same model instead of creating a new model server for every new model version (see the
deploy_model
abstract method). This functionality can be consumed directly from ZenML pipeline steps, but it can also be used outside the pipeline to deploy ad hoc models. It is also usually coupled with a standard model deployer step, implemented by each integration, that hides the details of the deployment process away from the user. -
It acts as a ZenML BaseService registry, where every BaseService instance is used as an internal representation of a remote model server (see the
find_model_server
abstract method). To achieve this, it must be able to re-create the configuration of a BaseService from information that is persisted externally, alongside or even part of the remote model server configuration itself. For example, for model servers that are implemented as Kubernetes resources, the BaseService instances can be serialized and saved as Kubernetes resource annotations. This allows the model deployer to keep track of all externally running model servers and to re-create their corresponding BaseService instance representations at any given time. The model deployer also defines methods that implement basic life-cycle management on remote model servers outside the coverage of a pipeline (seestop_model_server
,start_model_server
anddelete_model_server
).
Source code in src/zenml/model_deployers/base_model_deployer.py
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 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 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 231 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 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 476 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 |
|
config
property
Returns the BaseModelDeployerConfig
config.
Returns:
Type | Description |
---|---|
BaseModelDeployerConfig
|
The configuration. |
delete_model_server(uuid, timeout=DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT, force=False)
Abstract method to delete a model server.
This operation is irreversible. A deleted model server must no longer
show up in the list of model servers returned by find_model_server
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uuid
|
UUID
|
UUID of the model server to stop. |
required |
timeout
|
int
|
timeout in seconds to wait for the service to stop. If set to 0, the method will return immediately after deprovisioning the service, without waiting for it to stop. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
force
|
bool
|
if True, force the service to stop. |
False
|
Raises:
Type | Description |
---|---|
RuntimeError
|
if the model server is not found. |
Source code in src/zenml/model_deployers/base_model_deployer.py
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 |
|
deploy_model(config, service_type, replace=False, continuous_deployment_mode=False, timeout=DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT)
Deploy a model.
the deploy_model method is the main entry point for deploying models using the model deployer. It is used to deploy a model to a model server instance that is running on a remote serving platform or service. The method is responsible for detecting if there is an existing model server instance running serving one or more previous versions of the same model and deploying the model to the serving platform or updating the existing model server instance to include the new model version. The method returns a Service object that is a representation of the external model server instance. The Service object must implement basic operational state tracking and lifecycle management operations for the model server (e.g. start, stop, etc.).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
ServiceConfig
|
Custom Service configuration parameters for the model deployer. Can include the pipeline name, the run id, the step name, the model name, the model uri, the model type etc. |
required |
replace
|
bool
|
If True, it will replace any existing model server instances that serve the same model. If False, it does not replace any existing model server instance. |
False
|
continuous_deployment_mode
|
bool
|
If True, it will replace any existing model server instances that serve the same model, regardless of the configuration. If False, it will only replace existing model server instances that serve the same model if the configuration is exactly the same. |
False
|
timeout
|
int
|
The maximum time in seconds to wait for the model server to start serving the model. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
service_type
|
ServiceType
|
The type of the service to deploy. If not provided, the default service type of the model deployer will be used. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the model deployment fails. |
Returns:
Type | Description |
---|---|
BaseService
|
The deployment Service object. |
Source code in src/zenml/model_deployers/base_model_deployer.py
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 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 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 231 232 233 |
|
find_model_server(config=None, running=None, service_uuid=None, pipeline_name=None, pipeline_step_name=None, service_name=None, model_name=None, model_version=None, service_type=None, type=None, flavor=None, pipeline_run_id=None)
Abstract method to find one or more a model servers that match the given criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
running
|
Optional[bool]
|
If true, only running services will be returned. |
None
|
service_uuid
|
Optional[UUID]
|
The UUID of the service that was originally used to deploy the model. |
None
|
pipeline_step_name
|
Optional[str]
|
The name of the pipeline step that was originally used to deploy the model. |
None
|
pipeline_name
|
Optional[str]
|
The name of the pipeline that was originally used to deploy the model from the model registry. |
None
|
model_name
|
Optional[str]
|
The name of the model that was originally used to deploy the model from the model registry. |
None
|
model_version
|
Optional[str]
|
The version of the model that was originally used to deploy the model from the model registry. |
None
|
service_type
|
Optional[ServiceType]
|
The type of the service to find. |
None
|
type
|
Optional[str]
|
The type of the service to find. |
None
|
flavor
|
Optional[str]
|
The flavor of the service to find. |
None
|
pipeline_run_id
|
Optional[str]
|
The UUID of the pipeline run that was originally used to deploy the model. |
None
|
config
|
Optional[Dict[str, Any]]
|
Custom Service configuration parameters for the model deployer. Can include the pipeline name, the run id, the step name, the model name, the model uri, the model type etc. |
None
|
service_name
|
Optional[str]
|
The name of the service to find. |
None
|
Returns:
Type | Description |
---|---|
List[BaseService]
|
One or more Service objects representing model servers that match |
List[BaseService]
|
the input search criteria. |
Source code in src/zenml/model_deployers/base_model_deployer.py
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 |
|
get_active_model_deployer()
classmethod
Get the model deployer registered in the active stack.
Returns:
Type | Description |
---|---|
BaseModelDeployer
|
The model deployer registered in the active stack. |
Raises:
Type | Description |
---|---|
TypeError
|
if a model deployer is not part of the active stack. |
Source code in src/zenml/model_deployers/base_model_deployer.py
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 |
|
get_model_server_info(service)
abstractmethod
staticmethod
Give implementation specific way to extract relevant model server properties for the user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service
|
BaseService
|
Integration-specific service instance |
required |
Returns:
Type | Description |
---|---|
Dict[str, Optional[str]]
|
A dictionary containing the relevant model server properties. |
Source code in src/zenml/model_deployers/base_model_deployer.py
267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
get_model_server_logs(uuid, follow=False, tail=None)
Get the logs of a model server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uuid
|
UUID
|
UUID of the model server to get the logs of. |
required |
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 yields the logs of the model server. |
Raises:
Type | Description |
---|---|
RuntimeError
|
if the model server is not found. |
Source code in src/zenml/model_deployers/base_model_deployer.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
|
load_service(service_id)
Load a service from a URI.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service_id
|
UUID
|
The ID of the service to load. |
required |
Returns:
Type | Description |
---|---|
BaseService
|
The loaded service. |
Source code in src/zenml/model_deployers/base_model_deployer.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
|
perform_delete_model(service, timeout=DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT, force=False)
abstractmethod
Abstract method to delete a model server.
This operation is irreversible. A deleted model server must no longer
show up in the list of model servers returned by find_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. If set to 0, the method will return immediately after deprovisioning the service, without waiting for it to stop. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
force
|
bool
|
if True, force the service to stop. |
False
|
Source code in src/zenml/model_deployers/base_model_deployer.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 |
|
perform_deploy_model(id, config, timeout=DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT)
abstractmethod
Abstract method to deploy a model.
Concrete model deployer subclasses must implement the following functionality in this method: - Detect if there is an existing model server instance running serving one or more previous versions of the same model - Deploy the model to the serving platform or update the existing model server instance to include the new model version - Return a Service object that is a representation of the external model server instance. The Service must implement basic operational state tracking and lifecycle management operations for the model server (e.g. start, stop, etc.)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
UUID
|
UUID of the service that was originally used to deploy the model. |
required |
config
|
ServiceConfig
|
Custom Service configuration parameters for the model deployer. Can include the pipeline name, the run id, the step name, the model name, the model uri, the model type etc. |
required |
timeout
|
int
|
The maximum time in seconds to wait for the model server to start serving the model. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
Returns:
Type | Description |
---|---|
BaseService
|
The deployment Service object. |
Source code in src/zenml/model_deployers/base_model_deployer.py
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 |
|
perform_start_model(service, timeout=DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT)
abstractmethod
Abstract 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. If set to 0, the method will return immediately after provisioning the service, without waiting for it to become active. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
Source code in src/zenml/model_deployers/base_model_deployer.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
|
perform_stop_model(service, timeout=DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT, force=False)
abstractmethod
Abstract method to stop a model server.
This operation should be reversible. A stopped model server should still
show up in the list of model servers returned by find_model_server
and
it should be possible to start it again by calling start_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. If set to 0, the method will return immediately after deprovisioning the service, without waiting for it to stop. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
force
|
bool
|
if True, force the service to stop. |
False
|
Source code in src/zenml/model_deployers/base_model_deployer.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
start_model_server(uuid, timeout=DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT)
Abstract method to start a model server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uuid
|
UUID
|
UUID of the model server to start. |
required |
timeout
|
int
|
timeout in seconds to wait for the service to start. If set to 0, the method will return immediately after provisioning the service, without waiting for it to become active. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
Raises:
Type | Description |
---|---|
RuntimeError
|
if the model server is not found. |
Source code in src/zenml/model_deployers/base_model_deployer.py
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 |
|
stop_model_server(uuid, timeout=DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT, force=False)
Abstract method to stop a model server.
This operation should be reversible. A stopped model server should still
show up in the list of model servers returned by find_model_server
and
it should be possible to start it again by calling start_model_server
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uuid
|
UUID
|
UUID of the model server to stop. |
required |
timeout
|
int
|
timeout in seconds to wait for the service to stop. If set to 0, the method will return immediately after deprovisioning the service, without waiting for it to stop. |
DEFAULT_DEPLOYMENT_START_STOP_TIMEOUT
|
force
|
bool
|
if True, force the service to stop. |
False
|
Raises:
Type | Description |
---|---|
RuntimeError
|
if the model server is not found. |
Source code in src/zenml/model_deployers/base_model_deployer.py
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 |
|
BaseModelDeployerFlavor
Bases: Flavor
Base class for model deployer flavors.
Source code in src/zenml/model_deployers/base_model_deployer.py
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
|
config_class
property
Returns BaseModelDeployerConfig
config class.
Returns:
Type | Description |
---|---|
Type[BaseModelDeployerConfig]
|
The config class. |
implementation_class
abstractmethod
property
The class that implements the model deployer.