Views
No views yet
I am laughing at myself, I am also laughing at all of you. Love and friendship, killing and slaughtering, don't you all find this very boring? — Fang Yuan (方源)
Qwen/Qwen3-8B16320.0q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_projpip install torch transformers peft bitsandbytes accelerate1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3from peft import PeftModel
4
5BASE_MODEL = "Qwen/Qwen3-8B"
6ADAPTER_REPO = "lynzl/FangYuan-8B"
7
8# 1. 4-bit Quantization Configuration
9bnb_config = BitsAndBytesConfig(
10 load_in_4bit=True,
11 bnb_4bit_quant_type="nf4",
12 bnb_4bit_compute_dtype=torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float16,
13)
14
15# 2. Load Tokenizer & Base Model
16tokenizer = AutoTokenizer.from_pretrained(ADAPTER_REPO, trust_remote_code=True)
17base_model = AutoModelForCausalLM.from_pretrained(
18 BASE_MODEL,
19 quantization_config=bnb_config,
20 device_map="auto",
21 trust_remote_code=True,
22)
23
24# 3. Attach Fang Yuan LoRA Adapter
25model = PeftModel.from_pretrained(base_model, ADAPTER_REPO)
26model.eval()
27
28# 4. Generate with Fang Yuan's persona
29system_prompt = "You are Fang Yuan, the protagonist of Reverend Insanity. You embody the Demonic Path—calm, rational, utilitarian, and utterly free of societal conditioning. You pursue Eternal Life with unyielding perseverance and zero regrets."
30messages = [
31 {"role": "system", "content": system_prompt},
32 {"role": "user", "content": "I worked hard for years at my company, but someone else got the promotion through connections. Should I be angry?"}
33]
34
35prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
36inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
37
38with torch.no_grad():
39 output = model.generate(
40 **inputs,
41 max_new_tokens=400,
42 temperature=0.4,
43 top_p=0.9,
44 repetition_penalty=1.1,
45 )
46
47response = tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
48print("Fang Yuan:\n", response)