TheFocus.AI TheFocus.AI
About: Fine-Tune a Self-Improving Local Coding Agent

About: Fine-Tune a Self-Improving Local Coding Agent

How the course works, the hardware and toolchain, and the reading list.

TUTOR WITH THEFOCUS.AI

Agent Integration

Copy this prompt into Claude, ChatGPT, or any external AI assistant. It points the assistant to the course instructions and links it to your student profile to track your progress and customize observations.

Please tutor me in this lesson using the following context. First, read the instructions at: https://courses.thefocus.ai/llms.txt My Student ID is: <none> The lesson markdown source is at: https://courses.thefocus.ai/fine-tune-local-agent/about.md

You are not enrolled yet. Enroll to generate a Student ID to track lesson completions and store learning notes.

About This Course

How It Works

This course is a ladder. Each part produces an artifact the next part consumes:

  1. Part 1 builds intuition — an image LoRA where overfitting is visible
  2. Part 2 builds the pipeline — train, fuse, serve, on a model small enough to iterate in minutes
  3. Part 3 builds the data format — an agent harness that logs every trajectory
  4. Part 4 builds the scoreboard — a mechanical pass/fail verifier on real tasks
  5. Part 5 closes the loop — the agent trains on its own verified successes

Nothing is decorative. If a part feels skippable, the part after it will tell you why it wasn’t.


Hardware

BoxRoleToolchain
M4 MacBook, 64GBIteration, dataset work, Parts 1–4MLX (mlx_lm.lora, mflux)
Jetson AGX Thor, 128GBScale runs, Nemotron, final servingUnsloth / CUDA, Ollama

You can complete Parts 1–4 entirely on Apple Silicon. A 64GB machine is comfortable; 32GB works with --low-ram flags and smaller batch sizes. The Thor (or any CUDA box) only enters at Part 5’s scale-up.


The Toolchain

ToolWhat It IsUsed In
mfluxMLX port of FLUX image generation, with Dreambooth trainingPart 1
mlx-lmApple’s LLM training and serving toolkit for MLXParts 2–5
Gemma 3The model ladder: 270M → 1B → 4B → 12B → 27BParts 2–5
Claude (Anthropic API)The teacher for trajectory distillationPart 3
UnslothCUDA fine-tuning for the Thor scale-upPart 5
OllamaFinal serving via GGUFPart 5

Everything is driven from a Makefile/justfile you build in Part 2 and never stop using.


Why Gemma 3 and Not Nemotron (on the Mac)

Nemotron’s hybrid Mamba2-Transformer architecture is still maturing in mlx-lm — it runs for inference but fights you for training. Save it for the Thor, where Unsloth on CUDA handles it (with caveats covered in Chapter 16).

Gemma 3’s size ladder is exactly the ramp this course wants: prove everything on 1B where iteration is minutes, then move the same pipeline up.


The Core Insight

You are not fine-tuning the model on your code. You are fine-tuning it on the shape of agentic behavior.

Codebase knowledge belongs in context, retrieved at runtime — bake it into weights and you retrain every time the code changes, and it hallucinates moved APIs anyway. What small models are actually bad at, and what is stably trainable, is the loop: take a task, emit a well-formed tool call, read the result, reason, call again, stop when done, report.

That behavior is learnable. That behavior is what you train.


Safety Notes

  • The agent in Parts 4–5 gets edit_file and run_tests — write and execute tools. Sandbox them. Container, git worktree, whatever — the agent will do something stupid and you want to git checkout . and move on.
  • Fine-tuning runs are long. Don’t interleave generation with training in mflux (documented slowdowns); train, then generate.
  • Guard your eval set with your life. If eval tasks leak into training data, every number your scoreboard prints becomes fiction.

Reading, Roughly in Order

  • LoRA (Hu et al., 2022) — the original, still the clearest
  • STaR / expert iteration — the Part 5 method
  • DPO (Rafailov et al., 2023) — Chapter 14
  • Reflexion — Chapter 15
  • Nemotron Nano 2 tech report — a full post-training recipe (SFT → GRPO → DPO → RLHF), openly documented, worth reading as a map of where this ladder goes
  • The mflux source — a diffusion transformer with the abstractions removed. Short enough to read in an evening.

← Back to Course

hey@thefocus.ai · thefocus.ai