‹ 首页

fine-tuning-expert

@jeffallan · 收录于 1 周前 · 上游提交 1 个月前

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.

适合你,如果需要用自有数据微调LLM来提升特定任务表现

/ 下载安装
fine-tuning-expert.skill双击,或拖进 Claude 桌面版 / Cowork,即完成安装↓ .skill↓ .zip
用别的 agent?下载 .zip 解压,把文件夹放进它的技能目录
Claude Code~/.claude/skills/(项目级 .claude/skills/)
Codex CLI~/.codex/skills/
Cursor自动读取上面两处目录
其他工具见其文档的「skills」目录;两个下载是同一份文件,只是名字不同
/ 通过 npx 安装 校验哈希
npx oh-my-skill add jeffallan/claude-skills/fine-tuning-expert
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- jeffallan/claude-skills/fine-tuning-expert
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify jeffallan/claude-skills/fine-tuning-expert
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
10501GitHub stars
~1.2K最小装载
~14.4K含声明引用
~14.4K文本包总量
镜像托管

怎么用

商店整理自技能原文 · 版本 e8be415 · 表述以原文为准
它做什么

装上后,Claude 会指导你完成微调大语言模型的完整流程:准备数据集、选择 LoRA 或 QLoRA 等高效方法、配置超参数、训练、评估并部署模型。它会提供代码示例和检查点,确保每一步正确。

什么时候触发

当你提到“微调”、“LoRA”、“QLoRA”、“PEFT”、“模型训练”等关键词,或要求训练自定义模型、适配基础模型时触发。

装好后可以这样说
Claude 会给出数据集准备、训练配置和代码示例。
Claude 会提供数据验证和格式化的指导。
Claude 会解释两者适用场景和配置差异。
技能原文 SKILL.md作者撰写 · MIT · e8be415

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
  2. Checkpoint: python validate_dataset.py --input data.jsonl — fix all errors before proceeding
  3. Method selection — Choose PEFT technique based on GPU memory and task requirements
  4. Use LoRA for most tasks; QLoRA (4-bit) when GPU memory is constrained; full fine-tune only for small models
  5. Training — Configure hyperparameters, monitor loss curves, checkpoint regularly
  6. Checkpoint: validation loss must decrease; plateau or increase signals overfitting
  7. Evaluation — Benchmark against the base model; test on held-out set and edge cases
  8. Checkpoint: collect perplexity, task-specific metrics (BLEU/ROUGE), and latency numbers
  9. 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")
Constraints
MUST DO
  • Validate dataset quality before training
  • Use parameter-efficient methods for large models (>7B)
  • Monitor training/validation loss curves
  • Document hyperparameters and training config
  • Version datasets and model checkpoints
  • Always include a learning rate warmup
MUST NOT DO
  • Skip data quality validation
  • Overfit on small datasets — use regularisation (dropout, weight decay) and early stopping
  • Merge incompatible adapters (mismatched rank, base model, or target modules)
  • Deploy without evaluation against a held-out set and latency benchmark
Output Templates

When implementing fine-tuning, always provide:

  1. Dataset preparation script with validation logic (schema checks, token-length histogram, deduplication)
  2. Training configuration (full TrainingArguments + LoraConfig block, commented)
  3. Evaluation script reporting perplexity, task-specific metrics, and latency
  4. Brief design rationale — why this PEFT method, rank, and learning rate were chosen for this task

Documentation

按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。