Skip to content

Commit

Permalink
Documentation for Azure OpenAI v2 Model Deployments (#2825)
Browse files Browse the repository at this point in the history
* Glide up deployment via CLI documentation

* Script for glide up deployment via API

* Reformated deployment via API code using black formatter

---------

Co-authored-by: Pavan Kumar Reddy Y <[email protected]>
  • Loading branch information
PavanReddy28 and Pavan Kumar Reddy Y authored Nov 10, 2023
1 parent cb0b942 commit 3fa38d4
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# How to Deploy OpenAI Fine-tuned Models using Azure Cognitive Services CLI

This document provides a guide to deploy OpenAI models fine-tuned via Azure Machine Learning workspace. For deploying OpenAI models fine-tuned via Azure OpenAI services, please refer to the documentation [here](#).

### 1. Use the Azure Cloud Shell on the Microsoft Azure Portal
Visit [https://ms.portal.azure.com/#home](https://ms.portal.azure.com/#home)

![Azure Cloud Shell](images/image.png)

### 2. Define Your Azure OpenAI Account Resource
Add your Azure OpenAI studio account's name, subscription ID, and resource group in cloud shell.
```bash
export AOAI_RESOURCE_NAME="<YOUR-AOAI-ACCOUNT-NAME>"
export AOAI_ACCOUNT_SUBSCRIPTION_ID="<YOUR-AOAI-ACCOUNT-SUBSCRIPTION>"
export AOAI_ACCOUNT_RESOURCE_GROUP="<YOUR-AOAI-ACCOUNT-RESOURCE-GROUP>"
```

### 3. Add AzureML Registered Fine-Tuned Model Information
In Azure Cloud Shell, add the AzureML registered model name, registered model version, and the AzureML (AML) workspace path for your fine-tuned model.
Your registered models data can be found in the `Models` tab of your AzureML workspace.

```bash
export AML_REGISTERED_MODEL_NAME="<YOUR-AML-REGISTERED-MODEL-NAME>"
export AML_REGISTERED_MODEL_VERSION="<YOUR-AML-REGISTERD-MODEL-VERSION>"
export AML_WORKSPACE_PATH_MODEL_SOURCE="<YOUR-AML-WORKSPACE-PATH>"
```

Note: Azure ML workspace path format is `/subscriptions/<AML-WORKSPACE-SUBSCRIPTION-ID>/resourceGroups/<AML-WORKSPACE-RESOURCE-GROUP>/providers/Microsoft.MachineLearningServices/workspaces/<AML-WORKSPACE-NAME>`

### 4. Set the Deployment Name and Run the Azure Cognitive Service CLI Command
Set the deployment name and run the Azure Cognitive serivce CLI command to deploy your fientuned model on Azure OpenAI studio.
```
export AOAI_DEPLOYMENT_NAME="DEPLOYMENT-NAME"
az login
az cognitiveservices account deployment create \
--model-name $AML_REGISTERED_MODEL_NAME \
--model-version $AML_REGISTERED_MODEL_VERSION \
--model-source $AML_WORKSPACE_PATH_MODEL_SOURCE \
--subscription $AOAI_ACCOUNT_SUBSCRIPTION_ID \
--resource-group $AOAI_ACCOUNT_RESOURCE_GROUP \
--name $AOAI_RESOURCE_NAME \
--deployment-name $AOAI_DEPLOYMENT_NAME \
--model-format OpenAI \
--sku-capacity 1 \
--sku-name "Standard"
```
![Run Azure CLI command to deploy models](images/image-1.png)

### 5. View Your Azure OpenAI Model Deployment status in Azure OpenAI Studio portal
Visit [https://oai.azure.com/portal/](https://oai.azure.com/portal/) to view your model deployments.

![Deployment in provisioning state](images/image-2.png)

### 6. After your deployment succeeds, use Azure OpenAI chat playground to test your Deployment
View your deployments on Azure OpenAI studio as shown below.

![Succeeded deployment page](images/image-3.png)

Use Chat Playground features to make calls to your fine-tuned model:

![Chat playground](images/image-4.png)

### 7. Refer to the documentation on Azure OpenAI Studio here - [https://learn.microsoft.com/en-us/azure/ai-services/openai/](https://learn.microsoft.com/en-us/azure/ai-services/openai/) to learn more on how to use your model deployments.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import requests
import json
import subprocess

# 1. Add your Azure OpenAI account details
subscription = "<AOAI-ACCOUNT-SUBSCRIPTION-ID>"
resource_group = "<AOAI-ACCOUNT-RESOURCE-GROUP>"
resource_name = "<AOAI-RESOURCE-NAME>"
model_deployment_name = "<NEW-AOAI-DEPLOYMENT-NAME>"

# 2. Add the AzureML registered model name, registered model version, and the AzureML (AML) workspace path for your fine-tuned model.
# Your registered models data can be found in the `Models` tab of your AzureML workspace.
registered_model_name = "<AML-REGISTERED-MODEL-NAME>"
registered_model_version = "<AML-REGISTERED-MODEL-VERSION>"
workspace_path = "<AML-WORKSPACE-PATH-MODEL-SOURCE>"

# Run `az login` to login into your azure account in your system shell
# 3. Get Azure account access token
token = json.loads(
subprocess.run(
"az account get-access-token", capture_output=True, shell=True
).stdout
)["accessToken"]
deploy_params = {"api-version": "2023-05-01"}
deploy_headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
}

# 4. Set model deployment configuration. Here capacity refers to support for `1K Tokens Per Minute (TPM)` for your deployment.
deploy_data = {
"sku": {"name": "Standard", "capacity": 1},
"properties": {
"model": {
"format": "OpenAI",
"name": f"{registered_model_name}",
"version": f"{registered_model_version}",
"source": f"{workspace_path}",
}
},
}

deploy_data = json.dumps(deploy_data)

# 5. Send PUT request to Azure cognitive services to create model deployment
request_url = f"https://management.azure.com/subscriptions/{subscription}/resourceGroups/{resource_group}/providers/Microsoft.CognitiveServices/accounts/{resource_name}/deployments/{model_deployment_name}"

r = requests.put(
request_url, params=deploy_params, headers=deploy_headers, data=deploy_data
)

print(r)

# 6. View Your model deployment status in Azure OpenAI Studio portal
# Visit [https://oai.azure.com/portal/](https://oai.azure.com/portal/) to view your model deployments.

# 7. After your deployment succeeds, use Azure OpenAI chat playground to test your Deployment

0 comments on commit 3fa38d4

Please sign in to comment.