Skip to content

Command line

Every command and option, from tinydistill <command> --help.

Command What it does
label score every label with the teacher
train distil the student
export export the student to ONNX
eval quality and speed table
predict classify texts with an exported model
serve serve an exported model over HTTP (JSON)
plot charts of a run as PNG files: training, speed and accuracy, per label, confusions, cascade
web a static web page that runs the model in the browser
synth have the teacher write unlabelled example texts
init write a starter task file from a dataset's labels
push upload an exported model to the Hugging Face Hub, with a model card
report rebuild RUN/results.md from RUN/results.json
tune choose teacher, prompt and few-shot on a dev split
refresh retrain RUN with the texts its cascade sent to the teacher (a new run directory)
improve rounds of teacher-written hard examples for the labels the student confuses (new runs)
suggest which training texts a person should label next
analyse where the teacher and student go wrong (RUN/analysis.html)
status how far a run is, and whether it is still running (--live: a page that follows it); for a directory of runs, a table of them all
cache what a score cache directory holds, and which runs use it (--prune: delete the rest)
compare one markdown table comparing several runs (e.g. student sizes)
env versions and hardware, for bug reports
run label, train, export and eval

label

Score every label with the teacher.

usage: tinydistill label [-h] --data DATA [--test TEST] --out OUT [--teacher TEACHER]
                         [--prompts FILES] [--load-4bit] [--cache-dir CACHE_DIR]
                         [--vllm-url VLLM_URL] [--api-url API_URL] [--api-key-env VAR]
                         [--api-samples N] [--api-temperature T] [--shortlist K]
                         [--shortlist-model SHORTLIST_MODEL] [--shortlist-keep IDS] [--few-shot K]
                         [--few-shot-similar M] [--few-shot-sets K]
                         [--few-shot-model FEW_SHOT_MODEL] [--reason] [--reason-tokens K]
                         [--teacher-tokens TEACHER_TOKENS] [--chunk-tokens T] [--chunk-stride S]
                         [--chunk-tokenizer MODEL] [--limit LIMIT] [--test-limit TEST_LIMIT]
                         [--dry-run] [--price-in P] [--price-out Q] [--probe] [--no-probe]
                         [--probe-only] [--probe-dev S] [--probe-layer L]
                         [--probe-pool {last,mean}] [--probe-l2 L] [--gold-file GOLD_FILE]
                         [--gold-per-class K] [--device DEVICE] [--threads THREADS] [--seed SEED]
                         [--live] [--live-port P] [--no-browser]
                         task

positional arguments:
  task                  task YAML file

options:
  -h, --help            show this help message and exit
  --data DATA           unlabelled texts: .csv, .jsonl or hf:<dataset>[:<config>]:<split>
  --test TEST           optional gold-labelled test set, same formats
  --out OUT             run directory
  --teacher TEACHER     Hugging Face causal LM; several, comma-separated, are ensembled
  --prompts FILES       other task files (other prompts, same label ids in the same order), comma-
                        separated: each teacher also scores every text with each of them, and the
                        label probabilities are averaged (a prompt ensemble; local teachers only)
  --load-4bit           load the teacher in 4 bit (bitsandbytes, CUDA)
  --cache-dir CACHE_DIR
                        where teacher scores are cached (default: the run directory); runs that
                        share it label each text once
  --vllm-url VLLM_URL   score with this vLLM server (OpenAI API base, e.g. http://host:8000/v1),
                        not a local model
  --api-url API_URL     score with a hosted OpenAI-compatible chat API (base URL, e.g.
                        https://api.openai.com/v1; --teacher names the model there): the labels
                        are shown as options A, B, C, ... and scored by the answer letter's log-
                        probability; single-label tasks with at most 20 labels
  --api-key-env VAR     environment variable holding the API key for --api-url (default
                        OPENAI_API_KEY; unset: no key is sent, as for a local server)
  --api-samples N       for APIs without log-probabilities: sample N answers per text (N >= 2, N
                        times the requests) and score each label by its share of the answers
  --api-temperature T   sampling temperature for --api-samples (default 0.7)
  --shortlist K         score only the K labels most similar to each text (for tasks with very
                        many labels)
  --shortlist-model SHORTLIST_MODEL
                        sentence-embedding model for --shortlist (default: MiniLM)
  --shortlist-keep IDS  label ids the teacher always scores besides the shortlist, comma-
                        separated: catch-all labels such as other or out of scope, whose names
                        resemble no particular text
  --few-shot K          show K gold training examples per class in the teacher's prompt (needs
                        {examples} in it); default: with --gold-per-class K, those K, and each
                        text's 16 most similar of them
  --few-shot-similar M  show each text the M gold training examples most similar to it, most
                        similar last (needs {examples} before {text}); with --few-shot K they are
                        picked from those K per class. Default: 16 with --gold-per-class (when the
                        prompt has {examples}), else 0
  --few-shot-sets K     with --few-shot-similar M: score each text K times, set k showing it ranks
                        k*M+1 to (k+1)*M of its most similar gold examples, and average the label
                        probabilities (demonstration ensembling; default 1)
  --few-shot-model FEW_SHOT_MODEL
                        sentence-embedding model for --few-shot-similar (default: MiniLM)
  --reason              the teacher thinks briefly before it answers (greedy, up to --reason-
                        tokens), and the labels are scored after its reasoning; single-label
                        tasks, local or vLLM teachers; much slower
  --reason-tokens K     with --reason: the most tokens the teacher writes before its answer
                        (default 256)
  --teacher-tokens TEACHER_TOKENS
                        tokens per teacher forward pass; short texts with few labels are packed
                        together
  --chunk-tokens T      cut texts longer than T tokens of the student's tokenizer into overlapping
                        windows of T tokens: the teacher scores each window, the student trains on
                        them and averages its windows' probabilities per text when it predicts
                        (for documents longer than the student reads)
  --chunk-stride S      with --chunk-tokens: tokens from one window's start to the next (default T
                        // 2, so windows overlap by half; S = T for no overlap)
  --chunk-tokenizer MODEL
                        with --chunk-tokens: the student whose tokenizer counts the tokens
                        (default: the default student; `run` uses its --student); train warns if
                        its --student differs
  --limit LIMIT         use only the first N training texts
  --test-limit TEST_LIMIT
                        use only the first N test texts
  --dry-run             how long labelling the texts not in the cache yet would take, timed on a
                        sample of them (a local or vLLM teacher), or with --api-url the requests
                        and (approximate) tokens it would take, and with --price-in/--price-out
                        its cost; caches and writes nothing
  --price-in P          with --dry-run: the API's price per million input tokens
  --price-out Q         with --dry-run: the API's price per million output tokens
  --probe               also fit a linear probe on the teacher's hidden state at each text's last
                        token, on the gold labels train uses (--gold-per-class, --gold-file), and
                        add its probabilities to the teacher's (prompt-augmented linear probing);
                        local teachers only. Slower than the default, --probe-only, and a little
                        more accurate; the default with several teachers, --prompts or --few-shot-
                        sets
  --no-probe            do not fit the probe, which is otherwise the default with gold labels and
                        a local teacher: the teacher scores every label
  --probe-only          like --probe, but the probe alone is the teacher: no label is scored, only
                        each text's state, so labelling is much faster; one teacher, no --prompts
                        or --few-shot-sets. The default with gold labels and a local teacher (not
                        with --chunk-tokens or --reason)
  --probe-dev S         with --probe: first fit on all but this share of the gold texts and report
                        teacher accuracy on the rest (in context, probe, combined), then refit on
                        all of them (default 0.2; 0: no report)
  --probe-layer L       with --probe: the probe reads the output of the teacher's layer L (0: the
                        first, -1: the last, -2: the one before) instead of the input of its LM
                        head (the last layer's output, normed)
  --probe-pool {last,mean}
                        with --probe: the state the probe reads, at the text's last token
                        (default) or the mean over the text's own tokens (the text and the prompt
                        after it, not the examples before it)
  --probe-l2 L          with --probe: weight of the L2 penalty on the probe's weights (default
                        0.001)
  --gold-file GOLD_FILE
                        gold labels for some training texts (same text and label fields as the
                        task, or a Label Studio JSON export), e.g. the texts `tinydistill suggest`
                        picked, labelled by a person; used like --gold-per-class
  --gold-per-class K    also use the gold labels of K training examples per class (picked with
                        --seed): train adds a cross-entropy term on them, label --probe fits on
                        them
  --device DEVICE       auto, cpu or cuda (teacher labelling and training)
  --threads THREADS     CPU threads for torch and onnxruntime
  --seed SEED           seed for example selection and training
  --live                also serve a page on http://127.0.0.1 that shows the run as it goes
                        (stage, time left, loss per epoch, results) and open it in the browser
  --live-port P         the live page's port (default 8765, or the next free one)
  --no-browser          with --live: do not open the browser

train

Distil the student.

usage: tinydistill train [-h] [--student STUDENT] [--init-head {names}] [--warmup-pairs N]
                         [--warmup-epochs E] [--warmup-confidence C] [--epochs EPOCHS]
                         [--val-share S] [--patience PATIENCE] [--batch-size BATCH_SIZE] [--lr LR]
                         [--max-length MAX_LENGTH] [--ce-weight CE_WEIGHT] [--gold-only]
                         [--seeds SEEDS] [--trim-vocab] [--trim-keep K] [--upper-bound]
                         [--gold-file GOLD_FILE] [--gold-per-class K] [--device DEVICE]
                         [--threads THREADS] [--seed SEED] [--live] [--live-port P] [--no-browser]
                         [--out DIR]
                         run

positional arguments:
  run                   run directory

options:
  -h, --help            show this help message and exit
  --student STUDENT     Hugging Face encoder, or `static` / `static:<encoder>` for a static-
                        embedding student (no attention: much smaller and faster; try --epochs 20
                        --lr 1e-3); <encoder> may be a Model2Vec model such as minishlab/potion-
                        base-8M
  --init-head {names}   `names`: before training, set each label's classifier weights to the
                        student's own embedding of the label's name (and description), so the
                        untrained student ranks labels by similarity to their names (default: a
                        random head)
  --warmup-pairs N      before distillation, train the student's encoder contrastively on N pairs
                        of training texts, half of the same class and half of different classes,
                        as SetFit does: the gold label where a text has one, else the teacher's
                        top label if it is at least --warmup-confidence; single-label tasks only;
                        the gold-only and upper-bound baselines do not warm up (default 0: off)
  --warmup-epochs E     passes over the warm-up pairs (default 1)
  --warmup-confidence C
                        a text without a gold label joins the warm-up if the teacher's top label
                        has at least this probability, with that label as its class (default 0.9)
  --epochs EPOCHS       passes over the training texts (default 10)
  --val-share S         hold out this share of the training texts and keep the epoch with the
                        lowest loss on them, stopping early after --patience epochs without
                        improvement (e.g. 0.05; default: off, keep the last)
  --patience PATIENCE   epochs without improvement before stopping
  --batch-size BATCH_SIZE
  --lr LR
  --max-length MAX_LENGTH
  --ce-weight CE_WEIGHT
                        weight of that cross-entropy term
  --gold-only           also train the student on the K gold labels per class only, without the
                        teacher (a baseline)
  --seeds SEEDS         training seeds per student (mean and std in eval)
  --trim-vocab          before training, cut the student's vocabulary (its embedding matrix and
                        tokenizer) to the tokens of the training and test texts, plus its special
                        tokens and --trim-keep common ones; makes a multilingual student much
                        smaller. A new text's word whose tokens were not kept is split into kept
                        pieces, bytes or the unknown token
  --trim-keep K         with --trim-vocab: also keep the K most frequent tokens of the original
                        vocabulary, for texts with tokens the training texts lack (default 1000)
  --upper-bound         also train the student on all gold training labels, without the teacher
  --gold-file GOLD_FILE
                        gold labels for some training texts (same text and label fields as the
                        task, or a Label Studio JSON export), e.g. the texts `tinydistill suggest`
                        picked, labelled by a person; used like --gold-per-class
  --gold-per-class K    also use the gold labels of K training examples per class (picked with
                        --seed): train adds a cross-entropy term on them, label --probe fits on
                        them
  --device DEVICE       auto, cpu or cuda (teacher labelling and training)
  --threads THREADS     CPU threads for torch and onnxruntime
  --seed SEED           seed for example selection and training
  --live                also serve a page on http://127.0.0.1 that shows the run as it goes
                        (stage, time left, loss per epoch, results) and open it in the browser
  --live-port P         the live page's port (default 8765, or the next free one)
  --no-browser          with --live: do not open the browser
  --out DIR             train in a new run directory DIR with a copy of RUN's labels, so RUN keeps
                        its student (to compare students on the same labels); then export and eval
                        DIR

export

Export the student to onnx.

usage: tinydistill export [-h] [--int8] [--device DEVICE] [--threads THREADS] [--seed SEED]
                          [--labels FILE]
                          run

positional arguments:
  run                run directory

options:
  -h, --help         show this help message and exit
  --int8             also write an int8 dynamically quantised model
  --device DEVICE    auto, cpu or cuda (teacher labelling and training)
  --threads THREADS  CPU threads for torch and onnxruntime
  --seed SEED        seed for example selection and training
  --labels FILE      instead of the student, write the teacher's labels of the training texts as a
                     dataset (.csv or .jsonl): each text, its gold label if it has one, the
                     teacher's label, confidence and every label's probability

eval

Quality and speed table.

usage: tinydistill eval [-h] [--teacher-devices TEACHER_DEVICES] [--skip-teacher-bench]
                        [--reps REPS] [--teacher-reps TEACHER_REPS] [--device DEVICE]
                        [--threads THREADS] [--seed SEED]
                        run

positional arguments:
  run                   run directory

options:
  -h, --help            show this help message and exit
  --teacher-devices TEACHER_DEVICES
                        comma-separated devices to time the teacher on (default: the labelling
                        device)
  --skip-teacher-bench  report teacher quality only
  --reps REPS           timed runs per student benchmark at batch 1
  --teacher-reps TEACHER_REPS
                        timed runs of the teacher (batch 1)
  --device DEVICE       auto, cpu or cuda (teacher labelling and training)
  --threads THREADS     CPU threads for torch and onnxruntime
  --seed SEED           seed for example selection and training

predict

Classify texts with an exported model.

usage: tinydistill predict [-h] [--device DEVICE] [--threads THREADS] [--seed SEED] [--data DATA]
                           [--text-field TEXT_FIELD] [--out FILE.csv] [--fp32] [--cascade RUN]
                           [--log LOG] [--threshold THRESHOLD]
                           model [texts ...]

positional arguments:
  model                 directory written by `export` (run/onnx), or hf:user/name on the Hub
  texts

options:
  -h, --help            show this help message and exit
  --device DEVICE       auto, cpu or cuda (teacher labelling and training)
  --threads THREADS     CPU threads for torch and onnxruntime
  --seed SEED           seed for example selection and training
  --data DATA           file with texts (.csv, .jsonl or hf:...)
  --text-field TEXT_FIELD
                        the column of --data that holds the texts
  --out FILE.csv        write a CSV file instead of printing JSON lines: each row of --data (or
                        text) with its predicted label and confidence added
  --fp32                use the fp32 model even if an int8 one exists
  --cascade RUN         send texts the student is unsure about to RUN's teacher
  --log LOG             with --cascade: append the texts the teacher answered (for `refresh`)
  --threshold THRESHOLD
                        with --cascade: the student's top probability below which the teacher
                        answers

serve

Serve an exported model over http (json).

usage: tinydistill serve [-h] [--device DEVICE] [--threads THREADS] [--seed SEED] [--host HOST]
                         [--port PORT] [--cascade RUN] [--threshold THRESHOLD] [--log LOG]
                         model

positional arguments:
  model                 directory written by `export` (run/onnx), or hf:user/name on the Hub

options:
  -h, --help            show this help message and exit
  --device DEVICE       auto, cpu or cuda (teacher labelling and training)
  --threads THREADS     CPU threads for torch and onnxruntime
  --seed SEED           seed for example selection and training
  --host HOST           interface to listen on (default: this machine only)
  --port PORT
  --cascade RUN         send texts the student is unsure about to RUN's teacher
  --threshold THRESHOLD
                        with --cascade: see `predict --help`
  --log LOG             with --cascade: append the texts the teacher answered (for `refresh`)

plot

Charts of a run as png files: training, speed and accuracy, per label, confusions, cascade.

usage: tinydistill plot [-h] [--out OUT] run

positional arguments:
  run         run directory

options:
  -h, --help  show this help message and exit
  --out OUT   folder for the PNG files (default: RUN/plots)

web

A static web page that runs the model in the browser.

usage: tinydistill web [-h] [--out OUT] [--title TITLE] [--note NOTE] [--models MODELS] [--remote]
                       model

positional arguments:
  model            directory written by `export` (run/onnx), or hf:user/name on the Hub

options:
  -h, --help       show this help message and exit
  --out OUT        folder to write the page and model into
  --title TITLE    page title (default: from the task name)
  --note NOTE      an extra footer line, e.g. the dataset's licence and source
  --models MODELS  other models for a menu in the pages, comma-separated: hf:user/a,hf:user/b
                   (uploaded with `push`); visitors pick one and it loads from the Hub
  --remote         for MODEL=hf:user/name: write the pages with no model files; the model loads
                   from the Hub

synth

Have the teacher write unlabelled example texts.

usage: tinydistill synth [-h] [--device DEVICE] [--threads THREADS] [--seed SEED]
                         --per-label PER_LABEL --out OUT [--teacher TEACHER]
                         [--temperature TEMPERATURE] [--load-4bit] [--vary] [--dedup T]
                         [--data DATA]
                         task

positional arguments:
  task                  task YAML file

options:
  -h, --help            show this help message and exit
  --device DEVICE       auto, cpu or cuda (teacher labelling and training)
  --threads THREADS     CPU threads for torch and onnxruntime
  --seed SEED           seed for example selection and training
  --per-label PER_LABEL
                        texts to write per label
  --out OUT             JSONL file to write (usable as --data)
  --teacher TEACHER     the model that writes (the first if several)
  --temperature TEMPERATURE
  --load-4bit           load the model in 4 bit (bitsandbytes, CUDA)
  --vary                each request also names a length, a tone and a writer's situation, sampled
                        with --seed (the task file's `attributes:` mapping replaces these)
  --dedup T             drop texts whose cosine similarity (sentence embeddings, MiniLM) to a text
                        kept earlier, or to one in --data, is T or more (e.g. 0.95)
  --data DATA           with --dedup: existing texts (e.g. the real data) the new ones must differ
                        from

init

Write a starter task file from a dataset's labels.

usage: tinydistill init [-h] [--out OUT] [--text-field TEXT_FIELD] [--label-field LABEL_FIELD]
                        [--force]
                        data

positional arguments:
  data                  .csv, .jsonl or hf:<dataset>[:<config>]:<split> with gold labels

options:
  -h, --help            show this help message and exit
  --out OUT
  --text-field TEXT_FIELD
  --label-field LABEL_FIELD
  --force               overwrite an existing file

push

Upload an exported model to the hugging face hub, with a model card.

usage: tinydistill push [-h] --repo REPO [--private] [--license LICENSE] [--title TITLE]
                        [--note NOTE]
                        model

positional arguments:
  model              directory written by `export` (run/onnx)

options:
  -h, --help         show this help message and exit
  --repo REPO        Hub repository, e.g. user/my-classifier
  --private
  --license LICENSE  licence identifier for the model card (check student, teacher and data)
  --title TITLE      the model's title in the browser pages (default: from the task name)
  --note NOTE        the pages' footer line for this model, e.g. the dataset and its licence

report

Rebuild run/results.md from run/results.json.

usage: tinydistill report [-h] run

positional arguments:
  run         run directory

options:
  -h, --help  show this help message and exit

tune

Choose teacher, prompt and few-shot on a dev split.

usage: tinydistill tune [-h] [--device DEVICE] [--threads THREADS] [--seed SEED] --data DATA
                        [--teacher TEACHER] [--few-shot FEW_SHOT] [--prompt PROMPT] [--propose N]
                        [--rounds R] [--dev-size DEV_SIZE] [--limit LIMIT] [--load-4bit]
                        [--out OUT]
                        task

positional arguments:
  task                 task YAML file

options:
  -h, --help           show this help message and exit
  --device DEVICE      auto, cpu or cuda (teacher labelling and training)
  --threads THREADS    CPU threads for torch and onnxruntime
  --seed SEED          seed for example selection and training
  --data DATA          training data with gold labels for some texts
  --teacher TEACHER    one or more teachers, comma-separated
  --few-shot FEW_SHOT  comma-separated values of K to try (0 = zero-shot)
  --prompt PROMPT      another task file to try (same labels)
  --propose N          the (first) teacher writes N rewrites of the task's instruction, the text
                       before its first placeholder (the rest of the prompt is kept as written);
                       they are tried too, as is the task without label descriptions. Writes each
                       candidate as OUT-<name>.yaml and the best task file as OUT-best.yaml
  --rounds R           with --propose: up to R rounds. Each later round shows the teacher the best
                       instruction's mistakes on one half of the dev split and asks for N rewrites
                       that fix them (OUT-r2-1.yaml, ...); every candidate is scored on the other
                       half. Stops at the first round without an improvement
  --dev-size DEV_SIZE  gold-labelled training texts to score
  --limit LIMIT        use only the first N training texts
  --load-4bit          load teachers in 4 bit (bitsandbytes, CUDA)
  --out OUT            writes OUT.md and OUT.json

refresh

Retrain run with the texts its cascade sent to the teacher (a new run directory).

usage: tinydistill refresh [-h] [--student STUDENT] [--init-head {names}] [--warmup-pairs N]
                           [--warmup-epochs E] [--warmup-confidence C] [--epochs EPOCHS]
                           [--val-share S] [--patience PATIENCE] [--batch-size BATCH_SIZE]
                           [--lr LR] [--max-length MAX_LENGTH] [--ce-weight CE_WEIGHT]
                           [--gold-only] [--seeds SEEDS] [--trim-vocab] [--trim-keep K]
                           [--upper-bound] [--gold-file GOLD_FILE] [--gold-per-class K] [--int8]
                           [--teacher-devices TEACHER_DEVICES] [--skip-teacher-bench]
                           [--reps REPS] [--teacher-reps TEACHER_REPS] [--device DEVICE]
                           [--threads THREADS] [--seed SEED] --log LOG --out OUT
                           run

positional arguments:
  run                   run directory

options:
  -h, --help            show this help message and exit
  --student STUDENT     Hugging Face encoder, or `static` / `static:<encoder>` for a static-
                        embedding student (no attention: much smaller and faster; try --epochs 20
                        --lr 1e-3); <encoder> may be a Model2Vec model such as minishlab/potion-
                        base-8M
  --init-head {names}   `names`: before training, set each label's classifier weights to the
                        student's own embedding of the label's name (and description), so the
                        untrained student ranks labels by similarity to their names (default: a
                        random head)
  --warmup-pairs N      before distillation, train the student's encoder contrastively on N pairs
                        of training texts, half of the same class and half of different classes,
                        as SetFit does: the gold label where a text has one, else the teacher's
                        top label if it is at least --warmup-confidence; single-label tasks only;
                        the gold-only and upper-bound baselines do not warm up (default 0: off)
  --warmup-epochs E     passes over the warm-up pairs (default 1)
  --warmup-confidence C
                        a text without a gold label joins the warm-up if the teacher's top label
                        has at least this probability, with that label as its class (default 0.9)
  --epochs EPOCHS       passes over the training texts (default 10)
  --val-share S         hold out this share of the training texts and keep the epoch with the
                        lowest loss on them, stopping early after --patience epochs without
                        improvement (e.g. 0.05; default: off, keep the last)
  --patience PATIENCE   epochs without improvement before stopping
  --batch-size BATCH_SIZE
  --lr LR
  --max-length MAX_LENGTH
  --ce-weight CE_WEIGHT
                        weight of that cross-entropy term
  --gold-only           also train the student on the K gold labels per class only, without the
                        teacher (a baseline)
  --seeds SEEDS         training seeds per student (mean and std in eval)
  --trim-vocab          before training, cut the student's vocabulary (its embedding matrix and
                        tokenizer) to the tokens of the training and test texts, plus its special
                        tokens and --trim-keep common ones; makes a multilingual student much
                        smaller. A new text's word whose tokens were not kept is split into kept
                        pieces, bytes or the unknown token
  --trim-keep K         with --trim-vocab: also keep the K most frequent tokens of the original
                        vocabulary, for texts with tokens the training texts lack (default 1000)
  --upper-bound         also train the student on all gold training labels, without the teacher
  --gold-file GOLD_FILE
                        gold labels for some training texts (same text and label fields as the
                        task, or a Label Studio JSON export), e.g. the texts `tinydistill suggest`
                        picked, labelled by a person; used like --gold-per-class
  --gold-per-class K    also use the gold labels of K training examples per class (picked with
                        --seed): train adds a cross-entropy term on them, label --probe fits on
                        them
  --int8                also write an int8 dynamically quantised model
  --teacher-devices TEACHER_DEVICES
                        comma-separated devices to time the teacher on (default: the labelling
                        device)
  --skip-teacher-bench  report teacher quality only
  --reps REPS           timed runs per student benchmark at batch 1
  --teacher-reps TEACHER_REPS
                        timed runs of the teacher (batch 1)
  --device DEVICE       auto, cpu or cuda (teacher labelling and training)
  --threads THREADS     CPU threads for torch and onnxruntime
  --seed SEED           seed for example selection and training
  --log LOG             the log written by predict/serve --cascade RUN --log FILE
  --out OUT             new run directory

improve

Rounds of teacher-written hard examples for the labels the student confuses (new runs).

usage: tinydistill improve [-h] [--device DEVICE] [--threads THREADS] [--seed SEED]
                           [--rounds ROUNDS] [--per-round N] [--held-out S]
                           [--temperature TEMPERATURE] [--int8] [--out OUT]
                           run

positional arguments:
  run                   run directory

options:
  -h, --help            show this help message and exit
  --device DEVICE       auto, cpu or cuda (teacher labelling and training)
  --threads THREADS     CPU threads for torch and onnxruntime
  --seed SEED           seed for example selection and training
  --rounds ROUNDS       rounds at most (default 3)
  --per-round N         new texts asked for per round
  --held-out S          share of the training texts held out to find the confusions and compare
                        rounds, against the teacher's labels (default 0.1; never the test set)
  --temperature TEMPERATURE
                        sampling temperature of the teacher
  --int8                also export int8 models (as the run did if it has one)
  --out OUT             folder for the rounds (default: RUN-improve)

suggest

Which training texts a person should label next.

usage: tinydistill suggest [-h] [--n N] [--out OUT] run

positional arguments:
  run         run directory

options:
  -h, --help  show this help message and exit
  --n N       how many texts
  --out OUT   JSONL to write, with an empty label to fill in; a .json file: Label Studio tasks to
              import, with their labeling config in a .xml file next to it

analyse

Where the teacher and student go wrong (run/analysis.html).

usage: tinydistill analyse [-h] [--top TOP] [--review OUT.csv] run

positional arguments:
  run               run directory

options:
  -h, --help        show this help message and exit
  --top TOP         how many confusions and disagreements to list
  --review OUT.csv  instead of the page, write a CSV of training texts for a person to check:
                    where the teacher's label contradicts the gold label, the teacher's most
                    confident first, then (ensembles) where its members disagree most. Training is
                    not changed

status

How far a run is, and whether it is still running (--live: a page that follows it); for a directory of runs, a table of them all.

usage: tinydistill status [-h] [--live] [--live-port P] [--no-browser] [--watch] run

positional arguments:
  run            run directory

options:
  -h, --help     show this help message and exit
  --live         also serve a page on http://127.0.0.1 that shows the run as it goes (stage, time
                 left, loss per epoch, results) and open it in the browser
  --live-port P  the live page's port (default 8765, or the next free one)
  --no-browser   with --live: do not open the browser
  --watch        show it again every 2 seconds, until Ctrl+C

cache

What a score cache directory holds, and which runs use it (--prune: delete the rest).

usage: tinydistill cache [-h] [--runs RUNS] [--prune] [--keep-recent H] dir

positional arguments:
  dir              the score cache directory (a run's --cache-dir)

options:
  -h, --help       show this help message and exit
  --runs RUNS      the directory of runs whose meta.json say which caches they use (default: DIR's
                   parent)
  --prune          delete the caches no run uses
  --keep-recent H  with --prune: keep caches written in the last H hours (default 24): a run still
                   labelling writes its meta.json only when it is done

compare

One markdown table comparing several runs (e.g. student sizes).

usage: tinydistill compare [-h] runs [runs ...]

positional arguments:
  runs        run directories or results.json files

options:
  -h, --help  show this help message and exit

env

Versions and hardware, for bug reports.

usage: tinydistill env [-h]

options:
  -h, --help  show this help message and exit

run

Label, train, export and eval.

usage: tinydistill run [-h] --data DATA [--test TEST] --out OUT [--teacher TEACHER]
                       [--prompts FILES] [--load-4bit] [--cache-dir CACHE_DIR]
                       [--vllm-url VLLM_URL] [--api-url API_URL] [--api-key-env VAR]
                       [--api-samples N] [--api-temperature T] [--shortlist K]
                       [--shortlist-model SHORTLIST_MODEL] [--shortlist-keep IDS] [--few-shot K]
                       [--few-shot-similar M] [--few-shot-sets K]
                       [--few-shot-model FEW_SHOT_MODEL] [--reason] [--reason-tokens K]
                       [--teacher-tokens TEACHER_TOKENS] [--chunk-tokens T] [--chunk-stride S]
                       [--chunk-tokenizer MODEL] [--limit LIMIT] [--test-limit TEST_LIMIT]
                       [--dry-run] [--price-in P] [--price-out Q] [--probe] [--no-probe]
                       [--probe-only] [--probe-dev S] [--probe-layer L] [--probe-pool {last,mean}]
                       [--probe-l2 L] [--student STUDENT] [--init-head {names}] [--warmup-pairs N]
                       [--warmup-epochs E] [--warmup-confidence C] [--epochs EPOCHS]
                       [--val-share S] [--patience PATIENCE] [--batch-size BATCH_SIZE] [--lr LR]
                       [--max-length MAX_LENGTH] [--ce-weight CE_WEIGHT] [--gold-only]
                       [--seeds SEEDS] [--trim-vocab] [--trim-keep K] [--upper-bound]
                       [--gold-file GOLD_FILE] [--gold-per-class K] [--int8]
                       [--teacher-devices TEACHER_DEVICES] [--skip-teacher-bench] [--reps REPS]
                       [--teacher-reps TEACHER_REPS] [--device DEVICE] [--threads THREADS]
                       [--seed SEED] [--live] [--live-port P] [--no-browser] [--budget N]
                       [--rounds R]
                       task

positional arguments:
  task                  task YAML file

options:
  -h, --help            show this help message and exit
  --data DATA           unlabelled texts: .csv, .jsonl or hf:<dataset>[:<config>]:<split>
  --test TEST           optional gold-labelled test set, same formats
  --out OUT             run directory
  --teacher TEACHER     Hugging Face causal LM; several, comma-separated, are ensembled
  --prompts FILES       other task files (other prompts, same label ids in the same order), comma-
                        separated: each teacher also scores every text with each of them, and the
                        label probabilities are averaged (a prompt ensemble; local teachers only)
  --load-4bit           load the teacher in 4 bit (bitsandbytes, CUDA)
  --cache-dir CACHE_DIR
                        where teacher scores are cached (default: the run directory); runs that
                        share it label each text once
  --vllm-url VLLM_URL   score with this vLLM server (OpenAI API base, e.g. http://host:8000/v1),
                        not a local model
  --api-url API_URL     score with a hosted OpenAI-compatible chat API (base URL, e.g.
                        https://api.openai.com/v1; --teacher names the model there): the labels
                        are shown as options A, B, C, ... and scored by the answer letter's log-
                        probability; single-label tasks with at most 20 labels
  --api-key-env VAR     environment variable holding the API key for --api-url (default
                        OPENAI_API_KEY; unset: no key is sent, as for a local server)
  --api-samples N       for APIs without log-probabilities: sample N answers per text (N >= 2, N
                        times the requests) and score each label by its share of the answers
  --api-temperature T   sampling temperature for --api-samples (default 0.7)
  --shortlist K         score only the K labels most similar to each text (for tasks with very
                        many labels)
  --shortlist-model SHORTLIST_MODEL
                        sentence-embedding model for --shortlist (default: MiniLM)
  --shortlist-keep IDS  label ids the teacher always scores besides the shortlist, comma-
                        separated: catch-all labels such as other or out of scope, whose names
                        resemble no particular text
  --few-shot K          show K gold training examples per class in the teacher's prompt (needs
                        {examples} in it); default: with --gold-per-class K, those K, and each
                        text's 16 most similar of them
  --few-shot-similar M  show each text the M gold training examples most similar to it, most
                        similar last (needs {examples} before {text}); with --few-shot K they are
                        picked from those K per class. Default: 16 with --gold-per-class (when the
                        prompt has {examples}), else 0
  --few-shot-sets K     with --few-shot-similar M: score each text K times, set k showing it ranks
                        k*M+1 to (k+1)*M of its most similar gold examples, and average the label
                        probabilities (demonstration ensembling; default 1)
  --few-shot-model FEW_SHOT_MODEL
                        sentence-embedding model for --few-shot-similar (default: MiniLM)
  --reason              the teacher thinks briefly before it answers (greedy, up to --reason-
                        tokens), and the labels are scored after its reasoning; single-label
                        tasks, local or vLLM teachers; much slower
  --reason-tokens K     with --reason: the most tokens the teacher writes before its answer
                        (default 256)
  --teacher-tokens TEACHER_TOKENS
                        tokens per teacher forward pass; short texts with few labels are packed
                        together
  --chunk-tokens T      cut texts longer than T tokens of the student's tokenizer into overlapping
                        windows of T tokens: the teacher scores each window, the student trains on
                        them and averages its windows' probabilities per text when it predicts
                        (for documents longer than the student reads)
  --chunk-stride S      with --chunk-tokens: tokens from one window's start to the next (default T
                        // 2, so windows overlap by half; S = T for no overlap)
  --chunk-tokenizer MODEL
                        with --chunk-tokens: the student whose tokenizer counts the tokens
                        (default: the default student; `run` uses its --student); train warns if
                        its --student differs
  --limit LIMIT         use only the first N training texts
  --test-limit TEST_LIMIT
                        use only the first N test texts
  --dry-run             how long labelling the texts not in the cache yet would take, timed on a
                        sample of them (a local or vLLM teacher), or with --api-url the requests
                        and (approximate) tokens it would take, and with --price-in/--price-out
                        its cost; caches and writes nothing
  --price-in P          with --dry-run: the API's price per million input tokens
  --price-out Q         with --dry-run: the API's price per million output tokens
  --probe               also fit a linear probe on the teacher's hidden state at each text's last
                        token, on the gold labels train uses (--gold-per-class, --gold-file), and
                        add its probabilities to the teacher's (prompt-augmented linear probing);
                        local teachers only. Slower than the default, --probe-only, and a little
                        more accurate; the default with several teachers, --prompts or --few-shot-
                        sets
  --no-probe            do not fit the probe, which is otherwise the default with gold labels and
                        a local teacher: the teacher scores every label
  --probe-only          like --probe, but the probe alone is the teacher: no label is scored, only
                        each text's state, so labelling is much faster; one teacher, no --prompts
                        or --few-shot-sets. The default with gold labels and a local teacher (not
                        with --chunk-tokens or --reason)
  --probe-dev S         with --probe: first fit on all but this share of the gold texts and report
                        teacher accuracy on the rest (in context, probe, combined), then refit on
                        all of them (default 0.2; 0: no report)
  --probe-layer L       with --probe: the probe reads the output of the teacher's layer L (0: the
                        first, -1: the last, -2: the one before) instead of the input of its LM
                        head (the last layer's output, normed)
  --probe-pool {last,mean}
                        with --probe: the state the probe reads, at the text's last token
                        (default) or the mean over the text's own tokens (the text and the prompt
                        after it, not the examples before it)
  --probe-l2 L          with --probe: weight of the L2 penalty on the probe's weights (default
                        0.001)
  --student STUDENT     Hugging Face encoder, or `static` / `static:<encoder>` for a static-
                        embedding student (no attention: much smaller and faster; try --epochs 20
                        --lr 1e-3); <encoder> may be a Model2Vec model such as minishlab/potion-
                        base-8M
  --init-head {names}   `names`: before training, set each label's classifier weights to the
                        student's own embedding of the label's name (and description), so the
                        untrained student ranks labels by similarity to their names (default: a
                        random head)
  --warmup-pairs N      before distillation, train the student's encoder contrastively on N pairs
                        of training texts, half of the same class and half of different classes,
                        as SetFit does: the gold label where a text has one, else the teacher's
                        top label if it is at least --warmup-confidence; single-label tasks only;
                        the gold-only and upper-bound baselines do not warm up (default 0: off)
  --warmup-epochs E     passes over the warm-up pairs (default 1)
  --warmup-confidence C
                        a text without a gold label joins the warm-up if the teacher's top label
                        has at least this probability, with that label as its class (default 0.9)
  --epochs EPOCHS       passes over the training texts (default 10)
  --val-share S         hold out this share of the training texts and keep the epoch with the
                        lowest loss on them, stopping early after --patience epochs without
                        improvement (e.g. 0.05; default: off, keep the last)
  --patience PATIENCE   epochs without improvement before stopping
  --batch-size BATCH_SIZE
  --lr LR
  --max-length MAX_LENGTH
  --ce-weight CE_WEIGHT
                        weight of that cross-entropy term
  --gold-only           also train the student on the K gold labels per class only, without the
                        teacher (a baseline)
  --seeds SEEDS         training seeds per student (mean and std in eval)
  --trim-vocab          before training, cut the student's vocabulary (its embedding matrix and
                        tokenizer) to the tokens of the training and test texts, plus its special
                        tokens and --trim-keep common ones; makes a multilingual student much
                        smaller. A new text's word whose tokens were not kept is split into kept
                        pieces, bytes or the unknown token
  --trim-keep K         with --trim-vocab: also keep the K most frequent tokens of the original
                        vocabulary, for texts with tokens the training texts lack (default 1000)
  --upper-bound         also train the student on all gold training labels, without the teacher
  --gold-file GOLD_FILE
                        gold labels for some training texts (same text and label fields as the
                        task, or a Label Studio JSON export), e.g. the texts `tinydistill suggest`
                        picked, labelled by a person; used like --gold-per-class
  --gold-per-class K    also use the gold labels of K training examples per class (picked with
                        --seed): train adds a cross-entropy term on them, label --probe fits on
                        them
  --int8                also write an int8 dynamically quantised model
  --teacher-devices TEACHER_DEVICES
                        comma-separated devices to time the teacher on (default: the labelling
                        device)
  --skip-teacher-bench  report teacher quality only
  --reps REPS           timed runs per student benchmark at batch 1
  --teacher-reps TEACHER_REPS
                        timed runs of the teacher (batch 1)
  --device DEVICE       auto, cpu or cuda (teacher labelling and training)
  --threads THREADS     CPU threads for torch and onnxruntime
  --seed SEED           seed for example selection and training
  --live                also serve a page on http://127.0.0.1 that shows the run as it goes
                        (stage, time left, loss per epoch, results) and open it in the browser
  --live-port P         the live page's port (default 8765, or the next free one)
  --no-browser          with --live: do not open the browser
  --budget N            the teacher labels only N training texts (for paid APIs): N/R at random,
                        then in each of --rounds R rounds the N/R unlabelled texts the student
                        trained so far is least sure of
  --rounds R            with --budget: rounds; 1 (the default) labels N texts at random, more pick
                        each later round's texts by the student's uncertainty (worse than random
                        on Banking77, see the docs)