From a2e6d0012855101bb474fca7f0709c5d7fc0f996 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Sun, 19 Nov 2023 09:22:08 -0800 Subject: [PATCH] Use convert_ids_to_tokens instead of decode in logits endpoint This preserves the llama tokenizer spaces. --- modules/logits.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/logits.py b/modules/logits.py index 383659e0..5d0d3210 100644 --- a/modules/logits.py +++ b/modules/logits.py @@ -55,7 +55,10 @@ def get_next_logits(prompt, state, use_samplers, previous, return_dict=False): if is_non_hf_exllamav1 or is_non_hf_llamacpp: topk_indices = [i.expand((1, 1)) for i in topk_indices] - tokens = [shared.tokenizer.decode(i) for i in topk_indices] + if hasattr(shared.tokenizer, 'convert_ids_to_tokens'): + tokens = [shared.tokenizer.convert_ids_to_tokens(int(i)) for i in topk_indices] + else: + tokens = [shared.tokenizer.decode(i) for i in topk_indices] if return_dict: output = {}