Skip to main content

Create a Fine-tuned Model

Once you've prepared your dataset and designed your prompt template, you are ready to kickoff your fine-tuning job. You can start fine-tuning via the UI or via one of our programmatic interfaces.

Fine-Tuning with Defaults

To start fine-tuning using the Predibase SDK or CLI with default parameters:

# Specify the llm to fine-tune using a Huggingface URI which includes the organization and model name
llm = pc.LLM("hf://meta-llama/Llama-2-7b-hf")

# Start your fine-tuning job async
job = llm.finetune(
prompt_template=prompt_template,
target="output", # The column that the model should learn to generate.
dataset="file_uploads/code_alpaca_800",
)

# Wait for model training to complete
model = job.get()

Customize Fine-Tuning Parameters

If you would like to customize additional parameters, you have two options:

Option 1: Set commonly used parameters in the llm.finetune function call

Epochs, learning rate, rank, and train steps can be set in-line.

job = llm.finetune(
prompt_template=prompt_template,
target="output", # The column that the model should learn to generate.
dataset="file_uploads/code_alpaca_800",
epochs=5,
# train_steps=10000, # An alternative to epochs for specifying a training runway.
learning_rate=0.0002,
lora_rank=16,
)

# Wait for model training to complete
model = job.get()

Option 2: Modify the underlying config for more advanced parameters

If you're looking to modify other config parameters not listed above, you can modify the underlying Ludwig configuration via templates.

Warning

While we provide a method for you to modify Ludwig configs directly in Predibase, please note that customizing the config may cause your model not to train properly.

# Get the set of fine-tuning template for base LLM
llm = pc.LLM("hf://meta-llama/Llama-2-7b-hf")
tmpls = llm.get_finetune_templates()

# Get the config
cfg = tmpls["qlora_4bit"].to_config(prompt_template="{instruction}", target="response")

# Change speciic parameters
cfg["adapter"]["r"] = 8
cfg["adapter"]["dropout"] = 0.1
cfg["adapter"]["alpha"] = 16

cfg["trainer"]["batch_size"] = 1

ft_job = llm.finetune(
repo="my-finetuned-model",
dataset=dataset,
config=cfg,
epochs=1
)
note

In-line arguments (Option 1) take precedence over config values (Option 2).

Job visibility

After you've started a fine-tuning job, your model will be in a queued state until the necessary resources are available. The actual training time for a model will typically vary depending on parameters including model, dataset size, and epochs.