mirror of
https://github.com/vladmandic/automatic
synced 2026-09-17 08:19:11 +02:00
cache sampler
This commit is contained in:
@@ -109,29 +109,32 @@ class Script(scripts.Script):
|
||||
|
||||
processing.process_init(p)
|
||||
if mode == 'FaceID': # faceid runs as ipadapter in its own pipeline
|
||||
from modules.face.faceid import face_id
|
||||
from modules.face.insightface import get_app
|
||||
processed_images = face_id(p, app=get_app('buffalo_l'), source_image=source_image, model=ip_model, override=ip_override, cache=ip_cache, scale=ip_strength, structure=ip_structure) # run faceid pipeline
|
||||
app = get_app('buffalo_l')
|
||||
from modules.face.faceid import face_id
|
||||
processed_images = face_id(p, app=app, source_image=source_image, model=ip_model, override=ip_override, cache=ip_cache, scale=ip_strength, structure=ip_structure) # run faceid pipeline
|
||||
processed = processing.Processed(p, images_list=processed_images, seed=p.seed, subseed=p.subseed, index_of_first_image=0) # manually created processed object
|
||||
elif mode == 'PhotoMaker': # photomaker creates pipeline and triggers original process_images
|
||||
from modules.face.photomaker import photo_maker
|
||||
processed = photo_maker(p, input_images=input_images, trigger=pm_trigger, strength=pm_strength, start=pm_start)
|
||||
elif mode == 'InstantID':
|
||||
from modules.face.instantid import instant_id # instantid creates pipeline and triggers original process_images
|
||||
from modules.face.insightface import get_app
|
||||
processed = instant_id(p, app=get_app('antelopev2'), source_image=source_image, strength=id_strength, conditioning=id_conditioning, cache=id_cache)
|
||||
app=get_app('antelopev2')
|
||||
from modules.face.instantid import instant_id # instantid creates pipeline and triggers original process_images
|
||||
processed = instant_id(p, app=app, source_image=source_image, strength=id_strength, conditioning=id_conditioning, cache=id_cache)
|
||||
|
||||
if processed is None: # run normal pipeline
|
||||
processed = processing.process_images(p)
|
||||
|
||||
if mode == 'FaceSwap': # faceswap runs as postprocessing
|
||||
from modules.face.faceswap import face_swap
|
||||
from modules.face.insightface import get_app
|
||||
app=get_app('buffalo_l')
|
||||
from modules.face.faceswap import face_swap
|
||||
if shared.opts.save_images_before_face_restoration and not p.do_not_save_samples:
|
||||
for i, image in enumerate(processed.images):
|
||||
info = processing.create_infotext(p, index=i)
|
||||
images.save_image(image, path=p.outpath_samples, seed=p.all_seeds[i], prompt=p.all_prompts[i], info=info, p=p, suffix="-before-faceswap")
|
||||
processed.images = face_swap(p, app=get_app('buffalo_l'), input_images=processed.images, source_image=source_image, cache=fs_cache)
|
||||
processed.images = face_swap(p, app=app, input_images=processed.images, source_image=source_image, cache=fs_cache)
|
||||
|
||||
processed.info = processed.infotext(p, 0)
|
||||
processed.infotexts = [processed.info]
|
||||
|
||||
@@ -508,19 +508,16 @@ def process_diffusers(p: processing.StableDiffusionProcessing):
|
||||
shared.log.debug('Moving to CPU: model=base')
|
||||
shared.sd_model.to(devices.cpu)
|
||||
devices.torch_gc()
|
||||
|
||||
update_sampler(shared.sd_refiner, second_pass=True)
|
||||
|
||||
if shared.state.interrupted or shared.state.skipped:
|
||||
shared.sd_model = orig_pipeline
|
||||
return results
|
||||
|
||||
if shared.opts.diffusers_move_refiner and not getattr(shared.sd_refiner, 'has_accelerate', False):
|
||||
shared.sd_refiner.to(devices.device)
|
||||
p.ops.append('refine')
|
||||
p.is_refiner_pass = True
|
||||
shared.sd_model = sd_models.set_diffuser_pipe(shared.sd_model, sd_models.DiffusersTaskType.TEXT_2_IMAGE)
|
||||
shared.sd_refiner = sd_models.set_diffuser_pipe(shared.sd_refiner, sd_models.DiffusersTaskType.IMAGE_2_IMAGE)
|
||||
update_sampler(shared.sd_refiner, second_pass=True)
|
||||
for i in range(len(output.images)):
|
||||
image = output.images[i]
|
||||
noise_level = round(350 * p.denoising_strength)
|
||||
|
||||
+20
-13
@@ -10,6 +10,8 @@ all_samplers_map = {}
|
||||
samplers = all_samplers
|
||||
samplers_for_img2img = all_samplers
|
||||
samplers_map = {}
|
||||
loaded_config = None
|
||||
loaded_sampler = None
|
||||
|
||||
|
||||
def list_samplers(backend_name = shared.backend):
|
||||
@@ -45,6 +47,7 @@ def visible_sampler_names():
|
||||
|
||||
|
||||
def create_sampler(name, model):
|
||||
global loaded_config, loaded_sampler # pylint: disable=global-statement
|
||||
if name == 'Default' and hasattr(model, 'scheduler'):
|
||||
config = {k: v for k, v in model.scheduler.config.items() if not k.startswith('_')}
|
||||
shared.log.debug(f'Sampler default {type(model.scheduler).__name__}: {config}')
|
||||
@@ -53,22 +56,26 @@ def create_sampler(name, model):
|
||||
if config is None:
|
||||
shared.log.error(f'Attempting to use unknown sampler: {name}')
|
||||
config = all_samplers[0]
|
||||
sampler = loaded_sampler
|
||||
if shared.backend == shared.Backend.ORIGINAL:
|
||||
sampler = config.constructor(model)
|
||||
sampler.config = config
|
||||
if config != loaded_config:
|
||||
sampler = config.constructor(model)
|
||||
sampler.config = config
|
||||
sampler.name = name
|
||||
loaded_config = config
|
||||
shared.log.debug(f'Sampler: sampler="{name}" config={config.options}')
|
||||
sampler.initialize(p=None)
|
||||
sampler.name = name
|
||||
shared.log.debug(f'Sampler: sampler="{sampler.name}" config={sampler.config.options}')
|
||||
return sampler
|
||||
loaded_sampler = sampler
|
||||
elif shared.backend == shared.Backend.DIFFUSERS:
|
||||
sampler = config.constructor(model)
|
||||
if not hasattr(model, 'scheduler_config'):
|
||||
model.scheduler_config = sampler.sampler.config.copy()
|
||||
model.scheduler = sampler.sampler
|
||||
shared.log.debug(f'Sampler: sampler="{sampler.name}" config={sampler.config}')
|
||||
return sampler.sampler
|
||||
else:
|
||||
return None
|
||||
if config != loaded_config:
|
||||
sampler = config.constructor(model)
|
||||
loaded_config = config
|
||||
if not hasattr(model, 'scheduler_config'):
|
||||
model.scheduler_config = sampler.sampler.config.copy()
|
||||
shared.log.debug(f'Sampler: sampler="{sampler.name}" config={sampler.config}')
|
||||
loaded_sampler = sampler.sampler
|
||||
model.scheduler = loaded_sampler
|
||||
return loaded_sampler
|
||||
|
||||
|
||||
def set_samplers():
|
||||
|
||||
@@ -243,6 +243,10 @@ def start_ui():
|
||||
|
||||
global local_url # pylint: disable=global-statement
|
||||
stdout = io.StringIO()
|
||||
allowed_paths = [os.path.dirname(__file__)]
|
||||
if cmd_opts.data_dir is not None and os.path.isdir(cmd_opts.data_dir):
|
||||
allowed_paths.append(cmd_opts.data_dir)
|
||||
shared.log.debug(f'Root paths: {allowed_paths}')
|
||||
with contextlib.redirect_stdout(stdout):
|
||||
app, local_url, share_url = shared.demo.launch( # app is FastAPI(Starlette) instance
|
||||
share=cmd_opts.share,
|
||||
@@ -258,7 +262,7 @@ def start_ui():
|
||||
show_api=False,
|
||||
quiet=True,
|
||||
favicon_path='html/logo.ico',
|
||||
allowed_paths=[os.path.dirname(__file__), cmd_opts.data_dir],
|
||||
allowed_paths=allowed_paths,
|
||||
app_kwargs=fastapi_args,
|
||||
_frontend=True and cmd_opts.share,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user