← All articles
Guide · 2026-11-23

Local Model Fine-Tuning, Advanced: A Hands-On Path to DPO Preference Alignment

Published 2026-11-23 ·Mentions: Unsloth, Hugging Face, Ollama
Local Model Fine-Tuning, Advanced: A Hands-On Path to DPO Preference Alignment
The short version: when a model can talk but its answers miss the tone you want, the next step is not more SFT data — it is DPO preference alignment. Start from a model that has already been through SFT, prepare paired preference data (one question, one answer you want and one you do not), and optimize the preference directly with TRL's DPOTrainer, with no reward model to train. Unsloth runs this flow on consumer GPUs, and the trained model can be exported as GGUF and run locally with Ollama.

The Verdict: SFT Model First, Then DPO

This guide is for people who have already run a LoRA fine-tune and want the model's answers to match their taste better. The goal is to take an SFT model that already works and align it once more to your own preferences. If you have not done SFT yet, run the LoRA flow first — DPO cannot replace SFT.

The route has three parts: pick an already-trained SFT model on the Hub, or train one with your own data; then prepare preference data, one question plus one pair of answers per row; then train with Unsloth plus TRL's DPOTrainer, export to GGUF, and verify with Ollama.

What to Prepare

Prepare four things: a computer with an NVIDIA GPU, with the GPU and CUDA requirements checked against Unsloth's install notes; a Python environment with unsloth and trl installed; a preference dataset with prompt, chosen, and rejected columns; and an SFT model, found on the Hub or trained by yourself.

Public preference datasets can be taken straight from the Hub — the TRL documentation's quick start uses trl-lib/ultrafeedback_binarized. When building your own data, each pair of answers comes from the same question, and the difference should focus on the one point you want to correct. Validate the flow on a small batch first.

Step by Step: From Preference Data to a Local Model

Step one, set up the environment and confirm the SFT model: install everything the way Unsloth's install guide describes, load the SFT model, and run it once. Unsloth loads the model with FastLanguageModel, attaches LoRA weights, and patches the TRL trainer with PatchDPOTrainer; DPOTrainer comes from the TRL library.

Step two, prepare the preference data and start training: arrange the data into prompt, chosen, and rejected columns, pass them into DPOTrainer, and call train(). Beta is the temperature parameter of the DPO loss, usually 0.1 to 0.5, with 0.1 as the default; during training, watch whether the reward margin (rewards/margins) trends upward.

Step three, export and verify: export the trained model in GGUF format, write a Modelfile with FROM pointing at the GGUF file, then build the model with ollama create and run it with ollama run. FROM is required. Once built, verify it in a local chat and compare answers to the same questions before and after DPO to see whether they moved as expected.

Common Blocks and Fixes

Block one: the model gets worse after DPO. Check the SFT model first — the TRL documentation stresses that DPO always starts from an SFT model. Then check the preference data: when chosen and rejected differ too little, the model has no direction to learn.

Block two: out of memory. Shorten the sequence length and the batch first, then confirm the matching backend is installed the way Unsloth's install guide describes; Unsloth's official pages state that training runs faster with less memory, but you still need a GPU large enough for the target model. Block three: Ollama will not run the imported GGUF. Confirm the FROM path in the Modelfile, then run ollama create again.

Things to Watch

First, preference data is preference itself: the leanings in the data go straight into the model, so do not collect only answers you already like, and do not write contested judgments into chosen. Second, a DPO-trained model still needs human acceptance: prepare a dozen fixed questions and run them before and after training. Third, Unsloth's homepage now centers on its desktop app, so follow the PyPI package page and the documentation for the code-based install route instead of copying commands from older tutorials.

Record every training run: base model, dataset, beta, and epoch count, so it can be reproduced later, and verify a trained model locally before sharing it anywhere.

Verification Note

The steps in this article were checked against the official pages on 2026-11-23. If the platforms' rules change, the official pages apply.

Tools mentioned

AI Infrastructure · See official site — Open-source LLM fine-tuning library enabling faster fine-tuning and training of open-source models with lower VRAM usage.
AI Infrastructure · Free tier + paid — Global open-source AI hub hosting models, datasets, Spaces demos, and inference endpoints.
AI Infrastructure · Free tier + paid — Ollama is the easiest way to run and build with open AI models locally or in the cloud on macOS, Windows, and Linux.

Sources

  1. Unsloth
  2. Unsloth
  3. Hugging Face
  4. Ollama
  5. Ollama

This article is compiled from the public sources above and does not reproduce the originals in full; see the official sources for details.

Sign in to Lumo

Sign in with a one-time code sent to your email — no password. Your saved tools will sync across your devices.

The code is only used to sign you in. We store just your email and saved list (privacy policy, in Chinese).

—

Signed in. Your saved tools sync across all your devices.

0saved
View saved tools

Send feedback

Found a mistake, missing something, or have a suggestion? Tell us.