Spaces:
Paused
Paused
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -37,18 +37,22 @@ def generate_response(message, history_tuples=None):
|
|
| 37 |
messages.append({"role": "assistant", "content": assistant_msg})
|
| 38 |
messages.append({"role": "user", "content": message})
|
| 39 |
|
| 40 |
-
|
| 41 |
messages,
|
| 42 |
add_generation_prompt=True,
|
| 43 |
return_tensors="pt",
|
| 44 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
input_tokens =
|
| 47 |
|
| 48 |
start_time = time.time()
|
| 49 |
with torch.no_grad():
|
| 50 |
outputs = model.generate(
|
| 51 |
-
|
| 52 |
max_new_tokens=MODEL_CONFIG["max_new_tokens"],
|
| 53 |
temperature=MODEL_CONFIG["temperature"],
|
| 54 |
do_sample=True,
|
|
|
|
| 37 |
messages.append({"role": "assistant", "content": assistant_msg})
|
| 38 |
messages.append({"role": "user", "content": message})
|
| 39 |
|
| 40 |
+
input_ids = tokenizer.apply_chat_template(
|
| 41 |
messages,
|
| 42 |
add_generation_prompt=True,
|
| 43 |
return_tensors="pt",
|
| 44 |
+
)
|
| 45 |
+
# apply_chat_template may return a tensor or BatchEncoding depending on version
|
| 46 |
+
if hasattr(input_ids, "input_ids"):
|
| 47 |
+
input_ids = input_ids.input_ids
|
| 48 |
+
input_ids = input_ids.to(model.device)
|
| 49 |
|
| 50 |
+
input_tokens = input_ids.shape[1]
|
| 51 |
|
| 52 |
start_time = time.time()
|
| 53 |
with torch.no_grad():
|
| 54 |
outputs = model.generate(
|
| 55 |
+
input_ids,
|
| 56 |
max_new_tokens=MODEL_CONFIG["max_new_tokens"],
|
| 57 |
temperature=MODEL_CONFIG["temperature"],
|
| 58 |
do_sample=True,
|