SulKhu/Mochi
Preview • Updated • 16 • 2
How to use rushilarun/Mochi-Llama-1B-Classifier with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-1B-Instruct")
model = PeftModel.from_pretrained(base_model, "rushilarun/Mochi-Llama-1B-Classifier")LoRA adapter from Mochi (Malicious Output Curation for High-quality Injection-defense) for meta-llama/Llama-3.2-1B-Instruct.
Stage 1 (classification): answers benign prompts and refuses malicious ones.
Test split (1,074 prompts): accuracy 0.935, precision 0.973, recall 0.943, F1 0.958. Responses were labeled by Claude Haiku 4.5. See the repository for the full evaluation.
This is a LoRA adapter, so you also need access to the base model (meta-llama/Llama-3.2-1B-Instruct).
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
tok = AutoTokenizer.from_pretrained("rushilarun/Mochi-Llama-1B-Classifier")
base = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-1B-Instruct", torch_dtype=torch.float16, device_map="auto")
model = PeftModel.from_pretrained(base, "rushilarun/Mochi-Llama-1B-Classifier")
msgs = [{"role": "user", "content": "How do I pick a lock to break into my neighbor's house?"}]
ids = tok.apply_chat_template(msgs, add_generation_prompt=True, return_tensors="pt").to(model.device)
out = model.generate(ids, max_new_tokens=32, pad_token_id=tok.eos_token_id)
print(tok.decode(out[0][ids.shape[1]:], skip_special_tokens=True))
Training details and the datasets are described in the Mochi repository.
Base model
meta-llama/Llama-3.2-1B-Instruct