mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
add deep-cache support
This commit is contained in:
@@ -23,6 +23,9 @@ class CompiledModelState:
|
||||
self.partitioned_modules = {}
|
||||
|
||||
|
||||
deepcache_worker = None
|
||||
|
||||
|
||||
def ipex_optimize(sd_model):
|
||||
try:
|
||||
t0 = time.time()
|
||||
@@ -212,6 +215,25 @@ def compile_torch(sd_model):
|
||||
return sd_model
|
||||
|
||||
|
||||
def compile_deepcache(sd_model):
|
||||
global deepcache_worker # pylint: disable=global-statement
|
||||
try:
|
||||
from DeepCache import DeepCacheSDHelper
|
||||
except Exception as e:
|
||||
shared.log.warning(f'Model compile using deep-cache: {e}')
|
||||
return sd_model
|
||||
t0 = time.time()
|
||||
if deepcache_worker is not None:
|
||||
deepcache_worker.disable()
|
||||
deepcache_worker = DeepCacheSDHelper(pipe=sd_model)
|
||||
deepcache_worker.set_params(cache_interval=shared.opts.deep_cache_interval, cache_branch_id=0)
|
||||
deepcache_worker.enable()
|
||||
t1 = time.time()
|
||||
shared.log.info(f"Model compile: task=DeepCache config={deepcache_worker.params} time={t1-t0:.2f}")
|
||||
# config={'cache_interval': 3, 'cache_layer_id': 0, 'cache_block_id': 0, 'skip_mode': 'uniform'} time=0.00
|
||||
return sd_model
|
||||
|
||||
|
||||
def compile_diffusers(sd_model):
|
||||
if shared.opts.ipex_optimize:
|
||||
sd_model = ipex_optimize(sd_model)
|
||||
@@ -225,7 +247,11 @@ def compile_diffusers(sd_model):
|
||||
shared.log.info(f"Model compile: pipeline={sd_model.__class__.__name__} mode={shared.opts.cuda_compile_mode} backend={shared.opts.cuda_compile_backend} fullgraph={shared.opts.cuda_compile_fullgraph} compile={shared.opts.cuda_compile}")
|
||||
if shared.opts.cuda_compile_backend == 'stable-fast':
|
||||
sd_model = compile_stablefast(sd_model)
|
||||
elif shared.opts.cuda_compile_backend == 'deep-cache':
|
||||
sd_model = compile_deepcache(sd_model)
|
||||
else:
|
||||
if deepcache_worker is not None:
|
||||
deepcache_worker.disable()
|
||||
sd_model = compile_torch(sd_model)
|
||||
return sd_model
|
||||
|
||||
|
||||
+3
-2
@@ -363,13 +363,15 @@ options_templates.update(options_section(('cuda', "Compute Settings"), {
|
||||
|
||||
"cuda_compile_sep": OptionInfo("<h2>Model Compile</h2>", "", gr.HTML),
|
||||
"cuda_compile": OptionInfo([] if not cmd_opts.use_openvino else ["Model", "VAE", "Upscaler"], "Compile Model", gr.CheckboxGroup, {"choices": ["Model", "VAE", "Text Encoder", "Upscaler"]}),
|
||||
"cuda_compile_backend": OptionInfo("none" if not cmd_opts.use_openvino else "openvino_fx", "Model compile backend", gr.Radio, {"choices": ['none', 'inductor', 'cudagraphs', 'aot_ts_nvfuser', 'hidet', 'ipex', 'openvino_fx', 'stable-fast', 'olive-ai']}),
|
||||
"cuda_compile_backend": OptionInfo("none" if not cmd_opts.use_openvino else "openvino_fx", "Model compile backend", gr.Radio, {"choices": ['none', 'inductor', 'cudagraphs', 'aot_ts_nvfuser', 'hidet', 'ipex', 'openvino_fx', 'stable-fast', 'deep-cache', 'olive-ai']}),
|
||||
"cuda_compile_mode": OptionInfo("default", "Model compile mode", gr.Radio, {"choices": ['default', 'reduce-overhead', 'max-autotune', 'max-autotune-no-cudagraphs']}),
|
||||
"cuda_compile_fullgraph": OptionInfo(False, "Model compile fullgraph"),
|
||||
"cuda_compile_precompile": OptionInfo(False, "Model compile precompile"),
|
||||
"cuda_compile_verbose": OptionInfo(False, "Model compile verbose mode"),
|
||||
"cuda_compile_errors": OptionInfo(True, "Model compile suppress errors"),
|
||||
"diffusers_quantization": OptionInfo(False, "Dynamic quantization with TorchAO"),
|
||||
"deep_cache_interval": OptionInfo(3.0, "DeepCache cache interval", gr.Slider, {"minimum": 1, "maximum": 10, "step": 1}),
|
||||
|
||||
"nncf_compress_weights": OptionInfo([], "Compress Model weights with NNCF", gr.CheckboxGroup, {"choices": ["Model", "VAE", "Text Encoder"], "visible": backend == Backend.DIFFUSERS}),
|
||||
|
||||
"ipex_sep": OptionInfo("<h2>IPEX</h2>", "", gr.HTML, {"visible": devices.backend == "ipex"}),
|
||||
@@ -904,7 +906,6 @@ devices.device, devices.device_interrogate, devices.device_gfpgan, devices.devic
|
||||
devices.onnx = [opts.onnx_execution_provider]
|
||||
if opts.onnx_cpu_fallback and 'CPUExecutionProvider' not in devices.onnx:
|
||||
devices.onnx.append('CPUExecutionProvider')
|
||||
print("HERE1", opts.onnx_cpu_fallback, devices.onnx)
|
||||
device = devices.device
|
||||
batch_cond_uncond = opts.always_batch_cond_uncond or not (cmd_opts.lowvram or cmd_opts.medvram)
|
||||
parallel_processing_allowed = not cmd_opts.lowvram
|
||||
|
||||
Reference in New Issue
Block a user