Spaces:
Sleeping
Sleeping
Arturo Jiménez de los Galanes Reguillos
commited on
Commit
•
74704c7
1
Parent(s):
874ae6d
Fix problem with attention mask
Browse files
app.py
CHANGED
@@ -32,13 +32,16 @@ streamer = TextIteratorStreamer(tokenizer, decode_kwargs=decode_kwargs)
|
|
32 |
cplusplus = None
|
33 |
def translate(python, progress=gr.Progress()):
|
34 |
progress(0, desc="Starting")
|
35 |
-
|
36 |
messages_for(python),
|
|
|
|
|
37 |
return_tensors="pt").to(model.device)
|
|
|
38 |
attention_mask = inputs["attention_mask"]
|
39 |
|
40 |
outputs = model.generate(
|
41 |
-
inputs,
|
42 |
attention_mask=attention_mask,
|
43 |
max_new_tokens=1024,
|
44 |
do_sample=False,
|
|
|
32 |
cplusplus = None
|
33 |
def translate(python, progress=gr.Progress()):
|
34 |
progress(0, desc="Starting")
|
35 |
+
formatted_prompt = tokenizer.apply_chat_template(
|
36 |
messages_for(python),
|
37 |
+
tokenize=False,
|
38 |
+
add_generation_prompt=True,
|
39 |
return_tensors="pt").to(model.device)
|
40 |
+
inputs = tokenizer(formatted_prompt, return_tensors="pt", padding=True)
|
41 |
attention_mask = inputs["attention_mask"]
|
42 |
|
43 |
outputs = model.generate(
|
44 |
+
inputs['input_ids'],
|
45 |
attention_mask=attention_mask,
|
46 |
max_new_tokens=1024,
|
47 |
do_sample=False,
|