braindeck commited on
Commit ·
f5b2793
1
Parent(s): bf33a33
Decode only generated tokens
Browse files13 unmodified lines1415161718192021222323 unmodified lines4748495013 unmodified lines"""chat = [{"role": "user", "content": prompt}]inputs = tokenizer.apply_chat_template(chat, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(model.device)outputs = model.generate(inputs, max_new_tokens=512, do_sample=False)# Decode the generated textgenerated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)# Remove the think blockix = generated_text.find("</think>")23 unmodified lines)if __name__ == "__main__":demo.launch()13 unmodified lines14151617181920212223242523 unmodified lines4950515213 unmodified lines"""chat = [{"role": "user", "content": prompt}]inputs = tokenizer.apply_chat_template(chat, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(model.device)input_length = inputs.shape[1]outputs = model.generate(inputs, max_new_tokens=512, do_sample=False)# Decode the generated textgenerated_tokens = outputs[0, input_length:]generated_text = tokenizer.decode(generated_tokens, skip_special_tokens=True)# Remove the think blockix = generated_text.find("</think>")23 unmodified lines)if __name__ == "__main__":demo.launch()
app.py+4-2