OpenAI fine-tune with python return null model

Question:

I am trying to get fine-tune model from OpenAI GPT-3 using python with following code

#upload training data

upload_response = openai.File.create(
  file=open(file_name, "rb"),
  purpose='fine-tune'
)
file_id = upload_response.id
print(f'nupload training data respond:nn {upload_response}')

OpenAI respond with data

 {
  "bytes": 380,
  "created_at": 1675789714,
  "filename": "file",
  "id": "file-lKSQushd8eABcfiBVwhxBMOJ",
  "object": "file",
  "purpose": "fine-tune",
  "status": "uploaded",
  "status_details": null
}

My training file has been uploaded so I am checking for fine-tune response with code

fine_tune_response = openai.FineTune.create(training_file=file_id)
print(f'nfine-tune respond:nn {fine_tune_response}')

I am getting

 {
  "created_at": 1675789714,
  "events": [
    {
      "created_at": 1675789715,
      "level": "info",
      "message": "Created fine-tune: ft-IqBdk4WJETm4KakIzfZeCHgS",
      "object": "fine-tune-event"
    }
  ],
  "fine_tuned_model": null,
  "hyperparams": {
    "batch_size": null,
    "learning_rate_multiplier": null,
    "n_epochs": 4,
    "prompt_loss_weight": 0.01
  },
  "id": "ft-IqBdk4WJETm4KakIzfZeCHgS",
  "model": "curie",
  "object": "fine-tune",
  "organization_id": "org-R6DqvjTNimKtBzWWgae6VmAy",
  "result_files": [],
  "status": "pending",
  "training_files": [
    {
      "bytes": 380,
      "created_at": 1675789714,
      "filename": "file",
      "id": "file-lKSQushd8eABcfiBVwhxBMOJ",
      "object": "file",
      "purpose": "fine-tune",
      "status": "uploaded",
      "status_details": null
    }
  ],
  "updated_at": 1675789714,
  "validation_files": []
}

As you see, the fine_tune_model is null so I cant use it for Completion.
My question is how to check for example in While loop if my fine-tune is complete using ft id

Asked By: Martin

||

Answers:

Here is data from the OpenAI documentation on fine-tuning:

After you’ve started a fine-tune job, it may take some time to complete. Your job may be queued behind other jobs on our system, and training our model can take minutes or hours depending on the model and dataset size.

Ref: https://platform.openai.com/docs/guides/fine-tuning

The OpenAI guide uses the CLI tool to create the fine-tuning and then accesses the model programatically once the training has completed.

Therefore, you couldn’t run the code in Python as you have laid it out, since you need to wait for the training to complete. Meaning you can’t train the model on the fly and use it instantly.

Answered By: Kane Hooper

Here is a code to wait until your model is trained with updates:

print("Started Training ...")
id = fine_tune_response.id
while True:
    cmd = "openai -k " + api_key + " api fine_tunes.get -i " + id
    result = subprocess.run(cmd, stdout=subprocess.PIPE, shell=True)
    if ""status": "succeeded"" in str(result.stdout):
        print("Succeeded")
        break
    if result.stderr !="" or ""status": "failed"" in str(result.stdout):
        print("Error or failed job!")
        break
    time.sleep(20)
    print("Still training ...")
print("Done Training")
Answered By: Anton Andreev
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.