Recipes · MoE LoRA SFT (Local)
Hemma on Inkling-2-Mini: Fine-tuning a 26.4B MoE for Swedish in 27 minutes at home
Apply the Hemma Swedish SFT recipe (hemma-sv-sft-v0.2) to Thinking Machines' Apache-2.0 Inkling-2-Mini (26.4B-total looped MoE) in just 27 minutes on a 32 GB Apple M5 MacBook. By keeping the NVFP4/MXFP8 routed experts frozen, training attention LoRA on the top 4 layers (1.11M trainable params = 0.004%), and filtering sequences to <=500 tokens with mlx_lm's exact ChatDataset to prevent mask_prompt NaN, validation loss drops from 1.451 to 0.731 (best, step 400) / 0.867 (step 2,000), Sv-BLiMP climbs from 89.1% to 92.2% (+3.1 pp), and creative Swedish agreement errors disappear.
From Renaissance Labs × NAISSRecipe by Birger MoellComplete on Apple M5 (32 GB). Fused 4-bit MLX weights and unfused step-400/step-2000 LoRA adapters ready.
1Ingredients
Built from the <=500-token, zero-truncation slice (8,435 train + 418 valid rows) of RenaissanceLabsEU/hemma-sv-sft-v0.2 (https://huggingface.co/datasets/RenaissanceLabsEU/hemma-sv-sft-v0.2), spanning all 9 open-licensed Swedish and replay buckets while guaranteeing >=8 unmasked assistant tokens per example.
hemma-sv-sft-v0.2 <=500-token zero-truncation slice (8,435 train + 418 valid)
Filtered using mlx_lm's exact ChatDataset tokenizer so 100% of rows fit inside max_seq_length=512 with zero prompt truncation and zero 0/0 NaN loss under mask_prompt: true.
- hemma-sv-sft-v0.2 (<=500 tok, train split)
RenaissanceLabsEU/hemma-sv-sft-v0.2 · filtered trainAll 9 Swedish + replay buckets filtered with mlx_lm ChatDataset (max_len=500, >=8 assistant tokens) · CC-BY-4.0 / Apache-2.0 / CC08,43595.3%Pinned - hemma-sv-sft-v0.2 (<=500 tok, valid split)
RenaissanceLabsEU/hemma-sv-sft-v0.2 · filtered validStratified held-out validation split (max_len=500, >=8 assistant tokens) · CC-BY-4.0 / Apache-2.0 / CC04184.7%Pinned
SHA-256 fingerprints of the <=500-token Inkling-2-Mini data splits
train/data_v02_inkling512/train.jsonl | ac99af905652…0ab9fb |
train/data_v02_inkling512/valid.jsonl | f384f908f474…96b648 |
2Pinned inputs
Everything that must match for a faithful rerun.
- Base model
mlx-community/Inkling-2-Mini-4bit (thinkingmachines/Inkling-2-Mini)26.4B-total Apache 2.0 looped MoE (8 active experts/tok, 24 layers, 2.40 SV tok/word, 17.3 GB on disk)- mlx-lm branch
git+https://github.com/ml-explore/mlx-lm.git@refs/pull/2086/headAdds native inkling2_loop architecture support (NVFP4/MXFP8 routed experts + 4-bit affine attention)- Chat template fix
reasoning_effort default 0.9 → 0.0 in symlinked chat_template.jinjaInkling-2-Mini defaults to high thinking (0.9); defaulting to 0.0 keeps non-thinking SFT calibrated- Exact ChatDataset length filter
len(tokens) <= 500 and (len(tokens) - offset) >= 8Critical: avoids mask_prompt 0/0 NaN loss when long prompts get truncated at max_seq_length=512
3Equipment
Because Inkling-2-Mini-4bit weights occupy 17.3 GB against macOS's ~21.3 GB default Metal wired cap, targeting attention projections (q/k/v/o) on the top 4 layers (1.114M params = 0.004%) with max_seq_length=512 and grad_checkpoint=true keeps peak memory safely under the cap while sustaining ~130–160 tok/s (27 minutes for 2,000 steps).
4Method
Paths in angle brackets are yours to fill in. Account IDs and personal paths have been removed.
- 1
Use the mlx-lm PR #2086 branch for inkling2_loop
PyPI mlx-lm 0.32.2 does not yet include inkling2_loop. Run directly via uvx from git+https://github.com/ml-explore/mlx-lm.git@refs/pull/2086/head.
uvx --from "git+https://github.com/ml-explore/mlx-lm.git@refs/pull/2086/head" mlx_lm.lora --help - 2
Filter sequences with mlx_lm's exact ChatDataset
Filter hemma-sv-sft-v0.2 to len(tokens) <= 500 and (len(tokens) - offset) >= 8 using mlx_lm's own ChatDataset. Filtering with transformers AutoTokenizer alone lets some >512-token rows slip through, causing mask_prompt truncation NaN.
# Keeps 8,435 train / 418 valid rows with max_len=500 and zero truncation warningsCheck this. If any prompt exceeds max_seq_length=512 under mask_prompt: true, all assistant tokens are truncated off -> 0/0 = NaN loss poisons the LoRA weights.
- 3
Train attention LoRA on top 4 layers (27 min)
Keep NVFP4/MXFP8 routed experts frozen and adapt self_attn.{q,k,v,o}_proj on the top 4 layers (1.114M params) so peak Metal memory stays comfortably inside 32 GB.
caffeinate -i uvx --from "git+https://github.com/ml-explore/mlx-lm.git@refs/pull/2086/head" mlx_lm.lora --config ./lora_v02_inkling2_mini.yaml - 4
Pre-fill <|message_model|><|content_text|> for non-thinking eval
Inkling-2-Mini's chat template does not emit <|message_model|><|content_text|> on add_generation_prompt=True. Appending it lets you evaluate direct Swedish answers without burning tokens inside <|content_thinking|>.
python micro_sv_eval.py --model ./mlx_models/inkling-2-mini-4bit --adapter-path ./adapters/inkling-2-mini-sv-hemma-v0.1
Complete Inkling-2-Mini Hemma v0.1 training script (27 min on Apple M5)
#!/usr/bin/env bash
# Train Hemma v0.1 on Inkling-2-Mini-4bit (26.4B MoE) in 27 minutes on Apple M5.
set -euo pipefail
MLX_SPEC="git+https://github.com/ml-explore/mlx-lm.git@refs/pull/2086/head"
# 1. Symlink cached mlx-community/Inkling-2-Mini-4bit with reasoning_effort default=0.0
# 2. Filter hemma-sv-sft-v0.2 with mlx_lm ChatDataset to <=500 tokens & >=8 assistant tokens
# 3. Train 2,000 steps (27 min, ~130-160 tok/s, zero OOM, zero NaN)
caffeinate -i uvx --from "$MLX_SPEC" mlx_lm.lora --config ./lora_v02_inkling2_mini.yaml
# 4. Evaluate before vs after (pre-filling <|message_model|><|content_text|> for direct answers)
caffeinate -i uvx --from "$MLX_SPEC" --with datasets \
python micro_sv_eval.py \
--model ./mlx_models/inkling-2-mini-4bit \
--adapter-path ./adapters/inkling-2-mini-sv-hemma-v0.1 \
--output-json ./logs/v02_eval_inkling2_mini_after.json
# 5. Fuse 4-bit MLX release weights
uvx --from "$MLX_SPEC" mlx_lm.fuse \
--model ./mlx_models/inkling-2-mini-4bit \
--adapter-path ./adapters/inkling-2-mini-sv-hemma-v0.1 \
--save-path ./exports/inkling-2-mini-sv-hemma-v0.1
5Settings
Home Apple Silicon MoE Attention QLoRA
- Objective
- Causal LM cross-entropy, assistant-only loss (mask_prompt: true)
- Adapter
- LoRA rank 16, scale 32, dropout 0.05 on self_attn.{q,k,v,o}_proj across top 4 layers (1.114M params = 0.004%)
- 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 4 · 2,000 steps · 202.4k tokens (27 min)
- Validation loss
- 1.451 (step 1) → 0.731 (step 400, best) → 0.867 (step 2,000)
6What you should see
Numbers from the original run, so you can tell early whether yours is on track.
- Validation loss drops by halfDrops from 1.451 (step 1) to 0.731 at step 400 (best) and 0.867 at step 2,000, with zero NaN and zero OOM.
- Sv-BLiMP climbs 89.1% → 92.2% (+3.1 pp)Improves from 57/64 to 59/64 across all 16 Swedish grammar phenomena in just 202.4k tokens.
- Creative Swedish agreement errors eliminatedBase errors like 'en svag, osäker ljus' and 'I det tystnaden' disappear completely in Hemma v0.1, alongside proper constitutional verbs ('riksdagen stiftar', 'utfärdar').
- Zero regressions on JSON & codePreserves exact raw Swedish JSON, non-editing controls, and adds input validation in Swedish Python code.

| Metric (4-bit MLX) | Inkling-2-Mini Base | Inkling-2-Mini Hemma v0.1 | Gemma 4 12B Hemma v0.1 |
|---|---|---|---|
| Validation loss (↓) | 1.451 (step 1) | 0.731 (step 400) / 0.867 (step 2,000) | 1.059 (step 2,000) |
| Sv-BLiMP (64 pairs, 16 phenomena) | 57/64 (89.1%) | 59/64 (92.2%) | 61/64 (95.3%) |
| Swedish Facts (30 Qs) | 2/30 (6.7%) | 2/30 (6.7%) | 2/30 (6.7%) |
| Creative Swedish agreement | Errors: 'en svag, osäker ljus', 'I det tystnaden' | Zero agreement errors, natural prose ✓ | Zero agreement errors ✓ |
| Wall-clock & tokens on M5 | — | 27 min (202.4k tokens) | 1h 40m (679.9k tokens) |
In just 27 minutes and 0.004% trainable parameters, Hemma pushes Inkling-2-Mini (26.4B Apache 2.0 MoE) from 89.1% to 92.2% on Sv-BLiMP while eliminating subtle Swedish gender/definiteness agreement errors in creative prose and adopting natural Swedish klarspråk.
7Known gaps
What stands between this card and an exact copy of the run.
- Only sequences <=500 tokens (8,435 of 25,764 train rows) were used to stay inside macOS's ~21.3 GB Metal wired limit on a 32 GB MacBook; full 2,048-token MoE training can run on H200 (Berzelius).
- On grammar proofreading prompts that also request an explanation, Hemma v0.1 outputs the exact corrected sentence cleanly but skips the explanation because the KeTuTu grammar-repair SFT pairs omit explanations.
- Step 400 achieved the lowest validation loss (0.731 vs 0.867 at step 2,000); both checkpoints are preserved in adapters/.
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
Published in both 4-bit MLX fused form and unfused LoRA adapters.
Background: Head-to-head: Gemma 4 12B Hemma v0.1 recipe. Machine-readable: this recipe as JSON.