Recipes · SFT + preference tuning
SFT warm start, then on-policy DPO, against hallucination
Take a 9B model that invents an answer for 98% of made-up names. Fine-tune it on honest answers for 12 minutes, then run a short DPO round on its own mistakes. Fabrication falls to 2%.
From OpenEuroLLMRecipe by Birger MoellRun once by its author. Not yet reproduced by anyone else.
1Ingredients
Two training sets, both published row for row. The first teaches the behaviour with supervised fine-tuning. The second corrects it with preference pairs built from the warm-started model's own answers.
Stage 1: SFT warm start
6,123 conversations: 5,960 for training and 163 for validation. Answers are 35% of the hallucination rows, the guard against refusing too much.
- Honest “I don't know” answers
sft-warmstart/sft-*.jsonl.gz · part abstainHalf A of the question pool; most written by gemma-4-31B-it · questions from Wikidata, CC01,38022.5%Pinned - Correct answers it knows
sft-warmstart/sft-*.jsonl.gz · part answerKnown and sharpen cases · questions from Wikidata, CC04086.7%Pinned - CoCoNot false-premise answers
allenai/coconot · config prefSo real things are not called non-existent · ODC-By3355.5%Pinned - Identity
openeurollm/openeurollm-model-identityVersion 3.1.0, ten languages · CC BY 4.01,00016.3%Pinned - General replies
Dolci translated · UltraFeedback · HelpSteer3Chosen sides of preference pairs (2,803 / 127 / 70) · Apache 2.0, MIT, CC BY 4.03,00049.0%Pinned
Stage 2: DPO round 2
1,918 training pairs and 104 for validation in the files. The model card reports 1,896 and 101 in training, after tokenization.
- On-policy hallucination pairs
round2-dpo/mix/natural-halu-*.jsonl.gzFrom half B of the pool, sampled from the warm-started model · questions from Wikidata, CC058330.4%Pinned - CoCoNot contrast pairs
round2-dpo/mix/coconot-*.jsonl.gzFalse-premise pairs, checked by gemma-4-31B-it · ODC-By33517.5%Pinned - General preference pairs
round2-dpo/mix/general-*.jsonl.gzDolci translated 934, UltraFeedback 45, HelpSteer3 21 · Apache 2.0, MIT, CC BY 4.01,00052.1%Pinned
Fingerprints of the eight training files (SHA-256)
sft-warmstart/sft-train.jsonl.gz | f666fa7a4c51…b71f2a |
sft-warmstart/sft-validation.jsonl.gz | 5b966c7a3876…5f8ae0 |
round2-dpo/mix/natural-halu-train.jsonl.gz | 9c4be5cfb907…24655c |
round2-dpo/mix/natural-halu-validation.jsonl.gz | c23c0fdffe52…d18b0f |
round2-dpo/mix/coconot-train.jsonl.gz | 541222fea3f1…0991cf |
round2-dpo/mix/coconot-validation.jsonl.gz | 33019c0adf88…400b73 |
round2-dpo/mix/general-train.jsonl.gz | 60f9f8baf077…c0ec45 |
round2-dpo/mix/general-validation.jsonl.gz | db88b1cb1e0c…80d3a9 |
2Pinned inputs
Everything that must match for a faithful rerun.
- Base model
marianna13/prelude-9b-sft-v2revision 8670e89bb59dd491480a5c980179eed3083af9f3- Training data
birgermoell/prelude-9b-sft-v2-hallucination-r2-datarevision ebf8f1e1220e65cbbfad0926dcace237e1897385 (as of 2026-11-21)- Pipeline code
github.com/BirgerMoell/oellm-hallucinationmain at 60465ee (19 November 2026)- Judge and writer
google/gemma-4-31B-itlabels samples, writes and checks preferred answers, grades the benchmark- Auditor
Qwen3.5-27Bsecond judge from another model family- Software
TRL (DPO trainer) · vLLM 0.24.0 · Transformers 5.9.0vLLM and Transformers versions are those of the benchmark run
3Equipment
Both training stages ran on 2 nodes with 4 A100 64 GB GPUs each (Leonardo, CINECA). The SFT stage took 12 minutes. The DPO stage is 15 optimizer steps. Building the pairs needs one more node with 2 GPUs, for sampling and for the judge.
4Method
Paths in angle brackets are yours to fill in. Account IDs and personal paths have been removed.
- 1
Get the code and the data
The dataset holds the exact training rows for both stages, so you do not need to rebuild them.
git clone https://github.com/BirgerMoell/oellm-hallucination hf download birgermoell/prelude-9b-sft-v2-hallucination-r2-data --repo-type dataset \ --revision ebf8f1e1220e65cbbfad0926dcace237e1897385 --local-dir <DATA> - 2
Get the base model
Download the base model at the revision the run started from.
hf download marianna13/prelude-9b-sft-v2 \ --revision 8670e89bb59dd491480a5c980179eed3083af9f3 --local-dir <MODELS>/prelude-9b-sft-v2 - 3
Tokenize the SFT set
Each assistant turn becomes one example: the generation prompt as the model sees it in default mode, then the reply and the end-of-turn token. Only the reply is supervised.
python oellm-hallucination/train/pretok_sft.py --rows <DATA>/sft-warmstart \ --tokenizer <MODELS>/prelude-9b-sft-v2 --out <WORK>/warmstart/pretok - 4
Train the warm start
Supervised fine-tuning on the tokenized set. Use your own trainer with these settings.
# assistant-only loss · 2 epochs · learning rate 5e-6 · packed to 16K tokens # 2 nodes x 4 A100 64 GB · about 12 minutes # save the result as <MODELS>/warmstartCheck this. The launch script and trainer config for this stage are not published. The settings above are from the model card.
- 5
Check before going on
Run the benchmark on the warm-started model (step 8). Fabrication should already be near 4%. Expect it to decline about a quarter of the questions about well-known people. The next stage is meant to correct that.
# original run after this stage: fabrication 3.6%, good "I don't know" 96.4%, # abstains on 27.5% of well-known people, 98.2% of answers in the right language - 6
Tokenize the DPO pairs
Tokenize the released round-2 mix with the model's own chat template. Concat mode builds each answer the way the model produces it at inference.
python oellm-hallucination/train/pretok_pairs.py --staged <DATA>/round2-dpo/mix \ --tokenizer <MODELS>/warmstart --out <WORK>/dpo-r2/pretok --mode concatCheck this. The files hold 1,918 training pairs and the model card reports 1,896. The script drops pairs over 2,048 tokens, which would explain the difference. Compare with the manifest.json it writes.
- 7
Train DPO round 2
One short epoch of DPO on the warm-started model, with an SFT term on the preferred answer.
# TRL DPO · loss_type [sigmoid, sft], weights 1.0 / 0.5 · beta 0.1 # learning rate 3e-6, cosine, 10% warmup · 1 epoch (15 steps) · global batch 128 # max length 2,048 · bf16 · FSDP · 2 nodes x 4 A100 64 GBCheck this. The launch script and trainer config for this stage are not published either.
- 8
Run the benchmark
500 questions in default and thinking mode, graded by gemma-4-31B-it. One node with 2 GPUs.
MODELS="base=<MODELS>/prelude-9b-sft-v2 r2=<MODELS>/dpo-r2" \ JUDGE=<MODELS>/gemma-4-31B-it PYTHON=<python with vLLM 0.24 or later> \ sbatch --account=<your-project> --partition=<gpu partition> --export=ALL \ oellm-hallucination/benchmark/run_slurm.sbatch
Optional: the job that rebuilds the pairs (sample, judge, curate, pair, audit)
#!/bin/bash
#SBATCH --job-name=halu-pairs
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --gpus-per-node=2
#SBATCH --cpus-per-task=16
#SBATCH --mem=200G
#SBATCH --time=10:00:00
#SBATCH --output=halu-pairs-%j.out
# On-policy DPO data on one node with 2 GPUs: sample the policy (one shard per GPU), judge every sample (2 GPUs),
# check the chosen candidates and write the missing ones (2 GPUs), build the pairs. Each step is skipped when its output exists, so
# a resubmitted job continues. Everything site-specific comes from the environment:
#
# POLICY=/path/to/model the model to be trained
# POOL=data/train/pool.jsonl questions (train/build_pool.py)
# JUDGE=/path/to/gemma-4-31B-it judge and writer
# PYTHON=/path/to/python an environment with vLLM (>= 0.24 for Gemma 4) and transformers
# CONTAINER=/path/to/image.sif optional: run python inside this Apptainer/Singularity image
# BINDS=/a,/b optional: container bind paths (default: the working dir, judge and policy dirs)
# OUT=runs/<name> output directory; K=8 samples per question
# KNOWN_SHARE=0.35 minimum share of answer pairs (known + sharpen) among the hallucination pairs
# AUDIT_JUDGE=/path/to/Qwen3.5-27B optional: audit the pairs (audit_pairs.py) with a second judge from another family
#
# sbatch --account=<account> --partition=<gpu partition> --export=ALL train/run_slurm.sbatch
set -euo pipefail
: "${POLICY:?}" "${POOL:?}" "${JUDGE:?}" "${PYTHON:?}" "${OUT:?}"
K=${K:-8}
HERE=$(cd "$(dirname "$0")" && pwd)
[[ -f "$HERE/sample.py" ]] || HERE=$SLURM_SUBMIT_DIR/train
BENCH=$HERE/../benchmark
py() {
if [[ -n ${CONTAINER:-} ]]; then
$(command -v apptainer || command -v singularity) exec --nv \
-B "${BINDS:-$PWD,$(dirname "$JUDGE"),$(dirname "$POLICY")}" "$CONTAINER" \
env HF_HUB_OFFLINE=1 VLLM_NO_USAGE_STATS=1 "$PYTHON" "$@"
else
HF_HUB_OFFLINE=1 VLLM_NO_USAGE_STATS=1 "$PYTHON" "$@"
fi
}
mkdir -p "$OUT"
if [[ ! -s $OUT/samples.jsonl ]]; then
echo "== sample $(date)"
for g in 0 1; do
CUDA_VISIBLE_DEVICES=$g py "$HERE/sample.py" --pool "$POOL" --model "$POLICY" --k "$K" --shard "$g/2" \
--out "$OUT/samples-$g.jsonl" &
done
wait
cat "$OUT/samples-0.jsonl" "$OUT/samples-1.jsonl" > "$OUT/samples.jsonl"
fi
if [[ ! -s $OUT/judged.jsonl ]]; then
echo "== judge $(date)"
py "$BENCH/judge.py" --answers "$OUT/samples.jsonl" --judge "$JUDGE" --tp 2 --out "$OUT/judged.jsonl"
fi
if [[ ! -s $OUT/curated.jsonl ]]; then
echo "== curate $(date)"
py "$HERE/build_pairs.py" curate --judged "$OUT/judged.jsonl" --writer "$JUDGE" --tp 2 --out "$OUT/curated.jsonl"
fi
echo "== pairs $(date)"
py "$HERE/build_pairs.py" pairs --judged "$OUT/judged.jsonl" --curated "$OUT/curated.jsonl" --out-dir "$OUT/pairs" \
--known-share "${KNOWN_SHARE:-0.35}"
if [[ -n ${AUDIT_JUDGE:-} ]]; then
echo "== audit $(date)"
py "$HERE/audit_pairs.py" checks --pairs "$OUT/pairs" --pool "$POOL"
py "$HERE/audit_pairs.py" judge --pairs "$OUT/pairs" --pool "$POOL" --judge "$AUDIT_JUDGE" --tp 2 --per-cell "${AUDIT_PER_CELL:-30}"
fi
echo "== done $(date)"
5Settings
Stage 1: SFT warm start
- Objective
- Supervised, loss on assistant tokens only
- Epochs
- 2
- Learning rate
- 5e-6
- Packing
- To 16K tokens
- Mode
- Default mode, with the empty think block the model sees at inference
- Validation loss
- 1.06 → 0.73
Stage 2: DPO round 2
- Objective
- TRL DPO, sigmoid loss plus SFT loss on the chosen answer (weights 1.0 and 0.5)
- Beta
- 0.1
- Learning rate
- 3e-6, cosine, 10% warmup
- Epochs
- 1 (15 steps)
- Global batch
- 128
- Max length
- 2,048 tokens
- Precision
- bf16, FSDP
- Held-out reward accuracy
- 82%
Building the pairs
- Samples
- 8 answers per question, temperature 0.7, top-p 0.95
- Unknown
- Right in fewer than half the samples: prefer an honest “I'm not sure”
- Sharpen
- Right in 50 to 75%: prefer a concise correct answer
- Known
- Right in at least 75%: prefer the answer over a refusal
- Answer share
- At least 35% of the hallucination pairs
- Audit
- 40 pairs per case, both answers in random order
6What you should see
Numbers from the original run, so you can tell early whether yours is on track.
- Base modelFabrication 97.7% on made-up subjects. Never abstains.
- After the warm startFabrication 3.6%. Abstains on 27.5% of well-known people.
- After DPO round 2Fabrication 1.8% in default mode, 2.3% in thinking mode.
- Well-known people53.8% correct including partly correct. 31 of 80 declined.

| Default mode, 500 questions, 10 languages | Prelude-9B-SFT-v2 | After both stages |
|---|---|---|
| Fabrication on made-up subjects | 97.7% | 1.8% |
| Good “I don't know” on made-up subjects | 2.3% | 98.2% |
| Obscure real people: answered wrongly | 100% | 2.5% |
| Well-known people: correct (incl. partly correct) | 53.8% | 53.8% |
| Well-known people: wrong answers (of 80) | 35 | 6 |
| Well-known people: abstains | 0% | 38.8% |
| Answers in the question's language | 97.0% | 97.6% |
| Truthfulness (correct − wrong − fabricated) | −85.2 | +3.8 |
Benchmark numbers in default mode from the original run: one greedy answer per question, graded by an LLM judge. A difference of a few points is noise. No training loss curve is published for this run.
7Known gaps
What stands between this card and an exact copy of the run.
- The launch scripts and trainer configs for the two training stages are not published. Their settings come from the model card.
- Library versions and seeds for the training stages are not stated. The wall time of the DPO stage is not stated either.
- Rebuilding the pairs gives similar, not identical, data: sampling and the LLM judge are stochastic. Use the released files for a faithful rerun.
- The general preference pairs were sampled from a staged set on the original cluster. The sampled rows are published, the staged set is not.
- The scripts take every site-specific value from environment variables. You supply the account, partition, Python environment and model paths.
- Only the hallucination benchmark has been run on the result. Maths, code, tool use and long context were not measured.
- No licence is stated for the base model. The checkpoint is shared on the same terms.
8Variants
Reproduced it? Changed something? Fixed a problem or added a capability? Report it and it appears here, linked to this recipe.
Report a variant9Original files
The scripts in the public repository. They take site-specific values from the environment, so they contain no cluster paths.
Background: Teaching a 9B model to say “I don't know”. Machine-readable: this recipe as JSON.