GeezerVison is showing github.com — feat: support PSC-Interface in Ray on Vertex · googleapis/python-aiplatform@accaa97
File treeExpand file treeCollapse file tree Open diff view settings google/cloud/aiplatform/vertex_ray
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: google/cloud/aiplatform/vertex_ray/__init__.py +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 38 | 38 | from google.cloud.aiplatform.vertex_ray.util.resources import ( | 39 | 39 | Resources, | 40 | 40 | NodeImages, | | 41 | + PscIConfig, | 41 | 42 | ) | 42 | 43 |
| 43 | 44 | from google.cloud.aiplatform.vertex_ray.dashboard_sdk import ( | | 61 | 62 | "update_ray_cluster", | 62 | 63 | "Resources", | 63 | 64 | "NodeImages", | | 65 | + "PscIConfig", | 64 | 66 | ) |
Collapse file Copy file name to clipboardExpand all lines: google/cloud/aiplatform/vertex_ray/cluster_init.py +27-6Lines changed: 27 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 23 | 23 | from google.cloud.aiplatform import initializer | 24 | 24 | from google.cloud.aiplatform import utils | 25 | 25 | from google.cloud.aiplatform.utils import resource_manager_utils | 26 | | -from google.cloud.aiplatform_v1.types import persistent_resource_service | | 26 | +from google.cloud.aiplatform_v1beta1.types import persistent_resource_service | 27 | 27 |
| 28 | | -from google.cloud.aiplatform_v1.types.persistent_resource import ( | | 28 | +from google.cloud.aiplatform_v1beta1.types.persistent_resource import ( | 29 | 29 | PersistentResource, | | 30 | + RayLogsSpec, | 30 | 31 | RaySpec, | 31 | 32 | RayMetricSpec, | 32 | 33 | ResourcePool, | 33 | 34 | ResourceRuntimeSpec, | 34 | 35 | ServiceAccountSpec, | 35 | 36 | ) | 36 | | - | | 37 | +from google.cloud.aiplatform_v1beta1.types.service_networking import ( | | 38 | + PscInterfaceConfig, | | 39 | +) | 37 | 40 | from google.cloud.aiplatform.vertex_ray.util import ( | 38 | 41 | _gapic_utils, | 39 | 42 | _validation_utils, | @@ -56,6 +59,8 @@ def create_ray_cluster( | 56 | 59 | worker_node_types: Optional[List[resources.Resources]] = [resources.Resources()], | 57 | 60 | custom_images: Optional[resources.NodeImages] = None, | 58 | 61 | enable_metrics_collection: Optional[bool] = True, | | 62 | + enable_logging: Optional[bool] = True, | | 63 | + psc_interface_config: Optional[resources.PscIConfig] = None, | 59 | 64 | labels: Optional[Dict[str, str]] = None, | 60 | 65 | ) -> str: | 61 | 66 | """Create a ray cluster on the Vertex AI. | @@ -119,6 +124,8 @@ def create_ray_cluster( | 119 | 124 | head/worker_node_type(s). Note that configuring `Resources.custom_image` | 120 | 125 | will override `custom_images` here. Allowlist only. | 121 | 126 | enable_metrics_collection: Enable Ray metrics collection for visualization. | | 127 | + enable_logging: Enable exporting Ray logs to Cloud Logging. | | 128 | + psc_interface_config: PSC-I config. | 122 | 129 | labels: | 123 | 130 | The labels with user-defined metadata to organize Ray cluster. | 124 | 131 |
| @@ -258,10 +265,17 @@ def create_ray_cluster( | 258 | 265 | i += 1 | 259 | 266 |
| 260 | 267 | resource_pools = [resource_pool_0] + worker_pools | 261 | | - disabled = not enable_metrics_collection | 262 | | - ray_metric_spec = RayMetricSpec(disabled=disabled) | | 268 | + | | 269 | + metrics_collection_disabled = not enable_metrics_collection | | 270 | + ray_metric_spec = RayMetricSpec(disabled=metrics_collection_disabled) | | 271 | + | | 272 | + logging_disabled = not enable_logging | | 273 | + ray_logs_spec = RayLogsSpec(disabled=logging_disabled) | | 274 | + | 263 | 275 | ray_spec = RaySpec( | 264 | | - resource_pool_images=resource_pool_images, ray_metric_spec=ray_metric_spec | | 276 | + resource_pool_images=resource_pool_images, | | 277 | + ray_metric_spec=ray_metric_spec, | | 278 | + ray_logs_spec=ray_logs_spec, | 265 | 279 | ) | 266 | 280 | if service_account: | 267 | 281 | service_account_spec = ServiceAccountSpec( | @@ -274,11 +288,18 @@ def create_ray_cluster( | 274 | 288 | ) | 275 | 289 | else: | 276 | 290 | resource_runtime_spec = ResourceRuntimeSpec(ray_spec=ray_spec) | | 291 | + if psc_interface_config: | | 292 | + gapic_psc_interface_config = PscInterfaceConfig( | | 293 | + network_attachment=psc_interface_config.network_attachment, | | 294 | + ) | | 295 | + else: | | 296 | + gapic_psc_interface_config = None | 277 | 297 | persistent_resource = PersistentResource( | 278 | 298 | resource_pools=resource_pools, | 279 | 299 | network=network, | 280 | 300 | labels=labels, | 281 | 301 | resource_runtime_spec=resource_runtime_spec, | | 302 | + psc_interface_config=gapic_psc_interface_config, | 282 | 303 | ) | 283 | 304 |
| 284 | 305 | location = initializer.global_config.location | |
Collapse file Copy file name to clipboardExpand all lines: google/cloud/aiplatform/vertex_ray/util/_gapic_utils.py +14-3Lines changed: 14 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 28 | 28 | from google.cloud.aiplatform.vertex_ray.util import _validation_utils | 29 | 29 | from google.cloud.aiplatform.vertex_ray.util.resources import ( | 30 | 30 | Cluster, | | 31 | + PscIConfig, | 31 | 32 | Resources, | 32 | 33 | ) | 33 | | -from google.cloud.aiplatform_v1.types.persistent_resource import ( | | 34 | +from google.cloud.aiplatform_v1beta1.types.persistent_resource import ( | 34 | 35 | PersistentResource, | 35 | 36 | ) | 36 | | -from google.cloud.aiplatform_v1.types.persistent_resource_service import ( | | 37 | +from google.cloud.aiplatform_v1beta1.types.persistent_resource_service import ( | 37 | 38 | GetPersistentResourceRequest, | 38 | 39 | ) | 39 | 40 |
| @@ -47,7 +48,7 @@ def create_persistent_resource_client(): | 47 | 48 | return initializer.global_config.create_client( | 48 | 49 | client_class=PersistentResourceClientWithOverride, | 49 | 50 | appended_gapic_version="vertex_ray", | 50 | | - ) | | 51 | + ).select_version("v1beta1") | 51 | 52 |
| 52 | 53 |
| 53 | 54 | def polling_delay(num_attempts: int, time_scale: float) -> datetime.timedelta: | @@ -159,6 +160,10 @@ def persistent_resource_to_cluster( | 159 | 160 | % persistent_resource.name, | 160 | 161 | ) | 161 | 162 | return | | 163 | + if persistent_resource.psc_interface_config: | | 164 | + cluster.psc_interface_config = PscIConfig( | | 165 | + network_attachment=persistent_resource.psc_interface_config.network_attachment | | 166 | + ) | 162 | 167 | resource_pools = persistent_resource.resource_pools | 163 | 168 |
| 164 | 169 | head_resource_pool = resource_pools[0] | @@ -192,6 +197,12 @@ def persistent_resource_to_cluster( | 192 | 197 | ray_version = None | 193 | 198 | cluster.python_version = python_version | 194 | 199 | cluster.ray_version = ray_version | | 200 | + cluster.ray_metric_enabled = not ( | | 201 | + persistent_resource.resource_runtime_spec.ray_spec.ray_metric_spec.disabled | | 202 | + ) | | 203 | + cluster.ray_logs_enabled = not ( | | 204 | + persistent_resource.resource_runtime_spec.ray_spec.ray_logs_spec.disabled | | 205 | + ) | 195 | 206 |
| 196 | 207 | accelerator_type = head_resource_pool.machine_spec.accelerator_type | 197 | 208 | if accelerator_type.value != 0: | |
Collapse file Copy file name to clipboardExpand all lines: google/cloud/aiplatform/vertex_ray/util/resources.py +25-1Lines changed: 25 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 16 | 16 | # | 17 | 17 | import dataclasses | 18 | 18 | from typing import Dict, List, Optional | 19 | | -from google.cloud.aiplatform_v1.types import PersistentResource | | 19 | +from google.cloud.aiplatform_v1beta1.types import PersistentResource | 20 | 20 |
| 21 | 21 |
| 22 | 22 | @dataclasses.dataclass | @@ -68,6 +68,27 @@ class NodeImages: | 68 | 68 | worker: str = None | 69 | 69 |
| 70 | 70 |
| | 71 | +@dataclasses.dataclass | | 72 | +class PscIConfig: | | 73 | + """PSC-I config. | | 74 | +
| | 75 | + Attributes: | | 76 | + network_attachment: Optional. The name or full name of the Compute Engine | | 77 | + `network attachment <https://cloud.google.com/vpc/docs/about-network-attachments>` | | 78 | + to attach to the resource. It has a format: | | 79 | + ``projects/{project}/regions/{region}/networkAttachments/{networkAttachment}``. | | 80 | + Where {project} is a project number, as in ``12345``, and | | 81 | + {networkAttachment} is a network attachment name. To specify | | 82 | + this field, you must have already [created a network | | 83 | + attachment] | | 84 | + (https://cloud.google.com/vpc/docs/create-manage-network-attachments#create-network-attachments). | | 85 | + This field is only used for resources using PSC-I. Make sure you do not | | 86 | + specify the network here for VPC peering. | | 87 | + """ | | 88 | + | | 89 | + network_attachment: str = None | | 90 | + | | 91 | + | 71 | 92 | @dataclasses.dataclass | 72 | 93 | class Cluster: | 73 | 94 | """Ray cluster (output only). | @@ -111,6 +132,9 @@ class Cluster: | 111 | 132 | head_node_type: Resources = None | 112 | 133 | worker_node_types: List[Resources] = None | 113 | 134 | dashboard_address: str = None | | 135 | + ray_metric_enabled: bool = True | | 136 | + ray_logs_enabled: bool = True | | 137 | + psc_interface_config: PscIConfig = None | 114 | 138 | labels: Dict[str, str] = None | 115 | 139 |
| 116 | 140 |
| |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/vertex_ray/conftest.py +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 19 | 19 | from google.auth import credentials as auth_credentials | 20 | 20 | from google.cloud import resourcemanager | 21 | 21 | from google.cloud.aiplatform import vertex_ray | 22 | | -from google.cloud.aiplatform_v1.services.persistent_resource_service import ( | | 22 | +from google.cloud.aiplatform_v1beta1.services.persistent_resource_service import ( | 23 | 23 | PersistentResourceServiceClient, | 24 | 24 | ) | 25 | | -from google.cloud.aiplatform_v1.types.persistent_resource import ( | | 25 | +from google.cloud.aiplatform_v1beta1.types.persistent_resource import ( | 26 | 26 | PersistentResource, | 27 | 27 | ) | 28 | | -from google.cloud.aiplatform_v1.types.persistent_resource import ( | | 28 | +from google.cloud.aiplatform_v1beta1.types.persistent_resource import ( | 29 | 29 | ResourceRuntime, | 30 | 30 | ) | 31 | | -from google.cloud.aiplatform_v1.types.persistent_resource_service import ( | | 31 | +from google.cloud.aiplatform_v1beta1.types.persistent_resource_service import ( | 32 | 32 | DeletePersistentResourceRequest, | 33 | 33 | ) | 34 | 34 | import test_constants as tc | |
Collapse file Copy file name to clipboardExpand all lines: tests/unit/vertex_ray/test_cluster_init.py +9-3Lines changed: 9 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | Resources, | 23 | 23 | NodeImages, | 24 | 24 | ) | 25 | | -from google.cloud.aiplatform_v1.services.persistent_resource_service import ( | | 25 | +from google.cloud.aiplatform_v1beta1.services.persistent_resource_service import ( | 26 | 26 | PersistentResourceServiceClient, | 27 | 27 | ) | 28 | | -from google.cloud.aiplatform_v1.types import persistent_resource_service | | 28 | +from google.cloud.aiplatform_v1beta1.types import persistent_resource_service | 29 | 29 | import test_constants as tc | 30 | 30 | import mock | 31 | 31 | import pytest | @@ -352,13 +352,15 @@ def test_create_ray_cluster_1_pool_gpu_with_labels_success( | 352 | 352 | self, create_persistent_resource_1_pool_mock | 353 | 353 | ): | 354 | 354 | """If head and worker nodes are duplicate, merge to head pool.""" | | 355 | + # Also test disable logging and metrics collection. | 355 | 356 | cluster_name = vertex_ray.create_ray_cluster( | 356 | 357 | head_node_type=tc.ClusterConstants.TEST_HEAD_NODE_TYPE_1_POOL, | 357 | 358 | worker_node_types=tc.ClusterConstants.TEST_WORKER_NODE_TYPES_1_POOL, | 358 | 359 | network=tc.ProjectConstants.TEST_VPC_NETWORK, | 359 | 360 | cluster_name=tc.ClusterConstants.TEST_VERTEX_RAY_PR_ID, | 360 | 361 | labels=tc.ClusterConstants.TEST_LABELS, | 361 | 362 | enable_metrics_collection=False, | | 363 | + enable_logging=False, | 362 | 364 | ) | 363 | 365 |
| 364 | 366 | assert tc.ClusterConstants.TEST_VERTEX_RAY_PR_ADDRESS == cluster_name | @@ -401,11 +403,15 @@ def test_create_ray_cluster_2_pools_success( | 401 | 403 | self, create_persistent_resource_2_pools_mock | 402 | 404 | ): | 403 | 405 | """If head and worker nodes are not duplicate, create separate resource_pools.""" | | 406 | + # Also test PSC-I. | | 407 | + psc_interface_config = vertex_ray.PscIConfig( | | 408 | + network_attachment=tc.ClusterConstants.TEST_PSC_NETWORK_ATTACHMENT | | 409 | + ) | 404 | 410 | cluster_name = vertex_ray.create_ray_cluster( | 405 | 411 | head_node_type=tc.ClusterConstants.TEST_HEAD_NODE_TYPE_2_POOLS, | 406 | 412 | worker_node_types=tc.ClusterConstants.TEST_WORKER_NODE_TYPES_2_POOLS, | 407 | | - network=tc.ProjectConstants.TEST_VPC_NETWORK, | 408 | 413 | cluster_name=tc.ClusterConstants.TEST_VERTEX_RAY_PR_ID, | | 414 | + psc_interface_config=psc_interface_config, | 409 | 415 | ) | 410 | 416 |
| 411 | 417 | assert tc.ClusterConstants.TEST_VERTEX_RAY_PR_ADDRESS == cluster_name | |
|