Skip to main content

Fine-Tune using OpenAI SDK

ScaleGenAI provides OpenAI SDK compatibility, which implies you can fine-tune models using ScaleGenAI in the same way you would using OpenAI GPT models, by simply swapping the base URL.

The OpenAI SDK has the following methods.

FunctionDescription
createCreate a new fine-tuning task.
getGet fine-tuning job info.
finishFinish a running fine-tuning task.
cancelCancel a running fine-tuning task.

Create Fine-Tuning Job

Endpoint: /openai/v1/fine_tuning/jobs

Description

This method is used to create a new finetuning task.

Request

  • Method: POST
  • Headers:
    • Content-Type: application/json
  • Body:
    {
    "model": "string",
    "training_file": "string",
    "hyperparameters": {
    "batch_size": "auto",
    "learning_rate_multiplier": "auto",
    "n_epochs": "auto"
    },
    "suffix": "",
    "validation_file": "string"
    }

Parameter Description

  • model :: string : The name of the model to be used for finetuning.
  • training_file :: string : The ID of an uploaded file that contains training data.
  • **hyperparameters ** [optional] :: dict : Hyperparameter configuration for the finetuning job.
  • validation_file :: string : The ID of an uploaded file that contains validation data.

Response

Code: 200

{
"id": "string",
"created_at": 0,
"error": {
"code": "string",
"message": "string",
"param": "string"
},
"fine_tuned_model": "string",
"finished_at": 0,
"hyperparameters": {
"batch_size": "auto",
"learning_rate_multiplier": "auto",
"n_epochs": "auto"
},
"model": "string",
"object": "fine_tuning.job",
"organization_id": "scaletorch",
"result_files": [],
"status": "validating_files",
"trained_tokens": 0,
"training_file": "string",
"validation_file": "string"
}

Example

curl -X POST \
-H "Content-Type: application/json" \
-d '{
"model": "meta-llama/Llama-3-70b",
"training_file": "fileid01",
}' \
https://api.example.com/openai/v1/fine_tuning/jobs

Get Fine-Tuning Job

Endpoint: /openai/v1/fine_tuning/jobs/{fine_tuning_job_id}

Description

This method is used to get information regarding a fine-tuning task.

Request

  • Method: GET
  • Headers:
    • Content-Type: application/json

Parameter Description

  • fine_tuning_job_id :: string : The job ID associated with the fine-tuning job.

Response

Code: 200

{
"id": "string",
"created_at": 0,
"error": {
"code": "string",
"message": "string",
"param": "string"
},
"fine_tuned_model": "string",
"finished_at": 0,
"hyperparameters": {
"batch_size": "auto",
"learning_rate_multiplier": "auto",
"n_epochs": "auto"
},
"model": "string",
"object": "fine_tuning.job",
"organization_id": "scaletorch",
"result_files": [],
"status": "validating_files",
"trained_tokens": 0,
"training_file": "string",
"validation_file": "string"
}

Example

curl -X GET \
-H "Content-Type: application/json" \
https://api.example.com//openai/v1/fine_tuning/jobs/test_job_id

Finish Fine-Tuning Job

Endpoint: /openai/v1/fine_tuning/jobs/{fine_tuning_job_id}

Description

This method is used to finish a running fine-tuning task.

Request

  • Method: POST
  • Headers:
    • Content-Type: application/json
  • Body:
    {
    "result_model": "string",
    "result_files": [],
    "trained_tokens": 0
    }

Parameter Description

  • fine_tuning_job_id:: string : The job ID associated with the fine-tuning job.
  • result_model [optional] :: string : An openai file with resulting lora weights after finetuning.
  • result_files:: list[string] : Other resulting files, like logs.
  • fine_tuning_job_id [optional] :: int : Number of total consumed tokens.

Response

{
"success": true,
"message": "string"
}

Example

curl -X POST \
-H "Content-Type: application/json" \
-d '{
"result_files": ["fileid01"]
}' \
https://api.example.com/openai/v1/fine_tuning/jobs/test_job_id

Cancel Fine-Tuning Job

Endpoint: /openai/v1/fine_tuning/jobs/{fine_tuning_job_id}/cancel

Description

This method cancel/stop a running fine-tuning task.

Request

  • Method: POST
  • Headers:
    • Content-Type: application/json

Parameter Description

  • fine_tuning_job_id :: string : The job ID associated with the fine-tuning job.

Response

Code: 200

{
"id": "string",
"created_at": 0,
"error": {
"code": "string",
"message": "string",
"param": "string"
},
"fine_tuned_model": "string",
"finished_at": 0,
"hyperparameters": {
"batch_size": "auto",
"learning_rate_multiplier": "auto",
"n_epochs": "auto"
},
"model": "string",
"object": "fine_tuning.job",
"organization_id": "scaletorch",
"result_files": [],
"status": "validating_files",
"trained_tokens": 0,
"training_file": "string",
"validation_file": "string"
}

Example

curl -X POST \
-H "Content-Type: application/json" \
https://api.example.com//openai/v1/fine_tuning/jobs/test_job_id/cancel