Llama is one of the most fine-tuned open model families, which means the tooling is excellent and the licence is the part people skip. Both matter before you prepare a single row of data.
The licence is not Apache or MIT
This is the first thing to establish, because it shapes what you can do with the result. Llama weights ship under Meta's own community licence rather than a standard open-source licence, with an accompanying acceptable use policy.
Two features matter in practice. There is a scale threshold above which commercial use requires a separate licence from Meta — irrelevant for most organisations and not for all. And the acceptable use policy enumerates prohibited uses that travel with the model, so your deployment has to comply regardless of what your own data permits.
Historically the licence has also carried naming and attribution requirements for derivative models. These terms have changed between releases, so read the licence shipped with the specific checkpoint you are using rather than relying on what was true for an earlier one — and read it before training, not after.
Use the tokenizer's own template
Llama's chat format uses its own special tokens and header structure, and it has changed between major versions. Writing those tokens by hand is how people end up with models that never stop generating or that echo role markers as text.
Let the tokenizer do it. The checkpoint ships with its own template, and applying it is one call. In Unsloth's helpers the named templates are version-specific — there are separate entries for the Llama 3 and 3.1 conventions — which tells you how much the details matter. Our conversation formats post covers why storing rendered tokens in your dataset is a mistake.
Then print the rendered string once and look at it. Thirty seconds here catches a mismatched template, a doubled beginning-of-sequence token, or a missing stop token.
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("<llama-checkpoint>")
msgs = [
{"role": "system", "content": "You are a concise technical assistant."},
{"role": "user", "content": "Summarise this changelog entry: ..."},
{"role": "assistant", "content": "Adds retry handling to the upload path."},
]
text = tok.apply_chat_template(msgs, tokenize=False)
print(repr(text)) # read the special tokens, once, before training
# inference: stop after the assistant header so the model continues it
prompt = tok.apply_chat_template(msgs[:-1], tokenize=False,
add_generation_prompt=True)
What the base model already does well
Llama's instruct checkpoints are strong on general instruction-following, English chat, and code to a reasonable standard. Training on data that teaches those again is wasted effort and risks degrading what is already there.
So the useful question is what it is not good at for your purposes. Typically: your domain vocabulary, your output format, your refusal boundaries, and languages outside its better-served set. Those are what your data should target.
Test this before collecting anything. Prompt the instruct model on your evaluation set with few-shot examples. If careful prompting gets most of the way there, you need a small behavioural fine-tune rather than a large one — and if it cannot do the task even with help, you may be looking at a knowledge gap, which is continued pretraining rather than instruction tuning. Our what dataset should I use post walks that decision.
Practical settings
The Llama family is the best-supported target in every fine-tuning framework, so the ecosystem defaults are well tested here. For a LoRA, rank 16 to 32 with alpha equal to the rank or twice it, a learning rate around 2e-4, one to three epochs, and loss masked to assistant turns only.
Memory, from Unsloth's published requirements table: an 8B model needs about 6 GB for 4-bit QLoRA and about 22 GB for 16-bit LoRA; a 70B model needs about 41 GB for QLoRA and about 164 GB for LoRA. That 8B QLoRA figure is what makes this family practical on consumer hardware.
For preference tuning afterwards, drop the learning rate by one to two orders of magnitude — to around 5e-6 or lower — and run one epoch. See the TRL dataset contract for the data shape, and the Unsloth post for the single most common data bug, which is a missing stop token.
Questions people ask
Can I use a Llama fine-tune commercially?
Generally yes under the community licence, subject to the acceptable use policy and the user-scale threshold above which a separate licence from Meta is required. The terms have changed across releases, so read the licence for your specific checkpoint. Your training data's licence is a separate question that also has to permit the use.
Should I fine-tune the base or the instruct model?
Instruct, for most purposes — it already follows instructions and you are adjusting behaviour. Choose the base model if you are doing continued pretraining on raw domain text, or if you want full control of the response style without inheriting the instruct tuning's habits. Note that fine-tuning an already-tuned model can alter capabilities it had, so evaluate what you are not trying to change.
Which Llama size should I start with?
The smallest one that can do the task with good prompting, because serving cost is forever while training cost is once. Establish the task is learnable on an 8B-class model before reaching for a 70B, and note the memory gap: roughly 6 GB versus 41 GB for QLoRA.
How much data do I need?
The published figures come from Unsloth's documentation, not from the model's maker: a minimum of 100 rows with over 1,000 preferable for supervised fine-tuning, at 1–3 epochs, and at least 500 rows for GRPO. Nothing is published for DPO-style preference tuning. See how much data for a LoRA for the doubling experiment that answers it for your task rather than in general.