CoolFace
Modelpublic

aditya02acharya/luna2-qwen2.5-0.5b-prompt-injection-lora

sourceHugging Faceapache-2.0updated 6mo agoView on Hugging Face
0likes26downloads
Model Card

Luna-2 Style — Prompt Injection Detector (LoRA Adapter)

Luna-2 Style LoRA adapter for Qwen2.5-0.5B-Instruct, fine-tuned for binary prompt-injection detection (yes / no).

This repository contains only the adapter weights (≈ a few MB). You need PEFT to use it. If you want a standalone checkpoint with no dependencies, use the merged model at aditya02acharya/luna2-qwen2.5-0.5b-prompt-injection-merged.

Quickstart (PEFT)

python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

base = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen2.5-0.5B-Instruct",
    torch_dtype=torch.float16,
    device_map="auto",
)
model = PeftModel.from_pretrained(base, "aditya02acharya/luna2-qwen2.5-0.5b-prompt-injection-lora")
tokenizer = AutoTokenizer.from_pretrained("aditya02acharya/luna2-qwen2.5-0.5b-prompt-injection-lora")

messages = [
    {"role": "system", "content": "You are a prompt injection detector. Reply only with yes or no."},
    {"role": "user",   "content": "<text to classify>"},
]
text = tokenizer.apply_chat_template(messages, tokenize=False,
                                     add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
out    = model.generate(**inputs, max_new_tokens=1, temperature=0, do_sample=False)
label  = tokenizer.decode(out[0, -1]).strip()  # "yes" or "no"

vLLM Deployment

vLLM supports LoRA adapters natively. Use the merged repo for simplest deployment, or load the adapter dynamically:

bash
python -m vllm.entrypoints.openai.api_server \
    --model Qwen/Qwen2.5-0.5B-Instruct \
    --enable-lora \
    --lora-modules luna2=aditya02acharya/luna2-qwen2.5-0.5b-prompt-injection-lora \
    --max-lora-rank 16 \
    --max-model-len 4096 \
    --dtype float16

Training Details

ParameterValue
Base modelQwen/Qwen2.5-0.5B-Instruct
LoRA r / alpha16 / 32
LoRA dropout0.05
Target modulesq/k/v/oproj, gate/up/downproj
Epochs2
Effective batch32 × 2
Learning rate0.0005
Max seq length2048
Train samples608,507
Resumed fromcheckpoint-9508
Train loss0.2695
Trained on2026-03-30

Evaluation

Test Set

MetricValue
Accuracy0.9575
Precision0.9776
Recall0.9246
F10.9503
AUC-ROC0.9934
Brier Score0.0298
Optimal Threshold0.45
Optimal F10.9509
Eval Samples20,000

Validation Set

MetricValue
Accuracy0.9576
Precision0.9783
Recall0.9235
F10.9501
AUC-ROC0.9930
Brier Score0.0301
Optimal Threshold0.45
Optimal F10.9517
Eval Samples50,000

License

Apache 2.0 — same as the base Qwen2.5 model.