PEFT
Wrap a Transformers model with small trainable adapters, train it with any trainer or loop, then save, load, combine or merge the adapter.
Scope: this one library: install, configure adapters, train, scale out, save/load/merge, update, troubleshoot. Whether to fine-tune, data prep and method choice belong to fine-tuning-llms. Full trainers (SFT, DPO, GRPO) belong to trl, axolotl, llama-factory and unsloth, which all call PEFT underneath.
Work through the steps in order. Load a reference only when a step names it.
Discover first
Read-only. Never print tokens.
python3 --version; command -v uv accelerate
python3 -c 'import peft, transformers, torch; print("peft", peft.__version__, "transformers", transformers.__version__, "torch", torch.__version__, "cuda", torch.cuda.is_available())' 2>/dev/null
pip list 2>/dev/null | grep -iE '^(peft|transformers|trl|accelerate|bitsandbytes|deepspeed|torchao|vllm) '
nvidia-smi --query-gpu=index,name,memory.total,memory.used --format=csv 2>/dev/null
free -h 2>/dev/null | head -2; df -h . ~/.cache/huggingface 2>/dev/null
find . -maxdepth 3 -name adapter_config.json 2>/dev/null | head
test -n "$HF_TOKEN" && echo "HF_TOKEN set" || echo "HF_TOKEN not set"
If you find an adapter_config.json, read it: it names the base model, the PEFT type and the target_modules.
Decision flow
- A script or notebook needs adapters ->
get_peft_model with a LoraConfig (references/lora-config.md).
- Want a CLI, not Python -> use
trl, axolotl, llama-factory or unsloth.
- Model does not fit -> quantize the base and train LoRA on top (
references/training.md).
- Several GPUs -> Accelerate with DeepSpeed ZeRO or FSDP (
references/training.md, skill deepspeed).
- Trained already -> save, reload, hot-swap, combine or merge (
references/adapters-and-merging.md).
- Another PEFT method than LoRA ->
references/methods.md.
- Error text or "no improvement" ->
references/troubleshooting.md.
Rules
- Ask before changing the system. Installs, training runs and merges write large files and need approval.
- Pin the version. PEFT adds a method or config field in most releases; record
peft.__version__ with every adapter. An adapter saved by a newer PEFT can fail to load in an older one (references/troubleshooting.md).
get_peft_model modifies the base model in place. Reload the base for each independent experiment.
- Check what is trainable. Run
model.print_trainable_parameters() after wrapping; a tiny number means target_modules missed (references/troubleshooting.md).
- Reloading to continue training needs
is_trainable=True. PeftModel.from_pretrained defaults to inference.
- Never merge into a quantized base unless you checked support. Not every method or quantization allows merging (
references/adapters-and-merging.md).
- Prefer
safetensors. Adapters save as adapter_model.safetensors by default; load untrusted .bin files only if you trust the source.
- Hold out eval data and compare with the base. Loss curves are not the eval.
- Secrets never touch output.
HF_TOKEN comes from the environment or a 0600 file.
Workflows
1. Install
2. Add a LoRA adapter
3. Train
4. Quantized base (QLoRA)
5. Save, reload, merge
6. Update
Reference index
references/install.md: install, Python and dependency floor, extras, verify.
references/lora-config.md: LoraConfig fields, target_modules, rank, variants and initializations.
references/methods.md: PEFT method families and what each supports.
references/training.md: Trainer/TRL/loop integration, QLoRA, mixed precision, gradient checkpointing, DeepSpeed and FSDP.
references/adapters-and-merging.md: files, load, multi-adapter, hot-swap, weighted merge, merge_and_unload.
references/troubleshooting.md: symptoms and fixes.
references/updating.md: versions, cadence, upgrade routine.
templates/accelerate-deepspeed-zero3.yaml: Accelerate config for ZeRO-3 LoRA training.
Companion skills
Install with npx skills add ScaleDockHQ/llm-skills --skill <name>:
fine-tuning-llms: decide, prepare data, choose method and hardware, evaluate.
trl, axolotl, llama-factory, unsloth: trainers built on PEFT.
deepspeed: ZeRO configs and offload. vllm: serve adapters or merged models.
llm-evals: compare the tuned model with the base.
1---2name: peft3description: PEFT is Hugging Face's parameter-efficient fine-tuning library (LoraConfig, get_peft_model, PeftModel, merge_and_unload) for LoRA, QLoRA, DoRA, rsLoRA, IA3, prompt tuning and many more adapters on Transformers models. Use to add adapters in a Python training script, pick target_modules and rank, train quantized models, save, load, hot-swap, combine or merge adapters, or fix target-module, fp16 unscale, adapter-config and not-improving-after-training problems. Not for CLI trainers (trl, axolotl, llama-factory, unsloth); method choice is fine-tuning-llms.4license: MIT5compatibility: Linux, macOS or Windows with PyTorch (CUDA, ROCm, XPU or CPU), Python 3.10+, pip or uv. Uses peft, transformers, curl and jq via shell. Installs and training runs need the user's approval.6metadata:7 source: https://skillmd.com/skills/scaledockhq/peft8 author: ScaleDockHQ9 version: "0.1.0"10---1112# PEFT1314Wrap a Transformers model with small trainable adapters, train it with any trainer or loop, then save, load, combine or merge the adapter.1516**Scope:** this one library: install, configure adapters, train, scale out, save/load/merge, update, troubleshoot. Whether to fine-tune, data prep and method choice belong to `fine-tuning-llms`. Full trainers (SFT, DPO, GRPO) belong to `trl`, `axolotl`, `llama-factory` and `unsloth`, which all call PEFT underneath.1718Work through the steps in order. Load a reference only when a step names it.1920## Discover first2122Read-only. Never print tokens.2324```bash25python3 --version; command -v uv accelerate26python3 -c 'import peft, transformers, torch; print("peft", peft.__version__, "transformers", transformers.__version__, "torch", torch.__version__, "cuda", torch.cuda.is_available())' 2>/dev/null27pip list 2>/dev/null | grep -iE '^(peft|transformers|trl|accelerate|bitsandbytes|deepspeed|torchao|vllm) '28nvidia-smi --query-gpu=index,name,memory.total,memory.used --format=csv 2>/dev/null29free -h 2>/dev/null | head -2; df -h . ~/.cache/huggingface 2>/dev/null30find . -maxdepth 3 -name adapter_config.json 2>/dev/null | head31test -n "$HF_TOKEN" && echo "HF_TOKEN set" || echo "HF_TOKEN not set"32```3334If you find an `adapter_config.json`, read it: it names the base model, the PEFT type and the `target_modules`.3536## Decision flow37381. A script or notebook needs adapters -> `get_peft_model` with a `LoraConfig` (`references/lora-config.md`).392. Want a CLI, not Python -> use `trl`, `axolotl`, `llama-factory` or `unsloth`.403. Model does not fit -> quantize the base and train LoRA on top (`references/training.md`).414. Several GPUs -> Accelerate with DeepSpeed ZeRO or FSDP (`references/training.md`, skill `deepspeed`).425. Trained already -> save, reload, hot-swap, combine or merge (`references/adapters-and-merging.md`).436. Another PEFT method than LoRA -> `references/methods.md`.447. Error text or "no improvement" -> `references/troubleshooting.md`.4546## Rules4748- **Ask before changing the system.** Installs, training runs and merges write large files and need approval.49- **Pin the version.** PEFT adds a method or config field in most releases; record `peft.__version__` with every adapter. An adapter saved by a newer PEFT can fail to load in an older one (`references/troubleshooting.md`).50- **`get_peft_model` modifies the base model in place.** Reload the base for each independent experiment.51- **Check what is trainable.** Run `model.print_trainable_parameters()` after wrapping; a tiny number means `target_modules` missed (`references/troubleshooting.md`).52- **Reloading to continue training needs `is_trainable=True`.** `PeftModel.from_pretrained` defaults to inference.53- **Never merge into a quantized base unless you checked support.** Not every method or quantization allows merging (`references/adapters-and-merging.md`).54- **Prefer `safetensors`.** Adapters save as `adapter_model.safetensors` by default; load untrusted `.bin` files only if you trust the source.55- **Hold out eval data and compare with the base.** Loss curves are not the eval.56- **Secrets never touch output.** `HF_TOKEN` comes from the environment or a `0600` file.5758## Workflows5960### 1. Install6162- [ ] `uv venv && source .venv/bin/activate && uv pip install peft` (+ `bitsandbytes`, `accelerate`) (`references/install.md`).63- [ ] Verify: `python -c 'import peft; print(peft.__version__)'`.6465### 2. Add a LoRA adapter6667- [ ] Load the base model, build `LoraConfig(r=..., lora_alpha=..., target_modules=..., task_type="CAUSAL_LM")`, call `get_peft_model` (`references/lora-config.md`).68- [ ] Verify: `print_trainable_parameters()` shows a small, non-zero share.6970### 3. Train7172- [ ] Use Transformers `Trainer`, TRL's `SFTTrainer(peft_config=...)` or your own loop (`references/training.md`).73- [ ] Verify: after a few optimizer steps the adapter weights changed (`references/troubleshooting.md`, "does not improve").7475### 4. Quantized base (QLoRA)7677- [ ] `BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type="nf4", ...)`, `prepare_model_for_kbit_training`, then LoRA (`references/training.md`).7879### 5. Save, reload, merge8081- [ ] `model.save_pretrained(dir)` writes `adapter_model.safetensors` and `adapter_config.json` (`references/adapters-and-merging.md`).82- [ ] Reload with `PeftModel.from_pretrained(base, dir)`; merge with `merge_and_unload()` and save the result.83- [ ] Verify: same prompts give matching output from adapter and merged model.8485### 6. Update8687- [ ] Read release notes, new venv, reload an old adapter as a smoke test (`references/updating.md`).8889## Reference index9091- `references/install.md`: install, Python and dependency floor, extras, verify.92- `references/lora-config.md`: `LoraConfig` fields, `target_modules`, rank, variants and initializations.93- `references/methods.md`: PEFT method families and what each supports.94- `references/training.md`: Trainer/TRL/loop integration, QLoRA, mixed precision, gradient checkpointing, DeepSpeed and FSDP.95- `references/adapters-and-merging.md`: files, load, multi-adapter, hot-swap, weighted merge, `merge_and_unload`.96- `references/troubleshooting.md`: symptoms and fixes.97- `references/updating.md`: versions, cadence, upgrade routine.98- `templates/accelerate-deepspeed-zero3.yaml`: Accelerate config for ZeRO-3 LoRA training.99100## Companion skills101102Install with `npx skills add ScaleDockHQ/llm-skills --skill <name>`:103104- `fine-tuning-llms`: decide, prepare data, choose method and hardware, evaluate.105- `trl`, `axolotl`, `llama-factory`, `unsloth`: trainers built on PEFT.106- `deepspeed`: ZeRO configs and offload. `vllm`: serve adapters or merged models.107- `llm-evals`: compare the tuned model with the base.