<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>DPO Fine-Tuning on RockB</title><link>https://baeseokjae.github.io/tags/dpo-fine-tuning/</link><description>Recent content in DPO Fine-Tuning on RockB</description><image><title>RockB</title><url>https://baeseokjae.github.io/images/og-default.png</url><link>https://baeseokjae.github.io/images/og-default.png</link></image><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sun, 06 Sep 2026 07:01:19 +0000</lastBuildDate><atom:link href="https://baeseokjae.github.io/tags/dpo-fine-tuning/index.xml" rel="self" type="application/rss+xml"/><item><title>LabLLM: Teaching Tiny Language Models to Think on macOS</title><link>https://baeseokjae.github.io/posts/labllm-tiny-language-model-teaching-2026/</link><pubDate>Sun, 06 Sep 2026 07:01:19 +0000</pubDate><guid>https://baeseokjae.github.io/posts/labllm-tiny-language-model-teaching-2026/</guid><description>LabLLM is a free native macOS app for training tiny language models from scratch on Apple Silicon — no cloud, no subscription, all on-device.</description><content:encoded><![CDATA[<p>LabLLM is a free, native macOS app (Swift/SwiftUI) that lets you train tiny language models from scratch on Apple Silicon — no cloud, no subscription, everything stays on your Mac. Released as a beta in August 2026, it bundles a model builder, dataset browser, tokenizer, training dashboard, LoRA and DPO fine-tuning, a sampler, a chat window, and checkpoints into one GUI, so you can watch a small LLM &ldquo;emerge&rdquo; live on your own machine.</p>
<h2 id="what-is-labllm-a-native-macos-lab-for-teaching-tiny-language-models-to-think">What is LabLLM? A native macOS lab for teaching tiny language models to think</h2>
<p>LabLLM is a free, MIT-licensed macOS application built in Swift and SwiftUI that turns your Apple Silicon Mac into a complete training laboratory for small language models. Instead of juggling Python scripts, CUDA clusters, and cloud GPU bills, you get a single native app where you can build a Transformer, load or search training data, train it, fine-tune it, chat with it, and even serve it over a local OpenAI-shaped endpoint.</p>
<p>The project is young but active. It has roughly 76 GitHub stars and has shipped two beta releases: Beta 0.1 &ldquo;Teach Tiny Brains&rdquo; on 2026-08-15 and Beta 0.2 &ldquo;Remember the Run&rdquo; on 2026-08-18. The &ldquo;teach tiny brains&rdquo; metaphor is the whole point: building and training a small model is now as approachable as using a Mac app, rather than a command-line rite of passage.</p>
<p>Under the hood, LabLLM is built on Apple&rsquo;s MLX array framework and its Swift API, mlx-swift. That means it takes full advantage of the unified memory architecture on M-series chips, letting you train and run models on-device without ever sending data to a server.</p>
<h2 id="why-train-a-tiny-llm-on-your-own-mac">Why train a tiny LLM on your own Mac?</h2>
<p>There are three compelling reasons to train a small language model locally rather than renting cloud GPUs.</p>
<p><strong>Privacy first.</strong> Everything stays on your Mac. Your training data, your checkpoints, and your model weights never leave the device. For anyone working with sensitive or proprietary text, that is a decisive advantage over cloud training services.</p>
<p><strong>No cloud, no subscription.</strong> There is no per-hour GPU billing, no quota, no surprise invoice. Once you own an Apple Silicon Mac, the compute is already paid for and sitting on your desk. This makes experimentation effectively free, which changes how willing you are to try things and fail.</p>
<p><strong>Learning by doing.</strong> Reading about attention mechanisms in a book is one thing; watching a loss curve fall and seeing coherent text emerge from a model you trained is another. LabLLM sits at the bridge between theory — the kind found in Sebastian Raschka&rsquo;s &ldquo;Build a Large Language Model (From Scratch)&rdquo; or the reference implementation in karpathy/nanoGPT — and hands-on GUI experimentation.</p>
<p>The ecosystem momentum is real. Apple&rsquo;s MLX framework has roughly 28,314 GitHub stars, and karpathy/nanoGPT — the de-facto baseline for &ldquo;train your own LLM&rdquo; tutorials — has about 62,837. When Ollama added MLX preview support on Apple Silicon, it drew 648 Hacker News points, underscoring strong community demand for local, no-cloud MLX workflows.</p>
<h2 id="getting-started-requirements-and-building-labllm-from-source">Getting started: requirements and building LabLLM from source</h2>
<p>Before you can train anything, you need the right hardware and toolchain. LabLLM&rsquo;s requirements are specific but modest for a modern Mac:</p>
<ul>
<li><strong>macOS 14 or newer</strong></li>
<li><strong>Apple Silicon (M1 or newer)</strong> — this is non-negotiable, because the app depends on MLX&rsquo;s Metal acceleration</li>
<li><strong>Xcode 15 or newer</strong></li>
<li><strong>Swift Package Manager (SwiftPM)</strong></li>
</ul>
<p>The build bundles the MLX Metal library for the SwiftPM build, so you do not need to install MLX separately. To get started, clone the repository from GitHub, open the project in Xcode, and build. Because it is a native Swift app, there is no Python environment to set up, no virtualenv, and no dependency hell — the SwiftPM manifest handles the MLX and mlx-swift dependencies for you.</p>
<p>One thing to note: LabLLM pins mlx-swift to version 0.31.6. If you are building from source and hit a version mismatch, check that your local SwiftPM resolution matches the pinned version.</p>
<h2 id="building-a-transformer-from-scratch-inside-the-app">Building a Transformer from scratch inside the app</h2>
<p>The heart of LabLLM is the model builder. Rather than importing a pretrained checkpoint, you construct a Transformer architecture from scratch, choosing the hyperparameters that define your tiny model.</p>
<p>You will typically configure:</p>
<ul>
<li><strong>Vocabulary size</strong> — how many tokens the tokenizer can produce</li>
<li><strong>Context length</strong> — how many tokens the model can attend to at once</li>
<li><strong>Number of layers</strong> — the depth of the Transformer stack</li>
<li><strong>Embedding dimension</strong> — the size of the token and position embeddings</li>
<li><strong>Number of attention heads</strong> — for multi-head self-attention</li>
</ul>
<p>Because you are training a <em>tiny</em> model, these numbers stay small enough to fit comfortably in the unified memory of an M-series chip. This is the same territory as nanoGPT&rsquo;s small configs, but exposed through a GUI where you can change a value, rebuild, and retrain without touching a config file.</p>
<p>The point of building from scratch is understanding. You are not downloading a 7-billion-parameter model; you are constructing a small one and watching how each architectural choice affects training behavior.</p>
<h2 id="importing-and-preparing-your-own-training-data">Importing and preparing your own training data</h2>
<p>A model is only as good as its data, and LabLLM gives you two ways to get training data in.</p>
<p><strong>Hugging Face search.</strong> You can search the Hugging Face Hub directly from inside the app and pull datasets without leaving the GUI. This is the fastest path to a working training run with a well-known dataset.</p>
<p><strong>Text and instruction data.</strong> You can import your own text files and instruction-style data. This is where the privacy angle pays off — you can train on your own documents, notes, or domain-specific text entirely on-device.</p>
<p>Before training, the app tokenizes your data using the tokenizer you configured in the model builder. The dataset browser lets you inspect what you are about to train on, so you can catch formatting problems before they waste a training run.</p>
<h2 id="training-watching-loss-curves-throughput-and-live-samples-emerge">Training: watching loss curves, throughput, and live samples emerge</h2>
<p>The training dashboard is where LabLLM earns its &ldquo;teach tiny brains&rdquo; name. During training you can watch, in real time:</p>
<ul>
<li><strong>Blue train loss vs. orange validation loss</strong> — the classic signal that tells you whether the model is learning or overfitting</li>
<li><strong>Throughput</strong> — tokens per second, so you can see how fast your Mac is actually training</li>
<li><strong>Live samples</strong> — text generated by the model mid-training, so you can watch coherent language emerge from random noise</li>
</ul>
<p>This live feedback loop is the most educational part of the app. You see the moment a model stops producing gibberish and starts producing plausible text. You see overfitting happen in real time when validation loss diverges from training loss. You can experiment with learning rate, batch size, and architecture, and immediately observe the consequences.</p>
<p>For a tiny model on Apple Silicon, training runs are short enough that this kind of iterative experimentation is genuinely practical — you can try a configuration, watch it train, and try something different in the same sitting.</p>
<h2 id="fine-tuning-with-lora-and-dpo-on-your-own-data">Fine-tuning with LoRA and DPO on your own data</h2>
<p>Training from scratch is only half the story. LabLLM also supports fine-tuning a model you have trained — or, in principle, adapting it to a specific behavior — using two modern techniques.</p>
<p><strong>LoRA (Low-Rank Adaptation).</strong> LoRA freezes the base model weights and trains small low-rank adapter matrices instead. This dramatically reduces the number of trainable parameters and the memory footprint, making fine-tuning feasible on a laptop. It is the standard way to adapt a model to a new domain or style without retraining everything.</p>
<p><strong>DPO (Direct Preference Optimization).</strong> DPO aligns a model with human preferences without the complexity of a full reinforcement-learning pipeline. Instead of training a reward model and running RLHF, DPO directly optimizes the policy using preference pairs — &ldquo;this response is better than that one.&rdquo; It is a simpler, more stable path to making a model behave the way you want.</p>
<p>Both run locally, so you can fine-tune a model on your own data and then immediately chat with the result in the same app.</p>
<h2 id="sampling-chatting-and-inspecting-tokens-and-embeddings">Sampling, chatting, and inspecting tokens and embeddings</h2>
<p>Once you have a trained or fine-tuned model, LabLLM lets you interact with it directly.</p>
<p>The <strong>sampler</strong> lets you generate text and experiment with generation parameters like temperature and top-k sampling. The <strong>chat window</strong> turns the model into a conversational assistant you can talk to — the payoff for all the training work.</p>
<p>For the more curious, LabLLM also lets you <strong>inspect tokens and embeddings</strong>. You can see how the model represents words in its embedding space and examine the tokenization of your input. This is a valuable window into what the model has actually learned, and it reinforces the educational mission of the app.</p>
<h2 id="managing-checkpoints-save-resume-quantize-and-compare-runs">Managing checkpoints: save, resume, quantize, and compare runs</h2>
<p>Training is not a single shot; it is an iterative process, and LabLLM treats it that way with a checkpoint system.</p>
<ul>
<li><strong>Save</strong> — persist a model mid-training or after completion</li>
<li><strong>Resume</strong> — pick up a training run where you left off, which is essential for long experiments</li>
<li><strong>Quantize</strong> — reduce the model&rsquo;s precision to shrink its memory footprint and speed up inference, at a small cost in quality</li>
<li><strong>Compare runs</strong> — keep multiple checkpoints and compare their behavior side by side</li>
</ul>
<p>This is the &ldquo;Remember the Run&rdquo; feature set from Beta 0.2. It turns LabLLM from a toy into a genuine experiment tracker, letting you keep the good runs and discard the bad ones without losing your place.</p>
<h2 id="serving-your-model-locally-via-an-openai-shaped-endpoint">Serving your model locally via an OpenAI-shaped endpoint</h2>
<p>The most production-relevant feature is the ability to <strong>serve your model locally through an OpenAI-shaped endpoint</strong>. This means the model you trained in LabLLM can be exposed as a local API that speaks the same protocol as OpenAI&rsquo;s API.</p>
<p>Why this matters: any tool that already integrates with OpenAI — a chat frontend, an agent framework, a script — can point at your local LabLLM endpoint instead, with minimal or no code changes. You get a private, on-device model that slots into your existing tooling. This is the same pattern that makes local inference servers popular, but here the model is one you trained yourself.</p>
<h2 id="labllm-vs-the-alternatives">LabLLM vs. the alternatives</h2>
<p>To understand where LabLLM fits, it helps to compare it against the main alternatives.</p>
<table>
  <thead>
      <tr>
          <th>Tool</th>
          <th>What it is</th>
          <th>Training from scratch?</th>
          <th>GUI?</th>
          <th>Best for</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><strong>LabLLM</strong></td>
          <td>Native macOS app on MLX</td>
          <td>Yes</td>
          <td>Yes</td>
          <td>Hands-on, no-code training on Apple Silicon</td>
      </tr>
      <tr>
          <td><strong>nanoGPT</strong></td>
          <td>Python/PyTorch reference repo</td>
          <td>Yes</td>
          <td>No</td>
          <td>Learning the training loop from code</td>
      </tr>
      <tr>
          <td><strong>MLX</strong></td>
          <td>Apple&rsquo;s array framework</td>
          <td>Yes (via code)</td>
          <td>No</td>
          <td>Building custom training pipelines</td>
      </tr>
      <tr>
          <td><strong>mlx-swift</strong></td>
          <td>Swift API for MLX</td>
          <td>Yes (via code)</td>
          <td>No</td>
          <td>Native Swift ML apps</td>
      </tr>
      <tr>
          <td><strong>Raschka&rsquo;s book</strong></td>
          <td>Educational book</td>
          <td>Conceptually</td>
          <td>No</td>
          <td>Understanding LLM theory from first principles</td>
      </tr>
      <tr>
          <td><strong>Ollama (MLX)</strong></td>
          <td>Model serving/running</td>
          <td>No</td>
          <td>No</td>
          <td>Running/serving existing models locally</td>
      </tr>
  </tbody>
</table>
<p>The key differentiator is the GUI. nanoGPT and MLX are powerful but require you to write code. Raschka&rsquo;s book teaches theory but not a turnkey tool. Ollama runs models but does not train them from scratch. LabLLM is the only option here that packages the entire train-to-chat pipeline into a native Mac app.</p>
<h2 id="limitations-and-when-to-reach-for-a-production-stack">Limitations and when to reach for a production stack</h2>
<p>LabLLM is a beta, and it is honest about its scope. It is designed for <strong>tiny</strong> language models — educational, experimental, and small-scale work. If your goal is to train or serve a large production model, you should reach for a full stack.</p>
<ul>
<li><strong>Scale.</strong> LabLLM targets small models that fit in a laptop&rsquo;s unified memory. Training a multi-billion-parameter model is out of scope.</li>
<li><strong>Maturity.</strong> At ~76 stars and two beta releases, the project is early. Expect rough edges, and check the pinned mlx-swift version when building.</li>
<li><strong>Ecosystem.</strong> For serious distributed training, you would use a framework like PyTorch with a GPU cluster, not a single-Mac GUI app.</li>
</ul>
<p>The right mental model: LabLLM is a learning and experimentation tool, not a production training platform. Use it to understand how language models work, prototype ideas, and train small models for personal or edge use cases.</p>
<h2 id="roadmap-and-where-the-project-is-headed">Roadmap and where the project is headed</h2>
<p>LabLLM is moving fast for a project this young. Beta 0.1 &ldquo;Teach Tiny Brains&rdquo; established the core training loop, and Beta 0.2 &ldquo;Remember the Run&rdquo; added checkpoint save/resume and run comparison. The trajectory points toward a more complete, polished training environment.</p>
<p>Given the momentum of the MLX ecosystem — 28,314 stars on MLX, 2,014 on mlx-swift, and strong community demand for local workflows — LabLLM is well positioned to grow. The combination of a native GUI, on-device training, LoRA and DPO fine-tuning, and an OpenAI-shaped serving endpoint makes it a compelling entry point for anyone who wants to teach a tiny language model to think, right on their own Mac.</p>
<h2 id="faq">FAQ</h2>
<p><strong>Is LabLLM free to use?</strong>
Yes. LabLLM is free and MIT-licensed, and it is currently in beta. There is no subscription and no cloud component — everything runs locally on your Mac.</p>
<p><strong>What hardware do I need to run LabLLM?</strong>
You need a Mac running macOS 14 or newer with Apple Silicon (M1 or newer), Xcode 15 or newer, and Swift Package Manager. The app relies on MLX&rsquo;s Metal acceleration, so an Intel Mac will not work.</p>
<p><strong>Can I train a model without writing any code?</strong>
Yes. That is the core value of LabLLM. You build a Transformer, import or search for data, and train — all through a native GUI, with no Python or command-line work required.</p>
<p><strong>What is the difference between LoRA and DPO fine-tuning?</strong>
LoRA (Low-Rank Adaptation) fine-tunes small adapter matrices on top of a frozen base model, reducing memory and compute. DPO (Direct Preference Optimization) aligns a model with human preferences using preference pairs, without the complexity of a full RLHF pipeline.</p>
<p><strong>Can I use the model I train with other tools?</strong>
Yes. LabLLM can serve your model through a local OpenAI-shaped endpoint, so any tool that already integrates with OpenAI&rsquo;s API can point at your locally trained model instead.</p>
]]></content:encoded></item></channel></rss>