diff --git a/install.py b/install.py new file mode 100644 index 0000000..4e887c2 --- /dev/null +++ b/install.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright (c) Alibaba, Inc. and its affiliates. +import os +import shutil +import subprocess +import sys + +if sys.argv[0] == 'install.py': + sys.path.append('.') # for portable version + +source_folder = os.path.join(os.path.dirname(__file__), "scepter/workflow") +current_dir = os.path.dirname(__file__) +destination_folder = os.path.join(os.path.dirname(current_dir), "ComfyUI-Scepter") + +if not os.path.exists(destination_folder): + shutil.copytree(source_folder, destination_folder) + print(f"{os.path.abspath(source_folder)} copy to {os.path.abspath(destination_folder)} success!") +else: + print(f"{os.path.abspath(destination_folder)} exist.") + +# pip install scepter +subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'scepter']) \ No newline at end of file diff --git a/scepter/modules/model/diffusion/diffusions.py b/scepter/modules/model/diffusion/diffusions.py index 3fdf31a..127f807 100644 --- a/scepter/modules/model/diffusion/diffusions.py +++ b/scepter/modules/model/diffusion/diffusions.py @@ -46,19 +46,23 @@ class BaseDiffusion(object): def sample(self, noise, model, model_kwargs={}, steps=20, sampler=None, use_dynamic_cfg=False, guide_scale=None, guide_rescale=None, - show_progress=False, return_intermediate=None, intermediate_callback=None): + show_progress=False, return_intermediate=None, intermediate_callback=None, **kwargs): assert isinstance(steps, (int, torch.LongTensor)) assert return_intermediate in (None, 'x0', 'xt') assert isinstance(sampler, (str, dict, Config)) intermediates = [] def callback_fn(x_t, t, sigma=None, alpha=None): + timestamp = t t = t.repeat(len(x_t)).round().long().to(x_t.device) + sigma = sigma.repeat(len(x_t), *([1] * (len(sigma.shape) - 1))) + alpha = alpha.repeat(len(x_t), *([1] * (len(alpha.shape) - 1))) + if guide_scale is None or guide_scale == 1.0: out = model(x=x_t, t=t, **model_kwargs) else: if use_dynamic_cfg: - guidance_scale = 1 + guide_scale * ((1 - math.cos(math.pi * ((steps - t.item()) / steps) ** 5.0)) / 2) + guidance_scale = 1 + guide_scale * ((1 - math.cos(math.pi * ((steps - timestamp.item()) / steps) ** 5.0)) / 2) else: guidance_scale = guide_scale y_out = model(x=x_t, t=t, **model_kwargs[0]) diff --git a/scepter/modules/model/diffusion/samplers.py b/scepter/modules/model/diffusion/samplers.py index 0237b32..fd91d40 100644 --- a/scepter/modules/model/diffusion/samplers.py +++ b/scepter/modules/model/diffusion/samplers.py @@ -145,12 +145,12 @@ class DDIMSampler(BaseDiffusionSampler): return output def step(self, sampler_output): - step = sampler_output.step x_t = sampler_output.x_t + step = sampler_output.step t = sampler_output.ts[step] sigmas_vp = sampler_output.sigmas_vp.to(x_t.device) - alpha_init = _i(sampler_output.alphas_init, step, x_t) - sigma_init = _i(sampler_output.sigmas_init, step, x_t) + alpha_init = _i(sampler_output.alphas_init, step, x_t[:1]) + sigma_init = _i(sampler_output.sigmas_init, step, x_t[:1]) x = sampler_output.callback_fn(x_t, t, sigma_init, alpha_init) noise_factor = self.eta * (sigmas_vp[step + 1] ** 2 / sigmas_vp[step] ** 2 * diff --git a/scepter/modules/model/tuner/__init__.py b/scepter/modules/model/tuner/__init__.py index 097158f..bbb2076 100644 --- a/scepter/modules/model/tuner/__init__.py +++ b/scepter/modules/model/tuner/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- # Copyright (c) Alibaba, Inc. and its affiliates. from scepter.modules.model.tuner import sce -from scepter.modules.model.tuner.swift_tuner import (SwiftAdapter, SwiftFull, - SwiftLoRA) +from scepter.modules.model.tuner.swift_tuner import (SwiftPart, SwiftAdapter, SwiftFull, + SwiftLoRA, SwiftSCETuning) diff --git a/scepter/modules/model/tuner/swift_tuner.py b/scepter/modules/model/tuner/swift_tuner.py index f4890e6..68a195f 100644 --- a/scepter/modules/model/tuner/swift_tuner.py +++ b/scepter/modules/model/tuner/swift_tuner.py @@ -23,6 +23,29 @@ class SwiftFull(BaseTuner): SwiftFull.para_dict, set_name=True) +@TUNERS.register_class() +class SwiftPart(): + para_dict = { + 'TARGET_MODULES': { + 'value': '', + 'description': 'The norm expression of target modules.' + } + } + + def __init__(self, cfg, logger=None): + from swift.tuners.part import PartConfig + self.logger = logger + self.init_config = PartConfig(target_modules=cfg.TARGET_MODULES) + + def __call__(self, *args, **kwargs): + return self.init_config + + @staticmethod + def get_config_template(): + return dict_to_yaml('TUNERS', + __class__.__name__, + SwiftPart.para_dict, + set_name=True) @TUNERS.register_class() class SwiftLoRA(): diff --git a/scepter/modules/utils/file_system.py b/scepter/modules/utils/file_system.py index cb1a775..b3200e3 100644 --- a/scepter/modules/utils/file_system.py +++ b/scepter/modules/utils/file_system.py @@ -293,7 +293,7 @@ class FileSystem(object): wait_finish=wait_finish) else: local_path = None - R.acquire(timeout = 2) + R.acquire(timeout=60) try: data_quene.put_nowait([target_path, local_path]) except Exception: @@ -355,7 +355,7 @@ class FileSystem(object): pass else: flg = False - R.acquire(timeout=2) + R.acquire(timeout=60) try: data_quene.put_nowait([local_path, target_path, flg]) except Exception: