OpenAI:流中断(客户端断开连接)



我正在尝试OpenAI。

我准备了训练数据,使用fine_tunes.create。几分钟后,显示Stream interrupted (client disconnected)

$ openai api fine_tunes.create -t data_prepared.jsonl
Upload progress: 100%|██████████████████████████████████████████████| 47.2k/47.2k [00:00<00:00, 44.3Mit/s]
Uploaded file from data_prepared.jsonl: file-r6dbTH7rVsp6jJMgbX0L0bZx
Created fine-tune: ft-JRGzkYfXm7wnScUxRSBA2M2h
Streaming events until fine-tuning is complete...
(Ctrl-C will interrupt the stream, but not cancel the fine-tune)
[2022-12-02 11:10:08] Created fine-tune: ft-JRGzkYfXm7wnScUxRSBA2M2h
[2022-12-02 11:10:23] Fine-tune costs $0.06
[2022-12-02 11:10:24] Fine-tune enqueued. Queue number: 11
Stream interrupted (client disconnected).
To resume the stream, run:
openai api fine_tunes.follow -i ft-JRGzkYfXm7wnScUxRSBA2M2h

我尝试了fine_tunes.follow,几分钟后,它仍然失败:

$ openai api fine_tunes.follow -i ft-JRGzkYfXm7wnScUxRSBA2M2h
[2022-12-02 11:10:08] Created fine-tune: ft-JRGzkYfXm7wnScUxRSBA2M2h
[2022-12-02 11:10:23] Fine-tune costs $0.06
[2022-12-02 11:10:24] Fine-tune enqueued. Queue number: 11
Stream interrupted (client disconnected).
To resume the stream, run:
openai api fine_tunes.follow -i ft-JRGzkYfXm7wnScUxRSBA2M2h

openai api fine_tunes.list显示:

$ openai api fine_tunes.list
{
"data": [
{
"created_at": 1669975808,
"fine_tuned_model": null,
"hyperparams": {
"batch_size": 2,
"learning_rate_multiplier": 0.1,
"n_epochs": 4,
"prompt_loss_weight": 0.01
},
"id": "ft-JRGzkYfXm7wnScUxRSBA2M2h",
"model": "curie",
"object": "fine-tune",
"organization_id": "org-YyoQqNIrjGHYDnKt9t3T6x2J",
"result_files": [],
"status": "pending",
"training_files": [
{
"bytes": 47174,
"created_at": 1669975808,
"filename": "data_prepared.jsonl",
"id": "file-r6dbTH7rVsp6jJMgbX0L0bZx",
"object": "file",
"purpose": "fine-tune",
"status": "processed",
"status_details": null
}
],
"updated_at": 1669975824,
"validation_files": []
}
],
"object": "list"
}

$ openai api completions.create -m ft-JRGzkYfXm7wnScUxRSBA2M2h -p aprompt返回Error: That model does not exist (HTTP status code: 404)

有人能帮忙吗?

显然,OpenAI API有一个问题。(参见:这个reddit帖子和Git上的这个问题)我通过运行
pip install openai==0.25.0
将我的版本降级到v.0.25,这为我修复了它。不过,公平地说,您可以期望在将来解决这个问题。

这是OpenAI的一个临时问题,团队修复了这个问题。

好消息是,流中断只是阻止您查看进度,而不是实际的微调。您的任务已经在队列中。

坏消息是你永远不知道要花多长时间。根据https://platform.openai.com/docs/guides/fine-tuning

流事件直到任务完成(这通常需要几分钟,但是如果队列中有很多作业,或者您的数据集是大)

您可以使用以下命令定期检查作业的状态:

openai api fine_tunes.list

更多信息:https://community.openai.com/t/stream-interrupted-client-disconnected-during-fine-tunes-follow/70334/20

我收到了相同的错误,并最终创建了一个python程序来监视进度,而无需手动运行命令。只需更改ID,您就可以开始了。

import subprocess
import time
import threading
import json
import requests
class FineTuneMonitor:
def __init__(self):
self.cmd1 = "openai api fine_tunes.follow -i ft-YOUR_ID_TO_MONITOR"
self.cmd2 = "openai api fine_tunes.list"
self.id = "**YOUR_ID_TO_MONITOR**"  # Set the ID of your fine-tune process
self.process = None
self.success = False
def run_command(self):
self.process = subprocess.Popen(self.cmd1, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
while True:
output = self.process.stdout.readline().decode()
print(output.strip())
if self.process.poll() is not None:
break
if 'Stream interrupted' in output:
self.process.kill()
return False
return True
def monitor_status(self):
while True:
output = subprocess.check_output(self.cmd2, shell=True).decode()
data = json.loads(output)
status = next((item["status"] for item in data["data"] if item["id"] == self.id), None)
if status is None:
print("Could not find status for the given ID.")
return
print(f"Status: {status}")
if status != "pending":
if self.process is not None:
self.process.kill()
self.success = True
return
time.sleep(10)
def start(self):
threading.Thread(target=self.monitor_status).start()
while not self.success:
self.run_command()
print("Stream was interrupted, retrying in 10 seconds...")
time.sleep(10)
monitor = FineTuneMonitor()
monitor.start()

这个脚本创建了一个FineTuneMonitor类,它封装了运行和监控OpenAI命令的逻辑。start方法在一个新线程中启动状态监视,然后重复运行第一个命令,直到它成功完成。monitor_status方法每10秒运行第二个命令,如果状态从"pending"变为"pending",则杀死第一个命令的进程。

取代自己。id与您的微调过程id。脚本假定状态位于data ->第二个命令输出的状态。如果输出的结构发生了变化,则需要相应地更新脚本。

我一直在破坏这个命令:Openai API fine_tunes。

直到它得到队列号

最新更新