LLM Fine-Tuning and Experiments

how to fine tune an llm

You have a modest set of good examples and want to know how to fine tune an llm without wasting a training run. Clean the data, train with LoRA adapters, then compare outputs side by side before deployment.

This pillar maps the whole topic and sends you to the right depth. The full walkthrough lives in how to fine-tune an llm. This page helps you decide whether to fine-tune, how to prepare a small dataset, how to judge the result and where alignment methods fit.

Reader routes through fine-tuning and LLM experiments

Most readers arrive with one of four goals. Each route below is ordered so that the earlier steps lower the risk of the later ones, and each points to the section of this page that covers it.

A written log with a tick beside each completed step is a low-tech way to keep experiments comparable.

Route one: adapt a model to your own examples

This is the route for developers who already have examples of the behaviour they want, such as a tone, an output format or a narrow task.

Prompt iteration happens in an ordinary code editor, which makes it the cheapest experiment to run before any training job.
  1. Write a prompt baseline. Establish what the model does without training so you have something to beat (see the section on deciding whether to fine-tune).
  2. Prepare and clean the dataset. Format it as JSONL and remove duplicates and errors before anything else.
  3. Train with adapters. Pick a base model, set the core training parameters and run a small experiment.
  4. Evaluate side by side. Compare the tuned model against the baseline on the same inputs before you deploy.

Route two: ship an LLM feature in an app

If your goal is a working product feature rather than a trained model, start with the section on practical uses of LLMs in apps. Decide whether training is needed at all, then wire the model in through an API and keep logs from day one.

Route three: understand alignment methods

If you are curious how models are steered by human feedback or written principles, read the section on alignment after supervised tuning. It is best taken after you have seen a basic fine-tuning run, because the later methods build on that vocabulary.

Route four: measure whether a model is any good

If you already have a model and need evidence, go straight to the evaluation sections. They cover side-by-side checks, benchmarks, human review and production feedback.

Deciding whether to fine-tune at all

Fine-tuning takes a pre-trained base model and customises it with your own examples. Open-source models such as Llama-8b and Mixtral-8x7b-instruct are described in FinetuneDB’s guide to fine-tuning open-source models as a strong foundation for customization. That is the main appeal. You do not train a language model from nothing, you steer an existing one toward your task.

Training is not always the first thing to reach for. A carefully written prompt costs no training run, shows you the model’s default behaviour and gives you a baseline that any tuned model must beat. If a prompt already produces acceptable output, fine-tuning may add cost and maintenance without a measurable gain. If the prompt keeps failing in the same way, especially on style, structure or a narrow task, that repeated failure is the signal that examples may help more than instructions.

The trade-offs between tuning, retrieval and prompting deserve their own treatment. Read fine tuning vs rag when you are unsure which of the three fits your problem. As a rule of thumb for this page, treat prompting as the baseline, treat fine-tuning as the step you take when the baseline’s failures are consistent and describable, and keep a record of both so the comparison is honest.

Questions to answer before you spend compute

  • Can you describe the failure? “The answers are wrong” is too vague. “The model ignores my output format” is a problem that examples can address.
  • Do you have good examples? Training teaches what the data shows. If you cannot produce clean examples of the desired output, tuning will copy your inconsistencies.
  • How will you know it worked? Decide the evaluation inputs before training, so the result cannot quietly shape the test.
  • Who maintains it? A tuned model is an asset you must evaluate again when the base model or your requirements change.

Fine-tuning an LLM on a small dataset

Fine-tuning on a small dataset works best when the data is relevant and clean. FinetuneDB’s guidance is direct on this point: the relevance and quality of the data are more crucial than the quantity. For a small project, that shifts the work from collecting more rows to improving the rows you have.

Dataset format and structure

A common upload format is JSONL, with each line holding one dataset entry. The FinetuneDB guide describes uploading an existing dataset in this form, one entry per line. The practical benefit is that entries stay independent. You can append new examples, remove a bad one or split the file for experiments without reformatting everything.

Cleaning before training

Keymakr’s enterprise walkthrough lists a clear cleaning step: remove duplicates, errors and irrelevant information from the data. On a small dataset, each of those problems carries more weight, because a few repeated or faulty rows make up a larger share of what the model learns from. Read your own examples, one entry at a time, before you read any training log.

How much data is enough?

The documented guidance here centres on quality and relevance rather than a target row count, so treat any universal number you see elsewhere with caution. A better method is empirical. Start with a small, carefully cleaned set, train, evaluate against your prompt baseline and only then decide whether more data would help. If the failures that remain are about missing coverage, add examples that cover those cases. If they come from inconsistent labels, adding rows will not help, and fixing the existing ones will.

A practical small-dataset checklist

  • Consistency first. Make every example follow the same format and voice you want in the output.
  • Cover real inputs. Include the messy, edge-case requests your application actually receives, not only tidy ones.
  • Hold some back. Keep a portion of examples out of training so you can evaluate on inputs the model has not seen.
  • Version the file. Save each dataset version with a note so you can tie a result to the data that produced it.

The fine-tuning workflow, step by step

A fine-tuning run follows a repeatable order: choose a base model, prepare data, set parameters, train, merge or consolidate the result, evaluate and deploy. The condensed route is below. The longer tutorial is in how to fine-tune an llm.

Sketching the pipeline on paper, from raw examples to a deployed model, makes it easier to spot which stage you are about to skip.

Step one: choose a base model

Pick a model whose size your hardware can handle and whose licence suits your use. Hugging Face’s Optimum Neuron tutorials show instruction fine-tuning of Llama 3.1 8B with LoRA on the Dolly dataset, and fine-tuning of Qwen3 8B with LoRA on the Simple Recipes dataset. Those pairings are useful as worked examples of matching a base model to a dataset type. If Llama is your target, how to fine tune llama goes deeper, and fine-tune mistral 7b covers those families.

Step two: set the training parameters

FinetuneDB names the key parameters to adjust as learning rate, batch size and number of epochs. They interact, so change them deliberately and one at a time, and record each run. The guide to llm fine tuning hyperparameters treats them in detail.

Step three: train with LoRA adapters

The Hugging Face tutorial workflow sets up LoRA adapters and distributed training parameters rather than updating the whole model directly. For the mechanics and the trade-offs, see lora fine tuning explained. If you prefer a higher-level library over assembling the pieces yourself, the unsloth fine-tuning tutorial compares the common options.

Step four: consolidate and merge checkpoints

The same Hugging Face workflow ends by consolidating and merging model checkpoints for deployment. Treat this as a real step, not an afterthought. Training produces intermediate artefacts, and you need a single, deployable result that you have actually tested in its final form.

Step five: evaluate, then deploy

Do not deploy on the strength of a falling training loss. The next sections cover how to judge the result and how to serve it.

Compute, quantization and model size

Compute decides which routes are open to you. Hugging Face documents tutorials for running and fine-tuning models on AWS Trainium, so accelerator hardware beyond a standard GPU is a documented option for training. If you work from a laptop or a modest machine, your realistic path is a smaller model, adapter-based training and aggressive cost control.

Training workloads run on racked server hardware like this when a laptop is not enough, whether rented or owned.

Quantization

Keymakr’s enterprise guide describes quantization as representing weights with lower-precision numbers, which reduces model size and speeds up inference. For a developer, that means a quantized model is easier to host and cheaper to serve. The cost of lower precision is something you should measure on your own evaluation set instead of assuming it is free. If you are working on constrained hardware, the qlora fine tuning tutorial is the place to continue.

Smaller models and distillation

A smaller model that does one job well is often a better product decision than a large one that does everything adequately. Fine tuning small language models explains when that trade pays off. If you want a large model’s behaviour in a compact one, the llm distillation tutorial covers that approach.

Choosing a tooling route

There are several ways to run the same workflow, and the right one depends on how much infrastructure you want to manage. The table compares the options at a decision level.

Route Suits How it handles data and models Planning use
Hosted fine-tuning platform Teams that want upload, train, evaluate and serve in one place Datasets uploaded as JSONL with one entry per line; learning rate, batch size and epochs adjusted; a log viewer tracks production data and feedback; deployment uses an endpoint and API key, similar to the OpenAI API Choose it when speed to a working endpoint matters more than control over the training stack
Hugging Face Optimum Neuron tutorials Developers comfortable with code who want to see each stage LoRA adapters and distributed training parameters set up explicitly; checkpoints consolidated and merged for deployment; examples for Llama 3.1 8B and Qwen3 8B Choose it to learn the workflow or to run training on AWS Trainium
Prompting only, no training Early prototypes and anyone without clean examples No dataset or training run; behaviour is shaped by instructions alone Use it as the baseline every tuned model has to beat

Platform details come from FinetuneDB’s open-source fine-tuning guide, and the tutorial details come from Hugging Face’s Optimum Neuron documentation.

How to choose between them

If your priority is learning, start with the code-first route so every stage is visible, then move to a hosted workflow if the maintenance overhead is not worth it. If your priority is delivery, a hosted route gets a model behind an endpoint sooner, and its familiar API-style deployment keeps application code simple. Either way, keep the prompt-only baseline running in parallel, because it is the cheapest way to detect a tuned model that is not actually an improvement.

Evaluating a fine-tuned model

Evaluate a fine-tuned model by comparing it against your baseline on the same inputs, and then adding human judgement for the qualities that automated checks miss. FinetuneDB’s guide states that evaluations are key for reliable model performance and describes side-by-side evaluation of prompts and models. Keymakr’s guide recommends running benchmark tests and human assessment to verify that the model behaves reliably and meets accuracy and safety requirements.

A checklist with mostly empty boxes is a fair picture of an evaluation plan before any criterion has been tested.

Side-by-side comparison

Run the same set of inputs through the baseline prompt and the tuned model, then read the outputs next to each other. This is the simplest evaluation and often the most informative. It shows whether the new model follows your format, keeps your tone and avoids regressions on inputs it should handle as before. Use inputs held out from training, otherwise you are checking memory rather than behaviour.

Benchmarks and automated judging

Benchmarks give a repeatable number, which helps when you compare runs. They measure what they were designed to measure, so choose them to match your task. LLM benchmarks explained walks through what the common ones test and where they mislead. When you need to scale beyond reading outputs by hand, llm as a judge covers using a model to grade another model’s answers, including the biases to watch for.

Human review

Automated scores do not replace a person reading the output. Human assessment is what catches a confident but wrong answer, an off-brand tone or an unsafe response that a metric rates highly. Decide what reviewers look for before they start, such as accuracy, format adherence and safety, and have them apply the same criteria to both the baseline and the tuned model.

After deployment

Evaluation does not stop at release. FinetuneDB describes using a log viewer to track production data, identify issues and gather feedback. The practical loop is to review logged failures, add corrected examples to the dataset, retrain and re-evaluate against the same fixed test inputs, so you can see whether the change helped.

Running experiments you can reproduce

A fine-tuning experiment is reproducible when someone else can rerun it and compare results. That discipline matters more than any single tuning trick, because without it you cannot tell whether a change helped or whether the run was lucky.

What to record for every run

  • Base model and version. Name the exact model you started from.
  • Dataset version. Note which file produced which result, including the cleaning you applied.
  • Training parameters. Log learning rate, batch size and number of epochs, the settings FinetuneDB highlights as the main ones to adjust.
  • Adapter setup. If you use LoRA, record how the adapters were configured, since that is part of the workflow the Hugging Face tutorials set up explicitly.
  • Evaluation inputs and outcome. Keep the same held-out inputs across runs and store the outputs you judged.

Change one thing at a time

When a result improves, you want to know why. Changing the dataset, the learning rate and the base model together hides the cause. Alter a single variable between runs, compare against the previous run and your prompt baseline, and write down what you concluded. A short log of small, controlled changes teaches you more than a few large, confounded ones.

Alignment after supervised tuning

Supervised fine-tuning teaches a model from examples of the answer you want. A separate family of methods shapes behaviour through preferences or written principles instead. If your goal is to steer which of several outputs a model favours, rather than to teach a new format, these are the guides to read next.

  • Preference learning from human feedback. How does rlhf work explains the pipeline from a developer’s point of view, including how comparisons between a pair of outputs become a training signal.
  • A simpler alternative. DPO vs RLHF compares the two approaches so you can judge whether the lighter option fits your project.
  • Principles instead of per-example labels. What is constitutional ai covers steering a model with written rules.

These methods usually matter later in a project. If you cannot yet produce clean examples and a trustworthy evaluation, solving those problems first will move your results more than a more elaborate training method.

Practical uses of LLMs in apps

LLMs fit into applications mainly through APIs. Keymakr’s guide notes that APIs let you connect a fine-tuned model to chatbots, document search tools and analytics dashboards. Those three patterns cover a large share of everyday product work: a conversational interface for users, a search experience over your own documents and a layer that explains or summarises data.

Connecting a model to an app is ordinary code: a request, a response and the logic around them, written in a normal editor.

Serving a fine-tuned model

Deployment can look familiar if you have used a hosted model before. FinetuneDB describes deploying a fine-tuned model as straightforward and similar to using the OpenAI API, with an endpoint and an API key. For an application developer, that means the integration code for a tuned model can resemble code you would write for any hosted provider, which keeps switching and comparing models manageable.

Matching the use to the technique

  • Chatbots. Tone and format consistency are good candidates for fine-tuning, provided you have clean examples of the desired replies.
  • Document search. The value here comes from your documents, so evaluate whether answers stay grounded in them, and compare approaches in the guide to fine tuning vs rag linked earlier.
  • Analytics dashboards. Treat model-written explanations as output that needs the same review as any other, with human spot checks on accuracy.

Whatever the use, wire in logging from the first release. The production feedback loop described above is how a deployed model improves, and it only works if the data is captured.

Where to go next

Choose the next page by your current bottleneck. If you lack data, work through the small-dataset checklist above. If training fails or underperforms, tune parameters one at a time and compare against your baseline. If you cannot tell whether a model is better, build the evaluation first. Fine-tuning rewards patience and careful records far more than clever shortcuts.

Frequently asked questions

Question Answer
What file format should training data use? JSONL is a common choice, with each line holding a single dataset entry. It keeps examples independent, so you can add, remove or split them easily.
Which training settings should I adjust first? Learning rate, batch size and number of epochs are the key parameters named in FinetuneDB’s guidance. Change them one at a time and log each run.
Is benchmarking enough to approve a tuned model? No. Pair benchmark tests with human assessment, and compare the model side by side with your baseline before deployment.
Does deploying a tuned model require a new integration style? Not necessarily. A hosted fine-tuned model can be served through an endpoint and API key, similar to using the OpenAI API.