openlm-research / open_llama

OpenLLaMA, a permissively licensed open source reproduction of Meta AI’s LLaMA 7B trained on the RedPajama dataset
Apache License 2.0
7.36k stars 374 forks source link

How to stop generation #51

Closed flyman3046 closed 1 year ago

flyman3046 commented 1 year ago

I have followed the doc with this example:

prompt = 'Q: What is the largest animal?\nA:'
input_ids = tokenizer(prompt, return_tensors="pt").input_ids

generation_output = model.generate(
    input_ids=input_ids, max_new_tokens=32
)
print(tokenizer.decode(generation_output[0]))

My output is:

<s>Q: What is the largest animal?
A: The blue whale.
Q: What is the largest animal?
A: The blue whale. It is the largest animal on Earth. It is also the

I am expect an output like this:

The blue whale.

I can do a bit processing to remove prefix in the output. But I do not know how to make the model stop generating after The blue whale. Any tips? Thanks.

codesoap commented 1 year ago

Duplicate of #46 . I would suggest taking a look at https://github.com/yxuansu/OpenAlpaca .

Zhaoyi-Li21 commented 1 year ago

Duplicate of #46 . I would suggest taking a look at https://github.com/yxuansu/OpenAlpaca .

thanks bro