mirror of
https://github.com/vladmandic/automatic
synced 2026-09-20 01:31:13 +02:00
Merge remote-tracking branch 'origin/dev' into refactor/remove-face-restoration
# Conflicts: # .pylintrc # .ruff.toml
This commit is contained in:
@@ -156,7 +156,6 @@ def parse_prompt(prompt: str | None) -> tuple[str, defaultdict[str, list[ExtraNe
|
||||
if prompt is None:
|
||||
return "", res
|
||||
if isinstance(prompt, list):
|
||||
shared.log.warning(f"parse_prompt was called with a list instead of a string: {prompt}")
|
||||
return parse_prompts(prompt)
|
||||
|
||||
def found(m: re.Match[str]):
|
||||
@@ -168,13 +167,17 @@ def parse_prompt(prompt: str | None) -> tuple[str, defaultdict[str, list[ExtraNe
|
||||
return updated_prompt, res
|
||||
|
||||
|
||||
def parse_prompts(prompts: list[str]):
|
||||
def parse_prompts(prompts: list[str], extra_data=None):
|
||||
updated_prompt_list: list[str] = []
|
||||
extra_data: defaultdict[str, list[ExtraNetworkParams]] = defaultdict(list)
|
||||
extra_data: defaultdict[str, list[ExtraNetworkParams]] = extra_data or defaultdict(list)
|
||||
for prompt in prompts:
|
||||
updated_prompt, parsed_extra_data = parse_prompt(prompt)
|
||||
if not extra_data:
|
||||
extra_data = parsed_extra_data
|
||||
elif parsed_extra_data:
|
||||
extra_data = parsed_extra_data
|
||||
else:
|
||||
pass
|
||||
updated_prompt_list.append(updated_prompt)
|
||||
|
||||
return updated_prompt_list, extra_data
|
||||
|
||||
+4
-18
@@ -12,24 +12,10 @@ import piexif
|
||||
import piexif.helper
|
||||
from PIL import Image, PngImagePlugin, ExifTags, ImageDraw
|
||||
from modules import sd_samplers, shared, script_callbacks, errors, paths
|
||||
from modules.images_grid import (
|
||||
image_grid as image_grid,
|
||||
get_grid_size as get_grid_size,
|
||||
split_grid as split_grid,
|
||||
combine_grid as combine_grid,
|
||||
check_grid_size as check_grid_size,
|
||||
get_font as get_font,
|
||||
draw_grid_annotations as draw_grid_annotations,
|
||||
draw_prompt_matrix as draw_prompt_matrix,
|
||||
GridAnnotation as GridAnnotation,
|
||||
Grid as Grid,
|
||||
)
|
||||
from modules.images_resize import resize_image as resize_image
|
||||
from modules.images_namegen import (
|
||||
FilenameGenerator as FilenameGenerator,
|
||||
get_next_sequence_number as get_next_sequence_number,
|
||||
)
|
||||
from modules.video import save_video as save_video
|
||||
from modules.images_grid import image_grid, get_grid_size, split_grid, combine_grid, check_grid_size, get_font, draw_grid_annotations, draw_prompt_matrix, GridAnnotation, Grid # pylint: disable=unused-import
|
||||
from modules.images_resize import resize_image # pylint: disable=unused-import
|
||||
from modules.images_namegen import FilenameGenerator, get_next_sequence_number # pylint: disable=unused-import
|
||||
from modules.video import save_video # pylint: disable=unused-import
|
||||
|
||||
|
||||
debug = errors.log.trace if os.environ.get('SD_PATH_DEBUG', None) is not None else lambda *args, **kwargs: None
|
||||
|
||||
+25
-5
@@ -4,10 +4,27 @@ from installer import log, pip
|
||||
from modules import devices
|
||||
|
||||
|
||||
nunchaku_ver = '1.1.0'
|
||||
nunchaku_versions = {
|
||||
'2.5': '1.0.1',
|
||||
'2.6': '1.0.1',
|
||||
'2.7': '1.1.0',
|
||||
'2.8': '1.1.0',
|
||||
'2.9': '1.1.0',
|
||||
'2.10': '1.0.2',
|
||||
'2.11': '1.1.0',
|
||||
}
|
||||
ok = False
|
||||
|
||||
|
||||
def _expected_ver():
|
||||
try:
|
||||
import torch
|
||||
torch_ver = '.'.join(torch.__version__.split('+')[0].split('.')[:2])
|
||||
return nunchaku_versions.get(torch_ver)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def check():
|
||||
global ok # pylint: disable=global-statement
|
||||
if ok:
|
||||
@@ -16,8 +33,9 @@ def check():
|
||||
import nunchaku
|
||||
import nunchaku.utils
|
||||
from nunchaku import __version__
|
||||
expected = _expected_ver()
|
||||
log.info(f'Nunchaku: path={nunchaku.__path__} version={__version__.__version__} precision={nunchaku.utils.get_precision()}')
|
||||
if __version__.__version__ != nunchaku_ver:
|
||||
if expected is not None and __version__.__version__ != expected:
|
||||
ok = False
|
||||
return False
|
||||
ok = True
|
||||
@@ -49,14 +67,16 @@ def install_nunchaku():
|
||||
if devices.backend not in ['cuda']:
|
||||
log.error(f'Nunchaku: backend={devices.backend} unsupported')
|
||||
return False
|
||||
torch_ver = torch.__version__[:3]
|
||||
if torch_ver not in ['2.5', '2.6', '2.7', '2.8', '2.9', '2.10']:
|
||||
torch_ver = '.'.join(torch.__version__.split('+')[0].split('.')[:2])
|
||||
nunchaku_ver = nunchaku_versions.get(torch_ver)
|
||||
if nunchaku_ver is None:
|
||||
log.error(f'Nunchaku: torch={torch.__version__} unsupported')
|
||||
return False
|
||||
suffix = 'x86_64' if arch == 'linux' else 'win_amd64'
|
||||
url = os.environ.get('NUNCHAKU_COMMAND', None)
|
||||
if url is None:
|
||||
arch = f'{arch}_' if arch == 'linux' else ''
|
||||
url = f'https://huggingface.co/nunchaku-tech/nunchaku/resolve/main/nunchaku-{nunchaku_ver}'
|
||||
url = f'https://huggingface.co/nunchaku-ai/nunchaku/resolve/main/nunchaku-{nunchaku_ver}'
|
||||
url += f'+torch{torch_ver}-cp{python_ver}-cp{python_ver}-{arch}{suffix}.whl'
|
||||
cmd = f'install --upgrade {url}'
|
||||
log.debug(f'Nunchaku: install="{url}"')
|
||||
|
||||
+18
-6
@@ -255,13 +255,25 @@ def check_quant(module: str = ''):
|
||||
|
||||
def check_nunchaku(module: str = ''):
|
||||
from modules import shared
|
||||
if module not in shared.opts.nunchaku_quantization:
|
||||
model_name = getattr(shared.opts, 'sd_model_checkpoint', '')
|
||||
if '+nunchaku' not in model_name:
|
||||
return False
|
||||
from modules import mit_nunchaku
|
||||
mit_nunchaku.install_nunchaku()
|
||||
if not mit_nunchaku.ok:
|
||||
return False
|
||||
return True
|
||||
base_path = model_name.split('+')[0]
|
||||
for v in shared.reference_models.values():
|
||||
if v.get('path', '') != base_path:
|
||||
continue
|
||||
nunchaku_modules = v.get('nunchaku', None)
|
||||
if nunchaku_modules is None:
|
||||
continue
|
||||
if isinstance(nunchaku_modules, bool) and nunchaku_modules:
|
||||
nunchaku_modules = ['Model', 'TE']
|
||||
if not isinstance(nunchaku_modules, list):
|
||||
continue
|
||||
if module in nunchaku_modules:
|
||||
from modules import mit_nunchaku
|
||||
mit_nunchaku.install_nunchaku()
|
||||
return mit_nunchaku.ok
|
||||
return False
|
||||
|
||||
|
||||
def create_config(kwargs = None, allow: bool = True, module: str = 'Model', modules_to_not_convert: list = None, modules_dtype_dict: dict = None):
|
||||
|
||||
@@ -270,7 +270,6 @@ def process_init(p: StableDiffusionProcessing):
|
||||
p.all_prompts, p.all_negative_prompts = shared.prompt_styles.apply_styles_to_prompts(p.all_prompts, p.all_negative_prompts, p.styles, p.all_seeds)
|
||||
p.prompts = p.all_prompts[(p.iteration * p.batch_size):((p.iteration+1) * p.batch_size)]
|
||||
p.negative_prompts = p.all_negative_prompts[(p.iteration * p.batch_size):((p.iteration+1) * p.batch_size)]
|
||||
p.prompts, _ = extra_networks.parse_prompts(p.prompts)
|
||||
|
||||
|
||||
def process_samples(p: StableDiffusionProcessing, samples):
|
||||
|
||||
@@ -171,6 +171,7 @@ def process_base(p: processing.StableDiffusionProcessing):
|
||||
modelstats.analyze()
|
||||
try:
|
||||
t0 = time.time()
|
||||
p.prompts, p.network_data = extra_networks.parse_prompts(p.prompts, p.network_data)
|
||||
extra_networks.activate(p, exclude=['text_encoder', 'text_encoder_2', 'text_encoder_3'])
|
||||
|
||||
if hasattr(shared.sd_model, 'tgate') and getattr(p, 'gate_step', -1) > 0:
|
||||
@@ -297,10 +298,20 @@ def process_hires(p: processing.StableDiffusionProcessing, output):
|
||||
p.denoising_strength = strength
|
||||
orig_image = p.task_args.pop('image', None) # remove image override from hires
|
||||
process_pre(p)
|
||||
|
||||
prompts = p.prompts
|
||||
reset_prompts = False
|
||||
if len(p.refiner_prompt) > 0:
|
||||
prompts = len(output.images)* [p.refiner_prompt]
|
||||
prompts, p.network_data = extra_networks.parse_prompts(prompts)
|
||||
reset_prompts = True
|
||||
if reset_prompts or ('base' in p.skip):
|
||||
extra_networks.activate(p)
|
||||
|
||||
hires_args = set_pipeline_args(
|
||||
p=p,
|
||||
model=shared.sd_model,
|
||||
prompts=len(output.images)* [p.refiner_prompt] if len(p.refiner_prompt) > 0 else p.prompts,
|
||||
prompts=prompts,
|
||||
negative_prompts=len(output.images) * [p.refiner_negative] if len(p.refiner_negative) > 0 else p.negative_prompts,
|
||||
prompts_2=len(output.images) * [p.refiner_prompt] if len(p.refiner_prompt) > 0 else p.prompts,
|
||||
negative_prompts_2=len(output.images) * [p.refiner_negative] if len(p.refiner_negative) > 0 else p.negative_prompts,
|
||||
@@ -314,11 +325,10 @@ def process_hires(p: processing.StableDiffusionProcessing, output):
|
||||
strength=strength,
|
||||
desc='Hires',
|
||||
)
|
||||
|
||||
hires_steps = hires_args.get('prior_num_inference_steps', None) or p.hr_second_pass_steps or hires_args.get('num_inference_steps', None)
|
||||
shared.state.update(get_job_name(p, shared.sd_model), hires_steps, 1)
|
||||
try:
|
||||
if 'base' in p.skip:
|
||||
extra_networks.activate(p)
|
||||
taskid = shared.state.begin('Inference')
|
||||
output = shared.sd_model(**hires_args) # pylint: disable=not-callable
|
||||
shared.state.end(taskid)
|
||||
|
||||
+5
-4
@@ -18,14 +18,15 @@ def load_unet_sdxl_nunchaku(repo_id):
|
||||
shared.log.error(f'Load module: quant=Nunchaku module=unet repo="{repo_id}" low nunchaku version')
|
||||
return None
|
||||
if 'turbo' in repo_id.lower():
|
||||
nunchaku_repo = 'nunchaku-tech/nunchaku-sdxl-turbo/svdq-int4_r32-sdxl-turbo.safetensors'
|
||||
nunchaku_repo = 'nunchaku-ai/nunchaku-sdxl-turbo/svdq-int4_r32-sdxl-turbo.safetensors'
|
||||
else:
|
||||
nunchaku_repo = 'nunchaku-tech/nunchaku-sdxl/svdq-int4_r32-sdxl.safetensors'
|
||||
nunchaku_repo = 'nunchaku-ai/nunchaku-sdxl/svdq-int4_r32-sdxl.safetensors'
|
||||
|
||||
shared.log.debug(f'Load module: quant=Nunchaku module=unet repo="{nunchaku_repo}" offload={shared.opts.nunchaku_offload}')
|
||||
if shared.opts.nunchaku_offload:
|
||||
shared.log.warning('Load module: quant=Nunchaku module=unet offload not supported for SDXL, ignoring')
|
||||
shared.log.debug(f'Load module: quant=Nunchaku module=unet repo="{nunchaku_repo}"')
|
||||
unet = NunchakuSDXLUNet2DConditionModel.from_pretrained(
|
||||
nunchaku_repo,
|
||||
offload=shared.opts.nunchaku_offload,
|
||||
torch_dtype=devices.dtype,
|
||||
cache_dir=shared.opts.hfcache_dir,
|
||||
)
|
||||
|
||||
+8
-39
@@ -4,53 +4,23 @@ import os
|
||||
import sys
|
||||
import time
|
||||
import contextlib
|
||||
|
||||
from enum import Enum
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import gradio as gr
|
||||
|
||||
from installer import (
|
||||
log as log,
|
||||
print_dict,
|
||||
console as console,
|
||||
get_version as get_version,
|
||||
)
|
||||
|
||||
log.debug("Initializing: shared module")
|
||||
from installer import log, print_dict, console, get_version # pylint: disable=unused-import
|
||||
log.debug('Initializing: shared module')
|
||||
|
||||
import modules.memmon
|
||||
import modules.paths as paths
|
||||
from modules.json_helpers import (
|
||||
readfile as readfile,
|
||||
writefile as writefile,
|
||||
)
|
||||
from modules.shared_helpers import (
|
||||
listdir as listdir,
|
||||
walk_files as walk_files,
|
||||
html_path as html_path,
|
||||
html as html,
|
||||
req as req,
|
||||
total_tqdm as total_tqdm,
|
||||
)
|
||||
from modules.json_helpers import readfile, writefile # pylint: disable=W0611
|
||||
from modules.shared_helpers import listdir, walk_files, html_path, html, req, total_tqdm # pylint: disable=W0611
|
||||
from modules import errors, devices, shared_state, cmd_args, theme, history, files_cache
|
||||
from modules.shared_defaults import get_default_modes
|
||||
from modules.paths import (
|
||||
models_path as models_path, # For compatibility, do not modify from here...
|
||||
script_path as script_path,
|
||||
data_path as data_path,
|
||||
sd_configs_path as sd_configs_path,
|
||||
sd_default_config as sd_default_config,
|
||||
sd_model_file as sd_model_file,
|
||||
default_sd_model_file as default_sd_model_file,
|
||||
extensions_dir as extensions_dir,
|
||||
extensions_builtin_dir as extensions_builtin_dir, # ... to here.
|
||||
)
|
||||
from modules.memstats import (
|
||||
memory_stats,
|
||||
ram_stats as ram_stats,
|
||||
)
|
||||
from modules.paths import models_path, script_path, data_path, sd_configs_path, sd_default_config, sd_model_file, default_sd_model_file, extensions_dir, extensions_builtin_dir # pylint: disable=W0611
|
||||
from modules.memstats import memory_stats, ram_stats # pylint: disable=unused-import
|
||||
|
||||
log.debug("Initializing: pipelines")
|
||||
log.debug('Initializing: pipelines')
|
||||
from modules import shared_items
|
||||
from modules.interrogate.openclip import caption_models, caption_types, get_clip_models, refresh_clip_models
|
||||
from modules.interrogate.vqa import vlm_models, vlm_prompts, vlm_system, vlm_default
|
||||
@@ -280,7 +250,6 @@ options_templates.update(options_section(("quantization", "Model Quantization"),
|
||||
"sdnq_quantize_shuffle_weights": OptionInfo(False, "Shuffle weights in post mode", gr.Checkbox),
|
||||
|
||||
"nunchaku_sep": OptionInfo("<h2>Nunchaku Engine</h2>", "", gr.HTML),
|
||||
"nunchaku_quantization": OptionInfo([], "SVDQuant enabled", gr.CheckboxGroup, {"choices": ["Model", "TE"]}),
|
||||
"nunchaku_attention": OptionInfo(False, "Nunchaku attention", gr.Checkbox),
|
||||
"nunchaku_offload": OptionInfo(False, "Nunchaku offloading", gr.Checkbox),
|
||||
|
||||
|
||||
@@ -305,6 +305,7 @@ class ExtraNetworksPage:
|
||||
subdirs['Reference'] = 1
|
||||
subdirs['Distilled'] = 1
|
||||
subdirs['Quantized'] = 1
|
||||
subdirs['Nunchaku'] = 1
|
||||
subdirs['Community'] = 1
|
||||
subdirs['Cloud'] = 1
|
||||
subdirs[diffusers_base] = 1
|
||||
@@ -324,6 +325,8 @@ class ExtraNetworksPage:
|
||||
subdirs.move_to_end('Distilled', last=True)
|
||||
if 'Quantized' in subdirs:
|
||||
subdirs.move_to_end('Quantized', last=True)
|
||||
if 'Nunchaku' in subdirs:
|
||||
subdirs.move_to_end('Nunchaku', last=True)
|
||||
if 'Community' in subdirs:
|
||||
subdirs.move_to_end('Community', last=True)
|
||||
if 'Cloud' in subdirs:
|
||||
@@ -332,7 +335,7 @@ class ExtraNetworksPage:
|
||||
for subdir in subdirs:
|
||||
if len(subdir) == 0:
|
||||
continue
|
||||
if subdir in ['All', 'Local', 'Diffusers', 'Reference', 'Distilled', 'Quantized', 'Community', 'Cloud']:
|
||||
if subdir in ['All', 'Local', 'Diffusers', 'Reference', 'Distilled', 'Quantized', 'Nunchaku', 'Community', 'Cloud']:
|
||||
style = 'network-reference'
|
||||
else:
|
||||
style = 'network-folder'
|
||||
|
||||
@@ -3,7 +3,7 @@ import html
|
||||
import json
|
||||
import concurrent
|
||||
from datetime import datetime
|
||||
from modules import shared, ui_extra_networks, sd_models, modelstats, paths
|
||||
from modules import shared, ui_extra_networks, sd_models, modelstats, paths, devices
|
||||
from modules.json_helpers import readfile
|
||||
|
||||
|
||||
@@ -48,16 +48,21 @@ class ExtraNetworksPageCheckpoints(ui_extra_networks.ExtraNetworksPage):
|
||||
reference_distilled = readfile(os.path.join('data', 'reference-distilled.json'), as_type="dict")
|
||||
reference_community = readfile(os.path.join('data', 'reference-community.json'), as_type="dict")
|
||||
reference_cloud = readfile(os.path.join('data', 'reference-cloud.json'), as_type="dict")
|
||||
reference_nunchaku = readfile(os.path.join('data', 'reference-nunchaku.json'), as_type="dict")
|
||||
shared.reference_models = {}
|
||||
shared.reference_models.update(reference_base)
|
||||
shared.reference_models.update(reference_quant)
|
||||
shared.reference_models.update(reference_community)
|
||||
shared.reference_models.update(reference_distilled)
|
||||
shared.reference_models.update(reference_cloud)
|
||||
shared.reference_models.update(reference_nunchaku)
|
||||
|
||||
for k, v in shared.reference_models.items():
|
||||
count['total'] += 1
|
||||
url = v['path']
|
||||
if v.get('hidden', False):
|
||||
count['hidden'] += 1
|
||||
continue
|
||||
experimental = v.get('experimental', False)
|
||||
if experimental:
|
||||
if shared.cmd_opts.experimental:
|
||||
@@ -83,6 +88,9 @@ class ExtraNetworksPageCheckpoints(ui_extra_networks.ExtraNetworksPage):
|
||||
path = f'{v.get("path", "")}'
|
||||
|
||||
tag = v.get('tags', '')
|
||||
if tag == 'nunchaku' and (devices.backend != 'cuda' and not shared.cmd_opts.experimental):
|
||||
count['hidden'] += 1
|
||||
continue
|
||||
if tag in count:
|
||||
count[tag] += 1
|
||||
elif tag != '':
|
||||
|
||||
Reference in New Issue
Block a user