You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/ai-services/openai/tutorials/fine-tune.md
+43-41Lines changed: 43 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,21 @@
1
1
---
2
-
title: Azure OpenAI Service fine-tuning gpt-3.5-turbo
2
+
title: Azure OpenAI Service fine-tuning gpt-4o-mini
3
3
titleSuffix: Azure OpenAI
4
-
description: Learn how to use Azure OpenAI's latest fine-tuning capabilities with gpt-3.5-turbo.
4
+
description: Learn how to use Azure OpenAI's latest fine-tuning capabilities with gpt-4o-mini-2024-07-18
5
5
#services: cognitive-services
6
6
manager: nitinme
7
7
ms.service: azure-ai-openai
8
8
ms.topic: tutorial
9
-
ms.date: 05/15/2024
9
+
ms.date: 09/09/2024
10
10
author: mrbullwinkle
11
11
ms.author: mbullwin
12
12
recommendations: false
13
13
ms.custom: devx-track-python
14
14
---
15
15
16
-
# Azure OpenAI GPT-3.5 Turbo fine-tuning tutorial
16
+
# Azure OpenAI GPT-4o-mini fine-tuning tutorial
17
17
18
-
This tutorial walks you through fine-tuning a `gpt-35-turbo-0613` model.
18
+
This tutorial walks you through fine-tuning a `gpt-4o-mini-2024-07-18` model.
19
19
20
20
In this tutorial you learn how to:
21
21
@@ -24,7 +24,7 @@ In this tutorial you learn how to:
24
24
> * Create environment variables for your resource endpoint and API key.
25
25
> * Prepare your sample training and validation datasets for fine-tuning.
26
26
> * Upload your training file and validation file for fine-tuning.
27
-
> * Create a fine-tuning job for `gpt-35-turbo-0613`.
27
+
> * Create a fine-tuning job for `gpt-4o-mini-2024-07-18`.
28
28
> * Deploy a custom fine-tuned model.
29
29
30
30
## Prerequisites
@@ -33,13 +33,12 @@ In this tutorial you learn how to:
33
33
- Python 3.8 or later version
34
34
- The following Python libraries: `json`, `requests`, `os`, `tiktoken`, `time`, `openai`, `numpy`.
35
35
-[Jupyter Notebooks](https://jupyter.org/)
36
-
- An Azure OpenAI resource in a [region where `gpt-35-turbo-0613` fine-tuning is available](../concepts/models.md). If you don't have a resource the process of creating one is documented in our resource [deployment guide](../how-to/create-resource.md).
36
+
- An Azure OpenAI resource in a [region where `gpt-4o-mini-2024-07-18` fine-tuning is available](../concepts/models.md). If you don't have a resource the process of creating one is documented in our resource [deployment guide](../how-to/create-resource.md).
- If you do not already have access to view quota, and deploy models in Azure OpenAI Studio you will require [additional permissions](../how-to/role-based-access-control.md).
39
39
40
-
41
40
> [!IMPORTANT]
42
-
> We strongly recommend reviewing the [pricing information](https://azure.microsoft.com/pricing/details/cognitive-services/openai-service/#pricing) for fine-tuning prior to beginning this tutorial to make sure you are comfortable with the associated costs. In testing, this tutorial resulted in one training hour billed, in addition to the costs that are associated with fine-tuning inference, and the hourly hosting costs of having a fine-tuned model deployed. Once you have completed the tutorial, you should delete your fine-tuned model deployment otherwise you will continue to incur the hourly hosting cost.
41
+
> We recommend reviewing the [pricing information](https://azure.microsoft.com/pricing/details/cognitive-services/openai-service/#pricing) for fine-tuning to familiarize yourself with the associated costs. In testing, this tutorial resulted in 48,000 tokens being billed (4,800 training tokens * 10 epochs of training). Training costs are in addition to the costs that are associated with fine-tuning inference, and the hourly hosting costs of having a fine-tuned model deployed. Once you have completed the tutorial, you should delete your fine-tuned model deployment otherwise you will continue to incur the hourly hosting cost.
43
42
44
43
## Set up
45
44
@@ -106,7 +105,7 @@ source /etc/environment
106
105
107
106
### Create a sample dataset
108
107
109
-
Fine-tuning `gpt-35-turbo-0613` requires a specially formatted JSONL training file. OpenAI provides the following example in their documentation:
108
+
Fine-tuning `gpt-4o-mini-2024-07-18` requires a specially formatted JSONL training file. OpenAI provides the following example in their documentation:
110
109
111
110
```json
112
111
{"messages": [{"role": "system", "content": "Marv is a factual chatbot that is also sarcastic."}, {"role": "user", "content": "What's the capital of France?"}, {"role": "assistant", "content": "Paris, as if everyone doesn't know that already."}]}
@@ -206,7 +205,10 @@ First example in validation set:
206
205
207
206
In this case we only have 10 training and 10 validation examples so while this will demonstrate the basic mechanics of fine-tuning a model this in unlikely to be a large enough number of examples to produce a consistently noticeable impact.
208
207
209
-
Now you can then run some additional code from OpenAI using the tiktoken library to validate the token counts. Individual examples need to remain under the `gpt-35-turbo-0613` model's input token limit of 4096 tokens.
208
+
Now you can then run some additional code from OpenAI using the tiktoken library to validate the token counts. Token counting using this method is not going to give you the exact token counts that will be used for fine-tuning, but should provide a good estimate.
209
+
210
+
> [!NOTE]
211
+
> Individual examples need to remain under the `gpt-4o-mini-2024-07-18` model's current training example context legnth of: 64,536 tokens. The model's input token limit remains 128,000 tokens.
210
212
211
213
```python
212
214
# Validate token counts
@@ -216,7 +218,7 @@ import tiktoken
216
218
import numpy as np
217
219
from collections import defaultdict
218
220
219
-
encoding = tiktoken.get_encoding("cl100k_base") # default encoding used by gpt-4, turbo, and text-embedding-ada-002 models
221
+
encoding = tiktoken.get_encoding("o200k_base") # default encoding for gpt-4o models. This requires the latest version of tiktoken to be installed.
api_version="2024-05-01-preview"# This API version or later is required to access seed/events/checkpoint features
309
+
api_version="2024-08-01-preview"# This API version or later is required to access seed/events/checkpoint features
308
310
)
309
311
310
312
training_file_name ='training_set.jsonl'
@@ -381,7 +383,7 @@ In this example we're also passing the seed parameter. The seed controls the rep
381
383
response = client.fine_tuning.jobs.create(
382
384
training_file= training_file_id,
383
385
validation_file= validation_file_id,
384
-
model="gpt-35-turbo-0613", # Enter base model name. Note that in Azure OpenAI the model name contains dashes and cannot contain dot/period characters.
386
+
model="gpt-4o-mini-2024-07-18", # Enter base model name. Note that in Azure OpenAI the model name contains dashes and cannot contain dot/period characters.
385
387
seed=105# seed parameter controls reproducibility of the fine-tuning job. If no seed is specified one will be generated automatically.
API version: `2024-05-01-preview` or later is required for this command.
569
+
API version: `2024-08-01-preview` or later is required for this command.
568
570
569
571
While not necessary to complete fine-tuning it can be helpful to examine the individual fine-tuning events that were generated during training. The full training results can also be examined after training is complete in the [training results file](../how-to/fine-tuning.md#analyze-your-customized-model).
570
572
@@ -728,7 +730,7 @@ This command isn't available in the 0.28.1 OpenAI Python library. Upgrade to the
728
730
729
731
## List checkpoints
730
732
731
-
API version: `2024-05-01-preview` or later is required for this command.
733
+
API version: `2024-08-01-preview` or later is required for this command.
732
734
733
735
When each training epoch completes a checkpoint is generated. A checkpoint is a fully functional version of a model which can both be deployed and used as the target model for subsequent fine-tuning jobs. Checkpoints can be particularly useful, as they can provide a snapshot of your model prior to overfitting having occurred. When a fine-tuning job completes you will have the three most recent versions of the model available to deploy. The final epoch will be represented by your fine-tuned model, the previous two epochs will be available as checkpoints.
734
736
@@ -753,7 +755,7 @@ This command isn't available in the 0.28.1 OpenAI Python library. Upgrade to the
@@ -848,7 +850,7 @@ Alternatively, you can deploy your fine-tuned model using any of the other commo
848
850
| resource_group | The resource group name for your Azure OpenAI resource |
849
851
| resource_name | The Azure OpenAI resource name |
850
852
| 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. |
851
-
| fine_tuned_model | Retrieve this value from your fine-tuning job results in the previous step. It will look like `gpt-35-turbo-0613.ft-b044a9d3cf9c4228b5d393567f693b83`. You'll need to add that value to the deploy_data json. |
853
+
| fine_tuned_model | Retrieve this value from your fine-tuning job results in the previous step. It will look like `gpt-4o-mini-2024-07-18.ft-b044a9d3cf9c4228b5d393567f693b83`. You'll need to add that value to the deploy_data json. |
"name": "<YOUR_FINE_TUNED_MODEL>", #retrieve this value from the previous call, it will look like gpt-35-turbo-0613.ft-b044a9d3cf9c4228b5d393567f693b83
877
+
"name": "<YOUR_FINE_TUNED_MODEL>", #retrieve this value from the previous call, it will look like gpt-4o-mini-2024-07-18.ft-b044a9d3cf9c4228b5d393567f693b83
876
878
"version": "1"
877
879
}
878
880
}
@@ -911,11 +913,11 @@ from openai import AzureOpenAI
0 commit comments