zenml-nightly 0.70.0.dev20241120__py3-none-any.whl → 0.70.0.dev20241125__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. zenml/VERSION +1 -1
  2. zenml/artifacts/artifact_config.py +32 -4
  3. zenml/artifacts/utils.py +12 -24
  4. zenml/cli/base.py +1 -1
  5. zenml/client.py +4 -19
  6. zenml/constants.py +1 -0
  7. zenml/integrations/kubernetes/orchestrators/kube_utils.py +8 -7
  8. zenml/integrations/kubernetes/orchestrators/kubernetes_orchestrator.py +52 -1
  9. zenml/integrations/kubernetes/orchestrators/kubernetes_orchestrator_entrypoint.py +11 -1
  10. zenml/integrations/kubernetes/orchestrators/manifest_utils.py +3 -3
  11. zenml/integrations/kubernetes/service_connectors/kubernetes_service_connector.py +2 -1
  12. zenml/model/utils.py +0 -24
  13. zenml/models/__init__.py +6 -1
  14. zenml/models/v2/core/artifact_version.py +25 -2
  15. zenml/models/v2/core/model_version.py +0 -4
  16. zenml/models/v2/core/model_version_artifact.py +19 -76
  17. zenml/models/v2/core/model_version_pipeline_run.py +6 -39
  18. zenml/models/v2/core/service_connector.py +4 -0
  19. zenml/models/v2/misc/server_models.py +23 -0
  20. zenml/orchestrators/step_launcher.py +0 -1
  21. zenml/orchestrators/step_run_utils.py +4 -17
  22. zenml/orchestrators/step_runner.py +3 -1
  23. zenml/zen_server/deploy/helm/templates/_environment.tpl +117 -0
  24. zenml/zen_server/deploy/helm/templates/server-db-job.yaml +3 -14
  25. zenml/zen_server/deploy/helm/templates/server-deployment.yaml +16 -4
  26. zenml/zen_server/deploy/helm/templates/server-secret.yaml +2 -17
  27. zenml/zen_server/routers/model_versions_endpoints.py +59 -0
  28. zenml/zen_server/routers/server_endpoints.py +47 -0
  29. zenml/zen_server/routers/workspaces_endpoints.py +0 -130
  30. zenml/zen_server/zen_server_api.py +45 -6
  31. zenml/zen_stores/base_zen_store.py +2 -1
  32. zenml/zen_stores/migrations/utils.py +40 -24
  33. zenml/zen_stores/migrations/versions/ec6307720f92_simplify_model_version_links.py +118 -0
  34. zenml/zen_stores/rest_zen_store.py +42 -5
  35. zenml/zen_stores/schemas/model_schemas.py +10 -94
  36. zenml/zen_stores/schemas/user_schemas.py +0 -8
  37. zenml/zen_stores/schemas/workspace_schemas.py +0 -14
  38. {zenml_nightly-0.70.0.dev20241120.dist-info → zenml_nightly-0.70.0.dev20241125.dist-info}/METADATA +1 -1
  39. {zenml_nightly-0.70.0.dev20241120.dist-info → zenml_nightly-0.70.0.dev20241125.dist-info}/RECORD +42 -41
  40. {zenml_nightly-0.70.0.dev20241120.dist-info → zenml_nightly-0.70.0.dev20241125.dist-info}/LICENSE +0 -0
  41. {zenml_nightly-0.70.0.dev20241120.dist-info → zenml_nightly-0.70.0.dev20241125.dist-info}/WHEEL +0 -0
  42. {zenml_nightly-0.70.0.dev20241120.dist-info → zenml_nightly-0.70.0.dev20241125.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,118 @@
1
+ """Simplify model version links [ec6307720f92].
2
+
3
+ Revision ID: ec6307720f92
4
+ Revises: 0.70.0
5
+ Create Date: 2024-11-06 16:16:43.344569
6
+
7
+ """
8
+
9
+ import sqlalchemy as sa
10
+ from alembic import op
11
+
12
+ # revision identifiers, used by Alembic.
13
+ revision = "ec6307720f92"
14
+ down_revision = "0.70.0"
15
+ branch_labels = None
16
+ depends_on = None
17
+
18
+
19
+ def _migrate_artifact_type() -> None:
20
+ """Migrate the artifact type."""
21
+ meta = sa.MetaData()
22
+ meta.reflect(
23
+ bind=op.get_bind(),
24
+ only=("artifact_version", "model_versions_artifacts"),
25
+ )
26
+ artifact_version_table = sa.Table("artifact_version", meta)
27
+ model_versions_artifacts = sa.Table("model_versions_artifacts", meta)
28
+
29
+ connection = op.get_bind()
30
+
31
+ query = sa.select(
32
+ model_versions_artifacts.c.artifact_version_id,
33
+ model_versions_artifacts.c.is_model_artifact,
34
+ model_versions_artifacts.c.is_deployment_artifact,
35
+ )
36
+ result = connection.execute(query)
37
+
38
+ updated = set()
39
+ updates = []
40
+ for (
41
+ artifact_version_id,
42
+ is_model_artifact,
43
+ is_deployment_artifact,
44
+ ) in result:
45
+ if artifact_version_id in updated:
46
+ # If an artifact was a model artifact in one model version, and a
47
+ # deployment artifact in another model version, we only update it
48
+ # once.
49
+ continue
50
+
51
+ if is_model_artifact:
52
+ updated.add(artifact_version_id)
53
+ updates.append(
54
+ {"id_": artifact_version_id, "type": "ModelArtifact"}
55
+ )
56
+ elif is_deployment_artifact:
57
+ updated.add(artifact_version_id)
58
+ updates.append(
59
+ {"id_": artifact_version_id, "type": "ServiceArtifact"}
60
+ )
61
+
62
+ connection.execute(
63
+ sa.update(artifact_version_table).where(
64
+ artifact_version_table.c.id == sa.bindparam("id_")
65
+ ),
66
+ updates,
67
+ )
68
+
69
+
70
+ def upgrade() -> None:
71
+ """Upgrade database schema and/or data, creating a new revision."""
72
+ # ### commands auto generated by Alembic - please adjust! ###
73
+
74
+ _migrate_artifact_type()
75
+
76
+ with op.batch_alter_table(
77
+ "model_versions_artifacts", schema=None
78
+ ) as batch_op:
79
+ batch_op.drop_constraint(
80
+ "fk_model_versions_artifacts_workspace_id_workspace",
81
+ type_="foreignkey",
82
+ )
83
+ batch_op.drop_constraint(
84
+ "fk_model_versions_artifacts_user_id_user", type_="foreignkey"
85
+ )
86
+ batch_op.drop_constraint(
87
+ "fk_model_versions_artifacts_model_id_model", type_="foreignkey"
88
+ )
89
+ batch_op.drop_column("user_id")
90
+ batch_op.drop_column("model_id")
91
+ batch_op.drop_column("is_deployment_artifact")
92
+ batch_op.drop_column("workspace_id")
93
+ batch_op.drop_column("is_model_artifact")
94
+
95
+ with op.batch_alter_table("model_versions_runs", schema=None) as batch_op:
96
+ batch_op.drop_constraint(
97
+ "fk_model_versions_runs_model_id_model", type_="foreignkey"
98
+ )
99
+ batch_op.drop_constraint(
100
+ "fk_model_versions_runs_workspace_id_workspace", type_="foreignkey"
101
+ )
102
+ batch_op.drop_constraint(
103
+ "fk_model_versions_runs_user_id_user", type_="foreignkey"
104
+ )
105
+ batch_op.drop_column("model_id")
106
+ batch_op.drop_column("workspace_id")
107
+ batch_op.drop_column("user_id")
108
+
109
+ # ### end Alembic commands ###
110
+
111
+
112
+ def downgrade() -> None:
113
+ """Downgrade database schema and/or data back to the previous revision.
114
+
115
+ Raises:
116
+ NotImplementedError: Downgrade is not supported for this migration.
117
+ """
118
+ raise NotImplementedError("Downgrade is not supported for this migration.")
@@ -3672,10 +3672,10 @@ class RestZenStore(BaseZenStore):
3672
3672
  Returns:
3673
3673
  The newly created model version to artifact link.
3674
3674
  """
3675
- return self._create_workspace_scoped_resource(
3675
+ return self._create_resource(
3676
3676
  resource=model_version_artifact_link,
3677
3677
  response_model=ModelVersionArtifactResponse,
3678
- route=f"{MODEL_VERSIONS}/{model_version_artifact_link.model_version}{ARTIFACTS}",
3678
+ route=MODEL_VERSION_ARTIFACTS,
3679
3679
  )
3680
3680
 
3681
3681
  def list_model_version_artifact_links(
@@ -3752,10 +3752,10 @@ class RestZenStore(BaseZenStore):
3752
3752
  - Otherwise, returns the newly created model version to pipeline
3753
3753
  run link.
3754
3754
  """
3755
- return self._create_workspace_scoped_resource(
3755
+ return self._create_resource(
3756
3756
  resource=model_version_pipeline_run_link,
3757
3757
  response_model=ModelVersionPipelineRunResponse,
3758
- route=f"{MODEL_VERSIONS}/{model_version_pipeline_run_link.model_version}{RUNS}",
3758
+ route=MODEL_VERSION_PIPELINE_RUNS,
3759
3759
  )
3760
3760
 
3761
3761
  def list_model_version_pipeline_run_links(
@@ -4172,7 +4172,44 @@ class RestZenStore(BaseZenStore):
4172
4172
  )
4173
4173
 
4174
4174
  self._session = requests.Session()
4175
- retries = Retry(backoff_factor=0.1, connect=5)
4175
+ # Retries are triggered for idempotent HTTP methods (GET, HEAD, PUT,
4176
+ # OPTIONS and DELETE) on specific HTTP status codes:
4177
+ #
4178
+ # 500: Internal Server Error.
4179
+ # 502: Bad Gateway.
4180
+ # 503: Service Unavailable.
4181
+ # 504: Gateway Timeout.
4182
+ #
4183
+ # This also handles connection level errors, if a connection attempt
4184
+ # fails due to transient issues like:
4185
+ #
4186
+ # DNS resolution errors.
4187
+ # Connection timeouts.
4188
+ # Network disruptions.
4189
+ #
4190
+ # Additional errors retried:
4191
+ #
4192
+ # Read Timeouts: If the server does not send a response within
4193
+ # the timeout period.
4194
+ # Connection Refused: If the server refuses the connection.
4195
+ #
4196
+ retries = Retry(
4197
+ connect=5,
4198
+ read=8,
4199
+ redirect=3,
4200
+ status=10,
4201
+ allowed_methods=["HEAD", "GET", "PUT", "DELETE", "OPTIONS"],
4202
+ status_forcelist=[
4203
+ 408, # Request Timeout
4204
+ 429, # Too Many Requests
4205
+ 500, # Internal Server Error
4206
+ 502, # Bad Gateway
4207
+ 503, # Service Unavailable
4208
+ 504, # Gateway Timeout
4209
+ ],
4210
+ other=3,
4211
+ backoff_factor=0.5,
4212
+ )
4176
4213
  self._session.mount("https://", HTTPAdapter(max_retries=retries))
4177
4214
  self._session.mount("http://", HTTPAdapter(max_retries=retries))
4178
4215
  self._session.verify = self.config.verify_ssl
@@ -22,7 +22,11 @@ from pydantic import ConfigDict
22
22
  from sqlalchemy import BOOLEAN, INTEGER, TEXT, Column, UniqueConstraint
23
23
  from sqlmodel import Field, Relationship
24
24
 
25
- from zenml.enums import MetadataResourceTypes, TaggableResourceTypes
25
+ from zenml.enums import (
26
+ ArtifactType,
27
+ MetadataResourceTypes,
28
+ TaggableResourceTypes,
29
+ )
26
30
  from zenml.models import (
27
31
  BaseResponseMetadata,
28
32
  ModelRequest,
@@ -112,14 +116,6 @@ class ModelSchema(NamedSchema, table=True):
112
116
  back_populates="model",
113
117
  sa_relationship_kwargs={"cascade": "delete"},
114
118
  )
115
- artifact_links: List["ModelVersionArtifactSchema"] = Relationship(
116
- back_populates="model",
117
- sa_relationship_kwargs={"cascade": "delete"},
118
- )
119
- pipeline_run_links: List["ModelVersionPipelineRunSchema"] = Relationship(
120
- back_populates="model",
121
- sa_relationship_kwargs={"cascade": "delete"},
122
- )
123
119
 
124
120
  @classmethod
125
121
  def from_request(cls, model_request: ModelRequest) -> "ModelSchema":
@@ -377,11 +373,14 @@ class ModelVersionSchema(NamedSchema, table=True):
377
373
  artifact_name = artifact_link.artifact_version.artifact.name
378
374
  artifact_version = str(artifact_link.artifact_version.version)
379
375
  artifact_version_id = artifact_link.artifact_version.id
380
- if artifact_link.is_model_artifact:
376
+ if artifact_link.artifact_version.type == ArtifactType.MODEL.value:
381
377
  model_artifact_ids.setdefault(artifact_name, {}).update(
382
378
  {str(artifact_version): artifact_version_id}
383
379
  )
384
- elif artifact_link.is_deployment_artifact:
380
+ elif (
381
+ artifact_link.artifact_version.type
382
+ == ArtifactType.SERVICE.value
383
+ ):
385
384
  deployment_artifact_ids.setdefault(artifact_name, {}).update(
386
385
  {str(artifact_version): artifact_version_id}
387
386
  )
@@ -476,39 +475,6 @@ class ModelVersionArtifactSchema(BaseSchema, table=True):
476
475
 
477
476
  __tablename__ = "model_versions_artifacts"
478
477
 
479
- workspace_id: UUID = build_foreign_key_field(
480
- source=__tablename__,
481
- target=WorkspaceSchema.__tablename__,
482
- source_column="workspace_id",
483
- target_column="id",
484
- ondelete="CASCADE",
485
- nullable=False,
486
- )
487
- workspace: "WorkspaceSchema" = Relationship(
488
- back_populates="model_versions_artifacts_links"
489
- )
490
-
491
- user_id: Optional[UUID] = build_foreign_key_field(
492
- source=__tablename__,
493
- target=UserSchema.__tablename__,
494
- source_column="user_id",
495
- target_column="id",
496
- ondelete="SET NULL",
497
- nullable=True,
498
- )
499
- user: Optional["UserSchema"] = Relationship(
500
- back_populates="model_versions_artifacts_links"
501
- )
502
-
503
- model_id: UUID = build_foreign_key_field(
504
- source=__tablename__,
505
- target=ModelSchema.__tablename__,
506
- source_column="model_id",
507
- target_column="id",
508
- ondelete="CASCADE",
509
- nullable=False,
510
- )
511
- model: "ModelSchema" = Relationship(back_populates="artifact_links")
512
478
  model_version_id: UUID = build_foreign_key_field(
513
479
  source=__tablename__,
514
480
  target=ModelVersionSchema.__tablename__,
@@ -532,11 +498,6 @@ class ModelVersionArtifactSchema(BaseSchema, table=True):
532
498
  back_populates="model_versions_artifacts_links"
533
499
  )
534
500
 
535
- is_model_artifact: bool = Field(sa_column=Column(BOOLEAN, nullable=True))
536
- is_deployment_artifact: bool = Field(
537
- sa_column=Column(BOOLEAN, nullable=True)
538
- )
539
-
540
501
  # TODO: In Pydantic v2, the `model_` is a protected namespaces for all
541
502
  # fields defined under base models. If not handled, this raises a warning.
542
503
  # It is possible to suppress this warning message with the following
@@ -559,13 +520,8 @@ class ModelVersionArtifactSchema(BaseSchema, table=True):
559
520
  The converted schema.
560
521
  """
561
522
  return cls(
562
- workspace_id=model_version_artifact_request.workspace,
563
- user_id=model_version_artifact_request.user,
564
- model_id=model_version_artifact_request.model,
565
523
  model_version_id=model_version_artifact_request.model_version,
566
524
  artifact_version_id=model_version_artifact_request.artifact_version,
567
- is_model_artifact=model_version_artifact_request.is_model_artifact,
568
- is_deployment_artifact=model_version_artifact_request.is_deployment_artifact,
569
525
  )
570
526
 
571
527
  def to_model(
@@ -590,11 +546,8 @@ class ModelVersionArtifactSchema(BaseSchema, table=True):
590
546
  body=ModelVersionArtifactResponseBody(
591
547
  created=self.created,
592
548
  updated=self.updated,
593
- model=self.model_id,
594
549
  model_version=self.model_version_id,
595
550
  artifact_version=self.artifact_version.to_model(),
596
- is_model_artifact=self.is_model_artifact,
597
- is_deployment_artifact=self.is_deployment_artifact,
598
551
  ),
599
552
  metadata=BaseResponseMetadata() if include_metadata else None,
600
553
  )
@@ -605,39 +558,6 @@ class ModelVersionPipelineRunSchema(BaseSchema, table=True):
605
558
 
606
559
  __tablename__ = "model_versions_runs"
607
560
 
608
- workspace_id: UUID = build_foreign_key_field(
609
- source=__tablename__,
610
- target=WorkspaceSchema.__tablename__,
611
- source_column="workspace_id",
612
- target_column="id",
613
- ondelete="CASCADE",
614
- nullable=False,
615
- )
616
- workspace: "WorkspaceSchema" = Relationship(
617
- back_populates="model_versions_pipeline_runs_links"
618
- )
619
-
620
- user_id: Optional[UUID] = build_foreign_key_field(
621
- source=__tablename__,
622
- target=UserSchema.__tablename__,
623
- source_column="user_id",
624
- target_column="id",
625
- ondelete="SET NULL",
626
- nullable=True,
627
- )
628
- user: Optional["UserSchema"] = Relationship(
629
- back_populates="model_versions_pipeline_runs_links"
630
- )
631
-
632
- model_id: UUID = build_foreign_key_field(
633
- source=__tablename__,
634
- target=ModelSchema.__tablename__,
635
- source_column="model_id",
636
- target_column="id",
637
- ondelete="CASCADE",
638
- nullable=False,
639
- )
640
- model: "ModelSchema" = Relationship(back_populates="pipeline_run_links")
641
561
  model_version_id: UUID = build_foreign_key_field(
642
562
  source=__tablename__,
643
563
  target=ModelVersionSchema.__tablename__,
@@ -683,9 +603,6 @@ class ModelVersionPipelineRunSchema(BaseSchema, table=True):
683
603
  The converted schema.
684
604
  """
685
605
  return cls(
686
- workspace_id=model_version_pipeline_run_request.workspace,
687
- user_id=model_version_pipeline_run_request.user,
688
- model_id=model_version_pipeline_run_request.model,
689
606
  model_version_id=model_version_pipeline_run_request.model_version,
690
607
  pipeline_run_id=model_version_pipeline_run_request.pipeline_run,
691
608
  )
@@ -712,7 +629,6 @@ class ModelVersionPipelineRunSchema(BaseSchema, table=True):
712
629
  body=ModelVersionPipelineRunResponseBody(
713
630
  created=self.created,
714
631
  updated=self.updated,
715
- model=self.model_id,
716
632
  model_version=self.model_version_id,
717
633
  pipeline_run=self.pipeline_run.to_model(),
718
634
  ),
@@ -44,8 +44,6 @@ if TYPE_CHECKING:
44
44
  EventSourceSchema,
45
45
  FlavorSchema,
46
46
  ModelSchema,
47
- ModelVersionArtifactSchema,
48
- ModelVersionPipelineRunSchema,
49
47
  ModelVersionSchema,
50
48
  OAuthDeviceSchema,
51
49
  PipelineBuildSchema,
@@ -144,12 +142,6 @@ class UserSchema(NamedSchema, table=True):
144
142
  model_versions: List["ModelVersionSchema"] = Relationship(
145
143
  back_populates="user",
146
144
  )
147
- model_versions_artifacts_links: List["ModelVersionArtifactSchema"] = (
148
- Relationship(back_populates="user")
149
- )
150
- model_versions_pipeline_runs_links: List[
151
- "ModelVersionPipelineRunSchema"
152
- ] = Relationship(back_populates="user")
153
145
  auth_devices: List["OAuthDeviceSchema"] = Relationship(
154
146
  back_populates="user",
155
147
  sa_relationship_kwargs={"cascade": "delete"},
@@ -35,8 +35,6 @@ if TYPE_CHECKING:
35
35
  EventSourceSchema,
36
36
  FlavorSchema,
37
37
  ModelSchema,
38
- ModelVersionArtifactSchema,
39
- ModelVersionPipelineRunSchema,
40
38
  ModelVersionSchema,
41
39
  PipelineBuildSchema,
42
40
  PipelineDeploymentSchema,
@@ -142,18 +140,6 @@ class WorkspaceSchema(NamedSchema, table=True):
142
140
  back_populates="workspace",
143
141
  sa_relationship_kwargs={"cascade": "delete"},
144
142
  )
145
- model_versions_artifacts_links: List["ModelVersionArtifactSchema"] = (
146
- Relationship(
147
- back_populates="workspace",
148
- sa_relationship_kwargs={"cascade": "delete"},
149
- )
150
- )
151
- model_versions_pipeline_runs_links: List[
152
- "ModelVersionPipelineRunSchema"
153
- ] = Relationship(
154
- back_populates="workspace",
155
- sa_relationship_kwargs={"cascade": "delete"},
156
- )
157
143
 
158
144
  @classmethod
159
145
  def from_request(cls, workspace: WorkspaceRequest) -> "WorkspaceSchema":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: zenml-nightly
3
- Version: 0.70.0.dev20241120
3
+ Version: 0.70.0.dev20241125
4
4
  Summary: ZenML: Write production-ready ML code.
5
5
  Home-page: https://zenml.io
6
6
  License: Apache-2.0