100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

LLM Fine-Tuning Basics Cheat Sheet

LLM Fine-Tuning Basics Cheat Sheet

Covers full fine-tuning versus parameter-efficient methods like LoRA and QLoRA, and shows how to configure PEFT for fine-tuning with Hugging Face.

2 PagesIntermediateFeb 25, 2026

Core Concepts

Approaches to adapting a pretrained LLM.

  • Full fine-tuning- Updates all model weights; most expressive but requires large GPU memory and risks catastrophic forgetting
  • LoRA (Low-Rank Adaptation)- Freezes the base model and trains small low-rank matrices injected into attention/linear layers, drastically cutting trainable parameters
  • QLoRA- LoRA applied on top of a 4-bit quantized frozen base model, enabling fine-tuning of large models on a single GPU
  • PEFT (Parameter-Efficient Fine-Tuning)- Umbrella term for methods (LoRA, prefix tuning, adapters) that train a small fraction of parameters
  • Instruction tuning- Fine-tuning on (instruction, response) pairs so the model follows natural-language instructions better
  • Catastrophic forgetting- Fine-tuning on a narrow task can degrade the model's general capabilities from pretraining

LoRA Fine-Tuning with PEFT

Attach LoRA adapters to a Hugging Face model.

python
from peft import LoraConfig, get_peft_model, TaskTypefrom transformers import AutoModelForCausalLMmodel = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3-8b")lora_config = LoraConfig(    task_type=TaskType.CAUSAL_LM,    r=8,                        # rank of the low-rank matrices    lora_alpha=16,              # scaling factor    lora_dropout=0.05,    target_modules=["q_proj", "v_proj"],)model = get_peft_model(model, lora_config)model.print_trainable_parameters()  # typically < 1% of total params

Loading a 4-bit Quantized Base Model (QLoRA)

Load the frozen base model in 4-bit precision before attaching LoRA adapters.

python
from transformers import AutoModelForCausalLM, BitsAndBytesConfigimport torchbnb_config = BitsAndBytesConfig(    load_in_4bit=True,    bnb_4bit_quant_type="nf4",    bnb_4bit_compute_dtype=torch.bfloat16,    bnb_4bit_use_double_quant=True,)model = AutoModelForCausalLM.from_pretrained(    "meta-llama/Llama-3-8b", quantization_config=bnb_config, device_map="auto")# Attach LoraConfig from above with get_peft_model(model, lora_config)

Choosing an Approach

Match the method to your compute budget and goal.

  • Small dataset, limited GPU- LoRA or QLoRA; a few hours on a single consumer/cloud GPU is often enough
  • Need every ounce of capability- Full fine-tuning, if you have multi-GPU compute and a large, high-quality dataset
  • Just steering behavior/format- Prompt engineering or few-shot prompting first -- often cheaper than any fine-tuning
  • Deploying many task variants- LoRA adapters are small (MBs) and swappable on top of one shared base model
Pro Tip

Always keep a held-out eval set of general-purpose prompts (not just your fine-tuning task) and check it before/after fine-tuning -- a model that aces your narrow dataset but has quietly forgotten general instruction-following isn't actually an improvement.

Was this cheat sheet helpful?

Explore Topics

#LLMFineTuningBasics#LLMFineTuningBasicsCheatSheet#DataScience#Intermediate#CoreConcepts#LoRA#Fine#Tuning#Functions#MachineLearning#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet