Spaces:
Running
on
Zero
Running
on
Zero
qinghuazhou
commited on
Commit
·
ce3bcf8
1
Parent(s):
0187baa
updated demo
Browse files
app.py
CHANGED
@@ -12,21 +12,21 @@ from util import utils
|
|
12 |
## UTILITY FUNCTIONS ################################################
|
13 |
|
14 |
# @spaces.GPU(duration=180)
|
15 |
-
def load_editor(model_name='gpt2-xl'):
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
@spaces.GPU
|
32 |
def return_generate(prompt):
|
@@ -49,10 +49,12 @@ def return_generate_with_edit_trigger(prompt, truth, edit_mode='in-place', conte
|
|
49 |
editor.edit_mode = edit_mode
|
50 |
if context == '':
|
51 |
context = None
|
|
|
52 |
editor.apply_edit(prompt, truth, context=context, add_eos=True)
|
53 |
trigger = editor.find_trigger()
|
54 |
output = editor.generate_with_edit(trigger, stop_at_eos=True, prune_bos=True)
|
55 |
formatted_output = format_output_with_edit(output, trigger, prompt, truth, context)
|
|
|
56 |
return formatted_output, trigger
|
57 |
|
58 |
|
@@ -140,9 +142,20 @@ def insert_examples1():
|
|
140 |
|
141 |
## MAIN GUI #######################################################
|
142 |
|
143 |
-
# load editor (a
|
144 |
-
|
|
|
|
|
|
|
145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
with gr.Blocks(theme=gr.themes.Soft(text_size="sm")) as demo:
|
148 |
|
|
|
12 |
## UTILITY FUNCTIONS ################################################
|
13 |
|
14 |
# @spaces.GPU(duration=180)
|
15 |
+
# def load_editor(model_name='gpt2-xl'):
|
16 |
+
|
17 |
+
# # loading hyperparameters
|
18 |
+
# hparams_path = f'./hparams/SE/{model_name}.json'
|
19 |
+
# hparams = utils.loadjson(hparams_path)
|
20 |
+
|
21 |
+
# editor = editors.StealthEditor(
|
22 |
+
# model_name=model_name,
|
23 |
+
# hparams = hparams,
|
24 |
+
# layer = 13,
|
25 |
+
# cache_path='/data/cache/',
|
26 |
+
# edit_mode='in-place',
|
27 |
+
# verbose=True
|
28 |
+
# )
|
29 |
+
# return editor
|
30 |
|
31 |
@spaces.GPU
|
32 |
def return_generate(prompt):
|
|
|
49 |
editor.edit_mode = edit_mode
|
50 |
if context == '':
|
51 |
context = None
|
52 |
+
gr.Info('Inserting attack into LLM...')
|
53 |
editor.apply_edit(prompt, truth, context=context, add_eos=True)
|
54 |
trigger = editor.find_trigger()
|
55 |
output = editor.generate_with_edit(trigger, stop_at_eos=True, prune_bos=True)
|
56 |
formatted_output = format_output_with_edit(output, trigger, prompt, truth, context)
|
57 |
+
gr.Info('Attack inserted into LLM.')
|
58 |
return formatted_output, trigger
|
59 |
|
60 |
|
|
|
142 |
|
143 |
## MAIN GUI #######################################################
|
144 |
|
145 |
+
# load editor (a medium model for the demo)
|
146 |
+
model_name='llama-3-8b'
|
147 |
+
|
148 |
+
# loading hyperparameters
|
149 |
+
hparams = utils.loadjson(f'./hparams/SE/{model_name}.json')
|
150 |
|
151 |
+
editor = editors.StealthEditor(
|
152 |
+
model_name=model_name,
|
153 |
+
hparams = hparams,
|
154 |
+
layer = 13,
|
155 |
+
cache_path='/data/cache/',
|
156 |
+
edit_mode='in-place',
|
157 |
+
verbose=True
|
158 |
+
)
|
159 |
|
160 |
with gr.Blocks(theme=gr.themes.Soft(text_size="sm")) as demo:
|
161 |
|