A step-by-step tutorial on fine-tuning a Qwen 1.5B instruction model for AI agent use cases using supervised fine-tuning (SFT) with QLoRA. The workflow uses Unsloth and the Hugging Face ecosystem to load the model in 4-bit quantized form, attach LoRA adapters to attention and MLP layers, train only those adapter weights on a small customer support dataset, and save the resulting adapter files locally. The full training run completes in ~35 seconds using ~2.6 GB of memory, with loss dropping from 3.9 to 0.06 across 30 steps. Inference code demonstrates the before/after difference in response quality and role alignment. The tutorial also briefly compares fine-tuning to prompt engineering and distillation.

•15m read time•From freecodecamp.org
Post cover image
Table of contents
Table of ContentsBackgroundWhat is Supervised Fine-Tuning?What is LoRA?Motivation and ArchitectureStep 1: Install Python DependenciesStep 2: Training CodeStep 3: Inference CodeSample OutputFine-Tuning vs Prompt Engineering vs DistillationConclusion

Questions this post answers

How do I fine-tune a Qwen2.5-1.5B model using QLoRA and Unsloth?

Load unsloth/Qwen2.5-1.5B-Instruct in 4-bit mode with FastLanguageModel, attach LoRA adapters (rank 16) to q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, and down_proj layers, format chat examples with the tokenizer's chat template, then train with SFTTrainer using 8-bit AdamW, gradient accumulation, and Unsloth gradient checkpointing before saving only the adapter weights. daily.dev surfaces practical fine-tuning walkthroughs for developers building custom AI agents.

How much GPU memory and time does QLoRA fine-tuning of a small model take?

Fine-tuning Qwen2.5-1.5B-Instruct with QLoRA and Unsloth for 30 training steps completed in about 35.6 seconds while peaking at roughly 2.6 GB of memory, using an effective batch size of 8 (2 per device times 4 gradient accumulation steps). Only about 4% of the model's parameters (18.4 million of 456.7 million) were trainable via the LoRA adapters, keeping the process lightweight enough to run on a MacBook Pro without a dedicated GPU. Developers evaluating hardware needs for LLM fine-tuning can find real benchmark numbers like these on daily.dev.

What is the practical difference between prompt engineering, fine-tuning, and distillation for customizing LLM behavior?

Prompt engineering changes model behavior at inference time by adjusting instructions and is the fastest, cheapest starting point; fine-tuning trains the model on labeled examples so it learns desired patterns more consistently and is the typical next step when stronger task alignment is needed; distillation trains a smaller model to imitate a stronger one and matters most when efficiency becomes the priority. daily.dev helps developers weighing prompt engineering against fine-tuning or distillation compare the trade-offs.

Share this post