Model
zenml.model
Concepts related to the Model Control Plane feature.
Modules
lazy_load
Model Version Data Lazy Loader definition.
Classes
ModelVersionDataLazyLoader
Bases: BaseModel
Model Version Data Lazy Loader helper class.
It helps the inner codes to fetch proper artifact, model version metadata or artifact metadata from the model version during runtime time of the step.
Functions
model
Model user facing interface to pass into pipeline or step.
Classes
Model
Bases: BaseModel
Model class to pass into pipeline or step to set it into a model context.
name: The name of the model.
license: The license under which the model is created.
description: The description of the model.
audience: The target audience of the model.
use_cases: The use cases of the model.
limitations: The known limitations of the model.
trade_offs: The tradeoffs of the model.
ethics: The ethical implications of the model.
tags: Tags associated with the model.
version: The version name, version number or stage is optional and points model context
to a specific version/stage. If skipped new version will be created. version
also supports placeholders: standard {date}
and {time}
and any custom placeholders
that are passed as substitutions in the pipeline or step decorators.
save_models_to_registry: Whether to save all ModelArtifacts to Model Registry,
if available in active stack.
id: UUID
property
Get version id from the Model Control Plane.
Returns:
Type | Description |
---|---|
UUID
|
ID of the model version or None, if model version doesn't exist and can only be read given current config (you used stage name or number as a version name). |
Raises:
Type | Description |
---|---|
RuntimeError
|
if model version doesn't exist and cannot be fetched from the Model Control Plane. |
model_id: UUID
property
Get model id from the Model Control Plane.
Returns:
Type | Description |
---|---|
UUID
|
The UUID of the model containing this model version. |
number: int
property
Get version number from the Model Control Plane.
Returns:
Type | Description |
---|---|
int
|
Number of the model version or None, if model version doesn't exist and can only be read given current config (you used stage name or number as a version name). |
Raises:
Type | Description |
---|---|
KeyError
|
if model version doesn't exist and cannot be fetched from the Model Control Plane. |
run_metadata: Dict[str, MetadataType]
property
Get model version run metadata.
Returns:
Type | Description |
---|---|
Dict[str, MetadataType]
|
The model version run metadata. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the model version run metadata cannot be fetched. |
stage: Optional[ModelStages]
property
Get version stage from the Model Control Plane.
Returns:
Type | Description |
---|---|
Optional[ModelStages]
|
Stage of the model version or None, if model version doesn't exist and can only be read given current config (you used stage name or number as a version name). |
delete_all_artifacts(only_link: bool = True, delete_from_artifact_store: bool = False) -> None
Delete all artifacts linked to this model version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
only_link
|
bool
|
Whether to only delete the link to the artifact. |
True
|
delete_from_artifact_store
|
bool
|
Whether to delete the artifact from the artifact store. |
False
|
Source code in src/zenml/model/model.py
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 |
|
delete_artifact(name: str, version: Optional[str] = None, only_link: bool = True, delete_metadata: bool = True, delete_from_artifact_store: bool = False) -> None
Delete the artifact linked to this model version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the artifact to delete. |
required |
version
|
Optional[str]
|
The version of the artifact to delete (None for latest/non-versioned) |
None
|
only_link
|
bool
|
Whether to only delete the link to the artifact. |
True
|
delete_metadata
|
bool
|
Whether to delete the metadata of the artifact. |
True
|
delete_from_artifact_store
|
bool
|
Whether to delete the artifact from the artifact store. |
False
|
Source code in src/zenml/model/model.py
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 |
|
get_artifact(name: str, version: Optional[str] = None) -> Optional[ArtifactVersionResponse]
Get the artifact linked to this model version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the artifact to retrieve. |
required |
version
|
Optional[str]
|
The version of the artifact to retrieve (None for latest/non-versioned) |
None
|
Returns:
Type | Description |
---|---|
Optional[ArtifactVersionResponse]
|
Specific version of the artifact or placeholder in the design time of the pipeline. |
Source code in src/zenml/model/model.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
get_data_artifact(name: str, version: Optional[str] = None) -> Optional[ArtifactVersionResponse]
Get the data artifact linked to this model version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the data artifact to retrieve. |
required |
version
|
Optional[str]
|
The version of the data artifact to retrieve (None for latest/non-versioned) |
None
|
Returns:
Type | Description |
---|---|
Optional[ArtifactVersionResponse]
|
Specific version of the data artifact or placeholder in the design |
Optional[ArtifactVersionResponse]
|
time of the pipeline. |
Source code in src/zenml/model/model.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
get_deployment_artifact(name: str, version: Optional[str] = None) -> Optional[ArtifactVersionResponse]
Get the deployment artifact linked to this model version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the deployment artifact to retrieve. |
required |
version
|
Optional[str]
|
The version of the deployment artifact to retrieve (None for latest/non-versioned) |
None
|
Returns:
Type | Description |
---|---|
Optional[ArtifactVersionResponse]
|
Specific version of the deployment artifact or placeholder in the |
Optional[ArtifactVersionResponse]
|
design time of the pipeline. |
Source code in src/zenml/model/model.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
get_model_artifact(name: str, version: Optional[str] = None) -> Optional[ArtifactVersionResponse]
Get the model artifact linked to this model version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the model artifact to retrieve. |
required |
version
|
Optional[str]
|
The version of the model artifact to retrieve (None for latest/non-versioned) |
None
|
Returns:
Type | Description |
---|---|
Optional[ArtifactVersionResponse]
|
Specific version of the model artifact or placeholder in the design time of the pipeline. |
Source code in src/zenml/model/model.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
get_pipeline_run(name: str) -> PipelineRunResponse
Get pipeline run linked to this version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the pipeline run to retrieve. |
required |
Returns:
Type | Description |
---|---|
PipelineRunResponse
|
PipelineRun as PipelineRunResponse |
Source code in src/zenml/model/model.py
306 307 308 309 310 311 312 313 314 315 |
|
load_artifact(name: str, version: Optional[str] = None) -> Any
Load artifact from the Model Control Plane.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the artifact to load. |
required |
version
|
Optional[str]
|
Version of the artifact to load. |
None
|
Returns:
Type | Description |
---|---|
Any
|
The loaded artifact. |
Raises:
Type | Description |
---|---|
ValueError
|
if the model version is not linked to any artifact with the given name and version. |
Source code in src/zenml/model/model.py
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 |
|
log_metadata(metadata: Dict[str, MetadataType]) -> None
Log model version metadata.
This function can be used to log metadata for current model version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata
|
Dict[str, MetadataType]
|
The metadata to log. |
required |
Source code in src/zenml/model/model.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
|
set_stage(stage: Union[str, ModelStages], force: bool = False) -> None
Sets this Model to a desired stage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage
|
Union[str, ModelStages]
|
the target stage for model version. |
required |
force
|
bool
|
whether to force archiving of current model version in target stage or raise. |
False
|
Source code in src/zenml/model/model.py
317 318 319 320 321 322 323 324 325 326 327 |
|
Functions
utils
Utility functions for linking step outputs to model versions.
Classes
Functions
link_artifact_to_model(artifact_version: ArtifactVersionResponse, model: Optional[Model] = None) -> None
Link the artifact to the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
artifact_version
|
ArtifactVersionResponse
|
The artifact version to link. |
required |
model
|
Optional[Model]
|
The model to link to. |
None
|
Raises:
Type | Description |
---|---|
RuntimeError
|
If called outside a step. |
Source code in src/zenml/model/utils.py
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 |
|
link_artifact_version_to_model_version(artifact_version: ArtifactVersionResponse, model_version: ModelVersionResponse) -> None
Link an artifact version to a model version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
artifact_version
|
ArtifactVersionResponse
|
The artifact version to link. |
required |
model_version
|
ModelVersionResponse
|
The model version to link. |
required |
Source code in src/zenml/model/utils.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
link_service_to_model(service_id: UUID, model: Optional[Model] = None, model_version_id: Optional[UUID] = None) -> None
Links a service to a model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service_id
|
UUID
|
The ID of the service to link to the model. |
required |
model
|
Optional[Model]
|
The model to link the service to. |
None
|
model_version_id
|
Optional[UUID]
|
The ID of the model version to link the service to. |
None
|
Raises:
Type | Description |
---|---|
RuntimeError
|
If no model is provided and the model context cannot be identified. |
Source code in src/zenml/model/utils.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 |
|
log_model_metadata(metadata: Dict[str, MetadataType], model_name: Optional[str] = None, model_version: Optional[Union[ModelStages, int, str]] = None) -> None
Log model version metadata.
This function can be used to log metadata for existing model versions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata
|
Dict[str, MetadataType]
|
The metadata to log. |
required |
model_name
|
Optional[str]
|
The name of the model to log metadata for. Can
be omitted when being called inside a step with configured
|
None
|
model_version
|
Optional[Union[ModelStages, int, str]]
|
The version of the model to log metadata for. Can
be omitted when being called inside a step with configured
|
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If the function is not called with proper input. |
Source code in src/zenml/model/utils.py
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 |
|