Renaissance LabsLearn

Recipes · LoRA SFT (Part 1 · Local)

Hemma v0.1: Training a 9B Swedish model at home on an Apple M5 laptop

Fine-tune OpenEuroLLM's 9.1B Prelude-SFT-Propella-Excellent-v0.2 on 10,023 curated, open-licensed Swedish examples in 50 minutes on a single 32 GB Apple M5 MacBook using 4-bit MLX QLoRA. Validation loss drops from 2.242 to 1.434 (−0.81 nats), garbled Swedish spelling and word-fusion bugs disappear on qualitative probes, and both Swedish JSON keys and non-editing controls stay intact. This is Part 1 — we publish both ready-to-run 4-bit MLX weights and unfused LoRA adapters so we can continue training in Part 2.

From Renaissance LabsRecipe by Birger MoellPart 1 complete on Apple M5 (32 GB). Fused 4-bit MLX weights and unfused LoRA adapters published on Hugging Face for Part 2 continuation.

CapabilityCost to train

SwedishSupervised fine-tuningLoraMlxPreludeLocal trainingHemma

Makes19.1B 4-bit MLX + LoRA
Runtime50 min1,200 steps · 158 tok/s
Equipment1Apple M5 laptop (32 GB)
Ingredients10,0239,522 train · 501 valid

1Ingredients

A compact, zero-contamination Swedish SFT mixture built strictly from open-licensed (CC BY 4.0 / Apache 2.0) sources and published directly as RenaissanceLabsEU/hemma-sv-sft-v0.1 on Hugging Face (https://huggingface.co/datasets/RenaissanceLabsEU/hemma-sv-sft-v0.1). Every example is filtered to ≤ 6,000 characters so sequences fit cleanly inside a 2,048-token laptop budget, and strictly disjoint from our held-out evaluation benchmarks (Tarnyd/sv-blimp and liu-nlp/swedish-facts-v1).

Part 1 Swedish SFT mix (9,522 train + 501 stratified valid)

Three complementary Swedish buckets combining direct Swedish synthesis, native public-sector QA, and targeted grammar repair with unchanged-correct controls so the model learns not to over-edit already-correct Swedish.

  • EuroMultiSynth-Instruct (sv, score ≥ 4)openeurollm/EuroMultiSynth-Instruct-decontaminated-v0.1 · svDirect Swedish synthetic instructions filtered to judge_score ≥ 4.0 · Apache-2.0
    4,50044.9%
    Pinned
  • Swedish grammaticality repair pairsKeTuTu/swedish-grammaticality-pairs · trainWrapped in varied Swedish proofreading prompts targeting V2 word order, agreement, and spelling · CC-BY-4.0
    3,00029.9%
    Pinned
  • Upphandlingsmyndigheten native QAtomdickson/upphandlingsmyndigheten-qa · trainNative-source Swedish public procurement questions and answers · CC-BY-4.0
    2,02320.2%
    Pinned
  • Unchanged-correct Swedish controlsKeTuTu/swedish-grammaticality-pairs · correct -> correctTeaches the model to leave already-correct Swedish sentences untouched when asked to fix only real errors · CC-BY-4.0
    5005.0%
    Pinned
Fingerprints of the training, validation, and before/after micro-eval files (SHA-256)
train/data/train.jsonl31205ac75658…120f17
train/data/valid.jsonle05855ce6115…23c8ad
eval/eval_before.json7d15432454c2…c78bf9
eval/eval_after.json43ac7d82cfa7…e8dd31

2Pinned inputs

Everything that must match for a faithful rerun.

Base model
openeurollm/Prelude-SFT-Propella-Excellent-v0.29.1B dense Qwen3-style model on prelude-anneal300b-256k-rope20m-cont (256k EU tokenizer, 2.08 SV tok/word)
Published training dataset
RenaissanceLabsEU/hemma-sv-sft-v0.1Exact 9,522 train + 501 valid Swedish MLX chat JSONL published under CC BY 4.0 (https://huggingface.co/datasets/RenaissanceLabsEU/hemma-sv-sft-v0.1)
Local 4-bit base
mlx_lm.convert -q --q-bits 44.50 bits/weight (~5.5 GB on disk) — lets a 9.1B model train comfortably inside 32 GB unified memory
Chat template fix
chat_template.jinja line 1 -> default('no_think')Prelude's template raises TemplateError unless thinking_instruction='no_think' is set for non-reasoning targets
Held-out micro-eval
Tarnyd/sv-blimp + liu-nlp/swedish-facts-v1 + 4 probesRuns in <40 seconds on M5 Metal; strictly excluded from training
Software
mlx-lm (via uvx) · Python 3.12 · Hugging Face datasetsZero CUDA required; caffeinate -i keeps macOS awake during unattended runs

3Equipment

A full BF16 SFT of a 9.1B model needs ~85 GB (weights + AdamW states + activations), which OOMs on a laptop. Quantizing the frozen base weights to 4-bit MLX (~5.5 GB) and training rank-16 LoRA adapters on the top 16 layers (19.4M trainable params = 0.213%) with gradient checkpointing brings peak memory down to ~10.6 GB — leaving over 20 GB of headroom on a 32 GB MacBook while running at ~158 tok/s.

Node 1

4Method

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

  1. 1

    Quantize the 9B base model to 4-bit MLX

    Download openeurollm/Prelude-SFT-Propella-Excellent-v0.2 and convert it once to 4-bit MLX (4.50 bits/weight, ~5.5 GB). This is what makes a 9.1B model train comfortably on a 32 GB MacBook without swapping.

    uvx --from mlx-lm mlx_lm.convert \
      --hf-path openeurollm/Prelude-SFT-Propella-Excellent-v0.2 \
      --mlx-path ./prelude-excellent-v0.2-4bit -q --q-bits 4
  2. 2

    Set Prelude's chat template default to /no_think

    Prelude-SFT-Propella-Excellent-v0.2 ships a custom chat_template.jinja that raises TemplateError if an assistant message has no <think> block and thinking_instruction is unset. Setting line 1 to default('no_think') lets mlx_lm.lora apply Prelude's exact native /no_think formatting cleanly.

    sed -i '' "s/default(none)/default('no_think')/" ./prelude-excellent-v0.2-4bit/chat_template.jinja

    Check this. If you skip this line, mlx_lm.lora fails immediately on step 0 with Jinja TemplateError: A target without reasoning requires thinking_instruction=no_think.

  3. 3

    Download (or rebuild) the curated Swedish dataset

    Pull the exact 9,522 train + 501 valid Swedish JSONL directly from RenaissanceLabsEU/hemma-sv-sft-v0.1 (CC BY 4.0), or rebuild it from the 3 upstream sources using prepare_sv_sft_data.py.

    huggingface-cli download RenaissanceLabsEU/hemma-sv-sft-v0.1 --repo-type dataset --local-dir ./data
  4. 4

    Run a <40-second Swedish micro-eval before training

    Score 20 Tarnyd/sv-blimp grammar minimal pairs (across v2_violation, subordinate_word_order, gender_agreement, anaphor_agreement), 15 liu-nlp/swedish-facts-v1 questions, and 4 qualitative Swedish probes so you have an exact before/after reference.

    uvx --from mlx-lm --with datasets python micro_sv_eval.py \
      --model ./prelude-excellent-v0.2-4bit --output-json ./logs/eval_before.json
  5. 5

    Train with caffeinate -i and a conservative learning rate

    Because Prelude-SFT-Propella-Excellent-v0.2 already completed 58.4B tokens of SFT decaying from 8e-5 to 0, use a gentle 1e-5 cosine schedule with assistant-only loss masking. Wrap in caffeinate -i so macOS never sleeps mid-run.

    caffeinate -i uvx --from mlx-lm mlx_lm.lora --config ./lora_config.yaml
  6. 6

    Re-run the micro-eval and fuse the weights

    Verify before/after improvements on the identical /no_think prompts, then fuse into standalone 4-bit MLX weights while keeping the unfused adapters/ folder (including the lowest-val-loss step-800 checkpoint) for Part 2.

    uvx --from mlx-lm mlx_lm.fuse \
      --model ./prelude-excellent-v0.2-4bit \
      --adapter-path ./adapters/prelude-sv-overnight \
      --save-path ./exports/prelude-9b-sv-hemma-v0.1
Complete 'train at home' Apple Silicon MLX QLoRA script (copy & run)
#!/usr/bin/env bash
# Train Hemma v0.1 at home on a 32 GB Apple Silicon MacBook (~50 minutes).
set -euo pipefail

# 1. Quantize Prelude-SFT-Propella-Excellent-v0.2 to 4-bit MLX (~5.5 GB, ~35s)
uvx --from mlx-lm mlx_lm.convert \
  --hf-path openeurollm/Prelude-SFT-Propella-Excellent-v0.2 \
  --mlx-path ./prelude-excellent-v0.2-4bit -q --q-bits 4

# 2. Default Prelude's custom template to /no_think for non-reasoning SFT targets
sed -i '' "s/default(none)/default('no_think')/" ./prelude-excellent-v0.2-4bit/chat_template.jinja

# 3. Build the 10,023-row curated Swedish dataset (train.jsonl + valid.jsonl)
python3 prepare_sv_sft_data.py

# 4. Run the <40s baseline Swedish micro-eval before training
caffeinate -i uvx --from mlx-lm --with datasets python micro_sv_eval.py \
  --model ./prelude-excellent-v0.2-4bit \
  --output-json ./logs/eval_before.json

# 5. Train 4-bit MLX QLoRA (1,200 steps, ~158 tok/s, ~50 min on Apple M5)
caffeinate -i uvx --from mlx-lm mlx_lm.lora --config ./lora_config.yaml

# 6. Run the exact same <40s Swedish micro-eval with the trained adapter
caffeinate -i uvx --from mlx-lm --with datasets python micro_sv_eval.py \
  --model ./prelude-excellent-v0.2-4bit \
  --adapter-path ./adapters/prelude-sv-overnight \
  --output-json ./logs/eval_after.json

# 7. Fuse LoRA into standalone 4-bit MLX weights (~20s)
uvx --from mlx-lm mlx_lm.fuse \
  --model ./prelude-excellent-v0.2-4bit \
  --adapter-path ./adapters/prelude-sv-overnight \
  --save-path ./exports/prelude-9b-sv-hemma-v0.1

5Settings

Part 1: Home Apple Silicon MLX QLoRA

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.399M trainable params = 0.213%)
Learning rate
1.0e-5 cosine decay (60-step warmup from 1e-7, decaying to 1e-6) — intentionally low to preserve Prelude's 58.4B-token SFT calibration
Batch & steps
batch_size 1 · grad_accumulation_steps 8 · 1,200 steps · 426.9k supervised tokens (~50 minutes)
Max sequence length
2,048 tokens with grad_checkpoint: true
Validation loss
2.242 (step 1) → 1.434 (step 800, best) → 1.565 (step 1,200) on 25 validation batches

6What you should see

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

  • Validation loss convergenceDrops smoothly from 2.242 (step 1) to 1.434 at step 800 (−0.81 nats), finishing at 1.565 at step 1,200.
  • Garbled Swedish spelling eliminatedBaseline errors like 'medduta er', 'gemensammavättstugna', 'ochförtroendet', and 'yrket ni gör' disappear completely in Hemma v0.1.
  • Zero regressions on controlsBoth no_overedit (leaving correct Swedish untouched) and sv_json (exact Swedish keys myndighet/datum/belopp_sek) remain 100% intact.
  • Home hardware throughputSustains ~158 tok/s on Apple M5 (~10.6 GB peak unified memory, 50 minutes total wall-clock).
Two-panel chart showing how 4-bit MLX QLoRA fits a 9.1B model into 10.6 GB on a 32 GB MacBook alongside a donut chart of the 10,023-example curated Swedish SFT mix.
How to train a 9B Swedish model at home: 4-bit MLX QLoRA reduces memory from ~85 GB (full BF16 AdamW) to ~10.6 GB peak on a 32 GB Apple Silicon MacBook, trained on a zero-contamination 10,023-row Swedish mix.
Two-panel chart showing Hemma v0.1's training and validation loss curve dropping from 2.242 to 1.434 at step 800, next to a Swedish tokenizer fertility bar chart comparing Prelude 9B, Inkling-2-Mini, and Gemma 4 31B.
Left: Train and validation cross-entropy over 1,200 steps (426.9k tokens, ~50 minutes on Apple M5, best val 1.434 at step 800). Right: Prelude's 256k EU tokenizer uses ~18% fewer tokens on general Swedish and ~27% fewer on Swedish compound words than Gemma 4 31B.
Side-by-side visual comparison of baseline Prelude-SFT-Propella-Excellent-v0.2 vs Hemma v0.1 outputs on a Swedish BRF email and an Offentlighetsprincipen plain-language explanation.
Before vs. after qualitative Swedish outputs (/no_think). Hemma v0.1 eliminates baseline word-fusion and garbled-word errors ('medduta er', 'gemensammavättstugna', 'ochförtroendet') while preserving non-editing and Swedish JSON controls.
Probe / Metric (/no_think, 4-bit MLX)Baseline (Propella-Excellent-v0.2)Hemma v0.1 (50-min M5 QLoRA)
Validation loss (25 batches, ↓)2.242 (step 1)1.434 (step 800) / 1.565 (step 1,200)
Sv-BLiMP (20 grammar minimal pairs)10/20 (50.0%)10/20 (50.0%)
Swedish Facts (15 short-answer Qs)1/15 (6.7%)1/15 (6.7%)
plain_gov (Offentlighetsprincipen, ≤3 sent.)Clunky; fused typo 'ochförtroendet'Clean, natural 3-sentence Swedish
natural_email (BRF laundry dryer)Garbled: 'medduta er', 'gemensammavättstugna', 'yrket ni gör'Zero garbled words; coherent Swedish email
no_overedit (already-correct Swedish)Exact unchanged sentence ✓Exact unchanged sentence ✓
sv_json (myndighet / datum / belopp_sek)Valid Swedish JSON keys ✓Valid Swedish JSON keys ✓
1.434 (↓ from 2.242)Best validation loss (step 800)
~158 tok/s (50 min)Training throughput (Apple M5)
2.08 tok/word (−18% vs Gemma 4)Swedish tokenizer fertility
19.4M (0.213% LoRA)Trainable parameters

Part 1 proves that a 50-minute home laptop QLoRA pass (427k tokens) dramatically cleans up Prelude's surface Swedish fluency and eliminates word-fusion typos without breaking structured JSON or non-editing controls. Quantitative discrimination on Sv-BLiMP (10/20 = 50.0%) and factual recall on Swedish Facts (1/15 = 6.7%) stayed flat at this small token budget — motivating Part 2 (longer multi-epoch local continuation + full-parameter 200k-row Swedish SFT and on-policy DPO on LUMI).

7Known gaps

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

  • Part 1 trained on only 426.9k tokens (~12% of the 9,522-row training file) with 19.4M LoRA parameters: surface Swedish fluency jumped sharply, but grammar discrimination (Sv-BLiMP 50%) and factual recall (Swedish Facts 6.7%) did not move yet.
  • Stylistic polish is still slightly formal in everyday emails (e.g. 'bekväm boendestatus') — Part 2 will add persona-conditioned everyday Swedish tasks (naiss-se/swedish-personas-v3) and on-policy Swedish DPO.
  • Step 800 achieved the lowest validation loss (1.434 vs 1.565 at step 1,200); both 0000800_adapters.safetensors and final adapters.safetensors are published in adapters/ so Part 2 can resume from either.
  • Full 15-dataset EuroEval Swedish BF16 evaluation is queued on LUMI (project_465002530) and will serve as the reference benchmark for Part 2.

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

Artifacts published in the public Hugging Face model repository (RenaissanceLabsEU/prelude-9b-sv-hemma-v0.1).

Background: All Renaissance Labs training recipes. Machine-readable: this recipe as JSON.