Renaissance LabsLearn

Recipes · LoRA SFT + GGUF (Part 2 · Local)

Hemma v0.2 (Part 2): Prelude 9B on expanded Swedish data + on-device GGUF

Part 2 scales our home-forged Prelude 9B Swedish fine-tune to the 27,119-row hemma-sv-sft-v0.2 dataset (2,000 steps, 664.0k supervised tokens, ~1h 35m on Apple M5) with 100% matched hyperparameters against Gemma 4 12B Hemma v0.1. Held-out validation loss drops from 1.815 to 0.869 at step 1,200 (−0.946 nats), Swedish Facts improves from 10.0% to 13.3%, everyday Swedish emails become completely natural, and we document the exact SentencePiece SFT special-token patch required to export clean Prelude GGUF files for Ollama and llama.cpp.

From Renaissance Labs × NAISSRecipe by Birger MoellPart 2 complete on Apple M5 (32 GB). Published on RenaissanceLabsEU and naiss-se Hugging Face orgs in 4-bit MLX and verified Q4_K_M / Q6_K GGUF formats.

CapabilityCost to train

SwedishSupervised fine-tuningLoraMlxPreludeGgufLocal trainingHemma

Makes19.1B MLX + GGUF + LoRA
Runtime1h 35m2,000 steps · 664.0k tok
Best Val Loss0.869↓ from 1.815 (step 1,200)
Swedish Facts13.3%4/30 (highest in suite)

1Ingredients

Identical 27,119-row hemma-sv-sft-v0.2 dataset used for Gemma 4 12B Hemma v0.1 (https://huggingface.co/datasets/RenaissanceLabsEU/hemma-sv-sft-v0.2), enabling a controlled head-to-head comparison between OpenEuroLLM Prelude 9B and Gemma 4 12B on the same Apple M5 laptop.

hemma-sv-sft-v0.2 mixture (25,764 train + 1,355 stratified valid)

2.7× larger than Hemma v0.1, adding Swedish government klarspråk (Öppna statsliggaren & Regeringsuppdrag), Swedish personas v3, explicit grammar A/B discrimination pairs, and 15% English replay.

  • EuroMultiSynth-Instruct (sv, score ≥ 4)openeurollm/EuroMultiSynth-Instruct-decontaminated-v0.1 · svHigh-quality direct Swedish synthetic instructions · Apache-2.0
    8,00029.5%
    Pinned
  • Propella English replay (code & reasoning)openeurollm/Propella-Excellent · en~15% English replay to protect reasoning and code · Apache-2.0
    4,00014.7%
    Pinned
  • Swedish grammaticality repair pairsKeTuTu/swedish-grammaticality-pairs · repairProofreading prompts targeting V2 word order, agreement, and spelling · CC-BY-4.0
    3,00011.1%
    Pinned
  • Öppna statsliggaren (government klarspråk)naiss-se/oppna-statsliggarenNative Swedish public-sector governance prose · CC0-1.0
    3,00011.1%
    Pinned
  • Swedish personas v3 (everyday tasks)naiss-se/swedish-personas-v3Eliminates stiff v0.1 phrasing in everyday Swedish emails · CC-BY-4.0
    3,00011.1%
    Pinned
  • Upphandlingsmyndigheten native QAtomdickson/upphandlingsmyndigheten-qaNative Swedish public procurement QA · CC-BY-4.0
    2,0237.5%
    Pinned
  • Regeringsuppdrag (government assignments)naiss-se/regeringsuppdragSwedish government directives and summaries · CC0-1.0
    2,0007.4%
    Pinned
  • Swedish grammar A/B discriminationKeTuTu/swedish-grammaticality-pairs · A/BMinimal-pair grammaticality discrimination · CC-BY-4.0
    1,0964.0%
    Pinned
  • Unchanged-correct Swedish controlsKeTuTu/swedish-grammaticality-pairs · unchangedPrevents over-editing already-correct Swedish · CC-BY-4.0
    1,0003.7%
    Pinned
SHA-256 fingerprints of hemma-sv-sft-v0.2 splits
train/data_v02/train.jsonl2a15565d8f0e…2ecfee
train/data_v02/valid.jsonlb6d4cc396cfd…3846d6

2Pinned inputs

Everything that must match for a faithful rerun.

Base model
openeurollm/Prelude-SFT-Propella-Excellent-v0.29.1B Qwen3-architecture European base (256k EU SentencePiece tokenizer, 2.08 SV tok/word)
Published training dataset
RenaissanceLabsEU/hemma-sv-sft-v0.225,764 train + 1,355 valid Swedish + replay JSONL (https://huggingface.co/datasets/RenaissanceLabsEU/hemma-sv-sft-v0.2)
Prelude GGUF tokenizer fix
Patch token IDs 3–18 & CONTROL types in GGUF metadataCrucial gotcha: prelude-base tokenizer.model uses <start_of_turn>/<end_of_turn>/<unused_5>, while SFT chat_template uses <|im_start|>/<|im_end|>/<think>
On-device GGUF files
naiss-se/prelude-9b-sv-hemma-v0.2-GGUFQ4_K_M (5.3 GB) & Q6_K (7.0 GB) verified in llama-completion with clean <|im_end|> stop

3Equipment

Identical laptop hardware and hyperparameters as Gemma 4 12B Hemma v0.1. Prelude 9B runs at ~125 tok/s (~10.6 GB peak memory, ~1h 35m for 2,000 steps / 664.0k supervised tokens).

Node 1

4Method

Paths in angle brackets are yours to fill in. Account IDs and personal paths have been removed.

  1. 1

    Train 2,000 steps on hemma-sv-sft-v0.2

    Run 4-bit MLX QLoRA with identical hyperparameters to Gemma 4 12B Hemma v0.1 (lr=1e-5 cosine, rank 16, top 16 layers, mask_prompt: true). Best validation loss hits 0.869 at step 1,200.

    caffeinate -i uvx --from mlx-lm mlx_lm.lora --config ./lora_v02_prelude.yaml
  2. 2

    Export BF16 safetensors and quantize to Q4_K_M & Q6_K GGUF

    Dequantize-fuse the 4-bit MLX base + LoRA adapter, convert via convert_hf_to_gguf.py (using prelude-base's SentencePiece tokenizer.model), and quantize to Q4_K_M (5.3 GB) and Q6_K (7.0 GB).

    llama-quantize prelude-bf16.gguf prelude-9b-sv-hemma-v0.2-Q4_K_M.gguf Q4_K_M
  3. 3

    Patch Prelude SFT special tokens in the GGUF header

    Because prelude-base's tokenizer.model still labels IDs 3, 4, 13–18 as <start_of_turn>, <end_of_turn>, and <unused_0..5>, while Prelude-SFT's chat_template.jinja expects <|im_start|>, <|im_end|>, <tools>, <think>, and </think>, patch those 8 token strings and set IDs 3–10 to CONTROL type.

    python patch_prelude_gguf_tokens.py prelude-9b-sv-hemma-v0.2-Q4_K_M.gguf prelude-9b-sv-hemma-v0.2-Q6_K.gguf

    Check this. Without this patch, llama.cpp emits '<unused_5>' and fails to tokenize <|im_start|> / <|im_end|> as single control tokens.

  4. 4

    Run locally with Ollama or llama.cpp

    Verified in llama-completion with clean <|im_end|> stopping and natural Swedish output at 11.7 tok/s on CPU alone (and 40+ tok/s on Apple Silicon Metal).

    ollama run hf.co/naiss-se/prelude-9b-sv-hemma-v0.2-GGUF:Q4_K_M
Complete Prelude 9B Hemma v0.2 training + token-patched GGUF export script
#!/usr/bin/env bash
# Part 2: Train Prelude 9B Hemma v0.2 on hemma-sv-sft-v0.2 (~1h 35m on Apple M5)
# and export token-verified Q4_K_M + Q6_K GGUF files for Ollama / llama.cpp.
set -euo pipefail

# 1. Train 2,000 steps (matched 1:1 with Gemma 4 12B)
caffeinate -i uvx --from mlx-lm mlx_lm.lora --config ./lora_v02_prelude.yaml

# 2. Evaluate on 64 Sv-BLiMP + 30 Swedish Facts + 4 qualitative probes
caffeinate -i uvx --from mlx-lm --with datasets python micro_sv_eval.py \
  --model ./prelude-excellent-v0.2-4bit \
  --adapter-path ./adapters/prelude-9b-sv-hemma-v0.2 \
  --output-json ./logs/v02_eval_prelude_9b_after.json

# 3. Fuse standalone 4-bit MLX weights
uvx --from mlx-lm mlx_lm.fuse \
  --model ./prelude-excellent-v0.2-4bit \
  --adapter-path ./adapters/prelude-9b-sv-hemma-v0.2 \
  --save-path ./exports/prelude-9b-sv-hemma-v0.2

# 4. Dequantize-fuse to BF16 -> GGUF -> Q4_K_M / Q6_K
uvx --from mlx-lm mlx_lm.fuse \
  --model ./prelude-excellent-v0.2-4bit \
  --adapter-path ./adapters/prelude-9b-sv-hemma-v0.2 \
  --save-path ./tmp_gguf/prelude-hf --dequantize
# Copy prelude-base tokenizer.model, convert to GGUF, quantize, then patch SFT special tokens (IDs 3..18):
python convert_hf_to_gguf.py ./tmp_gguf/prelude-hf --outfile ./tmp_gguf/prelude-bf16.gguf --outtype bf16
llama-quantize ./tmp_gguf/prelude-bf16.gguf ./exports_gguf/prelude-9b-sv-hemma-v0.2-Q4_K_M.gguf Q4_K_M
llama-quantize ./tmp_gguf/prelude-bf16.gguf ./exports_gguf/prelude-9b-sv-hemma-v0.2-Q6_K.gguf Q6_K
python patch_prelude_gguf_tokens.py \
  ./exports_gguf/prelude-9b-sv-hemma-v0.2-Q4_K_M.gguf \
  ./exports_gguf/prelude-9b-sv-hemma-v0.2-Q6_K.gguf

5Settings

Part 2: Home Apple Silicon MLX QLoRA (Matched 1:1 with Gemma 4 12B)

Objective
Causal LM cross-entropy, assistant-only loss (mask_prompt: true)
Adapter
LoRA rank 16, scale 32, dropout 0.05 on top 16 layers (19.40M trainable params = 0.213%)
Learning rate
1.0e-5 cosine decay (100-step warmup from 1e-7, decaying to 1e-6)
Batch & steps
batch_size 1 · grad_accumulation_steps 8 · 2,000 steps · 664.0k supervised tokens (~1h 35m)
Validation loss
1.815 (step 1) → 0.869 (step 1,200, best) → 1.041 (step 2,000) on 30 validation batches

6What you should see

Numbers from the original run, so you can tell early whether yours is on track.

  • Validation loss drops below 0.90Drops from 1.815 (step 1) to 0.869 at step 1,200 (−0.946 nats), finishing at 1.041 at step 2,000.
  • Swedish Facts improves (10.0% → 13.3%)Reaches 4/30 (13.3%) on liu-nlp/swedish-facts-v1 — the highest factual recall in the matched local suite (vs 6.7% for Gemma 4 12B).
  • Natural everyday Swedish proseEliminates both baseline typos ('medduta er', 'gemensammavättstugna') and v0.1's stiff phrasing ('bekväm boendestatus').
  • Verified on-device GGUF tokenizationPatching token IDs 3–18 eliminates <unused_5> artifacts and gives clean <|im_end|> stopping in llama.cpp.
Two-panel chart showing the 27,119-row hemma-sv-sft-v0.2 dataset composition alongside head-to-head Sv-BLiMP and Swedish Facts accuracy for Prelude 9B and Gemma 4 12B.
Matched head-to-head evaluation on hemma-sv-sft-v0.2: Prelude 9B leads Swedish Facts (13.3%), while Gemma 4 12B dominates Sv-BLiMP grammar (95.3%).
Two-panel comparison of validation loss and Apple M5 training throughput/parameters between Gemma 4 12B Hemma v0.1 and Prelude 9B Hemma v0.2.
Validation loss and Apple M5 efficiency across matched 2,000-step QLoRA runs (~664k–680k tokens).
Metric (4-bit MLX)Prelude BasePrelude Hemma v0.1Prelude Hemma v0.2
Training data & tokens—v0.1 (10k rows, 426.9k tok)v0.2 (27.1k rows, 664.0k tok)
Best validation loss (↓)1.815 (v0.2 split)1.434 (v0.1 split)0.869 (step 1,200)
Sv-BLiMP (64 pairs)33/64 (51.6%)32/64 (50.0%)32/64 (50.0%)
Swedish Facts (30 Qs)3/30 (10.0%)3/30 (10.0%)4/30 (13.3%)
Everyday Swedish emailGarbled typosClean, slightly formalNatural, idiomatic Swedish ✓
On-device GGUF (Q4_K_M / Q6_K)——5.3 GB / 7.0 GB (verified ✓)
0.869 (↓ from 1.815)Best validation loss (step 1,200)
13.3% (↑ from 10.0%)Swedish Facts (30 Qs)
5.3 GB (11.7 tok/s CPU)GGUF Q4_K_M footprint
2.08 tok/word (−18% vs Gemma 4)Swedish tokenizer fertility

The matched Part 2 comparison reveals a clear architectural trade-off: Prelude 9B has an 18% more efficient Swedish tokenizer and leads Swedish Facts (13.3% vs 6.7%), while Gemma 4 12B dominates forced-choice Swedish grammar (95.3% vs 50.0% on Sv-BLiMP) and avoids greedy repetition loops. Next steps for Prelude are full-parameter Swedish SFT + DPO on LUMI (project_465002530) and FTPO (antidoom) to eliminate greedy repetition.

7Known gaps

What stands between this card and an exact copy of the run.

  • Prelude 9B remains at 50.0% on forced-choice Sv-BLiMP minimal pairs even after 664k SFT tokens — fixing discriminative grammar requires larger full-parameter SFT + on-policy DPO on LUMI.
  • Greedy decoding on open-ended creative prompts can still trigger repetition loops; applying Liquid4All/antidoom (FTPO) is the planned lightweight fix.
  • Step 1,200 achieved lower validation loss (0.869) than step 2,000 (1.041); both checkpoints are preserved in adapters/ for resumption.

8Variants

No variants yet.

Reproduced it? Changed something? Fixed a problem or added a capability? Report it and it appears here, linked to this recipe.

Report a variant

9Original files

Published on RenaissanceLabsEU/prelude-9b-sv-hemma-v0.2, naiss-se/prelude-9b-sv-hemma-v0.2, and naiss-se/prelude-9b-sv-hemma-v0.2-GGUF.

Background: Head-to-head: Gemma 4 12B Hemma v0.1 recipe. Machine-readable: this recipe as JSON.