Views
No views yet
mistralai/Mistral-7B-Instruct-v0.2 base model. The goal of this fine-tuning was to imbue the model with the unique literary style, tone, and internal thought processes found in the video game Disco Elysium, specifically focusing on generating multi-skill internal debates.mistralai/Mistral-7B-Instruct-v0.2 model using the PEFT library.pip install torch transformers accelerate peft bitsandbytes datasets1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3from peft import PeftModel
4
5base_model_name = "mistralai/Mistral-7B-Instruct-v0.2"
6adapter_repo_id = "canercetin/mistral-disco-adapter" # This repo
7
8# Load quantization config (recommended)
9quantization_config = BitsAndBytesConfig(
10 load_in_4bit=True,
11 bnb_4bit_quant_type="nf4",
12 bnb_4bit_compute_dtype=torch.bfloat16,
13)
14
15# Load the base model
16print(f"Loading base model ({base_model_name})...")
17base_model = AutoModelForCausalLM.from_pretrained(
18 base_model_name,
19 quantization_config=quantization_config,
20 torch_dtype=torch.bfloat16,
21 device_map="auto", # Handles GPU/CPU distribution
22)
23print("Base model loaded.")
24
25# Load the tokenizer (from the adapter repo is often best)
26print(f"Loading tokenizer from {adapter_repo_id}...")
27tokenizer = AutoTokenizer.from_pretrained(adapter_repo_id)
28if tokenizer.pad_token is None:
29 tokenizer.pad_token = tokenizer.eos_token
30 print("Set pad_token to eos_token")
31
32# Load the PEFT model by applying adapters
33print(f"Loading LoRA adapters from Hub: {adapter_repo_id}")
34model = PeftModel.from_pretrained(base_model, adapter_repo_id)
35print("LoRA adapters loaded and applied.")
36model.eval() # Set to evaluation mode
37
38# --- Prepare Prompt ---
39# Use the recommended System Prompt (see below)
40system_prompt = "Adopt *your* internal perspective within Disco Elysium. The input below presents a situation, external dialogue, or an internal thought. **Generate the ensuing internal debate** as different Skills (such as Logic, Volition, Empathy, Inland Empire, Electrochemistry, etc.) react to it. Present the distinct viewpoints, analyses, or urges from *multiple relevant skills*, each clearly identified (e.g., 'Skill Name: Dialogue text') and preferably on a new line. Capture the characteristic literary style, tangential thoughts, dark humor, and gritty realism of Revachol in this synthesized multi-voiced internal state. **Your output should be the multi-skill reaction itself.**"
41user_input = "Kim looks disappointed in my methods again." # Example input
42
43chat = [{"role": "system", "content": system_prompt}, {"role": "user", "content": user_input}]
44prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
45
46# --- Generate ---
47inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
48print("\nGenerating multi-skill internal debate...")
49with torch.no_grad():
50 outputs = model.generate(
51 **inputs,
52 max_new_tokens=350,
53 do_sample=True,
54 temperature=0.75,
55 top_p=0.9,
56 repetition_penalty=1.1,
57 pad_token_id=tokenizer.eos_token_id,
58 eos_token_id=[tokenizer.eos_token_id, tokenizer.convert_tokens_to_ids("</s>")]
59 )
60
61# --- Decode ---
62input_token_length = inputs.input_ids.shape
63response_ids = outputs[input_token_length:]
64response_text = tokenizer.decode(response_ids, skip_special_tokens=True).strip()
65print("\nModel Response:\n", response_text)Should I piss myself?Composure: A bad idea. Men like the lieutenant are not won over by such childish manoeuvres.
Half Light: So worth it -- can you feel how liberating that was? De-compression completed.I love you.Half Light: The fucking nerves on her?! Trying to hide behind WEAKNESS. You're a GOD. An angry but JUST God.
Rhetoric: This exact conversation has happened before. Establishing authority before trust -- classic mistake.Lieutenant, put on the maid outfit.Esprit de Corps: The lieutenant is concerned about your erratic behaviour -- and the potential consequences for the case.
Rhetoric: He's trying not to bring you down, but the words aren't coming out right.
Suggestion: What are you talking about? Don't say that, this is no time to nitpick.discobase3-29-2021-9-32-09-PM.db). The data was structured into Context -> Multi-Skill Response pairs using a custom Python script. The specific steps included:[...]), and short lines (<10 chars).<s>[INST] Context [/INST] Skill A: Response A\nSkill B: Response B... </s> strings.mistralai/Mistral-7B-Instruct-v0.2r=16, lora_alpha=32, lora_dropout=0.1, targeted QKV, O, and MLP projections.bitsandbytes (nf4, compute_dtype=bfloat16).transformers, accelerate, peft, torch.per_device_train_batch_size=12, gradient_accumulation_steps=1, dataloader_num_workers=12, gradient_checkpointing=False, num_train_epochs=1 (on the structured multi-skill dataset), learning_rate=2e-4, bf16=True, optim="paged_adamw_8bit".1@misc{jiang2023mistral,
2 title={Mistral 7B},
3 author={Albert Q. Jiang and Alexandre Sablayrolles and Arthur Mensch and Chris Bamford and Devendra Singh Chaplot and Diego de las Casas and Florian Bressand and Gianna Lengyel and Guillaume Lample and Lélio Renard Lavaud and Lucile Saulnier and Marie-Anne Lachaux and Pierre Stock and Teven Le Scao and Thibaut Lavril and Thomas Wang and Timothée Lacroix and William El Sayed},
4 year={2023},
5 eprint={2310.06825},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}1@misc{peft,
2 author = {Sourab Mangrulkar and Sylvain Gugger and Lysandre Debut and Younes Belkada and Sayak Paul},
3 title = {PEFT: Parameter-Efficient Fine-Tuning of Billion-Scale Models on Low-Resource Hardware},
4 year = {2022},
5 publisher = {GitHub},
6 journal = {GitHub repository},
7 howpublished = {\url{https://github.com/huggingface/peft}}
8}
---