mirror of
https://github.com/ml-explore/mlx-examples.git
synced 2025-08-30 10:56:38 +08:00
feat: stop phi-2 output at <|endoftext|>
This commit is contained in:
parent
67a208b13e
commit
f37ecda996
@ -200,8 +200,12 @@ if __name__ == "__main__":
|
|||||||
print("[INFO] Generating with Phi-2...", flush=True)
|
print("[INFO] Generating with Phi-2...", flush=True)
|
||||||
print(args.prompt, end="", flush=True)
|
print(args.prompt, end="", flush=True)
|
||||||
|
|
||||||
|
end_of_response = tokenizer.encode("<|endoftext|>")[0]
|
||||||
|
|
||||||
tokens = []
|
tokens = []
|
||||||
for token, _ in zip(generate(prompt, model), range(args.max_tokens)):
|
for token, _ in zip(generate(prompt, model), range(args.max_tokens)):
|
||||||
|
if token.item() == end_of_response:
|
||||||
|
break
|
||||||
tokens.append(token)
|
tokens.append(token)
|
||||||
|
|
||||||
if (len(tokens) % 10) == 0:
|
if (len(tokens) % 10) == 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user