llm-finetuning
Best practices for dataset preparation and PEFT/LoRA fine-tuning.
Skill by j4flmao
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/j4flmao-llm-finetuning
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: ml
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md and code. Checked Oct 26, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/llm-finetuning
What's inside
- Skill name
llm-finetuning- Description
- Best practices for dataset preparation and PEFT/LoRA fine-tuning.
- License
- MIT
- Instructions
- 37 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
# LLM Fine-Tuning (PEFT / LoRA)
## Purpose
Fine-tuning changes model behaviour (format, style, task skill, domain language) from examples. It is the wrong tool for injecting frequently changing facts; use retrieval for that. Parameter-efficient methods such as LoRA train small low-rank adapters on frozen base weights, making single-GPU training of 7-8B models routine and letting one base model serve many adapters.
## Agent Protocol
### Trigger
"fine-tune", "LoRA", "QLoRA", "PEFT", "SFT", "instruction tuning", "DPO", "preference tuning", "adapter", "merge_and_unload".
### Input Context
- Goal and why prompting/RAG is insufficient (with failing examples).
- Dataset: size, source, license, format, PII status.
- Base model and license; GPU type/VRAM; serving target.
- Eval set and success metric.
### Output Artifact
Go/no-go decision, dataset spec, training config, eval plan, export/serving instructions.
### Response Format
```
Decision: {fine-tune|RAG|prompting} because {reason}
Base model: {id} (license {x}) Method: {LoRA|QLoRA|full} Stage: {SFT|DPO}
Data: {n} examples, chat format, split {train/val/test}
LoRA: r={r} alpha={a} dropout={p} targets={modules}
Train: lr={lr} epochs={e} eff_batch={b} max_len={L}
Eval: base vs tuned on {metric}; regression suite {name}
Export: {adapter|merged} -> {engine}
```
### Completion Criteria
- [ ] Baseline (prompted base model, RAG) measured first.
- [ ] Held-out test set never used for tuning decisions.
- [ ] Chat template of the base model applied consistently in training and inference.
- [ ] Tuned model beats baseline on the target metric without regressions on general checks.
## Should You Fine-Tune?
| Goal | Best tool |
|---|---|
| New/changing facts, citations | RAG |
| Output format, tone, strict schema | Prompting + structured outputs first; SFT if still unreliable |
| Narrow task at lower cost/latency | SFT a smaller model (often distilled from a larger one) |
| Preference (helpfulness, style ranking) | DPO/ORPO after SFT |
| Domain vocabulary/style | SFT (or continued pre-training for large corpora) |
## Dataset
- Use the conversational format and let the tokenizer's chat template render it:
```json
{"messages": [{"role": "system", "content": "You extract invoice fields as JSON."},
{"role": "user", "content": "<invoice text>"},
{"role": "assistant", "content": "{\"total\": 129.5, \"currency\": \"EUR\"}"}]}
```
- Quality over quantity: a few hundred to a few thousand clean, diverse examples often suffice for format/task tuning.
- Deduplicate (exact + near-duplicate), remove PII/secrets, check licenses, balance classes, and keep a stratified held-out test split.
- Train on assistant tokens only (loss masking of prompts) unless you have a reason not to; TRL supports this via its completion/assistant-only loss options.
## LoRA / QLoRA Training (PEFT + TRL)
```python
from __future__ import annotations
import torch
from datasets import load_dataset
from peft import LoraConfig
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from trl import SFTConfig, SFTTrainer
BASE = "meta-llama/Llama-3.1-8B-Instruct"
USE_QLORA = True
tokenizer = AutoTokenizer.from_pretrained(BASE)
quant = BitsAndBytesConfig(
load_in_4bit=True, bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16, bnb_4bit_use_double_quant=True,
) if USE_QLORA else None
model = AutoModelForCausalLM.from_pretrained(
BASE,
dtype=torch.bfloat16, # transformers >= 4.56; older versions use torch_dtype=
quantization_config=quant,
device_map="auto",
)
lora = LoraConfig(
r=16, lora_alpha=32, lora_dropout=0.05, bias="none",
target_modules="all-linear", # attention + MLP projections; better than q/v only
task_type="CAUSAL_LM",
)
data = load_dataset("json", data_files={"train": "train.jsonl", "validation": "val.jsonl"})
args = SFTConfig(
output_dir="out/invoice-lora",
num_train_epochs=2,
per_device_train_batch_size=4,
gradient_accumulation_steps=4, # effective batch 16
learning_rate=2e-4, # LoRA tolerates higher LR than full FT (~1e-5)
lr_scheduler_type="cosine",
warmup_ratio=0.03,
bf16=True,
gradient_checkpointing=True,
logging_steps=10,
eval_strategy="steps",
eval_steps=100,
save_steps=100,
report_to="none",
)
trainer = SFTTrainer(
model=model, args=args, processing_class=tokenizer,
train_dataset=data["train"], eval_dataset=data["validation"], peft_config=lora,
)
trainer.train()
trainer.save_model("out/invoice-lora/final") # saves the adapter only
```
TRL and transformers rename arguments between releases (e.g. `tokenizer` → `processing_class`, `max_seq_length` → `max_length`); pin versions in `pyproject.toml` and check the installed release's docs.
## Hyperparameter GuideFrom j4flmao/agent-skills, MIT.
More from j4flmao/agent-skills
- 0.610score
dotnet-patterns
j4flmao
Use this skill when implementing .NET patterns — MediatR pipelines, CQRS, Result pattern, EF Core patterns, pipeline behaviors, and event sourcing.
SkillBFreshness: B★ 34Claude Code +9 - 0.610score
elysia-patterns
j4flmao
Use this skill when implementing Elysia.js patterns — Eden Treaty client, WebSocket handlers, auth/guard macros, custom plugins, performance optimization, and…
SkillBFreshness: B★ 34Claude Code +9 - 0.607score
genai-vision
j4flmao
Integrating Stable Diffusion for vision generation and Whisper for audio/multimodal tasks.
SkillBFreshness: B★ 34Claude Code +9 - 0.605score
micronaut
j4flmao
Use this skill when building Micronaut applications — compile-time DI, reactive HTTP server, AOT optimization, GraalVM native image.
SkillBFreshness: B★ 34Claude Code +9 - 0.605score
bun
j4flmao
Use this skill when building with Bun runtime — Bun APIs, testing, package management, shell scripting, hot reload, SQLite, file I/O.
SkillBFreshness: B★ 34Claude Code +9 - 0.605score
elixir
j4flmao
Use this skill when building with Elixir — Phoenix framework, OTP, BEAM, LiveView, Ecto, supervision trees.
SkillBFreshness: B★ 34Claude Code +9 - 0.605score
deno
j4flmao
Use this skill when building with Deno — TypeScript runtime, Deno Deploy, Fresh framework, Deno std library.
SkillBFreshness: B★ 34Claude Code +9 - 0.601score
nestjs-architecture
j4flmao
Use this skill when structuring NestJS applications — module-based architecture, dependency injection, provider scopes, dynamic modules, and monorepo structure.
SkillBFreshness: B★ 34Claude Code +9 - 0.601score
nestjs-patterns
j4flmao
Use this skill when implementing NestJS patterns — CQRS with @nestjs/cqrs, guards/interceptors/pipes/filters, event sourcing, custom decorators…
SkillBFreshness: B★ 34Claude Code +9 - 0.601score
kotlin-backend-patterns
j4flmao
Use this skill when implementing Kotlin backend patterns — repository pattern, service layer, DTO mapping, DI setup (Koin, Kodein), testing with MockK, and…
SkillBFreshness: B★ 34Claude Code +9 - 0.601score
kotlin-architecture
j4flmao
Use this skill when designing Kotlin backend architecture — Ktor, Spring WebFlux, http4k.
SkillBFreshness: B★ 34Claude Code +9 - 0.601score
nodejs-architecture
j4flmao
Use this skill when designing Node.js backend architecture — Express, Fastify, Hono.
SkillBFreshness: B★ 34Claude Code +9
Signals
- Stars
- 34
- Forks
- 4
- Open issues
- 0
- Last commit (this folder)
- Aug 30, 2026 (1 month ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/j4flmao/agent-skills
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
More from j4flmao
- 0.610score
dotnet-patterns
j4flmao
Use this skill when implementing .NET patterns — MediatR pipelines, CQRS, Result pattern, EF Core patterns, pipeline behaviors, and event sourcing.
SkillBFreshness: B★ 34Claude Code +9 - 0.610score
elysia-patterns
j4flmao
Use this skill when implementing Elysia.js patterns — Eden Treaty client, WebSocket handlers, auth/guard macros, custom plugins, performance optimization, and…
SkillBFreshness: B★ 34Claude Code +9 - 0.607score
genai-vision
j4flmao
Integrating Stable Diffusion for vision generation and Whisper for audio/multimodal tasks.
SkillBFreshness: B★ 34Claude Code +9 - 0.605score
bun
j4flmao
Use this skill when building with Bun runtime — Bun APIs, testing, package management, shell scripting, hot reload, SQLite, file I/O.
SkillBFreshness: B★ 34Claude Code +9 - 0.605score
deno
j4flmao
Use this skill when building with Deno — TypeScript runtime, Deno Deploy, Fresh framework, Deno std library.
SkillBFreshness: B★ 34Claude Code +9 - 0.605score
elixir
j4flmao
Use this skill when building with Elixir — Phoenix framework, OTP, BEAM, LiveView, Ecto, supervision trees.
SkillBFreshness: B★ 34Claude Code +9
Cite this page
llm-finetuning skill. Agent Mart. https://agentmart.dev/skills/j4flmao-llm-finetuning (last updated 2026-10-24)