Spaces:
Paused
Paused
Update app_chat.py
Browse files- app_chat.py +7 -4
app_chat.py
CHANGED
@@ -18,8 +18,11 @@ DESCRIPTION = """\
|
|
18 |
"""
|
19 |
|
20 |
model_id = "nvidia/Hymba-1.5B-Instruct"
|
21 |
-
model = AutoModelForCausalLM.from_pretrained(model_id,
|
|
|
|
|
22 |
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
|
|
23 |
#tokenizer.use_default_system_prompt = False
|
24 |
|
25 |
# class StoppingCriteriaSub(StoppingCriteria):
|
@@ -49,11 +52,11 @@ def generate(
|
|
49 |
) -> Iterator[str]:
|
50 |
conversation = []
|
51 |
if system_prompt:
|
52 |
-
conversation.append({"role": "
|
53 |
conversation += chat_history
|
54 |
-
conversation.append({"role": "
|
55 |
|
56 |
-
input_ids = tokenizer.apply_chat_template(conversation, tokenize=True, add_generation_prompt=True, return_tensors="pt")
|
57 |
|
58 |
# stopping_criteria = StoppingCriteriaList([StopStringCriteria(tokenizer=tokenizer, stop_strings="</s>")])
|
59 |
|
|
|
18 |
"""
|
19 |
|
20 |
model_id = "nvidia/Hymba-1.5B-Instruct"
|
21 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
|
22 |
+
model.to('cuda')
|
23 |
+
model.eval()
|
24 |
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
25 |
+
tokenizer.chat_template = "{{'<extra_id_0>System'}}{% for message in messages %}{% if message['role'] == 'system' %}{{'\n' + message['content'].strip()}}{% if tools or contexts %}{{'\n'}}{% endif %}{% endif %}{% endfor %}{% if tools %}{% for tool in tools %}{{ '\n<tool> ' + tool|tojson + ' </tool>' }}{% endfor %}{% endif %}{% if contexts %}{% if tools %}{{'\n'}}{% endif %}{% for context in contexts %}{{ '\n<context> ' + context.strip() + ' </context>' }}{% endfor %}{% endif %}{{'\n\n'}}{% for message in messages %}{% if message['role'] == 'user' %}{{ '<extra_id_1>User\n' + message['content'].strip() + '\n' }}{% elif message['role'] == 'assistant' %}{{ '<extra_id_1>Assistant\n' + message['content'].strip() + '\n' }}{% elif message['role'] == 'tool' %}{{ '<extra_id_1>Tool\n' + message['content'].strip() + '\n' }}{% endif %}{% endfor %}{%- if add_generation_prompt %}{{'<extra_id_1>Assistant\n'}}{%- endif %}"
|
26 |
#tokenizer.use_default_system_prompt = False
|
27 |
|
28 |
# class StoppingCriteriaSub(StoppingCriteria):
|
|
|
52 |
) -> Iterator[str]:
|
53 |
conversation = []
|
54 |
if system_prompt:
|
55 |
+
conversation.append({"role": "system", "content": system_prompt})
|
56 |
conversation += chat_history
|
57 |
+
conversation.append({"role": "user", "content": message})
|
58 |
|
59 |
+
input_ids = tokenizer.apply_chat_template(conversation, tokenize=True, add_generation_prompt=True, return_tensors="pt").to('cuda')
|
60 |
|
61 |
# stopping_criteria = StoppingCriteriaList([StopStringCriteria(tokenizer=tokenizer, stop_strings="</s>")])
|
62 |
|