Skip to content

Commit d0c3d70

Browse files
Merge pull request #260032 from mrbullwinkle/mrb_12_01_2023_fine_tuning
[Azure OpenAI] fine-tuning 1.x updates
2 parents 5b2a92e + 3fb2df9 commit d0c3d70

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

articles/ai-services/openai/includes/fine-tuning-python.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ For large data files, we recommend that you import from an Azure Blob store. La
140140
141141
The following Python example uploads local training and validation files by using the Python SDK, and retrieves the returned file IDs.
142142

143+
# [OpenAI Python 0.28.1](#tab/python)
144+
143145
```python
144146
# Upload fine-tuning files
145147

@@ -170,12 +172,50 @@ print("Training file ID:", training_file_id)
170172
print("Validation file ID:", validation_file_id)
171173
```
172174

175+
# [OpenAI Python 1.x](#tab/python-new)
176+
177+
```python
178+
# Upload fine-tuning files
179+
180+
import os
181+
from openai import AzureOpenAI
182+
183+
client = AzureOpenAI(
184+
azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
185+
api_key=os.getenv("AZURE_OPENAI_KEY"),
186+
api_version="2023-10-01-preview" # This API version or later is required to access fine-tuning for turbo/babbage-002/davinci-002
187+
)
188+
189+
training_file_name = 'training_set.jsonl'
190+
validation_file_name = 'validation_set.jsonl'
191+
192+
# Upload the training and validation dataset files to Azure OpenAI with the SDK.
193+
194+
training_response = client.files.create(
195+
file=open(training_file_name, "rb"), purpose="fine-tune"
196+
)
197+
training_file_id = training_response.id
198+
199+
validation_response = client.files.create(
200+
file=open(validation_file_name, "rb"), purpose="fine-tune"
201+
)
202+
validation_file_id = validation_response.id
203+
204+
print("Training file ID:", training_file_id)
205+
print("Validation file ID:", validation_file_id)
206+
207+
```
208+
209+
---
210+
173211
## Create a customized model
174212

175213
After you upload your training and validation files, you're ready to start the fine-tuning job.
176214

177215
The following Python code shows an example of how to create a new fine-tune job with the Python SDK:
178216

217+
# [OpenAI Python 0.28.1](#tab/python)
218+
179219
```python
180220

181221
response = openai.FineTuningJob.create(
@@ -195,8 +235,31 @@ print(response)
195235

196236
```
197237

238+
# [OpenAI Python 1.x](#tab/python-new)
239+
240+
```python
241+
response = client.fine_tuning.jobs.create(
242+
training_file=training_file_id,
243+
validation_file=validation_file_id,
244+
model="gpt-35-turbo", # Enter base model name. Note that in Azure OpenAI the model name contains dashes and cannot contain dot/period characters.
245+
)
246+
247+
job_id = response.id
248+
249+
# You can use the job ID to monitor the status of the fine-tuning job.
250+
# The fine-tuning job will take some time to start and complete.
251+
252+
print("Job ID:", response.id)
253+
print("Status:", response.id)
254+
print(response.model_dump_json(indent=2))
255+
```
256+
257+
---
258+
198259
## Check fine-tuning job status
199260

261+
# [OpenAI Python 0.28.1](#tab/python)
262+
200263
```python
201264
#Retrieve training job ID
202265

@@ -207,6 +270,18 @@ print("Status:", response["status"])
207270
print(response)
208271
```
209272

273+
# [OpenAI Python 1.x](#tab/python-new)
274+
275+
```python
276+
response = client.fine_tuning.jobs.retrieve(job_id)
277+
278+
print("Job ID:", response.id)
279+
print("Status:", response.status)
280+
print(response.model_dump_json(indent=2))
281+
```
282+
283+
---
284+
210285
## Deploy a customized model
211286

212287
When the fine-tune job succeeds, the value of the `fine_tuned_model` variable in the response body is set to the name of your customized model. Your model is now also available for discovery from the [list Models API](/rest/api/azureopenai/models/list). However, you can't issue completion calls to your customized model until your customized model is deployed. You must deploy your customized model to make it available for use with completion calls.

0 commit comments

Comments
 (0)