mirror of
https://github.com/vladmandic/automatic
synced 2026-09-18 16:54:33 +02:00
Add static dims option.
This commit is contained in:
+1
-1
@@ -26,7 +26,7 @@ class OnnxRuntimeModel(OnnxFakeModule, diffusers.OnnxRuntimeModel):
|
||||
return ()
|
||||
|
||||
|
||||
def optimize_pipeline(p, refiner_enabled: bool):
|
||||
def preprocess_pipeline(p, refiner_enabled: bool):
|
||||
from modules import shared, sd_models
|
||||
|
||||
if "ONNX" not in shared.opts.diffusers_pipeline:
|
||||
|
||||
@@ -349,7 +349,6 @@ class OnnxRawPipeline(OnnxPipelineBase):
|
||||
|
||||
kwargs = {
|
||||
"provider": get_provider(),
|
||||
"sess_options": get_sess_options(p.batch_size if disable_classifier_free_guidance else p.batch_size * 2, p.height, p.width, self._is_sdxl),
|
||||
}
|
||||
|
||||
converted_dir = self.convert(in_dir)
|
||||
@@ -358,10 +357,12 @@ class OnnxRawPipeline(OnnxPipelineBase):
|
||||
return self.derive_properties(load_pipeline(diffusers.StableDiffusionXLPipeline if self._is_sdxl else diffusers.StableDiffusionPipeline, self.path, **kwargs))
|
||||
out_dir = converted_dir
|
||||
|
||||
if shared.opts.onnx_enable_olive:
|
||||
if shared.opts.cuda_compile_backend == "olive-ai":
|
||||
log.warning("Olive implementation is experimental. It contains potentially an issue and is subject to change at any time.")
|
||||
if p.width != p.height:
|
||||
log.warning("Olive detected different width and height. The quality of the result is not guaranteed.")
|
||||
if shared.opts.olive_static_dims:
|
||||
kwargs["sess_options"] = get_sess_options(p.batch_size if disable_classifier_free_guidance else p.batch_size * 2, p.height, p.width, self._is_sdxl)
|
||||
optimized_dir = self.optimize(converted_dir)
|
||||
if optimized_dir is None:
|
||||
log.error('Failed to optimize pipeline. The generation will fall back to unoptimized one.')
|
||||
|
||||
@@ -7,7 +7,7 @@ import torch
|
||||
import torchvision.transforms.functional as TF
|
||||
import diffusers
|
||||
from modules import shared, devices, processing, sd_samplers, sd_models, images, errors, masking, prompt_parser_diffusers, sd_hijack_hypertile, processing_correction, processing_vae
|
||||
from modules.onnx import optimize_pipeline as onnx_optimize_pipeline
|
||||
from modules.onnx import preprocess_pipeline as onnx_preprocess_pipeline
|
||||
|
||||
|
||||
debug = shared.log.trace if os.environ.get('SD_DIFFUSERS_DEBUG', None) is not None else lambda *args, **kwargs: None
|
||||
@@ -464,7 +464,7 @@ def process_diffusers(p: processing.StableDiffusionProcessing):
|
||||
return max(1, int(steps))
|
||||
|
||||
shared.sd_model = update_pipeline(shared.sd_model, p)
|
||||
onnx_optimize_pipeline(p, is_refiner_enabled())
|
||||
onnx_preprocess_pipeline(p, is_refiner_enabled())
|
||||
base_args = set_pipeline_args(
|
||||
model=shared.sd_model,
|
||||
prompts=p.prompts,
|
||||
@@ -536,7 +536,7 @@ def process_diffusers(p: processing.StableDiffusionProcessing):
|
||||
if (latent_scale_mode is not None or p.hr_force) and p.denoising_strength > 0:
|
||||
p.ops.append('hires')
|
||||
shared.sd_model = sd_models.set_diffuser_pipe(shared.sd_model, sd_models.DiffusersTaskType.IMAGE_2_IMAGE)
|
||||
onnx_optimize_pipeline(p, is_refiner_enabled())
|
||||
onnx_preprocess_pipeline(p, is_refiner_enabled())
|
||||
recompile_model(hires=True)
|
||||
update_sampler(shared.sd_model, second_pass=True)
|
||||
hires_args = set_pipeline_args(
|
||||
|
||||
@@ -385,6 +385,10 @@ options_templates.update(options_section(('cuda', "Compute Settings"), {
|
||||
"directml_sep": OptionInfo("<h2>IPEX and DirectML</h2>", "", gr.HTML, {"visible": devices.backend == "directml"}),
|
||||
"directml_memory_provider": OptionInfo(default_memory_provider, 'DirectML memory stats provider', gr.Radio, {"choices": memory_providers, "visible": devices.backend == "directml"}),
|
||||
"directml_catch_nan": OptionInfo(False, "DirectML retry ops for NaN", gr.Checkbox, {"visible": devices.backend == "directml"}),
|
||||
"directml_olive_sep": OptionInfo("<h2>DirectML and Olive</h2>", "", gr.HTML),
|
||||
"olive_float16": OptionInfo(True, 'Olive use FP16 on optimization (will use FP32 if unchecked)'),
|
||||
"olive_static_dims": OptionInfo(True, 'Olive use static dimensions (make inference faster with OrtTransformersOptimization)'),
|
||||
"olive_cache_optimized": OptionInfo(True, 'Olive cache optimized models'),
|
||||
}))
|
||||
|
||||
options_templates.update(options_section(('advanced', "Inference Settings"), {
|
||||
|
||||
Reference in New Issue
Block a user