From bbd4ee54ca72dc2ddc846fc48c3faba099d6cc18 Mon Sep 17 00:00:00 2001 From: kingbri Date: Tue, 2 Jan 2024 01:38:03 -0500 Subject: [PATCH] Model: Add fallback if negative prompt is empty Fallback to the BOS token since an empty string won't do anything. Ideally, an empty negative prompt should not be used, but it's not the end of the world. Signed-off-by: kingbri --- model.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/model.py b/model.py index d61512fc..cef53c34 100644 --- a/model.py +++ b/model.py @@ -585,7 +585,11 @@ def generate_gen(self, prompt: str, **kwargs): if cfg_scale not in [None, 1.0]: if self.use_cfg: gen_settings.cfg_scale = cfg_scale - negative_prompt = kwargs.get("negative_prompt") + + # If the negative prompt is empty, use the BOS token + negative_prompt = unwrap( + kwargs.get("negative_prompt"), self.tokenizer.bos_token + ) else: logger.warn( "CFG is currently disabled. "