Compare two fine-tunes
Source on GitHub: the workflows/compare-fine-tunes folder, with its README and its workflow file.
Trains the same model twice on the same data, with two learning rates, as two tasks that run at the same time; scores both fine-tunes on one benchmark; and prints the scores side by side. Swap the learning rates for any other setting in the config the first task writes.
| Step | Task definition | Compute |
|---|---|---|
| Write the two training configs | swaleio/bash | cpu-4 |
| Fine-tune A, and B, in parallel | swaleio/trl-sft | a100-1 each |
| Evaluate A, and B, each as soon as its training ends | swaleio/lm-eval | a100-1 each |
| Read both results and compare them | swaleio/duckdb | cpu-4 |
The Compute column gives each step's compute type, the compute its tasks are allocated.
Every step is its own task. The two branches hold a GPU each while they run.
Inputs
| Input | Default | Description |
|---|---|---|
model | Qwen/Qwen2.5-0.5B-Instruct | Model to fine-tune. |
dataset | HuggingFaceH4/ultrafeedback_binarized | Hugging Face dataset with a messages column. |
split | train_sft[:5000] | Split, or slice of one, to train on. |
learning_rate_a | 1.0e-5 | Learning rate of fine-tune A. |
learning_rate_b | 5.0e-5 | Learning rate of fine-tune B. |
eval_task | gsm8k | The lm-evaluation-harness task both are scored on. |
Training reads the secret hf_token.
Output
The two fine-tuned models in sft-a/ and sft-b/ on the workspace, their
scores in eval-a/ and eval-b/, and a table of every metric of eval_task
for both in the last task's log.
Run it
You need the CLI, logged in to your account, and a project to add the workflow to; Getting started sets them up.
-
Save the file under The workflow file as
workflow.yaml, and add it to a project:swale workflow create --project-name my-project --file workflow.yamlThe command prints
Workflow created:followed by the workflow's ID. -
The workflow reads the secret
hf_token. Create it as a project secret, or as an account secret that allows the project, as Use secrets in workflows shows. -
Start a run with the workflow's ID:
swale workflow run start --project-name my-project --workflow-id <workflow-id>Each input you leave out takes its default from Inputs, and
--input <name>=<value>gives it another value.
Create and manage workflows covers the other ways to add a workflow, Start and manage workflow runs how to follow a run, and View and stream task logs how to read its tasks' logs.
The workflow file
Workflow definition syntax describes each key in it.
name: Compare two fine-tunes
description: Fine-tunes the same model twice with different learning rates, side by side, evaluates both on the same benchmark, and compares their scores.
compute_type: cpu-4
inputs:
model:
description: Hugging Face repo id of the model to fine-tune.
default: Qwen/Qwen2.5-0.5B-Instruct
dataset:
description: Hugging Face dataset with a messages column of chat turns.
default: HuggingFaceH4/ultrafeedback_binarized
split:
description: Split of the dataset to train on.
default: train_sft[:5000]
learning_rate_a:
description: Learning rate of fine-tune A.
default: "1.0e-5"
learning_rate_b:
description: Learning rate of fine-tune B.
default: "5.0e-5"
eval_task:
description: The lm-evaluation-harness task both fine-tunes are scored on.
default: gsm8k
entry_point: main
blocks:
main:
tasks:
write_configs:
name: Write training configs
uses: swaleio/bash
args:
script: |
for run in a b; do
if [ "$run" = a ]; then rate=${{inputs.learning_rate_a}}; else rate=${{inputs.learning_rate_b}}; fi
cat > "$WORKFLOW_STORAGE/sft-$run.yaml" <<EOF
model_name_or_path: ${{inputs.model}}
datasets:
- path: ${{inputs.dataset}}
split: ${{inputs.split}}
columns: [messages]
learning_rate: $rate
num_train_epochs: 1
per_device_train_batch_size: 8
gradient_accumulation_steps: 2
max_length: 1024
bf16: true
seed: 42
report_to: none
save_strategy: "no"
output_dir: $WORKFLOW_STORAGE/sft-$run
EOF
done
train_a:
name: Fine-tune A
uses: swaleio/trl-sft
compute_type: a100-1
start_on:
- write_configs
args:
config: ${{env.WORKFLOW_STORAGE}}/sft-a.yaml
token: ${{secrets.hf_token}}
train_b:
name: Fine-tune B
uses: swaleio/trl-sft
compute_type: a100-1
start_on:
- write_configs
args:
config: ${{env.WORKFLOW_STORAGE}}/sft-b.yaml
token: ${{secrets.hf_token}}
evaluate_a:
name: Evaluate A
uses: swaleio/lm-eval
compute_type: a100-1
start_on:
- train_a
args:
model_dir: ${{env.WORKFLOW_STORAGE}}/sft-a
tasks: ${{inputs.eval_task}}
output_path: ${{env.WORKFLOW_STORAGE}}/eval-a
evaluate_b:
name: Evaluate B
uses: swaleio/lm-eval
compute_type: a100-1
start_on:
- train_b
args:
model_dir: ${{env.WORKFLOW_STORAGE}}/sft-b
tasks: ${{inputs.eval_task}}
output_path: ${{env.WORKFLOW_STORAGE}}/eval-b
compare:
name: Compare
uses: swaleio/duckdb
start_on:
- evaluate_a
- evaluate_b
args:
sql: |
CREATE TABLE scores AS
SELECT CASE WHEN filename LIKE '%/eval-a/%' THEN 'A, learning rate ${{inputs.learning_rate_a}}'
ELSE 'B, learning rate ${{inputs.learning_rate_b}}' END AS fine_tune,
unnest(map_entries(results."${{inputs.eval_task}}"::MAP(VARCHAR, JSON)), recursive := true)
FROM read_json(['${{env.WORKFLOW_STORAGE}}/eval-a/*/results_*.json',
'${{env.WORKFLOW_STORAGE}}/eval-b/*/results_*.json'],
filename = true, columns = {'results': 'JSON'});
PIVOT (SELECT fine_tune, key AS metric, round(value::DOUBLE, 4) AS score
FROM scores WHERE key NOT LIKE '%stderr%' AND try_cast(value AS DOUBLE) IS NOT NULL
AND key <> 'sample_len')
ON fine_tune USING first(score) GROUP BY metric ORDER BY metric;
Licenses of the defaults
- Model: Qwen/Qwen2.5-0.5B-Instruct, Apache-2.0.
- Training data: HuggingFaceH4/ultrafeedback_binarized, MIT.
- Evaluation data: openai/gsm8k, MIT.