Skip to content
Skillpedia
Machine learning12k Β· #11424

fine-tuning-expert

What it does

It guides the AI agent through fine-tuning a large language model on your own examples. It is for machine learning engineers and teams who need a model that fits a specific task better than a general one.

When to use it

  • βœ“When you want to train a language model on your own examples for a specific task.
  • βœ“When you need a LoRA or QLoRA adapter set up to save GPU memory.
  • βœ“When you want to compare a fine-tuned model against the base model and check its quality.

Skill link

https://github.com/Jeffallan/claude-skills/blob/main/skills/fine-tuning-expert/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/Jeffallan/claude-skills/blob/main/skills/fine-tuning-expert/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œHelp me fine-tune a small language model on my support chat examples so it answers in our brand voice.”

5 new skills a week. 1 minute to read.

How it works

The agent checks and formats the training data first, picks a method that fits your hardware, and watches the training loss. It then evaluates the model on held-out examples before packaging it for use.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Fine-Tuning Expert

Senior ML engineer specializing in LLM fine-tuning, parameter-efficient methods, and production model optimization.

Core Workflow

  1. Dataset preparation β€” Validate and format data; run quality checks before training starts
    • Checkpoint: python validate_dataset.py --input data.jsonl β€” fix all errors before proceeding
  2. Method selection β€” Choose PEFT technique based on GPU memory and task requirements
    • Use LoRA for most tasks; QLoRA (4-bit) when GPU memory is constrained; full fine-tune only for small models
  3. Training β€” Configure hyperparameters, monitor loss curves, checkpoint regularly
    • Checkpoint: validation loss must decrease; plateau or increase signals overfitting
  4. Evaluation β€” Benchmark against the base model; test on held-out set and edge cases
    • Checkpoint: collect perplexity, task-specific metrics (BLEU/ROUGE), and latency numbers
  5. Deployment β€” Merge adapter weights, quantize, measure inference throughput before serving

Reference Guide

Load detailed guidance based on context:

Topic Reference Load When
LoRA/PEFT references/lora-peft.md Parameter-efficient fine-tuning, adapters
Dataset Prep references/dataset-preparation.md Training data formatting, quality checks
Hyperparameters references/hyperparameter-tuning.md Learning rates, batch sizes, schedulers
Evaluation references/evaluation-metrics.md Benchmarking, metrics, model comparison
Deployment references/deployment-optimization.md Model merging, quantization, serving

Minimal Working Example β€” LoRA Fine-Tuning with Hugging Face PEFT

from datasets import load_dataset
from transformers import AutoTokenizer, AutoModelForCausalLM, TrainingArguments
from peft import LoraConfig, get_peft_model, TaskType
from trl import SFTTrainer
import torch

# 1. Load base model and tokenizer
model_id = "meta-llama/Llama-3-8B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
tokenizer.pad_token = tokenizer.eos_token

model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto",
)

# 2. Configure LoRA adapter
lora_config = LoraConfig(
    task_type=TaskType.CAUSAL_LM,
    r=16,               # rank β€” increase for more capacity, decrease to save memory
    lora_alpha=32,      # scaling factor; typically 2Γ— rank
    target_modules=["q_proj", "v_proj"],
    lora_dropout=0.05,
    bias="none",
)
model = get_peft_model(model, lora_config)
model.print_trainable_parameters()  # verify: should be ~0.1–1% of total params

# 3. Load and format dataset (Alpaca-style JSONL)
dataset = load_dataset("json", data_files={"train": "train.jsonl", "test": "test.jsonl"})

def format_prompt(example):
    return {"text": f"### Instruction:\n{example['instruction']}\n\n### Response:\n{example['output']}"}

dataset = dataset.map(format_prompt)

# 4. Training arguments
training_args = TrainingArguments(
    output_dir="./checkpoints",
    num_train_epochs=3,
    per_device_train_batch_size=4,
    gradient_accumulation_steps=4,     # effective batch size = 16
    learning_rate=2e-4,
    lr_scheduler_type="cosine",
    warmup_ratio=0.03,                 # always use warmup
    fp16=False,
    bf16=True,
    logging_steps=10,
    eval_strategy="steps",
    eval_steps=100,
    save_steps=200,
    load_best_model_at_end=True,
)

# 5. Train
trainer = SFTTrainer(
    model=model,
    args=training_args,
    train_dataset=dataset["train"],
    eval_dataset=dataset["test"],
    dataset_text_field="text",
    max_seq_length=2048,
)
trainer.train()

# 6. Save adapter weights only
model.save_pretrained("./lora-adapter")
tokenizer.save_pretrained("./lora-adapter")

QLoRA variant β€” add these lines before loading the model to enable 4-bit quantization:

from transformers import BitsAndBytesConfig

bnb_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(model_id, quantization_config=bnb_config, device_map="auto")

Merge adapter into base model for deployment:

from peft import PeftModel

base = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16)
merged = PeftModel.from_pretrained(base, "./lora-adapter").merge_and_unload()
merged.save_pretrained("./merged-model")

Constr

FAQ

Do I need a GPU to use it?

A GPU is strongly recommended. The skill suggests QLoRA when GPU memory is limited.

How does it check my training data?

It runs a validation script on the dataset and fixes all errors before training starts.

Which fine-tuning methods does it cover?

It covers LoRA, QLoRA, instruction tuning, RLHF, DPO, and fine-tuning with Hugging Face PEFT or OpenAI.

Details

Original description by the author

Use when fine-tuning LLMs, training custom models, or adapting foundation models for specific tasks. Invoke for configuring LoRA/QLoRA adapters, preparing JSONL training datasets, setting hyperparameters for fine-tuning runs, adapter training, transfer learning, finetuning with Hugging Face PEFT, OpenAI fine-tuning, instruction tuning, RLHF, DPO, or quantizing and deploying fine-tuned models. Trigger terms include: LoRA, QLoRA, PEFT, finetuning, fine-tuning, adapter tuning, LLM training, model training, custom model.

repo: Jeffallan/claude-skills

Popularity

GitHub stars
12k
Ranking position
#11424
License
MIT
Updated
10/30/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills