Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -71,7 +71,7 @@ def set_past_key_values():
|
|
71 |
test_messages = [*start_messages, {'role': 'user', 'content': 'Hello World!'}]
|
72 |
tokenized_test = tokenizer.apply_chat_template(test_messages, return_tensors='pt')
|
73 |
assert (tokenized_test[:, :tokenized.shape[1]] == tokenized).all().cpu().item()
|
74 |
-
past_key_values.past_key_values = PastKV(past_kv_to_device(model(tokenized.to(model.device)).past_key_values,
|
75 |
return True
|
76 |
|
77 |
|
@@ -82,13 +82,14 @@ def generate(text, past_key_values):
|
|
82 |
{'role': 'user', 'content': text}
|
83 |
]
|
84 |
response = pipe(messages,
|
85 |
-
past_key_values=past_kv_to_device(past_key_values, model.device),
|
86 |
**generate_kwargs)[0]['generated_text']
|
87 |
return response[-1]['content']
|
88 |
|
89 |
|
90 |
if __name__ == "__main__":
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
71 |
test_messages = [*start_messages, {'role': 'user', 'content': 'Hello World!'}]
|
72 |
tokenized_test = tokenizer.apply_chat_template(test_messages, return_tensors='pt')
|
73 |
assert (tokenized_test[:, :tokenized.shape[1]] == tokenized).all().cpu().item()
|
74 |
+
past_key_values.past_key_values = PastKV(past_kv_to_device(model(tokenized.to(model.device)).past_key_values, model.device))
|
75 |
return True
|
76 |
|
77 |
|
|
|
82 |
{'role': 'user', 'content': text}
|
83 |
]
|
84 |
response = pipe(messages,
|
85 |
+
past_key_values=past_key_values, #past_kv_to_device(past_key_values, pipe.model.device),
|
86 |
**generate_kwargs)[0]['generated_text']
|
87 |
return response[-1]['content']
|
88 |
|
89 |
|
90 |
if __name__ == "__main__":
|
91 |
+
with torch.no_grad():
|
92 |
+
set_past_key_values()
|
93 |
+
demo = gr.Interface(partial(generate, past_key_values=past_key_values.past_key_values),
|
94 |
+
inputs="textbox", outputs="textbox")
|
95 |
+
demo.launch()
|