blackdark
Applied AIfine-tuningLLMLoRAQLoRAAI personalityPython

Fine-Tuning LLMs to Create AI Personalities: A Python Tutorial (2026)

A practical guide to fine-tuning LLMs to give a model its own voice: what it is and when it's worth it versus RAG, the step-by-step process with LoRA/QLoRA, dataset format, Python code with Unsloth, real cost, and the typical mistakes.

By BlackdarkUpdated on 9 min read

You ask ChatGPT to write "in your voice" and it hands you three generic paragraphs. You paste an 800-word prompt with examples and rules, and by the fourth reply it's forgotten half of them. The problem isn't that the model is bad. It's that you're asking the form for something that's fixed in the weights.

That's fine-tuning: instead of explaining to the model how to talk in every single prompt, you teach it once, training it on examples of your style until the voice comes out by default. It's the right tool for building your own AI personality. And in 2026 you no longer need a cluster or a master's degree: it fits on a single GPU. Let's build it, no hype.

Heads up

Before you continue: if you haven't squeezed prompt engineering and RAG, you almost certainly don't need fine-tuning yet. The right order is prompting β†’ RAG β†’ fine-tuning. This guide is for when the first two fall short, not for skipping them.

What Fine-Tuning Is (And When It's Worth It and When It Isn't)

A base model like Llama or Qwen already comes pretrained on half the internet. Fine-tuning doesn't start from scratch: it takes that model and keeps training it with your examples to lean it toward a specific behavior. It's not magic, it's adjusting weights.

The key idea almost nobody states plainly: fine-tuning is for FORM, not facts. It's for changing how it sounds, how it structures output, and what vocabulary it uses. It's not for injecting information that changes every week β€” that leaks into a knowledge gap fine-tuning doesn't cover well.

The leading 2026 models still fail at three things fine-tuning fixes at the root:

  • Exact output schema: returning the same JSON, the same format, every time, without drifting.
  • Narrow domain vocabulary: your industry's jargon, your terms, your conventions.
  • Brand voice: that specific tone that dilutes prompt by prompt with prompting alone.

That third point is exactly the heart of creating an AI personality. A consistent voice isn't held up by ever-longer prompts; it's trained once and it stays.

When it IS worth it:

  • You have a stable task with a predictable output (a tone, a format).
  • You've tried prompting and RAG and the model has plateaued.
  • You have (or can gather) 500+ good, coherent examples.

When it's NOT:

  • You need the model to know specific, up-to-date facts β†’ that's RAG.
  • Your case changes constantly β†’ retraining every week doesn't scale.
  • You haven't really tried a good prompt yet β†’ start there, it's free and reversible.

The Fine-Tuning Process at a Glance

Before the code, the map. These are the six steps you'll always walk through, regardless of the tool:

Pipeline for fine-tuning an AI personality

  1. Collect data

    You gather real examples of your voice: question-answer pairs, messages, your own text. This is where the result is won or lost.

  2. Format the dataset

    You convert those examples to JSONL with a chat structure (system / user / assistant). It's the standard format every tool understands.

  3. Choose a method (LoRA)

    You decide how to train. For almost everyone: QLoRA, which quantizes the model and trains a lightweight adapter on a single GPU.

  4. Train

    You launch training on a base model (Llama, Qwen). You touch <1% of the weights; it usually takes minutes to a few hours.

  5. Evaluate

    You test the model with cases that were NOT in the dataset. Does it sound like you? Does it keep the format? If not, tweak the data or hyperparameters.

  6. Deploy

    You merge the adapter, export to GGUF and run it locally with Ollama, or serve it via API. Your personality now lives in the weights.

Notice that training is just one of six steps, and not even the most important one. Steps 1 and 2 β€” the data β€” decide 80% of the result. We'll repeat that until it's boring.

Step by Step With Code (Python + Unsloth)

We'll use Unsloth, which in 2026 is the fastest path to training on a single GPU: its optimized kernels cut memory use by up to 74% and speed up training 2-5x versus plain Hugging Face Transformers. It runs on Google Colab's free GPU. If you prefer config-driven pipelines in YAML without writing Python, Axolotl does the same with a config file; and underneath, both lean on the Hugging Face ecosystem.

1. Install the Environment

Install Β· Unsloth + dependencies
pip install unsloth
pip install --no-deps trl peft accelerate bitsandbytes

2. Load the Base Model in 4-bit (QLoRA)

We load a small base model quantized to 4-bit so it fits in little VRAM, and plug in the LoRA adapters.

Load model + LoRA adapters
from unsloth import FastLanguageModel

model, tokenizer = FastLanguageModel.from_pretrained(
  model_name = "unsloth/Meta-Llama-3.1-8B-Instruct",
  max_seq_length = 2048,
  load_in_4bit = True,   # QLoRA: quantizes the base to 4-bit
)

model = FastLanguageModel.get_peft_model(
  model,
  r = 16,                # LoRA adapter rank (8-64 is typical)
  lora_alpha = 16,
  target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
                    "gate_proj", "up_proj", "down_proj"],
)

3. Train

With the dataset already formatted (we cover that next), training is standard. Few epochs: with clean data, 1-3 passes are enough, and overfitting is a real risk.

SFT training
from trl import SFTTrainer
from transformers import TrainingArguments

trainer = SFTTrainer(
  model = model,
  tokenizer = tokenizer,
  train_dataset = dataset,         # your formatted JSONL
  dataset_text_field = "text",
  max_seq_length = 2048,
  args = TrainingArguments(
      per_device_train_batch_size = 2,
      gradient_accumulation_steps = 4,
      num_train_epochs = 2,
      learning_rate = 2e-4,
      output_dir = "outputs",
  ),
)

trainer.train()

4. Infer and Export

You test the freshly trained personality and, if it convinces you, export it to GGUF to run locally with Ollama.

Test + export to GGUF
FastLanguageModel.for_inference(model)
inputs = tokenizer(["What do you make of the AI hype?"], return_tensors="pt").to("cuda")
print(tokenizer.decode(model.generate(**inputs, max_new_tokens=128)[0]))

# Export for Ollama / llama.cpp
model.save_pretrained_gguf("my-personality", tokenizer, quantization_method="q4_k_m")

The Data: The Dataset That Defines Your Personality

This is the real work. The 2026 standard format for supervised fine-tuning (SFT) is JSONL with a messages array in ChatML style: each line is one conversation. It works directly in Unsloth, Axolotl and TRL with no weird conversions.

Dataset format Β· one line per example (JSONL)
{"messages": [
{"role": "system", "content": "You are Blackdark: direct, practical, no hype. No filler."},
{"role": "user", "content": "Is paying for ChatGPT Plus worth it?"},
{"role": "assistant", "content": "Depends on how much you actually use it. If you open the app a couple of times a week, no. If you use it daily for work, the $20 a month pays for itself on day one. What's not worth it is paying 'just in case'."}
]}

The rules that actually matter in the dataset:

  • Voice consistency: every assistant reply has to sound like the personality you want. A single off-tone example pollutes the learning.
  • The system sets the character: use it the same way in every example. It's the anchor of the identity.
  • Quality > quantity: for tone and style, 500-2,000 curated examples beat 50,000 noisy ones. Below ~100 rows, don't even try.
  • Variety of situations: cover different question types so the voice holds up beyond the examples it saw.

Tip

Trick for gathering data fast without hand-writing thousands of lines: take your real text (posts, replies, messages) and use them as assistant responses, generating the user questions with a large model. Then review every pair by hand. The human review isn't optional: it's where the personality is forged.

Cost and Tools, No Surprises

The good news: for a 7-8B model with QLoRA, compute is almost free. It fits in around 8 GB of VRAM, so you train on Colab's free GPU or rent a cloud GPU for a few hours. The real cost isn't training, it's preparing the dataset: that's where the time goes.

The three tools that dominate in 2026:

  • Unsloth β€” the choice if you're on a single GPU and speed matters. Optimized kernels, less memory, faster. The one we used here.
  • Axolotl β€” pipelines defined in a YAML. You pick model, dataset, method and hyperparameters in one file and launch with one command, no Python. Great for repeatable processes.
  • Hugging Face (Transformers + PEFT + TRL) β€” the foundation the other two sit on. More control, more friction.

On the method: LoRA trains only 0.1-1% of the parameters with quality close to retraining the whole model. QLoRA adds 4-bit quantization and reaches around 90% of full fine-tuning quality at a much lower hardware cost. To create a personality at home, QLoRA is the sweet spot.

Typical Mistakes That Wreck the Result

  • Trying to inject facts with fine-tuning. Mistake #1. If you need the model to know up-to-date facts, that's RAG, not fine-tuning. Mixing the two concepts leads to models that hallucinate confidently.
  • A dirty or inconsistent dataset. Off-tone examples, inconsistent formats, mediocre answers. The model learns exactly what you give it, flaws included.
  • Overtraining. Too many epochs and the model memorizes the dataset instead of generalizing your voice. Start with 1-3 passes and measure.
  • Not evaluating with new cases. If you only test with examples that were in training, you're fooling yourself. Evaluate with questions the model hasn't seen.
  • Skipping prompting and RAG. If you haven't exhausted the cheap and reversible options, you're solving with fine-tuning something a good prompt fixed in five minutes.

Pros

  • You want a consistent VOICE or style that prompts can't maintain.
  • You need an exact, repeatable output format (always the same schema).
  • You work with domain vocabulary the base model doesn't master.
  • The behavior is stable and doesn't change every week.
  • You want to cut latency and cost per request versus giant prompts.

Cons

  • You need the model to know specific, up-to-date facts β†’ use RAG.
  • You haven't tried a good system prompt yet β†’ start with prompting, it's free.
  • Your case changes constantly β†’ retraining doesn't scale, RAG is better.
  • You don't have and can't gather hundreds of good examples β†’ no data.
  • You only want it for a one-off test β†’ the setup isn't worth it.

Who Is Fine-Tuning For?

It's not for everyone, and that's fine.

You'll be interested if: you're building a product or agent with its own brand personality and need the voice to be identical in every reply; you have an output format the base model doesn't respect on the first try; you work in a domain with its own jargon; or you want to cut the cost per request versus huge prompts you repeat a thousand times a day.

You won't be interested if: your problem is knowledge, not form (RAG rules there); you haven't squeezed a good system prompt yet; or your case is so one-off that building the pipeline costs more than the benefit.

The honest question isn't "should I fine-tune?", but "is what's failing me the form or the facts?". If it's the form β€” the tone, the voice, the format β€” fine-tuning is the right tool and, with QLoRA and a clean dataset, it's within reach of a single GPU. If it's the facts, skip the training and build a RAG. And if you still don't know, go back to the prompt: the answer was almost always there.

FAQ

It's continuing to train an already-pretrained model with your own examples so it adopts a specific behavior: a tone, an output format, or domain vocabulary. It doesn't start from scratch; it adjusts the weights of a base model like Llama or Qwen to lean it toward your use case. In 2026 the norm isn't retraining the whole model, but adding a lightweight adapter (LoRA) on top.

Rule of thumb: fine-tuning for form (style, voice, format), RAG for facts (information that changes or is yours). If you want the model to SOUND a certain way, fine-tuning. If you want it to KNOW specific, up-to-date things, RAG. For an AI personality with its own knowledge, you usually combine both: fine-tuning for the voice, RAG for the facts.

Fewer than you think, but good ones. To lock in tone and style, 500 to 2,000 curated examples usually beat 50,000 noisy ones. Quality wins over quantity: coherent examples, in your real voice, in the output format you want. Below ~100 rows the model barely moves.

LoRA inserts small matrices (adapters) into the model and trains only 0.1-1% of the parameters, with quality close to retraining everything but at a fraction of the GPU cost. QLoRA goes further: it quantizes the base model to 4-bit so it fits in less VRAM, which makes tuning large models on a single card possible. That's what makes home fine-tuning viable.

For a 7-8B model with QLoRA, the cost is low: it fits in around 8 GB of VRAM, so you can train it on Google Colab's free GPU or rent a cloud GPU for a few hours. The real expense isn't the compute, it's preparing a clean dataset: that's where the time goes and where the result is decided.

Keep digging into the same topic.

Share
Newsletter

Get the next guides in your inbox

AI and marketing ideas and resources, no filler. What works and how to apply it.

Ideas and resources, no spam. Unsubscribe anytime.

Finding this guide useful?

Subscribe