โ† All build guides

Fine-Tune an LLM on Your Own Data Locally

A LoRA fine-tune of Llama 3.1 8B on your own data, trained on a single consumer GPU and runnable in Ollama.

โฑ 3-4 hours (mostly waiting for training)๐Ÿ›  NVIDIA GPU (Unsloth lists 6 GB VRAM as the minimum for an 8B QLoRA), Python 3.10+, ~50 training examples.
  1. 1

    Prepare your dataset

    You need 50-1000 examples in `{instruction, input, output}` JSONL format. Quality > quantity โ€” 100 great examples beats 10,000 mediocre ones. Examples: support tickets paired with ideal replies, code snippets paired with reviews, raw prompts paired with style-corrected outputs. Save as `train.jsonl`.

  2. 2

    Install Unsloth

    `pip install unsloth` (it pulls in transformers, peft, trl and bitsandbytes). Unsloth wraps Hugging Face transformers with faster training kernels; its README lists Llama 3.1 (8B) fine-tuning at 2x faster with 70% less VRAM, and its requirements page lists 6 GB VRAM for an 8B model with QLoRA (4-bit) versus 22 GB for 16-bit LoRA. Those are Unsloth's own minimums, checked November 2026.

  3. 3

    Train the LoRA

    Load the base model with `FastLanguageModel.from_pretrained("unsloth/Llama-3.1-8B-Instruct-bnb-4bit", load_in_4bit=True)`. Wrap it with LoRA adapters via `FastLanguageModel.get_peft_model(...)`, target modules `["q_proj", "v_proj"]` to start. Use `SFTTrainer` (from trl) with `train.jsonl`, batch_size 4, lr 2e-4, 3 epochs. Training time scales with dataset size, sequence length and GPU, so run one epoch on a small slice first to see how long a full run will take.

  4. 4

    Convert to GGUF

    Unsloth can merge the LoRA and write a quantized GGUF in one call: `model.save_pretrained_gguf("my-model", tokenizer, quantization_method="q4_k_m")`. The manual route is `model.save_pretrained_merged("merged_model", tokenizer, save_method="merged_16bit")`, then `python llama.cpp/convert_hf_to_gguf.py merged_model --outfile my-model-f16.gguf --outtype f16` and `llama-quantize my-model-f16.gguf my-model.gguf Q4_K_M` (the converter has no Q4_K_M output type, so k-quants are a second step). Either way you get a quantized GGUF file ready for any local runtime.

  5. 5

    Run it in Ollama

    Create a `Modelfile`: `FROM ./my-model.gguf` + `TEMPLATE` matching Llama 3.1's chat format + your system prompt. Then `ollama create my-finetune -f Modelfile`. Run with `ollama run my-finetune` โ€” your LLM, fine-tuned on your data, running locally, no cloud bill.

  6. 6

    When fine-tuning is the wrong tool

    Fine-tuning is for changing the *style* or *format* the model uses. For knowledge โ€” "answer questions about my docs" โ€” RAG is usually the better fit, and updating it means re-indexing documents rather than retraining. The What is AI fine-tuning chapter covers when to choose which, and the Fine-Tuning, Distillation, and Model Adaptation course goes deeper.

Want the full path?

Continue with the full What is AI ยท Fine-tuning chapter course on Local AI Master.

This page is one chapter of a structured course covering everything from foundations to production. Go Pro for full access to all 561 chapters across 25 courses plus the Python Lab โ€” about $0.30/day, cancel anytime.

$8.99/mo ยท about $0.30/day ยท cancel anytime
Free Tools & Calculators