TRL distillation
Runs trl distillation --config <config>: knowledge distillation with
TRL's DistillationTrainer. The student,
model_name_or_path, learns to match the token distribution of the teacher,
teacher_model_name_or_path, on completions to the dataset's prompts, so a
small model picks up what a larger one does on your prompts. The two models must
share a vocabulary, as members of one model family usually do; the run stops
before training when their vocabulary sizes differ. Everything about the run
lives in the YAML file at config.
Inputs
| Input | Required | Default | Description |
|---|---|---|---|
config |
yes | — | Absolute path to the TRL distillation YAML config inside the container. Point it at the mounted workspace (e.g. ${{env.WORKFLOW_STORAGE}}/distillation.yaml) so an earlier task can write it there. |
token |
no | — | HF access token for gated/private models and datasets (pass a secret). Delivered to the trainer as HF_TOKEN via the definition's exec.env (an omitted token resolves to an empty value, which the Hugging Face stack treats as no token); it is never placed on the command line. |
The config must set teacher_model_name_or_path; without it the run stops
before training. Either model can be a Hub repo id or a local directory, such as
one swaleio/hf-download fetched.
Dataset
A prompt-only dataset: each row holds a prompt, as plain text or as chat
messages. Name a Hub dataset with dataset_name, or list one or more under
datasets, where columns keeps only the columns you name and data_files
reads JSON, CSV or Parquet files an earlier task wrote to the workspace.
Where the model lands
This task declares no outputs: the student, or its LoRA adapter when the
config sets use_peft: true, is written to the config's output_dir. Set
output_dir to a path on the mounted workspace that you choose (e.g.
${{env.WORKFLOW_STORAGE}}/distillation-out) so later tasks can read it from
there. To publish it, use swaleio/swale-push (the platform's own store) or
swaleio/hf-upload for the Hugging Face Hub.
Compute
GPU required. Both models sit on the GPU: the teacher, unquantized, for
inference, and the student for training. A 1.5B teacher with a 0.5B student fits on
a 24 GB-class GPU; a 7–8B teacher wants 40 GB or more, and larger teachers
80 GB-class hardware. The workflow selects the compute type via
compute_type; on a CPU compute type the task fails at runtime with CUDA
errors.
Example
A bash task writes the config onto the shared workspace, then
trl-distillation consumes it. The prompts come from
HuggingFaceH4/ultrafeedback_binarized
(MIT); both models are Apache-2.0.
name: TRL distillation example
compute_type: cpu-4
entry_point: main
blocks:
main:
tasks:
write_config:
name: Write config
uses: swaleio/bash
args:
script: |
cat > ${{env.WORKFLOW_STORAGE}}/distillation.yaml <<'EOF'
model_name_or_path: Qwen/Qwen2.5-0.5B-Instruct
teacher_model_name_or_path: Qwen/Qwen2.5-1.5B-Instruct
datasets:
- path: HuggingFaceH4/ultrafeedback_binarized
split: train_prefs[:10000]
columns: [prompt]
learning_rate: 2.0e-5
num_train_epochs: 1
per_device_train_batch_size: 4
gradient_accumulation_steps: 4
max_completion_length: 256
bf16: true
report_to: none
output_dir: ${{env.WORKFLOW_STORAGE}}/distillation-out
EOF
train:
name: Train
uses: swaleio/trl-distillation
compute_type: a100-1 # any GPU compute type — see Compute above
start_on:
- write_config
args:
config: ${{env.WORKFLOW_STORAGE}}/distillation.yaml
token: ${{secrets.hf_token}}
Downstream tasks read the distilled student at
${{env.WORKFLOW_STORAGE}}/distillation-out, the output_dir the config chose.
For the workflow syntax these examples use, see the workflow definition reference in the Swale documentation.
Licensed under the MIT License.