Renaissance LabsLearn

Recipes · LoRA SFT + GGUF (Local)

Hemma on Gemma 4 12B: Pushing Swedish grammar to 95.3% Sv-BLiMP at home

Apply the Hemma Swedish SFT brand to Google's Gemma 4 12B Instruct on 27,119 curated, open-licensed Swedish and replay examples (RenaissanceLabsEU/hemma-sv-sft-v0.2) in ~1h 40m on a single 32 GB Apple M5 MacBook. Held-out validation loss drops from 4.319 to 1.059 (−3.26 nats), Swedish grammaticality on all 16 Tarnyd/sv-blimp phenomena jumps from 87.5% (56/64) to 95.3% (61/64), and we export both 4-bit MLX weights and on-device Q4_K_M / Q6_K GGUF files using llama.cpp 1.0.0.

From Renaissance Labs × NAISSRecipe by Birger MoellComplete on Apple M5 (32 GB). Published on RenaissanceLabsEU and naiss-se Hugging Face orgs in both 4-bit MLX and on-device GGUF formats.

CapabilityCost to train

SwedishSupervised fine-tuningLoraMlxGemma4GgufLocal trainingHemma

Makes112B MLX + GGUF + LoRA
Runtime1h 40m2,000 steps · 679.9k tok
Equipment1Apple M5 laptop (32 GB)
Sv-BLiMP95.3%61/64 (+7.8 pp vs base)

1Ingredients

A 27,119-row, zero-contamination Swedish + replay SFT mixture published as RenaissanceLabsEU/hemma-sv-sft-v0.2 (https://huggingface.co/datasets/RenaissanceLabsEU/hemma-sv-sft-v0.2, CC BY 4.0 / Apache 2.0 / CC0). Every source is audited for licence and provenance (excluding COURTS, JO, and smol-smoltalk-swedish), and strictly disjoint from our held-out benchmarks (Tarnyd/sv-blimp and liu-nlp/swedish-facts-v1).

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

Nine complementary buckets combining direct Swedish instruction synthesis, Swedish grammar repair and A/B discrimination, native Swedish government klarspråk, persona-grounded everyday tasks, and 15% English reasoning/code replay to prevent catastrophic forgetting.

  • EuroMultiSynth-Instruct (sv, score ≥ 4)openeurollm/EuroMultiSynth-Instruct-decontaminated-v0.1 · svHigh-quality direct Swedish instruction synthesis · Apache-2.0
    8,00029.5%
    Pinned
  • Propella English replay (code & reasoning)openeurollm/Propella-Excellent · en~15% English replay to protect general reasoning and coding capability · Apache-2.0
    4,00014.7%
    Pinned
  • Swedish grammaticality repair pairsKeTuTu/swedish-grammaticality-pairs · repairProofreading prompts targeting V2 word order, gender agreement, and spelling · CC-BY-4.0
    3,00011.1%
    Pinned
  • Öppna statsliggaren (government klarspråk)naiss-se/oppna-statsliggarenNative Swedish public-sector budget & agency governance prose · CC0-1.0
    3,00011.1%
    Pinned
  • Swedish personas v3 (everyday tasks)naiss-se/swedish-personas-v3Natural, everyday Swedish persona-conditioned writing and dialogue · CC-BY-4.0
    3,00011.1%
    Pinned
  • Upphandlingsmyndigheten native QAtomdickson/upphandlingsmyndigheten-qaNative Swedish public procurement questions and answers · CC-BY-4.0
    2,0237.5%
    Pinned
  • Regeringsuppdrag (government assignments)naiss-se/regeringsuppdragSwedish government directives and plain-language summaries · CC0-1.0
    2,0007.4%
    Pinned
  • Swedish grammar A/B discriminationKeTuTu/swedish-grammaticality-pairs · A/BExplicit minimal-pair discrimination between grammatical and ungrammatical Swedish · CC-BY-4.0
    1,0964.0%
    Pinned
  • Unchanged-correct Swedish controlsKeTuTu/swedish-grammaticality-pairs · unchangedTeaches the model not to over-edit already-correct Swedish sentences · CC-BY-4.0
    1,0003.7%
    Pinned
SHA-256 fingerprints of the hemma-sv-sft-v0.2 dataset 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
mlx-community/gemma-4-12B-it-4bit (google/gemma-4-12B-it)12B Gemma 4 Unified model quantized to 4-bit MLX (~7.2 GB on disk)
Published training dataset
RenaissanceLabsEU/hemma-sv-sft-v0.225,764 train + 1,355 valid Swedish + replay chat JSONL (https://huggingface.co/datasets/RenaissanceLabsEU/hemma-sv-sft-v0.2)
Held-out micro-eval
Tarnyd/sv-blimp (64 pairs, all 16 configs) + liu-nlp/swedish-facts-v1 (30 Qs) + 4 probesRuns in ~92 seconds on M5 Metal; strictly excluded from training
On-device GGUF export
llama.cpp 1.0.0 (convert_hf_to_gguf.py + llama-quantize)Native Gemma4UnifiedForConditionalGeneration support (Q4_K_M & Q6_K) for Ollama / llama.cpp / LM Studio
Software
mlx-lm (via uvx) · Python 3.12 · llama.cpp 1.0.0Zero CUDA required; caffeinate -i keeps macOS awake during unattended runs

3Equipment

Training rank-16 LoRA adapters on the top 16 layers of 4-bit Gemma 4 12B (21.86M trainable parameters = 0.184%) with gradient checkpointing fits inside ~13 GB peak unified memory on a 32 GB MacBook and sustains ~115 tok/s (~1h 40m for 2,000 steps / 679.9k tokens).

Node 1

4Method

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

  1. 1

    Download hemma-sv-sft-v0.2

    Pull the 25,764 train + 1,355 valid Swedish + English replay JSONL directly from RenaissanceLabsEU/hemma-sv-sft-v0.2.

    huggingface-cli download RenaissanceLabsEU/hemma-sv-sft-v0.2 --repo-type dataset --local-dir ./data_v02
  2. 2

    Run the 90-second baseline Swedish micro-eval

    Score all 16 Tarnyd/sv-blimp grammar phenomena (64 minimal pairs), 30 liu-nlp/swedish-facts-v1 short-answer questions, and 4 qualitative Swedish probes before training.

    uvx --from mlx-lm --with datasets python micro_sv_eval.py \
      --model mlx-community/gemma-4-12B-it-4bit --output-json ./logs/v02_eval_gemma4_12b_before.json
  3. 3

    Train 2,000 steps of 4-bit MLX QLoRA

    Train rank-16 LoRA on the top 16 layers with lr=1e-5 cosine decay, assistant-only loss masking, and gradient checkpointing (~679.9k tokens, ~1h 40m on Apple M5).

    caffeinate -i uvx --from mlx-lm mlx_lm.lora --config ./lora_v02_gemma4_12b.yaml
  4. 4

    Verify Swedish grammar gain and fuse MLX weights

    Re-run the identical micro-eval (Sv-BLiMP jumps 87.5% → 95.3%), then fuse into standalone 4-bit MLX weights while preserving the unfused adapters/ folder.

    uvx --from mlx-lm mlx_lm.fuse \
      --model mlx-community/gemma-4-12B-it-4bit \
      --adapter-path ./adapters/gemma-4-12b-sv-hemma-v0.1 \
      --save-path ./exports/gemma-4-12b-sv-hemma-v0.1
  5. 5

    Export on-device GGUF (Q4_K_M & Q6_K) with llama.cpp 1.0.0

    Dequantize-fuse to BF16 safetensors, convert with llama.cpp 1.0.0 (which adds native Gemma4UnifiedForConditionalGeneration support), and quantize to Q4_K_M and Q6_K for Ollama / llama.cpp / LM Studio.

    ollama run hf.co/naiss-se/gemma-4-12b-sv-hemma-v0.1-GGUF:Q4_K_M

    Check this. Older llama.cpp builds (pre-1.0.0) fail with 'Model Gemma4UnifiedForConditionalGeneration is not supported'. Upgrade to llama.cpp >= 1.0.0.

Complete Gemma 4 12B Hemma v0.1 training + GGUF export script (Apple Silicon)
#!/usr/bin/env bash
# Train Hemma on Gemma 4 12B at home on a 32 GB Apple Silicon MacBook (~1h 40m)
# and export both 4-bit MLX and on-device GGUF (Q4_K_M + Q6_K).
set -euo pipefail

# 1. Download hemma-sv-sft-v0.2 (25,764 train + 1,355 valid)
huggingface-cli download RenaissanceLabsEU/hemma-sv-sft-v0.2 \
  --repo-type dataset --local-dir ./data_v02

# 2. Baseline micro-eval (64 Sv-BLiMP + 30 Swedish Facts + 4 probes)
caffeinate -i uvx --from mlx-lm --with datasets python micro_sv_eval.py \
  --model mlx-community/gemma-4-12B-it-4bit \
  --output-json ./logs/v02_eval_gemma4_12b_before.json

# 3. Train 4-bit MLX QLoRA (2,000 steps, ~115 tok/s, ~1h 40m on Apple M5)
caffeinate -i uvx --from mlx-lm mlx_lm.lora --config ./lora_v02_gemma4_12b.yaml

# 4. Post-training micro-eval
caffeinate -i uvx --from mlx-lm --with datasets python micro_sv_eval.py \
  --model mlx-community/gemma-4-12B-it-4bit \
  --adapter-path ./adapters/gemma-4-12b-sv-hemma-v0.1 \
  --output-json ./logs/v02_eval_gemma4_12b_after.json

# 5. Fuse 4-bit MLX release weights
uvx --from mlx-lm mlx_lm.fuse \
  --model mlx-community/gemma-4-12B-it-4bit \
  --adapter-path ./adapters/gemma-4-12b-sv-hemma-v0.1 \
  --save-path ./exports/gemma-4-12b-sv-hemma-v0.1

# 6. Export on-device GGUF (requires llama.cpp >= 1.0.0)
uvx --from mlx-lm mlx_lm.fuse \
  --model mlx-community/gemma-4-12B-it-4bit \
  --adapter-path ./adapters/gemma-4-12b-sv-hemma-v0.1 \
  --save-path ./tmp_gguf/gemma4-hf --dequantize
python convert_hf_to_gguf.py ./tmp_gguf/gemma4-hf --outfile ./tmp_gguf/gemma4-bf16.gguf --outtype bf16
llama-quantize ./tmp_gguf/gemma4-bf16.gguf ./exports_gguf/gemma-4-12b-sv-hemma-v0.1-Q4_K_M.gguf Q4_K_M
llama-quantize ./tmp_gguf/gemma4-bf16.gguf ./exports_gguf/gemma-4-12b-sv-hemma-v0.1-Q6_K.gguf Q6_K

5Settings

Home Apple Silicon MLX QLoRA (Matched 1:1 with Prelude v0.2)

Objective
Causal LM cross-entropy, assistant-only loss (mask_prompt: true)
Adapter
LoRA rank 16, scale 32, dropout 0.05 on top 16 layers (21.86M trainable params = 0.184%)
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 · 679.9k supervised tokens (~1h 40m)
Max sequence length
2,048 tokens with grad_checkpoint: true
Validation loss
4.319 (step 1) → 1.059 (step 2,000) on 30 validation batches (−3.260 nats)

6What you should see

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

  • Validation loss convergenceDrops sharply from 4.319 (step 1) to 1.059 (step 2,000) across 30 held-out Swedish validation batches (−3.260 nats).
  • Sv-BLiMP grammar jump (+7.8 pp)Improves from 56/64 (87.5%) to 61/64 (95.3%) across all 16 Swedish grammar phenomena on Tarnyd/sv-blimp.
  • Zero regressions on controls & codePreserves exact non-editing control, valid Swedish JSON schema keys, native-grade Swedish prose, and clean Swedish Python code with zero greedy doom loops.
  • On-device GGUF compatibilityCleanly converts all 667 tensors via llama.cpp 1.0.0 (Gemma4UnifiedModel) into Q4_K_M and Q6_K GGUF files.
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.
Left: The 27,119-row open-licensed hemma-sv-sft-v0.2 SFT mixture (9 buckets, including 15% English replay). Right: Matched 4-bit MLX micro-eval showing Gemma 4 12B jumping from 87.5% to 95.3% on Sv-BLiMP while Prelude 9B leads Swedish Facts (13.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.
Matched 2,000-step Apple M5 QLoRA runs (~680k tokens each). Gemma 4 12B drops val loss 4.319 → 1.059 and gains +7.8 pp on Sv-BLiMP; Prelude 9B reaches 0.869 best val loss at step 1,200.
Metric (4-bit MLX, matched 2,000 steps)Gemma 4 12B BaseGemma 4 12B Hemma v0.1Prelude 9B Hemma v0.2
Validation loss (30 batches, ↓)4.319 (step 1)1.059 (step 2,000)0.869 (step 1,200) / 1.041 (step 2,000)
Sv-BLiMP (64 pairs, 16 phenomena)56/64 (87.5%)61/64 (95.3%)32/64 (50.0%)
Swedish Facts (30 short-answer Qs)2/30 (6.7%)2/30 (6.7%)4/30 (13.3%)
Supervised tokens trained—679.9k tokens664.0k tokens
Apple M5 wall-clock & throughput—1h 40m (~115 tok/s)1h 35m (~125 tok/s)
no_overedit & sv_json controlsExact ✓Exact ✓Exact ✓
95.3% (↑ from 87.5%)Sv-BLiMP (64 pairs, 16 phenomena)
1.059 (↓ from 4.319)Validation loss (30 batches, ↓)
679.9k tokens (2,000 steps)Supervised training tokens
~115 tok/s (1h 40m)Apple M5 throughput

Applying the Hemma recipe to Gemma 4 12B demonstrates that Hemma works as a base-model-agnostic Swedish quality layer: in just 679.9k tokens on a laptop, Gemma 4 12B climbs from 87.5% to 95.3% on Sv-BLiMP while adopting natural Swedish klarspråk and everyday register without losing code or reasoning ability.

7Known gaps

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

  • Only 679.9k tokens (~6.5% of one epoch over hemma-sv-sft-v0.2) were seen in this 2,000-step laptop run — a full-epoch H200 / Berzelius run will cover all 25,764 training examples.
  • Swedish factual recall (liu-nlp/swedish-facts-v1) stayed at 2/30 (6.7%) at 680k tokens; factual knowledge requires larger Swedish CPT/SFT volume rather than short LoRA SFT.
  • Gemma 4's tokenizer uses 2.54 SV tok/word (vs 2.08 for Prelude), making it ~18% more token-expensive on Swedish despite stronger zero-shot grammar.

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 both RenaissanceLabsEU/gemma-4-12b-sv-hemma-v0.1 and naiss-se/gemma-4-12b-sv-hemma-v0.1, plus on-device GGUFs at naiss-se/gemma-4-12b-sv-hemma-v0.1-GGUF.

Background: Part 2: Matched Prelude 9B Hemma v0.2 recipe. Machine-readable: this recipe as JSON.