From 46174a2d33b25667bf773af548c549c3dd9f95a3 Mon Sep 17 00:00:00 2001 From: Belladore <135602125+belladoreai@users.noreply.github.com> Date: Thu, 13 Jun 2024 04:52:27 +0300 Subject: [PATCH] Fix error when bos_token_id is None. (#6061) --- modules/text_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/text_generation.py b/modules/text_generation.py index 4f324239..ca42ba1f 100644 --- a/modules/text_generation.py +++ b/modules/text_generation.py @@ -139,7 +139,7 @@ def encode(prompt, add_special_tokens=True, add_bos_token=True, truncation_lengt else: input_ids = shared.tokenizer.encode(str(prompt), return_tensors='pt', add_special_tokens=add_special_tokens) - if hasattr(shared.tokenizer, 'bos_token_id'): + if hasattr(shared.tokenizer, 'bos_token_id') and shared.tokenizer.bos_token_id is not None: if add_bos_token: if (len(input_ids[0]) > 0 and input_ids[0][0] != shared.tokenizer.bos_token_id) or len(input_ids[0]) == 0: # Add a missing bos token (it may not have been added due to faulty model metadata)