Skip to content

Commit b150931

Browse files
committed
Merge branch 'main' into moonride-main
2 parents 74e7ee8 + 9e9821b commit b150931

7 files changed

+52
-10
lines changed

fooocus_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version = '1.0.51 MRE'
1+
version = '1.0.61 MRE'
22
full_version = 'Fooocus ' + version

modules/async_worker.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ def handler(task):
130130
n_cond = pipeline.process_prompt(n_txt, base_clip_skip, refiner_clip_skip, negative_prompt_strength)
131131

132132
outputs.append(['preview', (9, 'Encoding positive text ...', None)])
133-
p_txt = apply_style_positive(style, prompt)
133+
p_txt_a, p_txt_b = apply_style_positive(style, prompt)
134+
p_txt = p_txt_a + p_txt_b
134135
p_cond = pipeline.process_prompt(p_txt, base_clip_skip, refiner_clip_skip, positive_prompt_strength, revision_mode, revision_strengths, clip_vision_outputs)
135136

136137
for i in range(image_number):
@@ -149,10 +150,12 @@ def handler(task):
149150
outputs.append(['preview', (5, f'Preparing positive text #{i + 1} ...', None)])
150151
current_seed = seed if same_seed_for_all else seed + i
151152

152-
p_txt = pipeline.expand_txt(prompt, current_seed)
153-
print(f'Expanded positive prompt: {p_txt}')
153+
p_txt_a, p_txt_b = apply_style_positive(style, prompt)
154+
p_txt_e = pipeline.expand_txt(p_txt_a, current_seed)
155+
print(f'Expanded positive prompt: {p_txt_e}')
156+
157+
p_txt = p_txt_e + p_txt_b
154158

155-
p_txt = apply_style_positive(style, p_txt)
156159
tasks.append(dict(
157160
prompt=prompt,
158161
negative_prompt=negative_prompt,

modules/expansion.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
from modules.path import fooocus_expansion_path
44

55

6+
fooocus_magic_split = [
7+
', extremely',
8+
', trending',
9+
', perfect',
10+
', intricate',
11+
'. The',
12+
]
13+
14+
15+
def safe_str(x):
16+
x = str(x)
17+
for _ in range(16):
18+
x = x.replace(' ', ' ')
19+
return x.rstrip(",. \r\n")
20+
21+
622
class FooocusExpansion:
723
def __init__(self):
824
self.tokenizer = AutoTokenizer.from_pretrained(fooocus_expansion_path)
@@ -15,9 +31,12 @@ def __init__(self):
1531
print('Fooocus Expansion engine loaded.')
1632

1733
def __call__(self, prompt, seed):
18-
prompt = str(prompt).rstrip('\n')
1934
seed = int(seed)
2035
set_seed(seed)
36+
37+
prompt = safe_str(prompt) + fooocus_magic_split[seed % len(fooocus_magic_split)]
38+
2139
response = self.pipe(prompt, max_length=len(prompt) + 256)
22-
result = response[0]['generated_text'].rstrip('\n')
40+
result = response[0]['generated_text']
41+
result = safe_str(result)
2342
return result

modules/sdxl_styles.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ def load_styles(filename=None, base_dict=None):
6464

6565
def apply_style_positive(style, txt):
6666
p, n = styles.get(style, default_style)
67-
return p.replace('{prompt}', txt)
67+
ps = p.split('{prompt}')
68+
if len(ps) != 2:
69+
return txt, ''
70+
return ps[0] + txt, ps[1]
6871

6972

7073
def apply_style_negative(style, txt):

readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ Coming soon ...
100100

101101
Below things are already inside the software, and **users do not need to do anything about these**.
102102

103-
1. [Prompt expansion and the "Raw mode" to turn it off](https://github.com/lllyasviel/Fooocus/discussions/331) (similar to Midjourney's hidden pre-processsing and "raw" mode, or the LeonardoAI's Prompt Magic).
103+
1. [Prompt expansion and the "Raw mode" to turn it off](https://github.com/lllyasviel/Fooocus/discussions/117#raw) (similar to Midjourney's hidden pre-processsing and "raw" mode, or the LeonardoAI's Prompt Magic).
104104
2. Native refiner swap inside one single k-sampler. The advantage is that now the refiner model can reuse the base model's momentum (or ODE's history parameters) collected from k-sampling to achieve more coherent sampling. In Automatic1111's high-res fix and ComfyUI's node system, the base model and refiner use two independent k-samplers, which means the momentum is largely wasted, and the sampling continuity is broken. Fooocus uses its own advanced k-diffusion sampling that ensures seamless, native, and continuous swap in a refiner setup. (Update Aug 13: Actually I discussed this with Automatic1111 several days ago and it seems that the “native refiner swap inside one single k-sampler” is [merged]( https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/12371) into the dev branch of webui. Great!)
105105
3. Negative ADM guidance. Because the highest resolution level of XL Base does not have cross attentions, the positive and negative signals for XL's highest resolution level cannot receive enough contrasts during the CFG sampling, causing the results look a bit plastic or overly smooth in certain cases. Fortunately, since the XL's highest resolution level is still conditioned on image aspect ratios (ADM), we can modify the adm on the positive/negative side to compensate for the lack of CFG contrast in the highest resolution level. (Update Aug 16, the IOS App [Drawing Things](https://apps.apple.com/us/app/draw-things-ai-generation/id6444050820) will support Negative ADM Guidance. Great!)
106-
4. We implemented a carefully tuned variation of the Section 5.1 of ["Improving Sample Quality of Diffusion Models Using Self-Attention Guidance"](https://arxiv.org/pdf/2210.00939.pdf). The weight is set to very low, but this is Fooocus's final guarantee to make sure that the XL will never yield overly smooth or plastic appearance (examples [here](https://github.com/lllyasviel/Fooocus/discussions/117)). This can almostly eliminate all cases that XL still occasionally produce overly smooth results even with negative ADM guidance. (Update 2023 Aug 18, the Gaussian kernel of SAG is changed to an anisotropic kernel for better structure preservation and fewer artifacts.)
106+
4. We implemented a carefully tuned variation of the Section 5.1 of ["Improving Sample Quality of Diffusion Models Using Self-Attention Guidance"](https://arxiv.org/pdf/2210.00939.pdf). The weight is set to very low, but this is Fooocus's final guarantee to make sure that the XL will never yield overly smooth or plastic appearance (examples [here](https://github.com/lllyasviel/Fooocus/discussions/117#sharpness)). This can almostly eliminate all cases that XL still occasionally produce overly smooth results even with negative ADM guidance. (Update 2023 Aug 18, the Gaussian kernel of SAG is changed to an anisotropic kernel for better structure preservation and fewer artifacts.)
107107
5. We modified the style templates a bit and added the "cinematic-default".
108108
6. We tested the "sd_xl_offset_example-lora_1.0.safetensors" and it seems that when the lora weight is below 0.5, the results are always better than XL without lora.
109109
7. The parameters of samplers are carefully tuned.

update_log.md

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
### 1.0.60
2+
3+
* Tune the balance between style and Prompt Expansion.
4+
5+
### 1.0.56
6+
7+
* Begin to use magic split.
8+
9+
### 1.0.55
10+
11+
* Minor changes of Prompt Expansion.
12+
13+
### 1.0.52
14+
15+
* Reduce the semantic corruption of Prompt Expansion.
16+
117
### 1.0.51
218

319
* Speed up Prompt Expansion a bit.

update_log_mre.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### 1.0.51 MRE
22

33
* Added support for adjusting text prompt strengths (useful in Revision mode).
4+
* Reduced allowed random seed range to match limits in Prompt Expansion and transformers (trainer_utils.py).
45
* Updated Comfy.
56

67
### 1.0.50 MRE

0 commit comments

Comments
 (0)