Fine-tuning models via API
Introduction
This guide walks you through the process of fine-tuning a model using the Fireworks REST API.
For an overview of fine-tuning see https://docs.fireworks.ai/fine-tuning/fine-tuning-models
Prepare the dataset
Create your dataset file in JSONL format. Each line should be a valid JSON object containing your training examples.
Create a dataset record
- Endpoint: POST /v1/accounts/{account_id}/datasets
- Request Body:
- Curl Example:
This will create a record with a dataset id you can use to upload the file.
Upload your dataset file
Option 1 - Upload your dataset file directly (recommended for files < 150MB)
A streamlined file upload API is available for file sizes less than 150 MB.
- Endpoint: POST /v1/accounts/{account_id}/datasets/{dataset_id}:upload
- Curl Example:
Post the file using the multipart/form-data format.
After this step you can skip to Check the dataset state
Option 2 - Upload your file using the signed upload URL (recommended for files > 150MB)
Alternatively, for larger files, get the signed URL for uploading your file directly to cloud storage.
-
Endpoint: POST /v1/accounts/{account_id}/datasets/{dataset_id}:getUploadEndpoint
-
Request Body:
-
Curl Example:
You can use jq to directly extract the signed URL:
The response will contain a signed URL that looks similar to this:
Upload your dataset ( Option 2 continued )
Use the following curl command to upload your file:
Validate the dataset upload ( Option 2 continued )
- Endpoint: POST /v1/accounts/{account_id}/datasets/{dataset_id}:validateUpload
- Curl Example:
Calling validate will finalize the dataset upload.
Check the dataset state
- Endpoint: GET /v1/accounts/{account_id}/datasets/{dataset_id}
- Curl Example:
After successful creation and upload, the API will set the dataset state to READY
Create a fine-tuning job
After uploading your dataset, create a fine-tuning job using the following command:
- Endpoint: POST /v1/accounts/{account_id}/fineTuningJobs
- Request Body:
- Curl Example:
Adjust the input_template
and output_template
fields as needed to match your dataset format.
By default, the fine-tuning job will generate a random unique ID for the model. This ID is used to refer to the model at inference time. You can optionally choose a custom model_id
.
Get the job status
- Endpoint: GET /v1/accounts/{account_id}/fineTuningJobs/{fine_tuning_job_id}
- Curl Example:
The job should now have state PENDING or RUNNING.
Deleting a job
- Endpoint: DELETE /v1/accounts/{account_id}/fineTuningJobs/
- Curl Example:
Downloading model weights
After your fine-tuning job is complete, a model will be created in your account. You can download the model weights using the following steps.
If you specified a model_id when creating the fine-tuning job, you can get the model weights directly.
You can see a list of models by running.
- Endpoint: GET /v1/accounts/{account_id}/models/
Use the model_id to get the signed URLs for downloading the model files.
- Endpoint: GET /v1/accounts/{account_id}/models/{model_id}:getDownloadEndpoint
- Curl Example:
The response will contain a map of filenames to signed URLs for downloading each file.
For each file in the response, use the provided signed URL to download the file.
- Curl Example:
Was this page helpful?