-
Notifications
You must be signed in to change notification settings - Fork 1
[CLI][SDK] Add supports to CServe V3 #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
03b1152
implement v3
V2arK 7f58300
change default to v3
V2arK 2f37c56
format
V2arK 8b37022
black format
V2arK 059bb0c
black format
V2arK da862d9
addressing comments
V2arK 7c2e67b
gs
V2arK ff716b1
unify v2 / v3 getters, change get replica info helper
V2arK ac79cec
make update cserve not choosing version
V2arK 2db4023
simplify update
V2arK 73e8e69
revert changes done by black
V2arK 6367b1c
add inference v3 support - testing
V2arK 7924f56
pylint
V2arK e328151
black format
V2arK 5dfc12f
Remove create and update support for V2 deployment types
anandj91 eb6e5d8
Lint fix
anandj91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,16 @@ | ||
| from contextlib import contextmanager | ||
| from typing import Union | ||
|
|
||
| import platform_api_python_client | ||
| from platform_api_python_client import ( | ||
| DeploymentType, | ||
| DeploymentStatus, | ||
| CreateInferenceDeploymentRequest, | ||
| CreateInferenceV3DeploymentRequest, | ||
| CreateComputeDeploymentRequest, | ||
| CreateCServeV2DeploymentRequest, | ||
| CreateCServeV3DeploymentRequest, | ||
| ApiException, | ||
| Metric, | ||
| ) | ||
|
|
||
|
|
@@ -27,31 +31,163 @@ def get_status(self, id): | |
| return self._api.get_deployment_status_deployments_status_deployment_id_get(id) | ||
|
|
||
| def get_inference(self, id): | ||
| return self._api.get_inference_deployment_deployments_inference_deployment_id_get(id) | ||
| """Get Inference deployment details - automatically handles both V2 and V3 deployments""" | ||
| # Try V3 first (recommended), fallback to V2 if deployment is V2 | ||
| try: | ||
| return self._api.get_inference_v3_deployment_deployments_inference_v3_deployment_id_get(id) | ||
| except ApiException as e: | ||
| # If V3 fails with 404 or similar, try V2 | ||
| if e.status in [404, 400]: # Deployment might be V2 or endpoint not found | ||
anandj91 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| try: | ||
| return self._api.get_inference_deployment_deployments_inference_deployment_id_get(id) | ||
| except ApiException as v2_error: | ||
| # If both fail, raise the original V3 error as it's more likely to be the real issue | ||
| raise e from v2_error | ||
| else: | ||
| # For other errors (auth, network, etc.), raise immediately | ||
| raise | ||
|
|
||
| def get_compute(self, id): | ||
| return self._api.get_compute_deployment_deployments_compute_deployment_id_get(id) | ||
|
|
||
| def get_cserve(self, id): | ||
| return self._api.get_cserve_v2_deployment_deployments_cserve_v2_deployment_id_get(id) | ||
|
|
||
| def create_inference(self, request: CreateInferenceDeploymentRequest): | ||
| """Get CServe deployment details - automatically handles both V2 and V3 deployments""" | ||
| # Try V3 first (recommended), fallback to V2 if deployment is V2 | ||
| try: | ||
| return self._api.get_cserve_v3_deployment_deployments_cserve_v3_deployment_id_get(id) | ||
| except ApiException as e: | ||
| # If V3 fails with 404 or similar, try V2 | ||
| if e.status in [404, 400]: # Deployment might be V2 or endpoint not found | ||
| try: | ||
| return self._api.get_cserve_v2_deployment_deployments_cserve_v2_deployment_id_get(id) | ||
| except ApiException as v2_error: | ||
| # If both fail, raise the original V3 error as it's more likely to be the real issue | ||
| raise e from v2_error | ||
| else: | ||
| # For other errors (auth, network, etc.), raise immediately | ||
| raise | ||
|
|
||
| def create_inference(self, request: CreateInferenceV3DeploymentRequest): | ||
| return self._api.create_inference_v3_deployment_deployments_inference_v3_post(request) | ||
|
|
||
| def create_inference_v2(self, request: CreateInferenceDeploymentRequest): | ||
| return self._api.create_inference_deployment_deployments_inference_post(request) | ||
|
|
||
| def create_inference_v3(self, request: CreateInferenceV3DeploymentRequest): | ||
| return self._api.create_inference_v3_deployment_deployments_inference_v3_post(request) | ||
|
|
||
|
||
| def create_compute(self, request: CreateComputeDeploymentRequest): | ||
| return self._api.create_compute_deployment_deployments_compute_post(request) | ||
|
|
||
| def create_cserve(self, request: CreateCServeV2DeploymentRequest): | ||
| def create_cserve(self, request: CreateCServeV3DeploymentRequest): | ||
| return self._api.create_cserve_v3_deployment_deployments_cserve_v3_post(request) | ||
|
|
||
| def create_cserve_v2(self, request: CreateCServeV2DeploymentRequest): | ||
| return self._api.create_cserve_v2_deployment_deployments_cserve_v2_post(request) | ||
|
|
||
| def update_inference(self, deployment_id: int, request: CreateInferenceDeploymentRequest): | ||
| return self._api.update_inference_deployment_deployments_inference_put(deployment_id, request) | ||
| def create_cserve_v3(self, request: CreateCServeV3DeploymentRequest): | ||
| return self._api.create_cserve_v3_deployment_deployments_cserve_v3_post(request) | ||
|
|
||
| def detect_inference_deployment_version(self, deployment_id: int) -> str: | ||
| """Detect if an inference deployment is V2 or V3 by testing the specific API endpoints""" | ||
| try: | ||
| # Try V3 endpoint first | ||
| self._api.get_inference_v3_deployment_deployments_inference_v3_deployment_id_get(deployment_id) | ||
| return 'v3' | ||
| except ApiException as e: | ||
| if e.status in [404, 400]: # V3 endpoint doesn't exist for this deployment | ||
| try: | ||
| # Try V2 endpoint | ||
| self._api.get_inference_deployment_deployments_inference_deployment_id_get(deployment_id) | ||
| return 'v2' | ||
| except ApiException as exc: | ||
| # If both fail, it might not be an inference deployment or doesn't exist | ||
| raise ValueError( | ||
| f"Deployment {deployment_id} is not a valid inference deployment or does not exist" | ||
| ) from exc | ||
| else: | ||
| # Other error (auth, network, etc.) | ||
| raise | ||
|
|
||
| def update_inference( | ||
| self, deployment_id: int, request: Union[CreateInferenceDeploymentRequest, CreateInferenceV3DeploymentRequest] | ||
| ): | ||
| """Update Inference deployment - validates request type matches deployment version""" | ||
| # Detect the deployment version | ||
| deployment_version = self.detect_inference_deployment_version(deployment_id) | ||
|
|
||
| # Validate request type matches deployment version | ||
| if isinstance(request, CreateInferenceV3DeploymentRequest): | ||
| if deployment_version != 'v3': | ||
| raise ValueError( | ||
| f"Deployment {deployment_id} is Inference {deployment_version.upper()}, " | ||
| f"but you provided a V3 request. Please use CreateInferenceDeploymentRequest instead." | ||
| ) | ||
| return self._api.update_inference_v3_deployment_deployments_inference_v3_put(deployment_id, request) | ||
| elif isinstance(request, CreateInferenceDeploymentRequest): | ||
| if deployment_version != 'v2': | ||
| raise ValueError( | ||
| f"Deployment {deployment_id} is Inference {deployment_version.upper()}, " | ||
| f"but you provided a V2 request. Please use CreateInferenceV3DeploymentRequest instead." | ||
| ) | ||
| return self._api.update_inference_deployment_deployments_inference_put(deployment_id, request) | ||
| else: | ||
| raise ValueError( | ||
| f"Unsupported request type: {type(request)}. " | ||
| f"Expected CreateInferenceDeploymentRequest or CreateInferenceV3DeploymentRequest." | ||
| ) | ||
|
|
||
| def update_compute(self, deployment_id: int, request: CreateComputeDeploymentRequest): | ||
| return self._api.update_compute_deployment_deployments_compute_put(deployment_id, request) | ||
|
|
||
| def update_cserve(self, deployment_id: int, request: CreateCServeV2DeploymentRequest): | ||
| return self._api.update_cserve_v2_deployment_deployments_cserve_v2_put(deployment_id, request) | ||
| def detect_deployment_version(self, deployment_id: int) -> str: | ||
| """Detect if a deployment is V2 or V3 by testing the specific API endpoints""" | ||
| try: | ||
| # Try V3 endpoint first | ||
| self._api.get_cserve_v3_deployment_deployments_cserve_v3_deployment_id_get(deployment_id) | ||
| return 'v3' | ||
| except ApiException as e: | ||
| if e.status in [404, 400]: # V3 endpoint doesn't exist for this deployment | ||
| try: | ||
| # Try V2 endpoint | ||
| self._api.get_cserve_v2_deployment_deployments_cserve_v2_deployment_id_get(deployment_id) | ||
| return 'v2' | ||
| except ApiException as exc: | ||
| # If both fail, it might not be a CServe deployment or doesn't exist | ||
| raise ValueError( | ||
| f"Deployment {deployment_id} is not a valid CServe deployment or does not exist" | ||
| ) from exc | ||
| else: | ||
| # Other error (auth, network, etc.) | ||
| raise | ||
|
|
||
| def update_cserve( | ||
| self, deployment_id: int, request: Union[CreateCServeV2DeploymentRequest, CreateCServeV3DeploymentRequest] | ||
| ): | ||
| """Update CServe deployment - validates request type matches deployment version""" | ||
| # Detect the deployment version | ||
| deployment_version = self.detect_deployment_version(deployment_id) | ||
|
|
||
| # Validate request type matches deployment version | ||
| if isinstance(request, CreateCServeV3DeploymentRequest): | ||
| if deployment_version != 'v3': | ||
| raise ValueError( | ||
| f"Deployment {deployment_id} is CServe {deployment_version.upper()}, " | ||
| f"but you provided a V3 request. Please use CreateCServeV2DeploymentRequest instead." | ||
| ) | ||
| return self._api.update_cserve_v3_deployment_deployments_cserve_v3_put(deployment_id, request) | ||
| elif isinstance(request, CreateCServeV2DeploymentRequest): | ||
| if deployment_version != 'v2': | ||
| raise ValueError( | ||
| f"Deployment {deployment_id} is CServe {deployment_version.upper()}, " | ||
| f"but you provided a V2 request. Please use CreateCServeV3DeploymentRequest instead." | ||
| ) | ||
| return self._api.update_cserve_v2_deployment_deployments_cserve_v2_put(deployment_id, request) | ||
| else: | ||
| raise ValueError( | ||
| f"Unsupported request type: {type(request)}. " | ||
| f"Expected CreateCServeV2DeploymentRequest or CreateCServeV3DeploymentRequest." | ||
| ) | ||
|
|
||
| def _update_status(self, id, new_status): | ||
| status_req = platform_api_python_client.DeploymentStatusRequest(status=new_status) | ||
|
|
@@ -93,6 +229,20 @@ def get_user_vault(self, type): | |
|
|
||
| return {i.key: i.value for i in items} | ||
|
|
||
| def detect_cserve_deployment_version(self, deployment_response): | ||
| """Detect if a CServe deployment is V2 or V3 based on response fields""" | ||
| # Check for V3-specific fields | ||
| if hasattr(deployment_response, 'max_surge') or hasattr(deployment_response, 'max_unavailable'): | ||
| return 'v3' | ||
| # Check for V3 field names (min_replicas vs min_scale) | ||
| if hasattr(deployment_response, 'min_replicas'): | ||
| return 'v3' | ||
| # Check for V2 field names | ||
| if hasattr(deployment_response, 'min_scale'): | ||
| return 'v2' | ||
| # Default to V2 for backward compatibility | ||
| return 'v2' | ||
|
|
||
| # pylint: disable=R0917 | ||
| def get_deployment_usage( | ||
| self, id: int, metric: Metric, start_time_in_seconds: int, end_time_in_seconds: int, step: int | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.