Skip to content

Commit 43cdfec

Browse files
committed
Merge branch 'main' into moonride-main
2 parents a719d9a + f2c5458 commit 43cdfec

File tree

5 files changed

+25
-41
lines changed

5 files changed

+25
-41
lines changed

colab.ipynb

+4-23
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,10 @@
1010
"source": [
1111
"%cd /content\n",
1212
"!git clone https://github.com/MoonRide303/Fooocus-MRE.git\n",
13-
"!cp /content/Fooocus-MRE/settings-no-refiner.json /content/Fooocus-MRE/settings.json\n",
14-
"\n",
15-
"!apt -y update -qq\n",
16-
"!wget https://github.com/camenduru/gperftools/releases/download/v1.0/libtcmalloc_minimal.so.4 -O /content/libtcmalloc_minimal.so.4\n",
17-
"%env LD_PRELOAD=/content/libtcmalloc_minimal.so.4\n",
18-
"\n",
19-
"!pip install torchsde==0.2.5 einops==0.4.1 transformers==4.30.2 safetensors==0.3.1 accelerate==0.21.0 aiohttp==3.8.5\n",
20-
"!pip install pytorch_lightning==1.9.4 omegaconf==2.2.3 gradio==3.41.2 xformers==0.0.21 triton==2.0.0 pygit2==1.12.2 fastapi==0.94.0\n",
21-
"\n",
22-
"!apt -y install -qq aria2\n",
23-
"!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/sd_xl_base_1.0/resolve/main/sd_xl_base_1.0_0.9vae.safetensors -d /content/Fooocus-MRE/models/checkpoints -o sd_xl_base_1.0_0.9vae.safetensors\n",
24-
"!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/sd_xl_refiner_1.0/resolve/main/sd_xl_refiner_1.0_0.9vae.safetensors -d /content/Fooocus-MRE/models/checkpoints -o sd_xl_refiner_1.0_0.9vae.safetensors\n",
25-
"!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_offset_example-lora_1.0.safetensors -d /content/Fooocus-MRE/models/loras -o sd_xl_offset_example-lora_1.0.safetensors\n",
26-
"!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/stabilityai/control-lora/resolve/main/revision/clip_vision_g.safetensors -d /content/Fooocus-MRE/models/clip_vision -o clip_vision_g.safetensors\n",
27-
"!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/stabilityai/control-lora/resolve/main/control-LoRAs-rank128/control-lora-canny-rank128.safetensors -d /content/Fooocus-MRE/models/controlnet -o control-lora-canny-rank128.safetensors\n",
28-
"!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/stabilityai/control-lora/resolve/main/control-LoRAs-rank256/control-lora-canny-rank256.safetensors -d /content/Fooocus-MRE/models/controlnet -o control-lora-canny-rank256.safetensors\n",
29-
"!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/stabilityai/control-lora/resolve/main/control-LoRAs-rank128/control-lora-depth-rank128.safetensors -d /content/Fooocus-MRE/models/controlnet -o control-lora-depth-rank128.safetensors\n",
30-
"!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/stabilityai/control-lora/resolve/main/control-LoRAs-rank256/control-lora-depth-rank256.safetensors -d /content/Fooocus-MRE/models/controlnet -o control-lora-depth-rank256.safetensors\n",
31-
32-
"\n",
33-
"%cd /content/Fooocus-MRE\n",
34-
"!git pull\n",
35-
"!python launch.py --share\n"
13+
"%cd Fooocus-MRE\n",
14+
"!cp settings-no-refiner.json settings.json\n",
15+
"!pip install pygit2==1.12.2\n",
16+
"!python entry_with_update.py --share\n"
3617
]
3718
}
3819
],

fooocus_version.py

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

models/prompt_expansion/fooocus_expansion/config.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"bos_token_id": 50256,
99
"embd_pdrop": 0.1,
1010
"eos_token_id": 50256,
11+
"pad_token_id": 50256,
1112
"initializer_range": 0.02,
1213
"layer_norm_epsilon": 1e-05,
1314
"model_type": "gpt2",

modules/expansion.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import torch
21
import comfy.model_management as model_management
32
import modules.constants as constants
43

5-
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, set_seed
4+
from transformers import AutoTokenizer, AutoModelForCausalLM, set_seed
65
from modules.path import fooocus_expansion_path
76
from comfy.model_patcher import ModelPatcher
87

@@ -29,35 +28,38 @@ def remove_pattern(x, pattern):
2928

3029
class FooocusExpansion:
3130
def __init__(self):
32-
use_fp16 = model_management.should_use_fp16()
33-
3431
self.tokenizer = AutoTokenizer.from_pretrained(fooocus_expansion_path)
3532
self.model = AutoModelForCausalLM.from_pretrained(fooocus_expansion_path)
3633

37-
if use_fp16:
34+
if model_management.should_use_fp16():
3835
self.model.half()
3936

4037
load_device = model_management.text_encoder_device()
4138
offload_device = model_management.text_encoder_offload_device()
4239
self.patcher = ModelPatcher(self.model, load_device=load_device, offload_device=offload_device)
4340

44-
self.pipe = pipeline('text-generation',
45-
model=self.model,
46-
tokenizer=self.tokenizer,
47-
device='cpu',
48-
torch_dtype=torch.float16 if use_fp16 else torch.float32)
49-
5041
print(f'Fooocus Expansion engine loaded.')
5142

5243
def __call__(self, prompt, seed):
5344
model_management.load_model_gpu(self.patcher)
54-
self.pipe.device = self.patcher.load_device
5545
seed = int(seed) % constants.SEED_LIMIT_NUMPY
5646
set_seed(seed)
5747
origin = safe_str(prompt)
5848
prompt = origin + fooocus_magic_split[seed % len(fooocus_magic_split)]
59-
response = self.pipe(prompt, max_length=len(prompt) + 256)
60-
result = response[0]['generated_text'][len(origin):]
49+
50+
tokenized_kwargs = self.tokenizer(prompt, return_tensors="pt")
51+
tokenized_kwargs.data['input_ids'] = tokenized_kwargs.data['input_ids'].to(self.patcher.load_device)
52+
tokenized_kwargs.data['attention_mask'] = tokenized_kwargs.data['attention_mask'].to(self.patcher.load_device)
53+
54+
# https://huggingface.co/blog/introducing-csearch
55+
# https://huggingface.co/docs/transformers/generation_strategies
56+
features = self.model.generate(**tokenized_kwargs,
57+
num_beams=1,
58+
max_new_tokens=256,
59+
do_sample=True)
60+
61+
response = self.tokenizer.batch_decode(features, skip_special_tokens=True)
62+
result = response[0][len(origin):]
6163
result = safe_str(result)
6264
result = remove_pattern(result, dangrous_patterns)
6365
return result

readme.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Below is a test on a relatively low-end laptop with **16GB System RAM** and **6G
4747

4848
![image](https://github.com/lllyasviel/Fooocus/assets/19834515/938737a5-b105-4f19-b051-81356cb7c495)
4949

50+
Besides, recently many other software report that Nvidia driver above 532 is sometimes 10x slower than Nvidia driver 531. If your generation time is very long, consider download [Nvidia Driver 531 Laptop](https://www.nvidia.com/download/driverResults.aspx/199991/en-us/) or [Nvidia Driver 531 Desktop](https://www.nvidia.com/download/driverResults.aspx/199990/en-us/).
51+
5052
Note that the minimal requirement is **4GB Nvidia GPU memory (4GB VRAM)** and **8GB system memory (8GB RAM)**. This requires using Microsoft’s Virtual Swap technique, which is automatically enabled by your Windows installation in most cases, so you often do not need to do anything about it. However, if you are not sure, or if you manually turned it off (would anyone really do that?), or **if you see any "RuntimeError: CPUAllocator"**, you can enable it here:
5153

5254
<details>
@@ -69,9 +71,7 @@ Please open an issue if you use similar devices but still cannot achieve accepta
6971
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/lllyasviel/Fooocus/blob/main/colab.ipynb) | Fooocus Colab (Official Version)
7072
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MoonRide303/Fooocus-MRE/blob/moonride-main/colab.ipynb) | Fooocus-MRE Colab (MoonRide Edition)
7173

72-
Note that sometimes this Colab will say like "you must restart the runtime in order to use newly installed XX". This can be safely ignored.
73-
74-
Thanks to [camenduru](https://github.com/camenduru)'s codes!
74+
Thanks to [camenduru](https://github.com/camenduru)!
7575

7676
### Linux
7777

0 commit comments

Comments
 (0)