From a8abed125ecdfe1085c40174cc29d25fbc9b1577 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sun, 13 Apr 2025 08:39:31 -0400 Subject: [PATCH] xyz grid allow bool Signed-off-by: Vladimir Mandic --- CHANGELOG.md | 8 +++++--- modules/cfgzero/__init__.py | 1 + modules/images_grid.py | 2 +- scripts/xyz_grid_classes.py | 3 ++- scripts/xyz_grid_shared.py | 16 +++++++++++++--- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68570bcc2..fabfb4ab6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,13 @@ ## Update for 2025-04-13 -- [CFG-Zero](https://github.com/WeichenFan/CFG-Zero-star) yet-another guidance method optimized for flow-matching models - implemented for `FLUX.1`, `SD3.x`, `CogView4`, `HunyuanVideo`, `WanAI` - enable in *settings -> pipeline modifiers -> cfg zero* +- [CFG-Zero](https://github.com/WeichenFan/CFG-Zero-star) new guidance method optimized for flow-matching models + implemented for `FLUX.1`, `SD3.x`, `CogView4`, `HunyuanVideo`, `WanAI` + enable and configure in *settings -> pipeline modifiers -> cfg zero* + experiment with CFGZero support in XYZ-grid - cleanup `CogView3` and `CogView4` model loader - ui display reference models with subdued color +- xyz grid support bool ## Update for 2025-04-12 diff --git a/modules/cfgzero/__init__.py b/modules/cfgzero/__init__.py index 1e5cc5ff8..21d92a6a2 100644 --- a/modules/cfgzero/__init__.py +++ b/modules/cfgzero/__init__.py @@ -40,6 +40,7 @@ def apply(p: processing.StableDiffusionProcessing): from modules.cfgzero.hunyuan_t2v_pipeline import HunyuanVideoCFGZeroPipeline shared.sd_model = sd_models.switch_pipe(HunyuanVideoCFGZeroPipeline, shared.sd_model) + shared.log.debug(f'Apply CFGZero: cls={cls} init={shared.opts.cfgzero_enabled} star={shared.opts.cfgzero_star} steps={shared.opts.cfgzero_steps}') p.task_args['use_zero_init'] = shared.opts.cfgzero_enabled p.task_args['use_cfg_zero_star'] = shared.opts.cfgzero_star p.task_args['zero_steps'] = int(shared.opts.cfgzero_steps) diff --git a/modules/images_grid.py b/modules/images_grid.py index 262440f75..c9da5e928 100644 --- a/modules/images_grid.py +++ b/modules/images_grid.py @@ -118,7 +118,7 @@ def combine_grid(grid): class GridAnnotation: def __init__(self, text='', is_active=True): - self.text = text + self.text = str(text) self.is_active = is_active self.size = None diff --git a/scripts/xyz_grid_classes.py b/scripts/xyz_grid_classes.py index cae9daef5..683672319 100644 --- a/scripts/xyz_grid_classes.py +++ b/scripts/xyz_grid_classes.py @@ -1,4 +1,4 @@ -from scripts.xyz_grid_shared import apply_field, apply_task_arg, apply_task_args, apply_setting, apply_prompt_primary, apply_prompt_refine, apply_prompt_detailer, apply_prompt_all, apply_order, apply_sampler, apply_hr_sampler_name, confirm_samplers, apply_checkpoint, apply_refiner, apply_unet, apply_dict, apply_clip_skip, apply_vae, list_lora, apply_lora, apply_lora_strength, apply_te, apply_styles, apply_upscaler, apply_context, apply_detailer, apply_override, apply_processing, apply_options, apply_seed, format_value_add_label, format_value, format_value_join_list, do_nothing, format_nothing, str_permutations # pylint: disable=no-name-in-module, unused-import +from scripts.xyz_grid_shared import apply_field, apply_task_arg, apply_task_args, apply_setting, apply_prompt_primary, apply_prompt_refine, apply_prompt_detailer, apply_prompt_all, apply_order, apply_sampler, apply_hr_sampler_name, confirm_samplers, apply_checkpoint, apply_refiner, apply_unet, apply_dict, apply_clip_skip, apply_vae, list_lora, apply_lora, apply_lora_strength, apply_te, apply_styles, apply_upscaler, apply_context, apply_detailer, apply_override, apply_processing, apply_options, apply_seed, format_value_add_label, format_bool, format_value, format_value_join_list, do_nothing, format_nothing, str_permutations # pylint: disable=no-name-in-module, unused-import from modules import shared, shared_items, sd_samplers, ipadapter, sd_models, sd_vae, sd_unet @@ -213,4 +213,5 @@ axis_options = [ AxisOption("[IY] Start", float, apply_task_arg('infusenet_guidance_start')), AxisOption("[IY] End", float, apply_task_arg('infusenet_guidance_end')), AxisOption("[TeaCache] Threshold", float, apply_setting('teacache_thresh')), + AxisOption("[CFGZero] Enabled", bool, apply_setting('cfgzero_enabled'), fmt=format_bool, choices=lambda: [False, True]), ] diff --git a/scripts/xyz_grid_shared.py b/scripts/xyz_grid_shared.py index 6b1d814b3..2d594bac7 100644 --- a/scripts/xyz_grid_shared.py +++ b/scripts/xyz_grid_shared.py @@ -58,7 +58,13 @@ def apply_options(p, x, xs): def apply_setting(field): def fun(p, x, xs): - shared.log.debug(f'XYZ grid apply setting: {field}={x}') + t = type(shared.opts.get(field)) + if t == bool: + if isinstance(x, str): + x = x.lower() in ['true', 't', 'yes', 'y'] + if isinstance(x, int) or isinstance(x, float): + x = x > 0 + shared.log.debug(f'XYZ grid apply setting: {field}={t}:{x}') shared.opts.data[field] = x return fun @@ -288,15 +294,19 @@ def apply_override(field): return fun +def format_bool(p, opt, x): + return f"{opt.label}: {x}" + + def format_value_add_label(p, opt, x): if type(x) == float: - x = round(x, 8) + x = round(x, 4) return f"{opt.label}: {x}" def format_value(p, opt, x): if type(x) == float: - x = round(x, 8) + x = round(x, 4) return x