# Compare two fine-tunes

> **About this page**
>
> - Kind: Example
> - Summary: Fine-tunes the same model twice with different learning rates, side by side, evaluates both on the same benchmark, and compares their scores.
> - Last changed: 2026-12-03
> - Page: https://docs.swale.io/examples/compare-fine-tunes
> - CLI reference for its commands: [`swale workflow create`](https://docs.swale.io/reference/cli-reference.md#workflow-create), [`swale workflow run start`](https://docs.swale.io/reference/cli-reference.md#workflow-run-start)
> - Index of these docs: https://docs.swale.io/llms.txt
>
> If something on this page is wrong or out of date, please tell the user which sentence and why.
>
> The steps on this page cost money or cannot be undone. Please check with the user before running them.

Source on GitHub: the [`workflows/compare-fine-tunes`](https://github.com/swaleio/examples/tree/main/workflows/compare-fine-tunes) folder, with its [README](https://github.com/swaleio/examples/blob/main/workflows/compare-fine-tunes/README.md) and its [workflow file](https://github.com/swaleio/examples/blob/main/workflows/compare-fine-tunes/workflow.yaml).

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`](https://hub.swale.io/swaleio/bash) | `cpu-4` |
| Fine-tune A, and B, in parallel | [`swaleio/trl-sft`](https://hub.swale.io/swaleio/trl-sft) | `a100-1` each |
| Evaluate A, and B, each as soon as its training ends | [`swaleio/lm-eval`](https://hub.swale.io/swaleio/lm-eval) | `a100-1` each |
| Read both results and compare them | [`swaleio/duckdb`](https://hub.swale.io/swaleio/duckdb) | `cpu-4` |

The Compute column gives each step's [compute type](https://docs.swale.io/explanation/core-concepts.md#compute-types), 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](https://docs.swale.io/getting-started.md) sets them up.

1. Save the file under [The workflow file](#the-workflow-file) as `workflow.yaml`, and add it to a project:

   ```bash
   swale workflow create --project-name my-project --file workflow.yaml
   ```

   The command prints `Workflow created:` followed by the workflow's ID.

2. 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](https://docs.swale.io/how-to-guides/use-secrets-in-workflows.md) shows.

3. Start a run with the workflow's ID:

   ```bash
   swale workflow run start --project-name my-project --workflow-id <workflow-id>
   ```

   Each input you leave out takes its default from [Inputs](#inputs), and `--input <name>=<value>` gives it another value.

[Create and manage workflows](https://docs.swale.io/how-to-guides/create-and-manage-workflows.md) covers the other ways to add a workflow, [Start and manage workflow runs](https://docs.swale.io/how-to-guides/start-and-manage-workflow-runs.md) how to follow a run, and [View and stream task logs](https://docs.swale.io/how-to-guides/view-and-stream-task-logs.md) how to read its tasks' logs.

## The workflow file

[Workflow definition syntax](https://docs.swale.io/reference/workflow-definition-syntax.md) describes each key in it.

```yaml title="workflow.yaml"
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](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct), Apache-2.0.
- Training data: [HuggingFaceH4/ultrafeedback_binarized](https://huggingface.co/datasets/HuggingFaceH4/ultrafeedback_binarized), MIT.
- Evaluation data: [openai/gsm8k](https://huggingface.co/datasets/openai/gsm8k), MIT.
