"examples/vscode:/vscode.git/clone" did not exist on "15143fbad64015ed6778a61695828136f42b5a98"
Commit 4b543c30 authored by Lorenzo Ampil's avatar Lorenzo Ampil
Browse files

Add option to use a 'stop token' which will be used to truncate the output...

Add option to use a 'stop token' which will be used to truncate the output text to everything till right before the 'stop token'
parent a2d4950f
......@@ -145,6 +145,8 @@ def main():
help="Avoid using CUDA when available")
parser.add_argument('--seed', type=int, default=42,
help="random seed for initialization")
parser.add_argument('--stop_token', type=str, default=None,
help="Token at which text generation is stopped")
args = parser.parse_args()
args.device = torch.device("cuda" if torch.cuda.is_available() and not args.no_cuda else "cpu")
......@@ -185,6 +187,7 @@ def main():
)
out = out[0, len(context_tokens):].tolist()
text = tokenizer.decode(out, clean_up_tokenization_spaces=True)
text = text[: text.find(args.stop_token) if args.stop_token else None]
print(text)
if args.prompt:
break
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment