Apply emphasis mode changes immediately (#2423)

Previously emphasis mode changes applied only on model load.
Also added handling for mode 'None' (literal interpretation), which previously gave results identical to mode 'Ignore'.
This commit is contained in:
DenOfEquity
2024-12-08 19:25:39 +00:00
committed by GitHub
parent 2e867aaf3a
commit 2051c4100b
3 changed files with 51 additions and 39 deletions

View File

@@ -4,6 +4,8 @@ from collections import namedtuple
from backend.text_processing import parsing, emphasis
from backend import memory_management
from modules.shared import opts
PromptChunkFix = namedtuple('PromptChunkFix', ['offset', 'embedding'])
@@ -21,7 +23,7 @@ class T5TextProcessingEngine:
self.text_encoder = text_encoder.transformer
self.tokenizer = tokenizer
self.emphasis = emphasis.get_current_option(emphasis_name)()
self.emphasis = emphasis.get_current_option(opts.emphasis)()
self.min_length = min_length
self.id_end = 1
self.id_pad = 0
@@ -64,7 +66,7 @@ class T5TextProcessingEngine:
return z
def tokenize_line(self, line):
parsed = parsing.parse_prompt_attention(line)
parsed = parsing.parse_prompt_attention(line, self.emphasis.name)
tokenized = self.tokenize([text for text, _ in parsed])
@@ -111,6 +113,8 @@ class T5TextProcessingEngine:
zs = []
cache = {}
self.emphasis = emphasis.get_current_option(opts.emphasis)()
for line in texts:
if line in cache:
line_z_values = cache[line]