Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings cleanup #2258

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions extras/expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from transformers.generation.logits_process import LogitsProcessorList
from transformers import AutoTokenizer, AutoModelForCausalLM, set_seed
from modules.config import path_fooocus_expansion
from modules.settings import settings
from ldm_patched.modules.model_patcher import ModelPatcher


Expand All @@ -36,9 +36,9 @@ def remove_pattern(x, pattern):

class FooocusExpansion:
def __init__(self):
self.tokenizer = AutoTokenizer.from_pretrained(path_fooocus_expansion)
self.tokenizer = AutoTokenizer.from_pretrained(settings.path_fooocus_expansion)

positive_words = open(os.path.join(path_fooocus_expansion, 'positive.txt'),
positive_words = open(os.path.join(settings.path_fooocus_expansion, 'positive.txt'),
encoding='utf-8').read().splitlines()
positive_words = ['Ġ' + x.lower() for x in positive_words if x != '']

Expand Down
4 changes: 2 additions & 2 deletions extras/face_crop.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cv2
import numpy as np
import modules.config
from modules.settings import settings


faceRestoreHelper = None
Expand Down Expand Up @@ -28,7 +28,7 @@ def crop_image(img_rgb):
from extras.facexlib.utils.face_restoration_helper import FaceRestoreHelper
faceRestoreHelper = FaceRestoreHelper(
upscale_factor=1,
model_rootpath=modules.config.path_controlnet,
model_rootpath=settings.path_controlnet,
device='cpu' # use cpu is safer since we are out of memory management
)

Expand Down
4 changes: 2 additions & 2 deletions extras/interrogate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from torchvision import transforms
from torchvision.transforms.functional import InterpolationMode
from modules.model_loader import load_file_from_url
from modules.config import path_clip_vision
from modules.settings import settings
from ldm_patched.modules.model_patcher import ModelPatcher
from extras.BLIP.models.blip import blip_decoder

Expand All @@ -27,7 +27,7 @@ def interrogate(self, img_rgb):
if self.blip_model is None:
filename = load_file_from_url(
url='https://huggingface.co/lllyasviel/misc/resolve/main/model_base_caption_capfilt_large.pth',
model_dir=path_clip_vision,
model_dir=settings.path_clip_vision,
file_name='model_base_caption_capfilt_large.pth',
)

Expand Down
4 changes: 2 additions & 2 deletions extras/vae_interpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import ldm_patched.modules.model_management

from ldm_patched.modules.model_patcher import ModelPatcher
from modules.config import path_vae_approx
from modules.settings import settings


class Block(nn.Module):
Expand Down Expand Up @@ -63,7 +63,7 @@ def forward(self, x):


vae_approx_model = None
vae_approx_filename = os.path.join(path_vae_approx, 'xl-to-v1_interposer-v3.1.safetensors')
vae_approx_filename = os.path.join(settings.path_vae_approx, 'xl-to-v1_interposer-v3.1.safetensors')


def parse(x):
Expand Down
6 changes: 3 additions & 3 deletions extras/wd14tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from PIL import Image
from onnxruntime import InferenceSession
from modules.config import path_clip_vision
from modules.settings import settings
from modules.model_loader import load_file_from_url


Expand All @@ -31,13 +31,13 @@ def default_interrogator(image_rgb, threshold=0.35, character_threshold=0.85, ex

model_onnx_filename = load_file_from_url(
url=f'https://huggingface.co/lllyasviel/misc/resolve/main/{model_name}.onnx',
model_dir=path_clip_vision,
model_dir=settings.path_clip_vision,
file_name=f'{model_name}.onnx',
)

model_csv_filename = load_file_from_url(
url=f'https://huggingface.co/lllyasviel/misc/resolve/main/{model_name}.csv',
model_dir=path_clip_vision,
model_dir=settings.path_clip_vision,
file_name=f'{model_name}.csv',
)

Expand Down
30 changes: 15 additions & 15 deletions launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ def ini_args():
print("Set device to:", args.gpu_device_id)


from modules import config
from modules.settings import settings

def download_models():
for file_name, url in vae_approx_filenames:
load_file_from_url(url=url, model_dir=config.path_vae_approx, file_name=file_name)
load_file_from_url(url=url, model_dir=settings.path_vae_approx, file_name=file_name)

load_file_from_url(
url='https://huggingface.co/lllyasviel/misc/resolve/main/fooocus_expansion.bin',
model_dir=config.path_fooocus_expansion,
model_dir=settings.path_fooocus_expansion,
file_name='pytorch_model.bin'
)

Expand All @@ -101,23 +101,23 @@ def download_models():
return

if not args.always_download_new_model:
if not os.path.exists(os.path.join(config.path_checkpoints, config.default_base_model_name)):
for alternative_model_name in config.previous_default_models:
if os.path.exists(os.path.join(config.path_checkpoints, alternative_model_name)):
print(f'You do not have [{config.default_base_model_name}] but you have [{alternative_model_name}].')
if not os.path.exists(os.path.join(settings.path_checkpoints, settings.default_base_model_name)):
for alternative_model_name in settings.previous_default_models:
if os.path.exists(os.path.join(settings.path_checkpoints, alternative_model_name)):
print(f'You do not have [{settings.default_base_model_name}] but you have [{alternative_model_name}].')
print(f'Fooocus will use [{alternative_model_name}] to avoid downloading new models, '
f'but you are not using latest models.')
print('Use --always-download-new-model to avoid fallback and always get new models.')
config.checkpoint_downloads = {}
config.default_base_model_name = alternative_model_name
settings.checkpoint_downloads = {}
settings.default_base_model_name = alternative_model_name
break

for file_name, url in config.checkpoint_downloads.items():
load_file_from_url(url=url, model_dir=config.path_checkpoints, file_name=file_name)
for file_name, url in config.embeddings_downloads.items():
load_file_from_url(url=url, model_dir=config.path_embeddings, file_name=file_name)
for file_name, url in config.lora_downloads.items():
load_file_from_url(url=url, model_dir=config.path_loras, file_name=file_name)
for file_name, url in settings.checkpoint_downloads.items():
load_file_from_url(url=url, model_dir=settings.path_checkpoints, file_name=file_name)
for file_name, url in settings.embeddings_downloads.items():
load_file_from_url(url=url, model_dir=settings.path_embeddings, file_name=file_name)
for file_name, url in settings.lora_downloads.items():
load_file_from_url(url=url, model_dir=settings.path_loras, file_name=file_name)

return

Expand Down
18 changes: 9 additions & 9 deletions modules/async_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def worker():
import modules.default_pipeline as pipeline
import modules.core as core
import modules.flags as flags
import modules.config
import modules.settings
import modules.patch
import ldm_patched.modules.model_management
import extras.preprocessors as preprocessors
Expand Down Expand Up @@ -180,7 +180,7 @@ def handler(async_task):
if performance_selection == 'Extreme Speed':
print('Enter LCM mode.')
progressbar(async_task, 1, 'Downloading LCM components ...')
loras += [(modules.config.downloading_sdxl_lcm_lora(), 1.0)]
loras += [(modules.settings.downloading_sdxl_lcm_lora(), 1.0)]

if refiner_model_name != 'None':
print(f'Refiner disabled in LCM mode.')
Expand Down Expand Up @@ -269,7 +269,7 @@ def handler(async_task):
steps = 8

progressbar(async_task, 1, 'Downloading upscale models ...')
modules.config.downloading_upscale_model()
modules.settings.downloading_upscale_model()
if (current_tab == 'inpaint' or (
current_tab == 'ip' and advanced_parameters.mixing_image_prompt_and_inpaint)) \
and isinstance(inpaint_input_image, dict):
Expand All @@ -295,10 +295,10 @@ def handler(async_task):
if isinstance(inpaint_image, np.ndarray) and isinstance(inpaint_mask, np.ndarray) \
and (np.any(inpaint_mask > 127) or len(outpaint_selections) > 0):
progressbar(async_task, 1, 'Downloading upscale models ...')
modules.config.downloading_upscale_model()
modules.settings.downloading_upscale_model()
if inpaint_parameterized:
progressbar(async_task, 1, 'Downloading inpainter ...')
inpaint_head_model_path, inpaint_patch_model_path = modules.config.downloading_inpaint_models(
inpaint_head_model_path, inpaint_patch_model_path = modules.settings.downloading_inpaint_models(
advanced_parameters.inpaint_engine)
base_model_additional_loras += [(inpaint_patch_model_path, 1.0)]
print(f'[Inpaint] Current inpaint model is {inpaint_patch_model_path}')
Expand All @@ -320,13 +320,13 @@ def handler(async_task):
goals.append('cn')
progressbar(async_task, 1, 'Downloading control models ...')
if len(cn_tasks[flags.cn_canny]) > 0:
controlnet_canny_path = modules.config.downloading_controlnet_canny()
controlnet_canny_path = modules.settings.downloading_controlnet_canny()
if len(cn_tasks[flags.cn_cpds]) > 0:
controlnet_cpds_path = modules.config.downloading_controlnet_cpds()
controlnet_cpds_path = modules.settings.downloading_controlnet_cpds()
if len(cn_tasks[flags.cn_ip]) > 0:
clip_vision_path, ip_negative_path, ip_adapter_path = modules.config.downloading_ip_adapters('ip')
clip_vision_path, ip_negative_path, ip_adapter_path = modules.settings.downloading_ip_adapters('ip')
if len(cn_tasks[flags.cn_ip_face]) > 0:
clip_vision_path, ip_negative_path, ip_adapter_face_path = modules.config.downloading_ip_adapters(
clip_vision_path, ip_negative_path, ip_adapter_face_path = modules.settings.downloading_ip_adapters(
'face')
progressbar(async_task, 1, 'Loading control models ...')

Expand Down
Loading