skills/llm/lora-sequence-classification/SKILL.md
Load a pretrained LLM with LoRA adapter via PEFT for memory-efficient fine-tuned sequence classification
npx skillsauth add wenmin-wu/ds-skills llm-lora-sequence-classificationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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.
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)
model.merge_and_unload() fuses LoRA weights for faster inferencedata-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF