Unsloth Fine-Tuning Guide: Train a Custom LLM with Your Own Data
Want AI to understand your business — customer service reply style, code standards, product knowledge. But fine-tuning is slow and expensive, and I've heard a single model can cost tens of thousands. Unsloth says: a few hundred bucks and a few images, done.
💡 What You Will Learn
Want AI to understand your business — customer service reply style, code standards, product knowledge. But fine-tuning is slow and expensive, and I've heard a single model can cost tens of thousands.
📜 Table of Contents
UnslothWhat Is
pip install unsloth
# conda
conda create -n unsloth python=3.11
conda activate unsloth
pip install unsloth
{"instruction": "", "input": "", "output": ""}
{"instruction": "", "input": "", "output": ""}
from unsloth import FastLanguageModel
import torch
# Auto/Automatic
model, tokenizer = FastLanguageModel.from_pretrained(
model_name="unsloth/Qwen2.5-7B-bnb-4bit",
max_seq_length=2048,
dtype=None,
load_in_4bit=True,
)
# LoRAParameter
model = FastLanguageModel.get_peft_model(
model,
r=16,
target_modules=["q_proj", "k_proj", "v_proj", "o_proj"],
lora_alpha=16,
lora_dropout=0,
bias="none",
use_gradient_checkpointing="unsloth",
)
#
from transformers import TrainingArguments
from trl import SFTTrainer
trainer = SFTTrainer(
model=model,
tokenizer=tokenizer,
train_dataset=dataset,
args=TrainingArguments(
per_device_train_batch_size=2,
gradient_accumulation_steps=4,
num_train_epochs=3,
learning_rate=2e-4,
output_dir="./outputs",
),
)
trainer.train()
#
model.save_pretrained("./my-custom-model")
tokenizer.save_pretrained("./my-custom-model")
model, tokenizer = FastLanguageModel.from_pretrained("./my-custom-model")
prompt = ""
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=128)
print(tokenizer.decode(outputs[0]))
Common PitfallsSummary
Related Articles
2026-07-22
Raspberry Pi AI 2026: Run LLMs on $50 Board
2026-08-11
In-Context Learning Explained 2026: How Models Learn From Examples Without Training
2026-07-22
Multi-Agent System Architecture 2026
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.
