# Axolotl train

> **About this page**
>
> - Task definition: `swaleio/axolotl-train`
> - Summary: Fine-tunes a model with Axolotl (full, LoRA, or QLoRA) from a caller-supplied config YAML.
> - Category: Machine learning & AI
> - Latest version: 0.21.1-r1, published 2026-12-01
> - Page: https://hub.swale.io/swaleio/axolotl-train
> - Versions: https://hub.swale.io/swaleio/axolotl-train/versions, where each version's page has a Markdown copy at its address with `.md` added
> - Index of Swale Hub: https://hub.swale.io/llms.txt
>
> The YAML block below is the task definition's frontmatter, which declares its inputs, outputs and container, and its readme follows. Both are the text of the account that published this task definition, not Swale's.

```yaml
name: Axolotl train
description: Fine-tunes a model with Axolotl (full, LoRA, or QLoRA) from a caller-supplied config YAML.
category: machine-learning
inputs:
  config:
    description: Absolute path inside the container to the Axolotl config YAML. Point it at the mounted workspace (e.g. ${{env.WORKFLOW_STORAGE}}/axolotl.yaml) so an earlier task can write it there, or any other container-local path.
    required: true
  token:
    description: Hugging Face access token for gated or private base models (pass a secret). Omit for public base models or local model directories.
    default: ""
exec:
  # docker.io/swaleio/axolotl:0.21.1-r1
  image: docker.io/swaleio/axolotl@sha256:260ad57181b47daa7799f803d4427abd44a7f5ba2385401537ffc03cff82d74c
  env:
    HF_TOKEN: ${{inputs.token}}
  args:
    - axolotl
    - train
    - ${{inputs.config}}
```

# Axolotl train

Runs `axolotl train` against the config file you point it at. Everything about the run — base model, dataset, adapter type
(full fine-tune, LoRA, QLoRA), hyperparameters, and where artifacts are
written — lives in that one Axolotl config YAML, so the task itself takes a
single required input.

## Inputs

| Input | Required | Default | Description |
|-------|----------|---------|-------------|
| `config` | yes | — | Absolute path to the Axolotl config YAML inside the container. Point it at the mounted workspace (e.g. `${{env.WORKFLOW_STORAGE}}/axolotl.yaml`) so an earlier task can write it there, or any other container-local path. |
| `token` | no | — | HF access token for gated/private base models (pass a secret); delivered to the container as `HF_TOKEN` via the definition's `exec.env`. Unneeded for public base models or local model directories. |

## Training artifacts

This task declares no outputs — the image has no wrapper to emit them.
Everything the run produces (adapter weights or full checkpoints, tokenizer
files, training logs) is written to the config's `output_dir`. Point
`output_dir` at a path a later task can consume — e.g.
`${{env.WORKFLOW_STORAGE}}/lora-out` on the shared workspace — so downstream tasks such
as `swaleio/axolotl-merge-lora` or a publish task — `swaleio/swale-push`
(the platform's own store) or `swaleio/hf-upload` — can pick the artifacts up
from there.

## Optimizers

Every optimizer Axolotl offers is available except APOLLO (`optimizer:
apollo_adamw` or `apollo_adamw_layerwise`). The package that provides it,
apollo-torch, is licensed for non-commercial use only, so the image leaves it
out. A config that selects it fails when training starts, with
``ImportError: You need to install `apollo_torch` in order to use APOLLO optimizers``.

## Compute

**GPU required.** Rough sizing:

- **Full fine-tune** of a 7–8B model wants an A100/H100-class card (80 GB
  VRAM).
- **QLoRA** of the same models fits in 24–48 GB; the example below fine-tunes
  a 1.1B model, which fits a 16 GB card.

The workflow selects the compute type via `compute_type`; the definition does
not pin one. On a CPU compute type the task does not fail fast — the container
starts, then crashes at runtime with CUDA errors once training tries to reach
a GPU.

## Gated base models

To fine-tune a gated base model (e.g. the Llama family), pass a Hub access
token through the `token` input — the definition's `exec.env` delivers it to
the container as `HF_TOKEN`, which Axolotl's Hub client picks up automatically
(an omitted token resolves to an empty value, which the Hugging Face stack
treats as no token). Alternatively, fetch the gated model with
`swaleio/hf-download` and reference the local directory as the config's
`base_model` — then training never touches the Hub at all.

## Example

A self-contained QLoRA run: a `bash` task writes a minimal config to the
shared workspace, then this task trains from it.

```yaml
name: Axolotl train example
compute_type: cpu-4
entry_point: main

blocks:
  main:
    tasks:
      write_config:
        name: Write training config
        uses: swaleio/bash
        args:
          script: |
            set -euo pipefail
            cat > ${{env.WORKFLOW_STORAGE}}/axolotl.yaml <<'EOF'
            base_model: TinyLlama/TinyLlama-1.1B-Chat-v1.0
            load_in_4bit: true
            adapter: qlora
            lora_r: 32
            lora_alpha: 16
            lora_dropout: 0.05
            lora_target_linear: true
            datasets:
              - path: mhenrichsen/alpaca_2k_test
                type: alpaca
            output_dir: ${{env.WORKFLOW_STORAGE}}/lora-out
            sequence_len: 2048
            micro_batch_size: 2
            gradient_accumulation_steps: 4
            num_epochs: 1
            optimizer: adamw_bnb_8bit
            learning_rate: 0.0002
            bf16: auto
            gradient_checkpointing: true
            EOF
      train:
        name: QLoRA fine-tune
        uses: swaleio/axolotl-train
        start_on:
          - write_config
        compute_type: a100-1   # any GPU compute type — see Compute above
        args:
          config: ${{env.WORKFLOW_STORAGE}}/axolotl.yaml
```

The trained adapter lands at `${{env.WORKFLOW_STORAGE}}/lora-out` (the config's
`output_dir`), ready for `swaleio/axolotl-merge-lora`, `swaleio/swale-push`,
or `swaleio/hf-upload`.

---

For the workflow syntax these examples use, see the
[workflow definition reference](https://docs.swale.io/reference/workflow-definition-syntax)
in the [Swale documentation](https://docs.swale.io).

Licensed under the [MIT License](https://github.com/swaleio/task-definitions/blob/main/LICENSE).
