From 6919ca310a5aa8fe58fda1c5b5682813abbc5295 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sat, 21 Sep 2024 15:44:53 -0400 Subject: [PATCH] lint updates --- .pylintrc | 1 + CHANGELOG.md | 1 + extensions-builtin/Lora/lora_patches.py | 4 ++-- modules/images.py | 2 +- modules/model_flux.py | 2 +- modules/model_te.py | 6 +++--- modules/prompt_parser_diffusers.py | 2 +- modules/sd_samplers.py | 2 +- modules/shared.py | 2 +- modules/ui_control.py | 1 + 10 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.pylintrc b/.pylintrc index 1ed4ebc66..e61d7e964 100644 --- a/.pylintrc +++ b/.pylintrc @@ -164,6 +164,7 @@ disable=bad-inline-option, too-many-locals, too-many-nested-blocks, too-many-statements, + too-many-positional-arguments, unidiomatic-typecheck, unnecessary-dict-index-lookup, unnecessary-dunder-call, diff --git a/CHANGELOG.md b/CHANGELOG.md index 8910cf871..32da9f705 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ - hide token counter until tokens are known - minor ui optimizations - massive log cleanup +- full lint pass - **experimental** - flux t5 load from gguf: requires transformers pr diff --git a/extensions-builtin/Lora/lora_patches.py b/extensions-builtin/Lora/lora_patches.py index 532782c80..f31e2cc44 100644 --- a/extensions-builtin/Lora/lora_patches.py +++ b/extensions-builtin/Lora/lora_patches.py @@ -21,7 +21,7 @@ class LoraPatches: if self.active or shared.opts.lora_force_diffusers: return if "Model" in shared.opts.optimum_quanto_weights or "Text Encoder" in shared.opts.optimum_quanto_weights: - from optimum import quanto + from optimum import quanto # pylint: disable=no-name-in-module self.QLinear_forward = patches.patch(__name__, quanto.nn.QLinear, 'forward', networks.network_QLinear_forward) # pylint: disable=attribute-defined-outside-init self.QConv2d_forward = patches.patch(__name__, quanto.nn.QConv2d, 'forward', networks.network_QConv2d_forward) # pylint: disable=attribute-defined-outside-init self.Linear_forward = patches.patch(__name__, torch.nn.Linear, 'forward', networks.network_Linear_forward) @@ -43,7 +43,7 @@ class LoraPatches: if not self.active or shared.opts.lora_force_diffusers: return if "Model" in shared.opts.optimum_quanto_weights or "Text Encoder" in shared.opts.optimum_quanto_weights: - from optimum import quanto + from optimum import quanto # pylint: disable=no-name-in-module self.QLinear_forward = patches.undo(__name__, quanto.nn.QLinear, 'forward') # pylint: disable=E1128, attribute-defined-outside-init self.QConv2d_forward = patches.undo(__name__, quanto.nn.QConv2d, 'forward') # pylint: disable=E1128, attribute-defined-outside-init self.Linear_forward = patches.undo(__name__, torch.nn.Linear, 'forward') # pylint: disable=E1128 diff --git a/modules/images.py b/modules/images.py index 3baa2c8fa..e4d435aaa 100644 --- a/modules/images.py +++ b/modules/images.py @@ -12,7 +12,7 @@ import piexif import piexif.helper from PIL import Image, PngImagePlugin, ExifTags from modules import sd_samplers, shared, script_callbacks, errors, paths -from modules.images_grid import image_grid, split_grid, combine_grid, check_grid_size, get_font, draw_grid_annotations, draw_prompt_matrix, GridAnnotation # pylint: disable=unused-import +from modules.images_grid import image_grid, split_grid, combine_grid, check_grid_size, get_font, draw_grid_annotations, draw_prompt_matrix, GridAnnotation, Grid # pylint: disable=unused-import from modules.images_resize import resize_image # pylint: disable=unused-import from modules.images_namegen import FilenameGenerator diff --git a/modules/model_flux.py b/modules/model_flux.py index 93845d192..324c2ee1b 100644 --- a/modules/model_flux.py +++ b/modules/model_flux.py @@ -147,7 +147,7 @@ def load_flux_gguf(file_path): # TODO add support for GGUF flux models def load_transformer(file_path): # triggered by opts.sd_unet change if file_path is None or not os.path.exists(file_path): - return + return None transformer = None quant = get_quant(file_path) diffusers_load_config = { diff --git a/modules/model_te.py b/modules/model_te.py index 78c604c13..27fa131b4 100644 --- a/modules/model_te.py +++ b/modules/model_te.py @@ -29,7 +29,7 @@ def install_gguf(): def load_t5(name=None, cache_dir=None): global loaded_te # pylint: disable=global-statement if name is None: - return + return None from modules import modelloader modelloader.hf_login() repo_id = 'stabilityai/stable-diffusion-3-medium-diffusers' @@ -100,7 +100,7 @@ def load_t5(name=None, cache_dir=None): def set_t5(pipe, module, t5=None, cache_dir=None): global loaded_te # pylint: disable=global-statement if loaded_te == shared.opts.sd_text_encoder: - return + return pipe if pipe is None or not hasattr(pipe, module): return pipe try: @@ -111,7 +111,7 @@ def set_t5(pipe, module, t5=None, cache_dir=None): errors.display(e, 'TE:') t5 = None if t5 is None: - return None + return pipe loaded_te = shared.opts.sd_text_encoder setattr(pipe, module, t5) if shared.opts.diffusers_offload_mode == "sequential": diff --git a/modules/prompt_parser_diffusers.py b/modules/prompt_parser_diffusers.py index 6b79c7bfd..0b8ad30fb 100644 --- a/modules/prompt_parser_diffusers.py +++ b/modules/prompt_parser_diffusers.py @@ -175,7 +175,7 @@ def encode_prompts(pipe, p, prompts: list, negative_prompts: list, steps: int, c last_prompt, last_negative = None, None for prompt, negative in zip(prompts, negative_prompts): prompt_embed, positive_pooled, negative_embed, negative_pooled = None, None, None, None - if last_prompt == prompt and last_negative == negative or False: + if last_prompt == prompt and last_negative == negative: prompt_embeds.append(prompt_embeds[-1]) positive_pooleds.append(positive_pooleds[-1]) negative_embeds.append(negative_embeds[-1]) diff --git a/modules/sd_samplers.py b/modules/sd_samplers.py index 5694dd096..aff3bda47 100644 --- a/modules/sd_samplers.py +++ b/modules/sd_samplers.py @@ -76,7 +76,7 @@ def create_sampler(name, model): return None if 'Lumina' in model.__class__.__name__: shared.log.warning(f'AlphaVLLM-Lumina: sampler="{name}" unsupported') - return + return None if not hasattr(model, 'scheduler_config'): model.scheduler_config = sampler.sampler.config.copy() model.scheduler = sampler.sampler diff --git a/modules/shared.py b/modules/shared.py index 39898a628..172ca42cb 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -484,7 +484,7 @@ options_templates.update(options_section(('cuda', "Compute Settings"), { "ipex_optimize": OptionInfo([], "IPEX Optimize for Intel GPUs", gr.CheckboxGroup, {"choices": ["Model", "VAE", "Text Encoder", "Upscaler"], "visible": devices.backend == "ipex"}), "openvino_sep": OptionInfo("

OpenVINO

", "", gr.HTML, {"visible": cmd_opts.use_openvino}), - "openvino_devices": OptionInfo([], "OpenVINO devices to use", gr.CheckboxGroup, {"choices": get_openvino_device_list() if cmd_opts.use_openvino else [], "visible": cmd_opts.use_openvino}), + "openvino_devices": OptionInfo([], "OpenVINO devices to use", gr.CheckboxGroup, {"choices": get_openvino_device_list() if cmd_opts.use_openvino else [], "visible": cmd_opts.use_openvino}), # pylint disable:possibly-used-before-assignment "nncf_quantize": OptionInfo([], "OpenVINO Quantize Models with NNCF", gr.CheckboxGroup, {"choices": ["Model", "VAE", "Text Encoder"], "visible": cmd_opts.use_openvino}), "nncf_quant_mode": OptionInfo("INT8", "OpenVINO quantization mode for NNCF", gr.Radio, {"choices": ['INT8', 'FP8_E4M3', 'FP8_E5M2'], "visible": cmd_opts.use_openvino}), "nncf_compress_weights_mode": OptionInfo("INT8", "OpenVINO compress mode for NNCF", gr.Radio, {"choices": ['INT8', 'INT8_SYM', 'INT4_ASYM', 'INT4_SYM', 'NF4'], "visible": cmd_opts.use_openvino}), diff --git a/modules/ui_control.py b/modules/ui_control.py index 07588eb25..5bad230bf 100644 --- a/modules/ui_control.py +++ b/modules/ui_control.py @@ -44,6 +44,7 @@ def return_controls(res): def get_units(*values): update = [] + what = None for c, v in zip(controls, values): if isinstance(c, gr.Label): # unit type indicator what = c.value['label']