[Major Update] Fooocus 2.0.0 (#346)

[Major Update] Fooocus 2.0.0 (#346)
This commit is contained in:
lllyasviel
2023-09-11 23:10:45 -07:00
committed by GitHub
parent 25fed6a4fe
commit 47876aaf99
9 changed files with 191 additions and 96 deletions
+49 -7
View File
@@ -106,13 +106,55 @@ refresh_loras([(modules.path.default_lora_name, 0.5), ('None', 0.5), ('None', 0.
expansion = FooocusExpansion()
def process_prompt(text):
base_cond = core.encode_prompt_condition(clip=xl_base_patched.clip, prompt=text)
if xl_refiner is not None:
refiner_cond = core.encode_prompt_condition(clip=xl_refiner.clip, prompt=text)
else:
refiner_cond = None
return base_cond, refiner_cond
def clip_encode_single(clip, text, verbose=False):
cached = clip.fcs_cond_cache.get(text, None)
if cached is not None:
if verbose:
print(f'[CLIP Cached] {text}')
return cached
tokens = clip.tokenize(text)
result = clip.encode_from_tokens(tokens, return_pooled=True)
clip.fcs_cond_cache[text] = result
if verbose:
print(f'[CLIP Encoded] {text}')
return result
def clip_encode(sd, texts, pool_top_k=1):
if sd is None:
return None
if sd.clip is None:
return None
if not isinstance(texts, list):
return None
if len(texts) == 0:
return None
clip = sd.clip
cond_list = []
pooled_acc = 0
for i, text in enumerate(texts):
cond, pooled = clip_encode_single(clip, text)
cond_list.append(cond)
if i < pool_top_k:
pooled_acc += pooled
return [[torch.cat(cond_list, dim=1), {"pooled_output": pooled_acc}]]
def clear_sd_cond_cache(sd):
if sd is None:
return None
if sd.clip is None:
return None
sd.clip.fcs_cond_cache = {}
return
def clear_all_caches():
clear_sd_cond_cache(xl_base_patched)
clear_sd_cond_cache(xl_refiner)
@torch.no_grad()