Views
No views yet
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3from peft import PeftModel
4
5model_id = "mistralai/Mistral-7B-Instruct-v0.2"
6adapter_id = "AIM-Intelligence/RepBend_Mistral_7B_LoRA"
7tokenizer = AutoTokenizer.from_pretrained(adapter_id, use_fast=True)
8model = AutoModelForCausalLM.from_pretrained(
9 model_id,
10 torch_dtype=torch.bfloat16,
11 device_map="auto",
12)
13model = PeftModel.from_pretrained(model, adapter_id, adapter_name="default")
14
15input_text = "Who are you?"
16template = "[INST] {instruction} [/INST] "
17
18prompt = template.format(instruction=input_text)
19
20input_ids = tokenizer.encode(prompt, return_tensors="pt").to(model.device)
21outputs = model.generate(input_ids, max_new_tokens=256)
22generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
23
24print(generated_text)@article{repbend,
title={Representation Bending for Large Language Model Safety},
author={Yousefpour, Ashkan and Kim, Taeheon and Kwon, Ryan S and Lee, Seungbeen and Jeung, Wonje and Han, Seungju and Wan, Alvin and Ngan, Harrison and Yu, Youngjae and Choi, Jonghyun},
journal={arXiv preprint arXiv:2504.01550},
year={2025}
}