gpt4 book ai didi

python - 微调 Azure OpenAI 模型时出现 openai.error.InvalidRequestError : The specified base model does not support fine-tuning.

转载 作者:行者123 更新时间:2023-12-03 06:08:17 25 4
gpt4 key购买 nike

我正在运行以下 Python 代码来微调 OpenAI 任务:

import openai
from openai import cli
import time
import shutil
import json


openai.api_key = "*********************"
openai.api_base = "https://*********************"
openai.api_type = 'azure'
openai.api_version = '2023-05-15'
deployment_name ='*********************'


training_file_name = 'training.jsonl'
validation_file_name = 'validation.jsonl'

# Samples data are fake
sample_data = [
{"prompt": "Questa parte del testo e’ invece in italiano, perche’ Giuseppe Coco vive a Milano, codice postale 09576.", "completion": "[type: LOCATION, start: 36, end: 44, score: 0.85, type: PERSON, start: 54, end: 72, score: 0.85, type: LOCATION, start: 75, end: 81, score: 0.85]"},
{"prompt": "In this fake document, we describe the ambarabacicicoco, of Alfred Johnson, who lives in Paris (France), the zip code is 21076, and his phone number is +32 475348723.", "completion": "[type: AU_TFN, start: 157, end: 166, score: 1.0, type: PERSON, start: 60, end: 74, score: 0.85, type: LOCATION, start: 89, end: 94, score: 0.85, type: LOCATION, start: 97, end: 103, score: 0.85, type: PHONE_NUMBER, start: 153, end: 166, score: 0.75]"},
{"prompt": "This document is a fac simile", "completion": "[]"},
{"prompt": "Here there are no PIIs", "completion": "[]"},
{"prompt": "Questa parte del testo e’ invece in italiano, perche’ Giuseppe Coco vive a Milano, codice postale 09576.", "completion": "[type: LOCATION, start: 36, end: 44, score: 0.85, type: PERSON, start: 54, end: 72, score: 0.85, type: LOCATION, start: 75, end: 81, score: 0.85]"},
{"prompt": "In this fake document, we describe the ambarabacicicoco, of Alfred Johnson, who lives in Paris (France), the zip code is 21076, and his phone number is +32 475348723.", "completion": "[type: AU_TFN, start: 157, end: 166, score: 1.0, type: PERSON, start: 60, end: 74, score: 0.85, type: LOCATION, start: 89, end: 94, score: 0.85, type: LOCATION, start: 97, end: 103, score: 0.85, type: PHONE_NUMBER, start: 153, end: 166, score: 0.75]"},
{"prompt": "This document is a fac simile", "completion": "[]"},
{"prompt": "Here there are no PIIs", "completion": "[]"},
{"prompt": "10 August 2023", "completion": "[type: DATE_TIME, start: 0, end: 14, score: 0.85]"},
{"prompt": "Marijn De Belie, Manu Brehmen (Deloitte Belastingconsulenten)", "completion": "[type: PERSON, start: 0, end: 15, score: 0.85, type: PERSON, start: 17, end: 29, score: 0.85]"},
{"prompt": "The content expressed herein is based on the facts and assumptions you have provided us. We have assumed that these facts and assumptions are correct, complete and accurate.", "completion": "[]"},
{"prompt": "This letter is solely for your benefit and may not be relied upon by anyone other than you.", "completion": "[]"},
{"prompt": "Dear Mr. Mahieu,", "completion": "[type: PERSON, start: 9, end: 15, score: 0.85]"},
{"prompt": "Since 1 January 2018, a capital reduction carried out in accordance with company law rules is partly imputed on the taxable reserves of the SPV", "completion": "[type: DATE_TIME, start: 6, end: 20, score: 0.85]"},
]

# Generate the training dataset file.
print(f'Generating the training file: {training_file_name}')
with open(training_file_name, 'w') as training_file:
for entry in sample_data:
json.dump(entry, training_file)
training_file.write('\n')

# Copy the validation dataset file from the training dataset file.
# Typically, your training data and validation data should be mutually exclusive.
# For the purposes of this example, you use the same data.
print(f'Copying the training file to the validation file')
shutil.copy(training_file_name, validation_file_name)

def check_status(training_id, validation_id):
train_status = openai.File.retrieve(training_id)["status"]
valid_status = openai.File.retrieve(validation_id)["status"]
print(f'Status (training_file | validation_file): {train_status} | {valid_status}')
return (train_status, valid_status)

# Upload the training and validation dataset files to Azure OpenAI.
training_id = cli.FineTune._get_or_upload(training_file_name, True)
validation_id = cli.FineTune._get_or_upload(validation_file_name, True)

# Check the upload status of the training and validation dataset files.
(train_status, valid_status) = check_status(training_id, validation_id)

# Poll and display the upload status once per second until both files succeed or fail to upload.
while train_status not in ["succeeded", "failed"] or valid_status not in ["succeeded", "failed"]:
time.sleep(1)
(train_status, valid_status) = check_status(training_id, validation_id)

# This example defines a fine-tune job that creates a customized model based on curie,
# with just a single pass through the training data. The job also provides
# classification-specific metrics by using our validation data, at the end of that epoch.
create_args = {
"training_file": training_id,
"validation_file": validation_id,
"model": "curie",
"n_epochs": 1,
"compute_classification_metrics": True,
"classification_n_classes": 3
}

# Create the fine-tune job and retrieve the job ID and status from the response.
resp = openai.FineTune.create(**create_args)
job_id = resp["id"]
status = resp["status"]

# You can use the job ID to monitor the status of the fine-tune job.
# The fine-tune job might take some time to start and complete.
print(f'Fine-tuning model with job ID: {job_id}.')

# Get the status of our fine-tune job.
status = openai.FineTune.retrieve(id=job_id)["status"]

# If the job isn't yet done, poll it every 2 seconds.
if status not in ["succeeded", "failed"]:
print(f'Job not in terminal status: {status}. Waiting.')
while status not in ["succeeded", "failed"]:
time.sleep(2)
status = openai.FineTune.retrieve(id=job_id)["status"]
print(f'Status: {status}')
else:
print(f'Fine-tune job {job_id} finished with status: {status}')

# Check if there are other fine-tune jobs in the subscription.
# Your fine-tune job might be queued, so this is helpful information to have
# if your fine-tune job hasn't yet started.
print('Checking other fine-tune jobs in the subscription.')
result = openai.FineTune.list()
print(f'Found {len(result)} fine-tune jobs.')

# Retrieve the name of the customized model from the fine-tune job.
result = openai.FineTune.retrieve(id=job_id)
if result["status"] == 'succeeded':
model = result["fine_tuned_model"]

# Create the deployment for the customized model by using the standard scale type
# without specifying a scale capacity.
print(f'Creating a new deployment with model: {model}')
result = openai.Deployment.create(model=model, scale_settings={"scale_type":"standard", "capacity": None})

# Retrieve the deployment job ID from the results.
deployment_id = result["id"]

基于此微软官方文档: Microsoft documentation for OpenAI fine-tuning

现在,当我运行此脚本时,出现以下错误:

openai.error.InvalidRequestError: The specified base model does not support fine-tuning.

基于类似的问题( similar question ),似乎问题与我的 OpenAI 服务部署的区域有关,实际上我的 OpenAI 服务部署在美国东部,据我了解,唯一的可进行微调的区域是美国中部。问题是我不认为美国中部是部署 OpenAI 服务的可用区域:

regions available for OpenAI deployment

请注意,我也尝试了“美国中北部”,并得到了相同的错误。

你知道这个错误的原因是什么吗?

最佳答案

openai.error.InvalidRequestError: The specified base model does not support fine-tuning.

根据MS-Q&A作者:AshokPeddakotla-MSFT,

  • 微调功能目前不适用于新客户,因为微调功能已在所有区域关闭。不幸的是,当微调再次开放时,他们目前没有任何预计到达时间。
  • 如果您之前已在某个区域进行过微调和部署,那么您可以在该区域(如果可用)中进行微调。

目前微调只能部署在美国中南部位置。

我有一个旧订阅,在美国中南部位置创建了 Azure 开放 AI 服务。

门户: enter image description here

现在,我尝试使用您的相同代码并且部署成功。

控制台:

enter image description here

门户:

enter image description here

但截至目前,新客户无法部署基于微调的模型。

引用:

Azure OpenAI Service models - Azure OpenAI | Microsoft Learn

关于python - 微调 Azure OpenAI 模型时出现 openai.error.InvalidRequestError : The specified base model does not support fine-tuning.,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77083082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com