Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
skeleton code for new deployment types
  • Loading branch information
needuv committed Feb 16, 2024
commit eee6ebddd0ab5d0d3104660aae0f11321188aa73
4 changes: 4 additions & 0 deletions sdk/ai/azure-ai-resources-autogen/dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-e ../../../tools/azure-sdk-tools
../../core/azure-core
-e ../../../tools/azure-devtools
../../identity/azure-identity
4 changes: 4 additions & 0 deletions sdk/ai/azure-ai-resources-autogen/tsp-location.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
directory: specification/machinelearningservices/AzureAI.Management
commit: 700388316ee014721ebde3dd4f022377ffb6ba92
repo: Azure/azure-rest-api-specs
additionalDirectories:
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from azure.ai.resources.operations import (
AIResourceOperations,
ConnectionOperations,
DeploymentOperations,
SingleDeploymentOperations,
MLIndexOperations,
PFOperations,
ProjectOperations,
Expand Down Expand Up @@ -121,7 +121,7 @@ def __init__(
self._connections = ConnectionOperations(resource_ml_client=self._ai_resource_ml_client, project_ml_client=self._ml_client, **app_insights_handler_kwargs)
self._mlindexes = MLIndexOperations(self._ml_client, **app_insights_handler_kwargs)
self._ai_resources = AIResourceOperations(self._ml_client, **app_insights_handler_kwargs)
self._deployments = DeploymentOperations(self._ml_client, self._connections, **app_insights_handler_kwargs)
self._single_deployments = SingleDeploymentOperations(self._ml_client, self._connections, **app_insights_handler_kwargs)
self._data = DataOperations(self._ml_client)
self._models = ModelOperations(self._ml_client)
# self._pf = PFOperations(self._ml_client, self._scope)
Expand Down Expand Up @@ -202,13 +202,13 @@ def data(self) -> DataOperations:
return self._data

@property
def deployments(self) -> DeploymentOperations:
def single_deployments(self) -> SingleDeploymentOperations:
"""A collection of deployment-related operations.

:return: Deployment operations
:rtype: DeploymentOperations
"""
return self._deployments
return self._single_deployments

@property
def models(self) -> ModelOperations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@dataclass
class Deployment:
class SingleDeployment:
name: str
model: Union[str, Model, PromptflowModel]
app_insights_enabled: bool = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ._acs_output_config import ACSOutputConfig
from ._ai_resource_operations import AIResourceOperations
from ._connection_operations import ConnectionOperations
from ._deployment_operations import DeploymentOperations
from ._single_deployment_operations import SingleDeploymentOperations
from ._index_data_source import ACSSource, GitSource, IndexDataSource, LocalSource
from ._mlindex_operations import MLIndexOperations
from ._pf_operations import PFOperations
Expand All @@ -27,7 +27,7 @@
"ProjectOperations",
"PFOperations",
"AIResourceOperations",
"DeploymentOperations",
"SingleDeploymentOperations",
"DataOperations",
"ModelOperations",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

from typing import Iterable
from azure.core.polling import LROPoller

class AzureOpenAIDeploymentOperations():
def __init__(self):
pass

def begin_create_or_update(self, deployment: "AzureOpenAIDeployment") -> LROPoller["AzureOpenAIDeployment"]:
pass

def get(self, deployment_name: str, connection_name: str = None):
pass

def list(self, include_connections: str = None) -> Iterable["AzureOpenAIDeployment"]:
pass

def begin_delete(self, deployment_name: str) -> LROPoller[None]:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .._utils._scoring_script_utils import create_chat_scoring_script, create_mlmodel_file
from .._utils._registry_utils import get_registry_model
from .._utils._deployment_utils import get_default_allowed_instance_type_for_hugging_face, get_empty_deployment_arm_template
from ..entities.deployment import Deployment
from ..entities.single_deployment import SingleDeployment
from ..entities.deployment_keys import DeploymentKeys
from ..entities.models import Model, PromptflowModel

Expand All @@ -33,16 +33,16 @@
logger, module_logger = ops_logger.package_logger, ops_logger.module_logger


class DeploymentOperations:
class SingleDeploymentOperations:
def __init__(self, ml_client: MLClient, connections, **kwargs) -> None:
self._ml_client = ml_client
self._connections = connections
ops_logger.update_info(kwargs)
self._resource_management_client = ResourceManagementClient(self._ml_client._credential, self._ml_client.subscription_id)

@distributed_trace
@monitor_with_activity(logger, "Deployment.BeginCreateOrUpdate", ActivityType.PUBLICAPI)
def begin_create_or_update(self, deployment: Deployment) -> LROPoller[Deployment]:
@monitor_with_activity(logger, "SingleDeployment.BeginCreateOrUpdate", ActivityType.PUBLICAPI)
def begin_create_or_update(self, deployment: SingleDeployment) -> LROPoller[SingleDeployment]:
model = deployment.model
endpoint_name = deployment.endpoint_name if deployment.endpoint_name else deployment.name

Expand Down Expand Up @@ -251,7 +251,7 @@ def begin_create_or_update(self, deployment: Deployment) -> LROPoller[Deployment

def lro_callback(raw_response, deserialized, headers):
outputs = deserialized.properties.outputs
return Deployment._from_v2_endpoint_deployment(
return SingleDeployment._from_v2_endpoint_deployment(
self._ml_client.online_endpoints.get(outputs["online_endpoint_name"]["value"]),
self._ml_client.online_deployments.get(outputs["online_deployment_name"]["value"], outputs["online_endpoint_name"]["value"])
)
Expand All @@ -269,43 +269,43 @@ def lro_callback(raw_response, deserialized, headers):
)

@distributed_trace
@monitor_with_activity(logger, "Deployment.Get", ActivityType.PUBLICAPI)
def get(self, name: str, endpoint_name: Optional[str] = None) -> Deployment:
@monitor_with_activity(logger, "SingleDeployment.Get", ActivityType.PUBLICAPI)
def get(self, name: str, endpoint_name: Optional[str] = None) -> SingleDeployment:
endpoint_name = endpoint_name if endpoint_name else name
deployment = self._ml_client.online_deployments.get(
name=name,
endpoint_name=endpoint_name if endpoint_name else name,
)
endpoint = self._ml_client.online_endpoints.get(endpoint_name)

return Deployment._from_v2_endpoint_deployment(endpoint, deployment)
return SingleDeployment._from_v2_endpoint_deployment(endpoint, deployment)

@distributed_trace
@monitor_with_activity(logger, "Deployment.List", ActivityType.PUBLICAPI)
def list(self) -> Iterable[Deployment]:
@monitor_with_activity(logger, "SingleDeployment.List", ActivityType.PUBLICAPI)
def list(self) -> Iterable[SingleDeployment]:
deployments = []
endpoints = self._ml_client.online_endpoints.list()
for endpoint in endpoints:
v2_deployments = self._ml_client.online_deployments.list(endpoint.name)
deployments.extend([Deployment._from_v2_endpoint_deployment(endpoint, deployment) for deployment in v2_deployments])
deployments.extend([SingleDeployment._from_v2_endpoint_deployment(endpoint, deployment) for deployment in v2_deployments])
return deployments

@distributed_trace
@monitor_with_activity(logger, "Deployment.GetKeys", ActivityType.PUBLICAPI)
@monitor_with_activity(logger, "SingleDeployment.GetKeys", ActivityType.PUBLICAPI)
def get_keys(self, name: str, endpoint_name: Optional[str] = None) -> DeploymentKeys:
endpoint_name = endpoint_name if endpoint_name else name
return DeploymentKeys._from_v2_endpoint_keys(self._ml_client.online_endpoints.get_keys(endpoint_name))

@distributed_trace
@monitor_with_activity(logger, "Deployment.Delete", ActivityType.PUBLICAPI)
@monitor_with_activity(logger, "SingleDeployment.Delete", ActivityType.PUBLICAPI)
def delete(self, name: str, endpoint_name: Optional[str] = None) -> None:
self._ml_client.online_deployments.delete(
name=name,
endpoint_name=endpoint_name if endpoint_name else name,
).result()

@distributed_trace
@monitor_with_activity(logger, "Deployment.Invoke", ActivityType.PUBLICAPI)
@monitor_with_activity(logger, "SingleDeployment.Invoke", ActivityType.PUBLICAPI)
def invoke(self, name: str, request_file: Union[str, os.PathLike], endpoint_name: Optional[str] = None) -> Any:
return self._ml_client.online_endpoints.invoke(
endpoint_name=endpoint_name if endpoint_name else name,
Expand All @@ -316,7 +316,7 @@ def invoke(self, name: str, request_file: Union[str, os.PathLike], endpoint_name
def _check_default_instance_type_and_populate(
self,
instance_type: str,
deployment: Deployment,
deployment: SingleDeployment,
allowed_instance_types: Optional[List[str]] = None,
min_sku_spec: Optional[str] = None,
) -> None:
Expand Down