|
| 1 | +--- |
| 2 | +title: 'Test a fine-tuned model' |
| 3 | +titleSuffix: Azure OpenAI |
| 4 | +description: Learn how to test your fine-tuned model with Azure OpenAI Service by using Python, the REST APIs, or Azure AI Foundry portal. |
| 5 | +manager: nitinme |
| 6 | +ms.service: azure-ai-openai |
| 7 | +ms.custom: build-2025 |
| 8 | +ms.topic: how-to |
| 9 | +ms.date: 05/20/2025 |
| 10 | +author: voutilad |
| 11 | +ms.author: davevoutila |
| 12 | +--- |
| 13 | + |
| 14 | +# Deploy a fine-tuned model for testing (Preview) |
| 15 | + |
| 16 | +After you've fine-tuned a model, you may want to test its quality via the Chat Completions API or the [Evaluations](./evaluations.md) service. |
| 17 | + |
| 18 | +A Developer Tier deployment allows you to deploy your new model without the hourly hosting fee incurred by Standard or Global deployments. The only charges incurred are per-token. Consult the [pricing page](https://aka.ms/aoaipricing) for the most up-to-date pricing. |
| 19 | + |
| 20 | +> [!IMPORTANT] |
| 21 | +> Developer Tier offers no availability SLA and no [data residency](https://aka.ms/data-residency) guarantees. If you require an SLA or data residency, choose an alternative [deployment type](./deployment-types.md) for testing your model. |
| 22 | +> |
| 23 | +> Developer Tier deployments have a fixed lifetime of **24 hours**. Learn more [below](#clean-up-your-deployment) about the deployment lifecycle. |
| 24 | +
|
| 25 | +## Deploy your fine-tuned model |
| 26 | + |
| 27 | +## [Portal](#tab/portal) |
| 28 | + |
| 29 | +To deploy your model candidate, select the fine-tuned model to deploy, and then select **Deploy**. |
| 30 | + |
| 31 | +The **Deploy model** dialog box opens. In the dialog box, enter your **Deployment name** and then select **Developer** from the deployment type drop-down. Select **Create** to start the deployment of your custom model. |
| 32 | + |
| 33 | +:::image type="content" source="../media/fine-tuning/developer.png" alt-text="Screenshot showing selecting Developer deployment in AI Foundry."::: |
| 34 | + |
| 35 | +You can monitor the progress of your new deployment on the **Deployments** pane in Azure AI Foundry portal. |
| 36 | + |
| 37 | +## [Python](#tab/python) |
| 38 | + |
| 39 | +```python |
| 40 | +import json |
| 41 | +import os |
| 42 | +import requests |
| 43 | + |
| 44 | +token = os.getenv("<TOKEN>") |
| 45 | +subscription = "<YOUR_SUBSCRIPTION_ID>" |
| 46 | +resource_group = "<YOUR_RESOURCE_GROUP_NAME>" |
| 47 | +resource_name = "<YOUR_AZURE_OPENAI_RESOURCE_NAME>" |
| 48 | +model_deployment_name = "gpt41-mini-candidate-01" # custom deployment name that you will use to reference the model when making inference calls. |
| 49 | + |
| 50 | +deploy_params = {'api-version': "2024-10-21"} |
| 51 | +deploy_headers = {'Authorization': 'Bearer {}'.format(token), 'Content-Type': 'application/json'} |
| 52 | + |
| 53 | +deploy_data = { |
| 54 | + "sku": {"name": "developer", "capacity": 50}, |
| 55 | + "properties": { |
| 56 | + "model": { |
| 57 | + "format": "OpenAI", |
| 58 | + "name": <"fine_tuned_model">, #retrieve this value from the previous call, it will look like gpt41-mini-candidate-01.ft-b044a9d3cf9c4228b5d393567f693b83 |
| 59 | + "version": "1" |
| 60 | + } |
| 61 | + } |
| 62 | +} |
| 63 | +deploy_data = json.dumps(deploy_data) |
| 64 | + |
| 65 | +request_url = f'https://management.azure.com/subscriptions/{subscription}/resourceGroups/{resource_group}/providers/Microsoft.CognitiveServices/accounts/{resource_name}/deployments/{model_deployment_name}' |
| 66 | + |
| 67 | +print('Creating a new deployment...') |
| 68 | + |
| 69 | +r = requests.put(request_url, params=deploy_params, headers=deploy_headers, data=deploy_data) |
| 70 | + |
| 71 | +print(r) |
| 72 | +print(r.reason) |
| 73 | +print(r.json()) |
| 74 | + |
| 75 | +``` |
| 76 | + |
| 77 | +|variable | Definition| |
| 78 | +|--------------|-----------| |
| 79 | +| token | There are multiple ways to generate an authorization token. The easiest method for initial testing is to launch the Cloud Shell from the [Azure portal](https://portal.azure.com). Then run [`az account get-access-token`](/cli/azure/account#az-account-get-access-token()). You can use this token as your temporary authorization token for API testing. We recommend storing this in a new environment variable. | |
| 80 | +| subscription | The subscription ID for the associated Azure OpenAI resource. | |
| 81 | +| resource_group | The resource group name for your Azure OpenAI resource. | |
| 82 | +| resource_name | The Azure OpenAI resource name. | |
| 83 | +| model_deployment_name | The custom name for your new fine-tuned model deployment. This is the name that will be referenced in your code when making chat completion calls. | |
| 84 | +| fine_tuned_model | Retrieve this value from your fine-tuning job results in the previous step. It will look like `gpt41-mini-candidate-01.ft-b044a9d3cf9c4228b5d393567f693b83`. You will need to add that value to the deploy_data json. Alternatively you can also deploy a checkpoint, by passing the checkpoint ID which will appear in the format `ftchkpt-e559c011ecc04fc68eaa339d8227d02d` | |
| 85 | + |
| 86 | +## [REST](#tab/rest) |
| 87 | + |
| 88 | +The following example shows how to use the REST API to create a model deployment for your customized model. The REST API generates a name for the deployment of your customized model. |
| 89 | + |
| 90 | + |
| 91 | +```bash |
| 92 | +curl -X POST "https://management.azure.com/subscriptions/<SUBSCRIPTION>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.CognitiveServices/accounts/<RESOURCE_NAME>/deployments/<MODEL_DEPLOYMENT_NAME>api-version=2024-10-21" \ |
| 93 | + -H "Authorization: Bearer <TOKEN>" \ |
| 94 | + -H "Content-Type: application/json" \ |
| 95 | + -d '{ |
| 96 | + "sku": {"name": "developer", "capacity": 50}, |
| 97 | + "properties": { |
| 98 | + "model": { |
| 99 | + "format": "OpenAI", |
| 100 | + "name": "<FINE_TUNED_MODEL>", |
| 101 | + "version": "1" |
| 102 | + } |
| 103 | + } |
| 104 | +}' |
| 105 | +``` |
| 106 | + |
| 107 | +|variable | Definition| |
| 108 | +|--------------|-----------| |
| 109 | +| token | There are multiple ways to generate an authorization token. The easiest method for initial testing is to launch the Cloud Shell from the [Azure portal](https://portal.azure.com). Then run [`az account get-access-token`](/cli/azure/account#az-account-get-access-token()). You can use this token as your temporary authorization token for API testing. We recommend storing this in a new environment variable. | |
| 110 | +| subscription | The subscription ID for the associated Azure OpenAI resource. | |
| 111 | +| resource_group | The resource group name for your Azure OpenAI resource. | |
| 112 | +| resource_name | The Azure OpenAI resource name. | |
| 113 | +| model_deployment_name | The custom name for your new fine-tuned model deployment. This is the name that will be referenced in your code when making chat completion calls. | |
| 114 | +| fine_tuned_model | Retrieve this value from your fine-tuning job results in the previous step. It will look like `gpt-35-turbo-0125.ft-b044a9d3cf9c4228b5d393567f693b83`. You'll need to add that value to the deploy_data json. Alternatively you can also deploy a checkpoint, by passing the checkpoint ID which will appear in the format `ftchkpt-e559c011ecc04fc68eaa339d8227d02d` | |
| 115 | + |
| 116 | + |
| 117 | +### Deploy a model with Azure CLI |
| 118 | + |
| 119 | +The following example shows how to use the Azure CLI to deploy your customized model. With the Azure CLI, you must specify a name for the deployment of your customized model. For more information about how to use the Azure CLI to deploy customized models, see [`az cognitiveservices account deployment`](/cli/azure/cognitiveservices/account/deployment). |
| 120 | + |
| 121 | +To run this Azure CLI command in a console window, you must replace the following _\<placeholders>_ with the corresponding values for your customized model: |
| 122 | + |
| 123 | +| Placeholder | Value | |
| 124 | +| --- | --- | |
| 125 | +| _\<YOUR_AZURE_SUBSCRIPTION>_ | The name or ID of your Azure subscription. | |
| 126 | +| _\<YOUR_RESOURCE_GROUP>_ | The name of your Azure resource group. | |
| 127 | +| _\<YOUR_RESOURCE_NAME>_ | The name of your Azure OpenAI resource. | |
| 128 | +| _\<YOUR_DEPLOYMENT_NAME>_ | The name you want to use for your model deployment. | |
| 129 | +| _\<YOUR_FINE_TUNED_MODEL_ID>_ | The name of your customized model. | |
| 130 | + |
| 131 | +```azurecli |
| 132 | +az cognitiveservices account deployment create |
| 133 | + --resource-group <YOUR_RESOURCE_GROUP> |
| 134 | + --name <YOUR_RESOURCE_NAME> |
| 135 | + --deployment-name <YOUR_DEPLOYMENT_NAME> |
| 136 | + --model-name <YOUR_FINE_TUNED_MODEL_ID> |
| 137 | + --model-version "1" |
| 138 | + --model-format OpenAI |
| 139 | + --sku-capacity "50" |
| 140 | + --sku-name "Developer" |
| 141 | +``` |
| 142 | +--- |
| 143 | + |
| 144 | +## Use your deployed fine-tuned model |
| 145 | + |
| 146 | +## [Portal](#tab/portal) |
| 147 | + |
| 148 | +After your custom model deploys, you can use it like any other deployed model. You can use the **Playgrounds** in the [Azure AI Foundry portal](https://ai.azure.com) to experiment with your new deployment. You can continue to use the same parameters with your custom model, such as `temperature` and `max_tokens`, as you can with other deployed models. |
| 149 | + |
| 150 | +:::image type="content" source="../media/fine-tuning/chat-playground.png" alt-text="Screenshot of the Playground pane in Azure AI Foundry portal, with sections highlighted." lightbox="../media/fine-tuning/chat-playground.png"::: |
| 151 | + |
| 152 | +You can also use the [Evaluations](./evaluations.md) service to create and run model evaluations against your deployed model candidate as well as other model versions. |
| 153 | + |
| 154 | +## [Python](#tab/python) |
| 155 | + |
| 156 | +```python |
| 157 | +import os |
| 158 | +from openai import AzureOpenAI |
| 159 | + |
| 160 | +client = AzureOpenAI( |
| 161 | + azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"), |
| 162 | + api_key=os.getenv("AZURE_OPENAI_API_KEY"), |
| 163 | + api_version="2024-02-01" |
| 164 | +) |
| 165 | + |
| 166 | +response = client.chat.completions.create( |
| 167 | + model="gpt41-mini-candidate-01", # model = "Custom deployment name you chose for your fine-tuning model" |
| 168 | + messages=[ |
| 169 | + {"role": "system", "content": "You are a helpful assistant."}, |
| 170 | + {"role": "user", "content": "Does Azure OpenAI support customer managed keys?"}, |
| 171 | + {"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."}, |
| 172 | + {"role": "user", "content": "Do other Azure AI services support this too?"} |
| 173 | + ] |
| 174 | +) |
| 175 | + |
| 176 | +print(response.choices[0].message.content) |
| 177 | +``` |
| 178 | + |
| 179 | +## [REST](#tab/rest) |
| 180 | + |
| 181 | +```bash |
| 182 | +curl $AZURE_OPENAI_ENDPOINT/openai/deployments/<deployment_name>/chat/completions?api-version=2024-10-21 \ |
| 183 | + -H "Content-Type: application/json" \ |
| 184 | + -H "api-key: $AZURE_OPENAI_API_KEY" \ |
| 185 | + -d '{"messages":[{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},{"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},{"role": "user", "content": "Do other Azure AI services support this too?"}]}' |
| 186 | +``` |
| 187 | +--- |
| 188 | + |
| 189 | +## Clean up your deployment |
| 190 | + |
| 191 | +Developer deployments will auto-delete on their own regardless of activity. Each deployment has a fixed lifetime of **24 hours** after which it is subject to removal. The deletion of a deployment doesn't delete or affect the underlying customized model and the customized model can be redeployed at any time. |
| 192 | + |
| 193 | +To delete a deployment manually, you can use the Azure AI Foundry portal or use [Azure CLI](/cli/azure/cognitiveservices/account/deployment?preserve-view=true#az-cognitiveservices-account-deployment-delete). |
| 194 | + |
| 195 | +To use the [Deployments - Delete REST API](/rest/api/aiservices/accountmanagement/deployments/delete?view=rest-aiservices-accountmanagement-2024-10-01&tabs=HTTP&preserve-view=true) send an HTTP `DELETE` to the deployment resource. Like with creating deployments, you must include the following parameters: |
| 196 | + |
| 197 | +- Azure subscription ID |
| 198 | +- Azure resource group name |
| 199 | +- Azure OpenAI resource name |
| 200 | +- Name of the deployment to delete |
| 201 | + |
| 202 | +Below is the REST API example to delete a deployment: |
| 203 | + |
| 204 | +```bash |
| 205 | +curl -X DELETE "https://management.azure.com/subscriptions/<SUBSCRIPTION>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.CognitiveServices/accounts/<RESOURCE_NAME>/deployments/<MODEL_DEPLOYMENT_NAME>api-version=2024-10-21" \ |
| 206 | + -H "Authorization: Bearer <TOKEN>" |
| 207 | +``` |
| 208 | + |
| 209 | + |
| 210 | +## Next steps |
| 211 | + |
| 212 | +- [Deploy for production](./fine-tuning-deploy.md) |
| 213 | +- Understand [Azure OpenAI Quotas & limits](./quota.md) |
| 214 | +- Read more about other [Azure OpenAI deployment types](./deployment-types.md) |
0 commit comments