Skip to content
Back to skills

Lora Sequence Classification

ASecurity

Load a pretrained LLM with LoRA adapter via PEFT for memory-efficient fine-tuned sequence classification

  • 61 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 12, 2026
developmentpythongogit

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill lora-sequence-classification --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Lora Sequence Classification?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Lora Sequence Classification
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-lora-sequence-classification/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-lora-sequence-classification)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: llm-lora-sequence-classification
description: Load a pretrained LLM with LoRA adapter via PEFT for memory-efficient fine-tuned sequence classification
domain: llm
---

# LoRA Sequence Classification

## Overview

Fine-tuning a full LLM (7B+ params) for classification is expensive. LoRA (Low-Rank Adaptation) freezes the base model and trains small rank-decomposed weight matrices (~0.1% of params). Load the base model for sequence classification, then apply a trained LoRA adapter via PEFT. Enables 7-9B model inference on a single GPU with fp16/bf16.

## Quick Start

```python
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
from peft import PeftModel

# Load base model with classification head
model = AutoModelForSequenceClassification.from_pretrained(
    "google/gemma-2-9b-it",
    num_labels=n_classes,
    torch_dtype=torch.bfloat16,
    device_map="auto",
)

# Apply LoRA adapter
model = PeftModel.from_pretrained(model, "path/to/lora-adapter")
model.eval()

# Inference
tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
inputs = tokenizer(texts, return_tensors="pt", padding=True, truncation=True)
with torch.no_grad():
    logits = model(**inputs.to(model.device)).logits
probs = torch.softmax(logits, dim=-1)
```

## Key Decisions

- **bf16/fp16**: halves memory; use bf16 for models trained with it (Gemma, Llama)
- **device_map="auto"**: automatically distributes layers across available GPUs
- **Adapter size**: rank 8-32 typical; higher rank = more capacity but more memory
- **Merge option**: `model.merge_and_unload()` fuses LoRA weights for faster inference

## References

- Source: [gemma2-9b-it-cv-0-945](https://www.kaggle.com/code/cdeotte/gemma2-9b-it-cv-0-945)
- Competition: MAP - Charting Student Math Misunderstandings

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…