Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
36 changes: 36 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Check workflows

# Checks every example workflow against the task definitions on the catalog's
# main branch: keys, compute types, the inputs each task passes, and that every
# script compiles.

on:
pull_request:
push:
branches: [main]

permissions:
contents: read

jobs:
check:
name: Check workflows against the catalog
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Check out the task-definition catalog
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
repository: swaleio/task-definitions
path: catalog

- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.13"

- name: Install the checker's dependencies
run: python -m pip install -r tools/requirements.txt

- name: Check workflows
run: python tools/check_workflows.py --catalog catalog
135 changes: 133 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,133 @@
# examples
Swale's example workflow definitions
# Swale example workflows

Ready-to-run [Swale](https://swale.io) workflows for the jobs machine-learning
teams run over and over: batch inference and labelling with an LLM, building
datasets from documents, images and audio, fine-tuning and aligning models,
evaluating, merging, quantizing and serving them. Each workflow is a YAML file
built from the task definitions published by `swaleio` on Swale Hub, and splits
its job into separate tasks, so a run's graph shows each step, its logs and its
outputs, and only the steps that need a GPU hold one.

Some workflows also run short Python scripts kept next to them in this
repository. Those workflows clone this repository at the branch, tag or full
commit SHA their `examples_ref` input names, `main` by default; pin a commit's
full SHA to keep a workflow's scripts fixed.

## Running a workflow

1. Clone this repository, or download a workflow's `workflow.yaml`, and add it
to a project with the CLI or with **Add Workflow → Upload File** in the app:

```sh
swale workflow create --project-name my-project --file workflows/generate-responses/workflow.yaml
```

**Import from GitHub** reads only repositories on GitHub accounts that the
Swale GitHub App is installed on and that your GitHub user can access, so it
cannot read this repository. To import a workflow from GitHub instead, fork
this repository to such an account and import it from your fork.

2. Workflows that download gated models or upload to the Hugging Face Hub read
a secret named `hf_token`; uploading needs a token with write access. Every
upload step runs only when its `hub_repo` input is set.

3. Start a run, overriding any input:

```sh
swale workflow run start --project-name my-project --workflow-id <id> --input limit=50
```

The [Swale documentation](https://docs.swale.io) covers workflows, task
definitions and compute types.

## Layout

```
workflows/<name>/workflow.yaml the workflow
workflows/<name>/README.md what it does, its steps, inputs, outputs and licenses
workflows/<name>/*.py the scripts it runs, if any
requirements/*.txt the pinned packages scripts install
tools/check_workflows.py the check CI runs on every workflow
```

## Workflows

### Inference, labelling and evaluation with LLMs

| Workflow | What it does | GPU steps |
|----------|--------------|-----------|
| [generate-responses](workflows/generate-responses) | Answers every prompt in a dataset with a chat model, as Parquet | vLLM batch |
| [label-text](workflows/label-text) | Labels texts with one of a fixed set of labels and measures agreement | vLLM batch |
| [classify-images](workflows/classify-images) | Labels images with a vision-language model and measures agreement | vLLM batch |
| [detect-objects](workflows/detect-objects) | Finds objects as bounding boxes with a vision-language model | vLLM batch |
| [caption-video](workflows/caption-video) | Captions a video frame by frame and summarises it | vLLM batch |
| [ocr-pages](workflows/ocr-pages) | Transcribes a PDF page by page with a vision-language model | vLLM batch |
| [synthetic-reasoning-data](workflows/synthetic-reasoning-data) | Builds a chain-of-thought dataset, judged against references | vLLM batch |
| [llm-as-a-judge](workflows/llm-as-a-judge) | Scores a model's answers from 1 to 10 with a judge model | vLLM batch |

### Datasets from documents, images, audio and text

| Workflow | What it does | GPU steps |
|----------|--------------|-----------|
| [pdfs-to-markdown](workflows/pdfs-to-markdown) | Converts PDFs to a Markdown dataset with Docling, one task per PDF | none |
| [scans-to-text](workflows/scans-to-text) | Reads scanned pages with Tesseract, one task per scan | none |
| [transcribe-audio](workflows/transcribe-audio) | Transcribes audio or video files with whisper.cpp, one task per file | whisper.cpp |
| [speech-dataset](workflows/speech-dataset) | Builds a speech-recognition dataset of transcribed clips | whisper.cpp |
| [dataset-statistics](workflows/dataset-statistics) | Profiles, filters, deduplicates and re-packs a Parquet dataset | none |
| [embed-dataset](workflows/embed-dataset) | Embeds every row with Text Embeddings Inference and parallel clients | TEI |
| [retrieval-index](workflows/retrieval-index) | Builds a RAG index from PDFs and answers a test query | TEI |
| [semantic-dedup](workflows/semantic-dedup) | Drops rows that mean nearly the same | vLLM batch |
| [entity-extraction](workflows/entity-extraction) | Extracts named entities of types you name with GLiNER | none |
| [web-text-curation](workflows/web-text-curation) | Filters and deduplicates web text with datatrove | none |

### Training and aligning language models

| Workflow | What it does | GPU steps |
|----------|--------------|-----------|
| [finetune-evaluate-quantize](workflows/finetune-evaluate-quantize) | Fine-tunes, evaluates, converts to GGUF, quantizes and publishes | TRL SFT, lm-eval |
| [compare-finetunes](workflows/compare-finetunes) | Fine-tunes twice with different settings and compares scores | TRL SFT, lm-eval |
| [train-then-serve](workflows/train-then-serve) | Fine-tunes a model and serves it with vLLM in the same run | TRL SFT, vLLM |
| [dpo-alignment](workflows/dpo-alignment) | Aligns a model with DPO and measures its win rate with a judge | TRL DPO, vLLM batch |
| [kto-alignment](workflows/kto-alignment) | Aligns a model with KTO and measures its win rate with a judge | TRL KTO, vLLM batch |
| [reward-model](workflows/reward-model) | Trains a reward model and scores held-out preference pairs | TRL reward |
| [grpo-math](workflows/grpo-math) | Trains maths reasoning with GRPO and a checked reward | TRL GRPO, lm-eval |
| [rloo-math](workflows/rloo-math) | Trains maths reasoning with RLOO and a checked reward | TRL RLOO, lm-eval |
| [distill-model](workflows/distill-model) | Distills a larger model into a smaller one | TRL distillation, lm-eval |
| [vlm-finetune](workflows/vlm-finetune) | Fine-tunes a vision-language model and compares accuracy | TRL SFT, vLLM batch |

### Merging, quantizing and serving

| Workflow | What it does | GPU steps |
|----------|--------------|-----------|
| [merge-models](workflows/merge-models) | Merges two fine-tunes with mergekit and scores all three | lm-eval |
| [quantize-and-pick](workflows/quantize-and-pick) | Quantizes to several presets and keeps the smallest good one | llama.cpp |
| [score-gguf](workflows/score-gguf) | Scores a GGUF model's maths answers on a CPU, with parallel clients | none by default |

### Training task-specific models with scripts

| Workflow | What it does | GPU steps |
|----------|--------------|-----------|
| [text-classification](workflows/text-classification) | Fine-tunes an encoder to classify text | training, prediction |
| [text-regression](workflows/text-regression) | Fine-tunes an encoder to predict a number per text | training, prediction |
| [token-classification](workflows/token-classification) | Fine-tunes an encoder to tag named entities | training, tagging |
| [extractive-qa](workflows/extractive-qa) | Fine-tunes a model to find answers in long documents | training, scoring tokens |
| [summarization](workflows/summarization) | Fine-tunes a sequence-to-sequence model to summarise | training, generation |
| [translation](workflows/translation) | Fine-tunes a translation model | training, generation |
| [sentence-embeddings](workflows/sentence-embeddings) | Fine-tunes a sentence-embedding model for retrieval | training, embedding |
| [setfit-classifier](workflows/setfit-classifier) | Trains a few-shot classifier with SetFit | training, prediction |
| [image-classification](workflows/image-classification) | Fine-tunes a vision transformer to classify images | training, prediction |
| [image-regression](workflows/image-regression) | Fine-tunes a vision transformer to predict a number per image | training, prediction |
| [object-detection](workflows/object-detection) | Fine-tunes an object detector and scores its mAP | training, detection |
| [tabular](workflows/tabular) | Trains gradient-boosted trees on a table | none |

Each workflow's README lists its steps, says which part stays one script and
why, and gives the licenses of its default model, data and the packages its
scripts install.

## Licenses

The workflows, scripts and tools in this repository are licensed under the
[MIT License](LICENSE). The models, datasets, documents and packages they use
keep their own licenses, listed in each workflow's README. Defaults are chosen
under licenses that allow commercial use; check the license of anything you put
in their place.
5 changes: 5 additions & 0 deletions requirements/cpu-chat-images.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# What vlm-finetune's step that writes chat rows installs into the python-3-13 task.
datasets==5.2.0
huggingface_hub==2.5.0
pillow==13.0.0
pyarrow==26.0.1
9 changes: 9 additions & 0 deletions requirements/cpu-datatrove.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# What the web-text curation steps install into the python-3-13 task, with their
# dependencies. spaCy splits text into words for the quality rules; NLTK splits sentences.
datatrove==0.10.1
nltk==3.10.4
pyarrow==26.0.1
tokenizers==0.23.3
xxhash==3.6.0
numpy==2.5.5
spacy==3.8.18
5 changes: 5 additions & 0 deletions requirements/cpu-detection.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# What the object-detection CPU steps install into the python-3-13 task.
pycocotools==2.0.11
numpy==2.5.5
pyarrow==26.0.1
pillow==13.0.0
10 changes: 10 additions & 0 deletions requirements/cpu-gliner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# What the GLiNER step installs into the python-3-13 task, with their dependencies.
# GLiNER 0.2.30 accepts Transformers below 5.23, so this step installs its own copy
# of the stack, with the CPU build of PyTorch, rather than using the GPU image.
--extra-index-url https://download.pytorch.org/whl/cpu
torch==2.14.1+cpu
transformers==5.22.2
gliner==0.2.30
pyarrow==26.0.1
# GLiNER's encoder tokenizer converts from SentencePiece, which needs protobuf.
protobuf==7.36.2
4 changes: 4 additions & 0 deletions requirements/cpu-images.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# What the CPU image preprocessing steps install into the python-3-13 task.
numpy==2.5.5
pillow==13.0.0
pyarrow==26.0.1
3 changes: 3 additions & 0 deletions requirements/cpu-numpy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# What the semantic deduplication step installs into the python-3-13 task.
numpy==2.5.5
pyarrow==26.0.1
3 changes: 3 additions & 0 deletions requirements/cpu-score-bleu.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# What the translation score step installs into the python-3-13 task.
sacrebleu==2.6.0
pyarrow==26.0.1
3 changes: 3 additions & 0 deletions requirements/cpu-score-rouge.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# What the summarization score step installs into the python-3-13 task.
rouge-score==0.1.2
pyarrow==26.0.1
4 changes: 4 additions & 0 deletions requirements/cpu-tabular.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# What the tabular steps install into the python-3-13 task, with their dependencies.
scikit-learn==1.9.1
pandas==3.1.1
pyarrow==26.0.1
8 changes: 8 additions & 0 deletions requirements/cpu-tokenize.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# What the CPU preprocessing steps install into the python-3-13 task: the same
# versions the GPU training image runs, without PyTorch. SentencePiece reads the
# tokenizers of models such as Marian and T5.
transformers==5.24.1
tokenizers==0.23.3
datasets==5.2.0
huggingface_hub==2.5.0
sentencepiece==0.2.3
4 changes: 4 additions & 0 deletions requirements/gpu-detection.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# What the object detection training step installs, with pip --no-deps, next to
# the PyTorch and Transformers the transformers task already has: the detector's
# loss matches predicted boxes to true ones with SciPy.
scipy==1.18.1
9 changes: 9 additions & 0 deletions requirements/gpu-sentence-transformers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# What the sentence-transformers and SetFit GPU steps install, with pip --no-deps,
# next to the PyTorch, Transformers and Datasets the transformers task already has.
sentence-transformers==6.3.0
scikit-learn==1.9.1
scipy==1.18.1
joblib==1.6.0
threadpoolctl==3.8.0
narwhals==2.30.0
cloudpickle==3.1.3
4 changes: 4 additions & 0 deletions requirements/gpu-setfit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# What the SetFit GPU steps install, with pip --no-deps, on top of
# gpu-sentence-transformers.txt.
setfit==1.2.0
evaluate==0.4.6
Loading
Loading