{"slug": "i-trained-a-gemma-4-31b-lora-on-my-pre-ai-writing-mac-vs-colab-blackwell", "title": "I trained a Gemma 4 31B LoRA on my pre-AI writing (Mac vs Colab Blackwell)", "summary": "Developer Flavio extracted 1,816 pre-2025 blog posts from a December 22, 2024 git commit (d9ae267fdc) and compared a locally trained 7B LoRA on an M4 Pro Mac against a Gemma 4 31B LoRA trained on a Colab G4 Blackwell GPU, then wired the adapter into his writing workflow as a style layer. His measurement of 1,816 pre-2025 posts versus 552 posts from 2026 found one-sentence paragraphs fell from 76.2% to 37.6%, first-person 'I/my' dropped from 16.45 to 7.26 per 1,000 words, questions fell from 1.72 to 0.47 per 1,000 words, and sentence-length standard deviation shrank 2.3x from 19.21 to 8.26 words. Flavio argues the fine-tune should not draft posts from scratch because it hallucinates APIs and outdated code, and instead runs plain prose through a local 'flavio-voice' CLI that keeps code blocks, headings, tables and links byte-identical for git diff review.", "body_md": "# I trained a Gemma 4 31B LoRA on my pre-AI writing (Mac vs Colab Blackwell)\n\nBy [Flavio](https://flaviocopes.com/about/)\n\nI extracted 1,816 pre-2025 posts from git, compared a local M4 Pro 7B LoRA against a Colab Blackwell Gemma 4 31B LoRA, and wired it into my workflow.\n\nI was reading on Twitter that people were using the Google AI subscription perks on Colab to train models on their own writing, including [Kitze training a Gemma 4 31B LoRA on a 98 GB Blackwell GPU](https://x.com/thekitze/status/2126647045268328730).\n\nThat got me thinking. Until late 2024 I wrote every single post on this blog myself.\n\nIn 2026 I started using coding agents to help me research, test commands, and draft posts. The technical facts were solid, and I already had a `flavioify` skill to strip out obvious AI clichés.\n\nBut the posts started to feel a bit too uniform.\n\nI wanted to train a model on everything I wrote before AI entered my workflow, straight from my git history, so it could pick up my real style. And I wanted to compare two setups head to head: training a small 7B LoRA 100% locally on my Mac, versus training a Gemma 4 31B LoRA on a Colab `G4` Blackwell GPU and bringing the adapter back to my Mac.\n\nThe harder question was not how to run a LoRA fine-tune. It was how I would actually use the outcome every day without breaking my workflow.\n\n## Why a style fine-tune should not write posts from scratch\n\nNow, let’s say you fine-tune a local model on your old blog posts, and you ask it to write a brand-new post about a 2026 tool. What will it write? It will hallucinate APIs, invent flags, and write outdated code in your voice.\n\nEven a 31B local fine-tune is not going to replace frontier agents like Claude, Codex, or Gemini for researching docs, running commands in a terminal, or inspecting a codebase.\n\nWhat it *is* great at is being a **style layer** at the end of the pipeline.\n\nLet the frontier agent do the real work: run the commands, take the screenshots, check the numbers, and write the factual draft. Then pass only the plain prose through a local LoRA CLI (`flavio-voice`) that rewrites it in your rhythm while keeping every code block, heading, table, and link byte-identical.\n\nThen let the agent (or you) review the `git diff` to make sure no technical detail shifted.\n\n## First, I measured how my writing actually drifted\n\nI ran a Python script against the last 2024 commit in this repo (`d9ae267fdc`, December 22, 2024) and compared all 1,816 pre-2025 posts against the 552 posts published in 2026.\n\nPulling straight from a late-2024 git commit guarantees none of my later AI-assisted edits are mixed into the baseline.\n\nHere is what the numbers showed:\n\n| Metric | Pre-2025 (1,816 posts) | 2026 (552 posts) | Difference | \n|---|---|---|---|\n| 1-sentence paragraphs | **76.2%** | 37.6% | Cut in half | \n| 3+ sentence paragraphs | **6.4%** | 23.9% | 3.7x denser | \n| Avg sentences per paragraph | **1.34** | 1.95 | Much heavier blocks | \n| Sentence length median | **13 words** | 14 words | Nearly identical | \n| Sentence length stdev | **19.21 words** | 8.26 words | 2.3x less variety | \n| `I/my` per 1,000 words | **16.45** | 7.26 | Dropped 2.3x | \n| `we/let's` per 1,000 words | **10.13** | 1.53 | Dropped 6.6x | \n| Questions ( `?` ) per 1,000 words | **1.72** | 0.47 | Dropped 3.7x | \n| Exclamations ( `!` ) per 1,000 words | **0.69** | 0.04 | Dropped 17x | \n| Semicolons ( `;` ) per 1,000 words | **0.04** | 0.22 | 5.5x higher | \n\nTwo things jumped out immediately.\n\nFirst, my old `flavioify` skill told agents that paragraphs should be “1 to 4 sentences”. In reality, 93.6% of my pre-2025 paragraphs are 1 or 2 sentences, and 76% are a single sentence!\n\nSecond, look at sentence starters. In 2026 drafts, imperative openers (`Watch`, `Keep`, `Give`, `Ask`, `Put`, `Never`, `Start`) jumped 6x to 16x. The drafts were barking orders at the reader.\n\nMeanwhile, my real pre-2025 posts opened sentences with `But` 12x more, `We` 10x more, `Or` 7x more, and `And` 4.5x more. The n-gram diff also surfaced 2026 phrase crutches that barely existed in my archive: `\"the exact same\"` (222 hits vs 4), `\"walks through\"` (100 vs 0), `\"side by side\"` (94 vs 2), `\"if you'd rather\"` (70 vs 0), `\"watch out for\"` (69 vs 1), and `\"which is why\"` (55 vs 0).\n\n## The whole pipeline\n\nHere’s how the training pipeline (both local Mac and Colab Blackwell) connects to my daily writing workflow on an M4 Pro with 48 GB RAM:\n\n## Step 1: Isolate prose so code blocks can never break\n\nBefore thinking about training, I built a strict Markdown segmenter (`flavio_voice/markdown_chunks.py`) in a small Python project at `~/dev/flavio-voice`.\n\nI never want a rewriter model touching YAML frontmatter, fenced code blocks, headings, tables, images, HTML tags, blockquotes, or bullet lists.\n\nThe segmenter splits any Markdown file into alternating `protected` and `prose` segments, grouping consecutive plain paragraphs into chunks of up to 240 words.\n\nJoining the segments back together reproduces the original file byte-for-byte. I verified this roundtrip invariant on 200 posts in `src/posts/` before generating any data.\n\nAt rewrite time, each chunk also goes through a validator (`validate_rewrite`). It checks that the output is not empty, did not get wrapped in a code fence, stayed within reasonable word-count bounds, kept every Markdown link URL verbatim, and kept at least 80% of inline code spans intact. If a chunk fails, the CLI retries once at a lower temperature (`0.15`), and if it still fails it keeps the original paragraph untouched.\n\n## Step 2: Why paired data beats raw pretraining\n\nIf you dump raw pre-2025 Markdown posts into continued pretraining, you do not get an editor. You get a model that rambles like a 2019 JavaScript tutorial and ignores editing instructions.\n\nTo make the outcome work as a rewriter, the training examples have to match the exact task you will run at inference time:\n\n- **Input:** a generic, AI-sounding version of a passage\n- **Output:** the exact original pre-2025 passage I wrote\n\nTo avoid training the model against a single monotonous template, I rotated every chunk across **3 different AI degradation prompts**:\n\n1. **Formal ChatGPT prose** (dense 3-sentence paragraphs, passive voice, “It is important to note that”, semicolons)\n2. **2026 coding-agent prose** (imperative stacks, “Not X. Y.” contrasts, “which is why”, “the exact same”, aphoristic closers)\n3. **Dry documentation prose** (uniform medium-length sentences, zero personal pronouns, no questions)\n\nHere is one real training pair generated from an old Swift post:\n\n```\nINPUT:\nThis marks the inaugural installment of a new series dedicated to Swift\nand iOS application development tutorials. A previous introductory Swift\nseries is archived [here](https://flaviocopes.com/tags/swift/), providing foundational material\nfor subsequent learning.\n\nTARGET:\nThis is the first of a new series of Swift and iOS application\ndevelopment tutorials I will write.\n\nI did a Swift introductory series a few months back, and you can see\nit [here](https://flaviocopes.com/tags/swift/).\n```\n\n## Step 3: Run 1 — 100% local on my M4 Pro (`Qwen2.5-7B` MLX)\n\nFirst I wanted to see how far I could get completely offline on my M4 Pro with zero cloud GPUs.\n\nI generated 185 validated pairs (153 train, 20 valid, 12 test) locally using [Ollama](https://flaviocopes.com/ai-fundamentals/) with `gemma3:4b`. One quick snag along the way: my first validator rejected 28% of synthetic pairs because I capped the length ratio at `1.85x`. When `gemma3:4b` turns a tight 75-word Flavio paragraph into verbose ChatGPT prose, it easily hits 160 words (`2.2x`). Raising the synthetic upper bound to `2.65x` fixed that immediately.\n\nThen I trained a 16-layer rank-8 MLX LoRA on `mlx-community/Qwen2.5-7B-Instruct-4bit` (4.0 GB on disk, `11.5M` trainable params, `--mask-prompt` enabled):\n\n```\nflavio-voice train --iters 200 --batch-size 2 --grad-accum 2 --lr 3e-5 --num-layers 16 --max-seq-length 1024\n```\n\nIt ran at 44 to 52 tokens/second (~25 minutes total). Watching the validation curve showed why intermediate checkpoints matter:\n\n| Iteration | Train loss | Validation loss | What happened | \n|---|---|---|---|\n| 1 | n/a | 2.876 | Untrained base model | \n| 50 | 1.580 (iter 40) | 1.887 | Big drop in 50 steps | \n| **100** | **1.270** | **1.780** | **Best checkpoint (promoted)** | \n| 150 | 1.011 (iter 140) | 1.849 | Starting to overfit | \n| 200 | 0.540 | 2.220 | Memorizing the 153 train pairs | \n\nThe iter-100 adapter (46 MB) worked surprisingly well on style: it stripped em dashes, broke dense paragraphs into 1–2 sentence beats, and even picked up writing `\"3 pieces\"` instead of `\"three pieces\"` straight from my pre-2025 posts.\n\nBut 153 pairs on a 7B model had clear limits. On harder technical passages it occasionally flipped subtle details or dropped Markdown link URLs.\n\n## Step 4: Run 2 — Scaling up to Gemma 4 31B on a Colab `G4` Blackwell\n\nNext I used the `colab` CLI (`google-colab-cli`) to run the same idea at 10x scale on a Colab `G4` GPU.\n\nOne honest hiccup: on Saturday evening, all four Colab GPU tiers (`G4`, `H100`, `A100`, `L4`) returned `503 Service Unavailable` on `/tun/m/assign`, while a plain CPU session allocated in 3 seconds. Clearly the Twitter rush had saturated the GPU pool. I retried Sunday morning at 09:30 CET and landed a **98 GB NVIDIA RTX PRO 6000 Blackwell** (`CUDA 13.0`, 236 GB disk) on the first try:\n\n```\ncolab new -s flavio-voice --gpu G4\n```\n\nI extracted 2,792 candidate chunks from `d9ae267fdc` and split them strictly **by post** so `train`, `val`, and `eval_blind` have zero overlapping articles.\n\nFirst, I ran `Qwen/Qwen2.5-14B-Instruct` in BF16 (`batch_size=32`) right on the Blackwell GPU to generate **1,650 validated pairs** (`1,516` train, `100` val, `34` blind eval) in about 20 minutes (~1.5 pairs/second, 83.5% accept rate).\n\nThen I restarted the kernel for a clean 98 GB VRAM slate and fine-tuned `google/gemma-4-31B-it` using Unsloth 4-bit QLoRA (`r=16`, `lora_alpha=32`, response-only loss via `train_on_responses_only`, `enable_thinking=False`) for 2 epochs (190 steps, effective batch size 16):\n\n| Step | Training loss | Validation loss | \n|---|---|---|\n| 0 | n/a | 3.4555 | \n| 40 | 1.2858 | 1.2994 | \n| 80 | 1.1904 | 1.2296 | \n| 120 | 1.1025 | 1.2116 | \n| 160 | 1.0958 | 1.2010 | \n| **190** | **1.0167** | **1.2001** | \n\nValidation loss dropped monotonically all the way to **1.2001** with zero overfitting in **15 minutes 49 seconds**.\n\nThe entire Colab session (generating 1,650 pairs with a 14B model, training Gemma 4 31B for 2 epochs, and running 42 blind evaluations) cost **8.99 compute units** (my balance moved from `2,463.05` to `2,454.06`). I downloaded the 498 MB adapter and stopped the VM immediately with `colab stop -s flavio-voice`.\n\n## Head-to-head blind benchmark (20 unseen pre-2025 posts)\n\nI ran all four setups on the same 20 unseen blind posts from `eval_blind.jsonl` (zero post overlap with training) and measured them with `scan.py` and the same style metrics:\n\n| Model | `scan.py` hits | 1-sent paras | Sents / para | `I/we` per 1k | Em dashes / `;` | Link URLs kept | Inline code kept | \n|---|---|---|---|---|---|---|---|\n| **Input (AI-degraded)** | 43 | 23.5% | 3.32 | 0.0 | 4 / 25 | 100.0% | 100.0% | \n| **Real Flavio (ground truth)** | 11 | **74.1%** | **1.30** | **29.6** | **0 / 0** | **100.0%** | **100.0%** | \n| **Local Qwen2.5-7B MLX LoRA** (153 pairs) | 9 | 63.2% | 1.69 | 30.7 | 0 / 0 | **85.7%** | 100.0% | \n| **Base Gemma 4 31B** (0-shot prompt) | 10 | 35.6% | 1.74 | 8.3 | 0 / 0 | 100.0% | 100.0% | \n| **Colab Gemma 4 31B LoRA** (1,516 pairs) | **6** | **80.8%** | **1.32** | **23.8** | **0 / 0** | **100.0%** | **100.0%** | \n\nThe gap is obvious even before you read the text:\n\n- **Base Gemma 4 31B** with the same system prompt stayed stuck at 35.6% single-sentence paragraphs (`1.74` sents/para) and only`8.3`` I/we` per 1,000 words. Prompting alone did not capture the cadence.\n- **Local Qwen2.5-7B LoRA** got much closer on rhythm (`63.2%` 1-sentence paras), but dropped 14.3% of Markdown link URLs on the blind set.\n- **Colab Gemma 4 31B LoRA** hit**1.32 sentences/paragraph** (vs my real`1.30` ), cut`scan.py` hits from**43 to 6** , restored`I/we` from`0.0` to`23.8/1k` , and preserved**100% of link URLs and inline code spans** .\n\nReading a real blind test item (`src/posts/how-to-set-alias-shell.md`) makes the difference even clearer.\n\nHere is the AI-degraded input:\n\n```\nAssuming one has [VS Code](https://flaviocopes.com/vscode/) installed,\nwhich provides the `code` command, it is important to note that if\n`~/.bash_profile` does not exist, it can be created; in this scenario,\nthe shell will automatically recognize and utilize it. Alternatively,\nthe `~/.bashrc` file, if available, can also be used for configuration.\n```\n\nLocal `Qwen2.5-7B` LoRA drifted on the meaning (telling the reader to install VS Code and flipping “otherwise”):\n\n```\nIf you don't have it already, [install VS Code](https://flaviocopes.com/vscode/),\nwhich comes with the `code` command.\n\nIf you don't have `~/.bash_profile`, create it. Otherwise, the shell will\nautomatically use it.\n```\n\nNow look at the Colab `Gemma 4 31B` LoRA output:\n\n```\nAssuming you have [VS Code](https://flaviocopes.com/vscode/) installed,\nwhich gives you the `code` command.\n\nIf `~/.bash_profile` does not exist, you can create it. The shell will\nautomatically pick it up.\n\nYou can also use `~/.bashrc` if it exists.\n```\n\nCompare that to my actual pre-2025 post: `\"If ~/.bash_profile does not exist, you can create it, and the shell will pick it up. You can also use the ~/.bashrc file, if present.\"` It even picked up `\"pick it up\"` without inventing anything.\n\n## Step 5: Bring the Colab Gemma 4 31B adapter back to my Mac (MLX)\n\nI did not want to pay for cloud hosting or wait on a 62 GB BF16 merge just to run my adapter locally.\n\nBecause `mlx-lm` supports `gemma4` natively and `mlx-community/gemma-4-31b-it-4bit` (17.18 GB) fits comfortably in my M4 Pro’s 48 GB memory, I wrote a 40-line converter (`scripts/convert_peft_to_mlx.py`) that maps all 820 HuggingFace PEFT tensors directly into MLX LoRA format (`lora_A.T` -> `lora_a`, `lora_B.T` -> `lora_b`, `scale = 32 / 16 = 2.0`, cast to `bfloat16`).\n\nThat turned the 498 MB Colab download into a **234 MB local MLX adapter** in 2 seconds with zero retraining and zero merge loss.\n\nNow `flavio-voice` defaults to **Gemma 4 31B 4-bit + my Colab LoRA**, with a `--fast` flag whenever I want the smaller `Qwen2.5-7B` MLX LoRA for instant turnaround:\n\nHere is `flavio-voice rewrite --diff` running locally on my M4 Pro against a real 2026 post ([Use 1Password Developer Environments with Cursor](https://flaviocopes.com/1password-cursor/)):\n\n## Step 6: Upgrade `flavioify` and wire it into my workflow + Raycast\n\nUsing the metrics from Step 1, I also updated my writing [Agent Skill](https://flaviocopes.com/agent-skills/) (`flavioify`) and its regex linter `scan.py` to flag the exact drift we measured:\n\n- Dense paragraph runs (`3+` consecutive paragraphs with 3+ sentences) and file-level`high-paragraph-density`\n- `low-personal-voice` when a 400+ word post has fewer than 6`I` /`we` pronouns per 1,000 words\n- Prose semicolons (`;` )\n- `imperative-stack` (3+ imperative sentence starters in a single paragraph)\n- The 2026 phrase crutches (`walks through` ,`watch out for` ,`if you'd rather` ,`the exact same` ,`which is why` ,`side by side` ,`all three` )\n\nRunning the updated scanner on that same 2026 post catches them right away:\n\nThen I connected `flavio-voice` into three places so I do not have to remember to invoke it:\n\n1. **`docs/blog-post-guide.md`** (the guide every agent reads before writing a post in this repo): after drafting and running`scan.py` , the agent runs`flavio-voice rewrite src/posts/<slug>.md --in-place` , inspects`git diff` , and verifies code blocks are unchanged.\n2. **`flavioify` and `/post` skills** : both the Write/Rewrite workflows and my publishing skill now include`flavio-voice rewrite` as a local pass.\n3. **Raycast Script Command** (`~/dev/raycast-scripts/flavio-voice-clipboard.sh` ): for quick snippets outside an agent session, I copy any text, trigger**“Rewrite Clipboard in Flavio’s Voice”** in Raycast, and get the rewritten text straight back in the clipboard:\n\n``` bash\n#!/bin/bash\n\n# Required parameters:\n# @raycast.schemaVersion 1\n# @raycast.title Rewrite Clipboard in Flavio's Voice\n# @raycast.mode silent\n\n# Optional parameters:\n# @raycast.packageName Writing\n# @raycast.icon ✍️\n\nset -euo pipefail\n\nINPUT=\"$(pbpaste)\"\nif [ -z \"${INPUT// /}\" ]; then\n  echo \"Clipboard is empty\"\n  exit 1\nfi\n\nOUTPUT=\"$(printf '%s' \"$INPUT\" | /Users/flaviocopes/.local/bin/flavio-voice rewrite -)\"\nif [ -z \"${OUTPUT// /}\" ]; then\n  echo \"Rewrite returned empty output (clipboard unchanged)\"\n  exit 1\nfi\n\nprintf '%s' \"$OUTPUT\" | pbcopy\necho \"Rewrote clipboard in Flavio's voice\"\n```\n\n## Where the limits are\n\nEven with Gemma 4 31B and 1,516 pairs, there are real boundaries:\n\n- **Always review `git diff`.** Because my pre-2025 posts are very personal, the 31B LoRA can occasionally inject extra personal color (like`\"I've used it for years\"` ) on a generic paragraph. Reviewing the diff catches that in seconds and keeps every claim honest.\n- **31B takes longer to load than 7B.** Loading a 17 GB model on an M4 Pro takes a few seconds and runs slower per token than a 4 GB 7B model. For full blog drafts that tradeoff is completely worth it, and for quick one-line clipboard tweaks I kept`--fast` pointing at the 7B LoRA.\n- **Voice cannot fix a hollow post.** You still need real commands, real numbers, and real screenshots first, and only then run the style pass on top.\n\nIf you want to go deeper into how local models and training loops work under the hood, see [How to build an LLM from scratch](https://flaviocopes.com/build-llm-from-scratch/) and [AI fundamentals](https://flaviocopes.com/ai-fundamentals/). If you want to build similar reusable workflows for [Claude Code](https://flaviocopes.com/claude-code-guide/) or [Codex](https://flaviocopes.com/codex/), check out [How to write an Agent Skill](https://flaviocopes.com/agent-skills/).\n\nWant me to talk about your product? You can [sponsor this site](https://flaviocopes.com/sponsor/).", "url": "https://wpnews.pro/news/i-trained-a-gemma-4-31b-lora-on-my-pre-ai-writing-mac-vs-colab-blackwell", "canonical_source": "https://flaviocopes.com/train-lora-writing-style/", "published_at": "2026-11-29 11:00:00+00:00", "updated_at": "2026-11-29 11:15:29.556225+00:00", "lang": "en", "topics": ["large-language-models", "ai-tools", "ai-agents", "ai-infrastructure"], "entities": ["Flavio", "Gemma 4 31B", "Apple M4 Pro", "Google Colab", "Blackwell", "Kitze", "flavio-voice", "flavioify"], "also_reported_by": [], "takeaway": "Use a LoRA fine-tune as a final style layer that rewrites only plain prose while leaving code blocks, headings, tables and links byte-identical, and review the git diff to confirm no technical detail shifted.", "recommendation": {"advice": "Fine-tune on a pre-AI git commit to keep the style baseline clean, then apply the adapter only to prose and diff the output to verify code and facts are unchanged.", "playbook": "training-data", "playbook_url": "https://wpnews.pro/playbooks/training-data"}, "alternates": {"html": "https://wpnews.pro/news/i-trained-a-gemma-4-31b-lora-on-my-pre-ai-writing-mac-vs-colab-blackwell", "markdown": "https://wpnews.pro/news/i-trained-a-gemma-4-31b-lora-on-my-pre-ai-writing-mac-vs-colab-blackwell.md", "text": "https://wpnews.pro/news/i-trained-a-gemma-4-31b-lora-on-my-pre-ai-writing-mac-vs-colab-blackwell.txt", "jsonld": "https://wpnews.pro/news/i-trained-a-gemma-4-31b-lora-on-my-pre-ai-writing-mac-vs-colab-blackwell.jsonld"}}