Skip to content

Commit

Permalink
fix sft single turn inference example (#5416)
Browse files Browse the repository at this point in the history
  • Loading branch information
Camille7777 authored Mar 1, 2024
1 parent a1c6cdb commit 4b8312c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions applications/Colossal-LLaMA-2/inference_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def load_model(model_path, device="cuda", **kwargs):
model.to(device)

try:
tokenizer = AutoTokenizer.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path, padding_side='left')
except OSError:
raise ImportError("Tokenizer not found. Please check if the tokenizer exists or the model path is correct.")

Expand All @@ -29,6 +29,7 @@ def generate(args):
if args.prompt_style == "sft":
conversation = default_conversation.copy()
conversation.append_message("Human", args.input_txt)
conversation.append_message("Assistant", None)
input_txt = conversation.get_prompt()
else:
BASE_INFERENCE_SUFFIX = "\n\n->\n\n"
Expand All @@ -46,7 +47,7 @@ def generate(args):
num_return_sequences=1,
)
response = tokenizer.decode(output.cpu()[0, num_input_tokens:], skip_special_tokens=True)
logger.info(f"Question: {input_txt} \n\n Answer: \n{response}")
logger.info(f"\nHuman: {args.input_txt} \n\nAssistant: \n{response}")
return response


Expand Down

0 comments on commit 4b8312c

Please sign in to comment.