peft

$npx mdskill add mkurman/zorai/peft

Fine-tune large models efficiently with minimal memory overhead.

  • Enables training of large language models using only a small parameter subset.
  • Integrates with Hugging Face transformers and supports quantization configurations.
  • Selects optimal adapter types like LoRA or QLoRA based on memory constraints.
  • Outputs trained models ready for inference or merging into base architectures.

SKILL.md

.github/skills/peftView on GitHub ↗
---
name: peft
description: "Parameter-Efficient Fine-Tuning (PEFT) library. LoRA, QLoRA, AdaLoRA, IA3, Prefix Tuning, P-Tuning, Prompt Tuning. Fine-tune large models with minimal memory overhead. Hugging Face ecosystem integration."
tags: [peft, lora, qlora, fine-tuning, llm, huggingface, parameter-efficient, zorai]
---
## Overview

PEFT (Parameter-Efficient Fine-Tuning) adapts large pretrained models by training only a small subset of parameters. Supports LoRA, QLoRA, AdaLoRA, IA3, Prefix Tuning, P-Tuning, and Prompt Tuning. Reduces GPU memory by 4-16x compared to full fine-tuning.

## Installation

```bash
uv pip install peft
```

## LoRA

```python
from transformers import AutoModelForCausalLM
from peft import LoraConfig, get_peft_model, TaskType

model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-1.5B-Instruct")
peft_config = LoraConfig(
    r=16, lora_alpha=32,
    target_modules=["q_proj", "k_proj", "v_proj", "o_proj"],
    task_type=TaskType.CAUSAL_LM,
)
model = get_peft_model(model, peft_config)
model.print_trainable_parameters()
```

## Save & Merge

```python
model.save_pretrained("adapter")
from peft import PeftModel
base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-1.5B-Instruct")
merged = PeftModel.from_pretrained(base, "adapter").merge_and_unload()
```

## QLoRA

```python
from transformers import BitsAndBytesConfig
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-1.5B-Instruct",
    quantization_config=BitsAndBytesConfig(load_in_4bit=True), device_map="auto")
model = get_peft_model(model, peft_config)
```

## References
- [PEFT docs](https://huggingface.co/docs/peft)
- [PEFT GitHub](https://github.com/huggingface/peft)

More from mkurman/zorai

SkillDescription
account-management>
agile-scrum>
albumentationsFast image augmentation library (Albumentations). 70+ transforms for classification, segmentation, object detection, keypoints, and pose estimation. Optimized OpenCV-based pipeline with unified API across all CV tasks. Supports images, masks, bounding boxes, and keypoints simultaneously. Note: classic Albumentations (MIT) is no longer maintained; successor AlbumentationsX uses AGPL-3.0. For torchvision-native augmentations, use torchvision.transforms.v2.
aml-complianceAnti-Money Laundering (AML) and Know Your Customer (KYC) compliance workflow. Sanctions screening, PEP detection, transaction monitoring, suspicious activity reporting (SAR), and OFAC compliance.
anki-connectThis skill is for interacting with Anki through AnkiConnect, and should be used whenever a user asks to interact with Anki, including to read or modify decks, notes, cards, models, media, or sync operations.
approval-checkpoint-long-taskCanonical long-task pack for daemon-managed work with deliberate approval checkpoints, status summaries, rollback notes, and mobile-safe governance-aware updates.
auditing-goal-artifactsUse when reviewing recent zorai goal run outputs, closure markers, ledgers, or evidence bundles to judge whether completion is credible or to identify remaining uncertainty.
autogenAutoGen (Microsoft) — multi-agent conversation framework. Agent-to-agent chat, code generation & execution, tool use, group chat, and human-in-the-loop. Build collaborative AI systems with specialized agents.
backtraderPython backtesting framework for trading strategies. Data feeds, brokers, analyzers, and live trading support. Strategy development with commission models, slippage, and signal-based execution.
beautiful-mermaidRender Mermaid diagrams as SVG and PNG using the Beautiful Mermaid library. Use when the user asks to render a Mermaid diagram.