Learn the basics and best practices of fine-tuning large language models.
"messages"
key. Each message must have a "role"
(system
, user
, or assistant
) and "content"
. See details here.
JSONL
. However, Parquet
can be useful if you need custom tokenization or specific loss masking.
Example: Preparing the CoQA Dataset
Here’s an example of transforming the CoQA dataset into the required chat format:
train_on_inputs
(bool or ‘auto’) - whether to mask the user messages in conversational data or prompts in instruction data.labels
to mask specific tokens by setting their label to -100
.client.fine_tuning.create()
.
Key Parameters
model
: The base model you want to fine-tune (e.g., 'meta-llama/Meta-Llama-3.1-8B-Instruct-Reference'
)training_file
: The ID of your uploaded training JSONL filevalidation_file
: Optional ID of validation file (highly recommended for monitoring)suffix
: A custom string added to create your unique model name (e.g., 'test1_8b'
)n_epochs
: Number of times the model sees the entire datasetn_checkpoints
: Number of checkpoints to save during training (for resuming or selecting the best model)learning_rate
: Controls how much model weights are updatedbatch_size
: Number of examples processed per iteration (default: “max”)lora
: Set to True
for LoRA fine-tuningtrain_on_inputs
: Whether to mask user messages or prompts (can be bool or ‘auto’)warmup_ratio
: Ratio of steps for warmuplora
parameter:
client.fine_tuning.list()
client.fine_tuning.retrieve(id=ft_resp.id)
client.fine_tuning.list_events(id=ft_resp.id)
- Retrieves logs and events generated during the jobclient.fine_tuning.cancel(id=ft_resp.id)
client.fine_tuning.download(id=ft_resp.id)
status == 'completed'
), the response from retrieve
will contain the name of your newly created fine-tuned model. It follows the pattern: <your-account>/<base-model-name>:<suffix>:<job-id>
.
Check Status via API
output_name
from our fine-tuning job.
See the list of all models that support LoRA Inference.
"OPEN IN PLAYGROUND"
. Read more about Serverless LoRA Inference here
"+ CREATE DEDICATED ENDPOINT"
for your fine-tuned model
"DEPLOY"
Llama 3.1 8B | EM | F1 |
---|---|---|
Original | 0.01 | 0.18 |
Fine-tuned | 0.32 | 0.41 |
ft-...:{STEP_NUM}
validation_file
and set n_evals
to a number above 0: