0

I follow Azure's tutorial on fine-tuning GPT. Here is the code for the deployment phase:

# Deploy fine-tuned model

import json
import requests

token = '[redacted]'
subscription = '[redacted]'
resource_group = "[redacted]"
resource_name = "[redacted]"
model_deployment_name = "gpt-4o-mini-2024-07-18-ft" # Custom deployment name you chose for your fine-tuning model

deploy_params = {'api-version': "2023-05-01"}
deploy_headers = {'Authorization': 'Bearer {}'.format(token), 'Content-Type': 'application/json'}

deploy_data = {
    "sku": {"name": "standard", "capacity": 1},
    "properties": {
        "model": {
            "format": "OpenAI",
            "name": "gpt-4o-mini-2024-07-18.ft-[redacted]", #retrieve this value from the previous call, it will look like gpt-4o-mini-2024-07-18.ft-[redacted]
            "version": "1"
        }
    }
}
deploy_data = json.dumps(deploy_data)

request_url = f'https://management.azure.com/subscriptions/{subscription}/resourceGroups/{resource_group}/providers/Microsoft.CognitiveServices/accounts/{resource_name}/deployments/{model_deployment_name}'

print('Creating a new deployment...')

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

print(r)
print(r.reason)
print(r.json())

That works fine, but the token generated via az account get-access-token expires quickly. Looking at the documentation:

az account get-access-token [--name]
                            [--resource]
                            [--resource-type {aad-graph, arm, batch, data-lake, media, ms-graph, oss-rdbms}]
                            [--scope]
                            [--tenant]

there are no parameters to extend the token lifespan.

This annoys me. How can I deploy a fine-tuned GPT model in Azure via Python without using a token (e.g., using an endpoint key instead)?

1 Answer 1

2

how to deploy the finetune model? using key based authentication?.

No, it is not possible to authenticate the Management API using key-based authentication.

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.CognitiveServices/accounts/{resourceName}/deployments/{deploymentName}?api-version=2024-10-01

is a management plane operation (via Azure Resource Manager), and API key authentication is not supported for management APIs.

The above management API will work on this Azure Service principal, Azure CLI and Managed Identity Authentication.

Reference: Deployments - Create Or Update - REST API (Azure Azure AI Services) | Microsoft Learn

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.