abrakjamson commited on
Commit
2fd6955
1 Parent(s): 85e58bb

Adding readme (and missing control model)

Browse files
Files changed (3) hide show
  1. README.md +15 -5
  2. app.py +9 -6
  3. control_models/truthful.gguf +0 -0
README.md CHANGED
@@ -1,13 +1,23 @@
1
  ---
2
- title: Controlled Chat
3
- emoji: 🏢
4
- colorFrom: indigo
5
- colorTo: blue
6
  sdk: gradio
7
  sdk_version: 4.44.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
 
 
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
1
  ---
2
+ title: LLM Mind Control
3
+ emoji:
4
+ colorFrom: pink
5
+ colorTo: gray
6
  sdk: gradio
7
  sdk_version: 4.44.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
+ preload_from_hub:
12
+ - mistralai/Mistral-7B-Instruct-v0.3
13
+ suggested_hardware:
14
+ - l4x1
15
  ---
16
 
17
+ # 🧠 LLM Mind Control"
18
+ Unlike prompting, direct weight manipulation lets you fine-tune the amount of a personality
19
+ trait or topic. Enabled through [Representation Engineering](https://arxiv.org/abs/2310.01405)
20
+ via the [repeng](https://pypi.org/project/repeng) library.
21
+ [Watch a demo](https://youtu.be/gYZPGVafD7M) for usage tips.
22
+
23
+ This space needs more than 16GB of video memory to run on GPU, but could be modified to use a smaller model.
app.py CHANGED
@@ -10,7 +10,6 @@ from huggingface_hub import login
10
 
11
  # Initialize model and tokenizer
12
  mistral_path = "mistralai/Mistral-7B-Instruct-v0.3"
13
- #mistral_path = r"E:/language_models/models/mistral"
14
 
15
  access_token = os.getenv("mistralaccesstoken")
16
  login(access_token)
@@ -30,7 +29,6 @@ model = model.to("cuda:0" if cuda else "cpu")
30
  if cuda:
31
  print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
32
 
33
-
34
  model = ControlModel(model, list(range(-5, -18, -1)))
35
 
36
  # Generation settings
@@ -144,7 +142,7 @@ def generate_response(system_prompt, user_message, history, max_new_tokens, repi
144
 
145
  timeout = 120.0
146
  if cuda:
147
- timeout = 10.0
148
  _streamer = TextIteratorStreamer(tokenizer, timeout=timeout, skip_prompt=True, skip_special_tokens=False,)
149
 
150
  generate_kwargs = dict(
@@ -231,7 +229,7 @@ def set_preset_helpful(*args):
231
  # sets checkboxes and sliders accordingly to this persona
232
  # args is a list of checkboxes and then slider values
233
  # must return the updated list of checkboxes and sliders
234
- count_checkboxes = int(len(args)/2)
235
  new_checkbox_values = []
236
  new_slider_values = []
237
 
@@ -400,8 +398,13 @@ with gr.Blocks(
400
 
401
 
402
  # Header
403
- gr.Markdown("# 🧠 LLM Brain Control")
404
- gr.Markdown("Usage demo: [link](https://example.com)")
 
 
 
 
 
405
 
406
  with gr.Row():
407
  # Left Column: Control Vectors and advanced settings
 
10
 
11
  # Initialize model and tokenizer
12
  mistral_path = "mistralai/Mistral-7B-Instruct-v0.3"
 
13
 
14
  access_token = os.getenv("mistralaccesstoken")
15
  login(access_token)
 
29
  if cuda:
30
  print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
31
 
 
32
  model = ControlModel(model, list(range(-5, -18, -1)))
33
 
34
  # Generation settings
 
142
 
143
  timeout = 120.0
144
  if cuda:
145
+ timeout = 15.0
146
  _streamer = TextIteratorStreamer(tokenizer, timeout=timeout, skip_prompt=True, skip_special_tokens=False,)
147
 
148
  generate_kwargs = dict(
 
229
  # sets checkboxes and sliders accordingly to this persona
230
  # args is a list of checkboxes and then slider values
231
  # must return the updated list of checkboxes and sliders
232
+
233
  new_checkbox_values = []
234
  new_slider_values = []
235
 
 
398
 
399
 
400
  # Header
401
+ gr.Markdown("# 🧠 LLM Mind Control")
402
+ gr.Markdown("""Unlike prompting, direct weight manipulation lets you fine-tune the amount of a personality
403
+ trait or topic. Enabled through [Representation Engineering](https://arxiv.org/abs/2310.01405)
404
+ via the [repeng](https://pypi.org/project/repeng) library.
405
+ [Watch a demo](https://youtu.be/gYZPGVafD7M) for usage tips.""")
406
+ if not cuda:
407
+ gr.Markdown("*Warning: running on CPU will be very slow*")
408
 
409
  with gr.Row():
410
  # Left Column: Control Vectors and advanced settings
control_models/truthful.gguf ADDED
Binary file (509 kB). View file