diff --git a/modules/onnx_impl/pipelines/onnx_stable_diffusion_pipeline.py b/modules/onnx_impl/pipelines/onnx_stable_diffusion_pipeline.py index 2b583e8f5..dc2aa9e75 100644 --- a/modules/onnx_impl/pipelines/onnx_stable_diffusion_pipeline.py +++ b/modules/onnx_impl/pipelines/onnx_stable_diffusion_pipeline.py @@ -30,7 +30,7 @@ class OnnxStableDiffusionPipeline(diffusers.OnnxStableDiffusionPipeline, Callabl def __call__( self, - prompt: str | list[str] = None, + prompt: str | list[str] | None = None, height: int | None = 512, width: int | None = 512, num_inference_steps: int | None = 50, diff --git a/modules/options_handler.py b/modules/options_handler.py index 5041eb86c..c14fadfb4 100644 --- a/modules/options_handler.py +++ b/modules/options_handler.py @@ -28,7 +28,7 @@ class Options: debug = os.environ.get('SD_CONFIG_DEBUG', None) is not None secrets_debug = os.environ.get("SD_SECRETS_DEBUG", None) is not None - def __init__(self, options_templates: dict[str, OptionInfo | LegacyOption] = None, restricted: set[str] | None = None, *, filename = '', secrets = ''): + def __init__(self, options_templates: dict[str, OptionInfo | LegacyOption] | None = None, restricted: set[str] | None = None, *, filename = '', secrets = ''): if options_templates is None: options_templates = {} if restricted is None: diff --git a/modules/postprocess/pixelart.py b/modules/postprocess/pixelart.py index 00b9b9636..57768b1b4 100644 --- a/modules/postprocess/pixelart.py +++ b/modules/postprocess/pixelart.py @@ -224,8 +224,8 @@ class JPEGEncoder(ImageProcessingMixin, ConfigMixin): block_size: int = 16, cbcr_downscale: int = 2, norm: str = "ortho", - latents_std: list[float] = None, - latents_mean: list[float] = None, + latents_std: list[float] | None = None, + latents_mean: list[float] | None = None, ): self.block_size = block_size self.cbcr_downscale = cbcr_downscale diff --git a/modules/postprocess/yolo.py b/modules/postprocess/yolo.py index 89802050d..e70df763f 100644 --- a/modules/postprocess/yolo.py +++ b/modules/postprocess/yolo.py @@ -96,11 +96,11 @@ class YoloRestorer(Detailer): imgsz: int = 640, half: bool = True, device = devices.device, - augment: bool = None, agnostic: bool = False, retina: bool = False, mask: bool = True, - offload: bool = None, + augment: bool | None = None, + offload: bool | None = None, p = None, ) -> list[YoloResult]: if augment is None: @@ -201,7 +201,7 @@ class YoloRestorer(Detailer): break return result - def load(self, model_name: str = None): + def load(self, model_name: str | None = None): with load_lock: from modules import modelloader model = None diff --git a/modules/processing_callbacks.py b/modules/processing_callbacks.py index 0f6fdb533..e1c2c19ba 100644 --- a/modules/processing_callbacks.py +++ b/modules/processing_callbacks.py @@ -51,7 +51,7 @@ def diffusers_callback_legacy(step: int, timestep: int, latents: torch.FloatTens time.sleep(0.1) -def diffusers_callback(pipe, step: int = 0, timestep: int = 0, kwargs: dict = None): +def diffusers_callback(pipe, step: int = 0, timestep: int = 0, kwargs: dict | None = None): if kwargs is None: kwargs = {} t0 = time.time() diff --git a/modules/processing_class.py b/modules/processing_class.py index 75ab9cb71..287a2b17a 100644 --- a/modules/processing_class.py +++ b/modules/processing_class.py @@ -35,10 +35,10 @@ class StableDiffusionProcessing: width: int = 1024, height: int = 1024, # samplers - sampler_index: int = None, # pylint: disable=unused-argument # used only to set sampler_name - sampler_name: str = None, - hr_sampler_name: str = None, - eta: float = None, + sampler_index: int | None = None, # pylint: disable=unused-argument # used only to set sampler_name + sampler_name: str | None = None, + hr_sampler_name: str | None = None, + eta: float | None = None, # modular guidance guidance_name: str = 'Default', guidance_scale: float = 6.0, @@ -52,7 +52,7 @@ class StableDiffusionProcessing: pag_scale: float = 0.0, pag_adaptive: float = 0.5, # styles - styles: list[str] = None, + styles: list[str] | None = None, # vae tiling: bool = False, vae_type: str = 'Full', @@ -66,53 +66,53 @@ class StableDiffusionProcessing: detailer_steps: int = 10, detailer_strength: float = 0.3, detailer_resolution: int = 1024, - detailer_segmentation: bool = None, - detailer_include_detections: bool = None, - detailer_merge: bool = None, - detailer_sort: bool = None, - detailer_classes: str = None, - detailer_conf: float = None, - detailer_iou: float = None, - detailer_max: int = None, - detailer_min_size: float = None, - detailer_max_size: float = None, - detailer_blur: int = None, - detailer_padding: int = None, - detailer_sigma_adjust: float = None, - detailer_sigma_adjust_max: float = None, - detailer_models: list = None, - detailer_augment: bool = None, + detailer_segmentation: bool | None = None, + detailer_include_detections: bool | None = None, + detailer_merge: bool | None = None, + detailer_sort: bool | None = None, + detailer_classes: str | None = None, + detailer_conf: float | None = None, + detailer_iou: float | None = None, + detailer_max: int | None = None, + detailer_min_size: float | None = None, + detailer_max_size: float | None = None, + detailer_blur: int | None = None, + detailer_padding: int | None = None, + detailer_sigma_adjust: float | None = None, + detailer_sigma_adjust_max: float | None = None, + detailer_models: list | None = None, + detailer_augment: bool | None = None, # img2img and mask - img2img_color_correction: bool = None, - color_correction_method: str = None, - img2img_background_color: str = None, - img2img_fix_steps: bool = None, - mask_apply_overlay: bool = None, - include_mask: bool = None, - inpainting_mask_weight: float = None, + img2img_color_correction: bool | None = None, + color_correction_method: str | None = None, + img2img_background_color: str | None = None, + img2img_fix_steps: bool | None = None, + mask_apply_overlay: bool | None = None, + include_mask: bool | None = None, + inpainting_mask_weight: float | None = None, # output and saving - samples_save: bool = None, - samples_format: str = None, - save_images_before_highres_fix: bool = None, - save_images_before_refiner: bool = None, - save_images_before_detailer: bool = None, - save_images_before_color_correction: bool = None, - grid_save: bool = None, - grid_format: str = None, - return_grid: bool = None, - save_mask: bool = None, - save_mask_composite: bool = None, - return_mask: bool = None, - return_mask_composite: bool = None, - keep_incomplete: bool = None, - image_metadata: bool = None, - jpeg_quality: int = None, + samples_save: bool | None = None, + samples_format: str | None = None, + save_images_before_highres_fix: bool | None = None, + save_images_before_refiner: bool | None = None, + save_images_before_detailer: bool | None = None, + save_images_before_color_correction: bool | None = None, + grid_save: bool | None = None, + grid_format: str | None = None, + return_grid: bool | None = None, + save_mask: bool | None = None, + save_mask_composite: bool | None = None, + return_mask: bool | None = None, + return_mask_composite: bool | None = None, + keep_incomplete: bool | None = None, + image_metadata: bool | None = None, + jpeg_quality: int | None = None, # lora behavior - lora_fuse_native: bool = None, - lora_fuse_diffusers: bool = None, - lora_force_reload: bool = None, - extra_networks_default_multiplier: float = None, - lora_apply_tags: int = None, + lora_fuse_native: bool | None = None, + lora_fuse_diffusers: bool | None = None, + lora_force_reload: bool | None = None, + extra_networks_default_multiplier: float | None = None, + lora_apply_tags: int | None = None, # hdr corrections hdr_mode: int = 0, hdr_brightness: float = 0, @@ -148,11 +148,11 @@ class StableDiffusionProcessing: grading_lut_file: str = "", grading_lut_strength: float = 1.0, # img2img - init_images: list = None, - init_control: list = None, denoising_strength: float = 0.3, - image_cfg_scale: float = None, - initial_noise_multiplier: float = None, # pylint: disable=unused-argument # a1111 compatibility + init_images: list | None = None, + init_control: list | None = None, + image_cfg_scale: float | None = None, + initial_noise_multiplier: float | None = None, # pylint: disable=unused-argument # a1111 compatibility # resize scale_by: float = 1, selected_scale_tab: int = 0, # pylint: disable=unused-argument # a1111 compatibility @@ -199,12 +199,12 @@ class StableDiffusionProcessing: hr_force: bool = False, hr_resize_mode: int = 0, hr_resize_context: str = 'None', - hr_upscaler: str = None, hr_second_pass_steps: int = 0, hr_resize_x: int = 0, hr_resize_y: int = 0, hr_denoising_strength: float = 0.0, refiner_steps: int = 5, + hr_upscaler: str | None = None, refiner_start: float = 0, refiner_prompt: str = '', refiner_negative: str = '', @@ -219,65 +219,65 @@ class StableDiffusionProcessing: # xyz flag xyz: bool = False, # scripts - script_args: list = [], + script_args: list | None = None, # scheduler/noise overrides - schedulers_prediction_type: str = None, - schedulers_beta_schedule: str = None, - schedulers_timesteps: str = None, - schedulers_sigma: str = None, - schedulers_use_thresholding: bool = None, - schedulers_use_loworder: bool = None, - schedulers_solver_order: int = None, - uni_pc_variant: str = None, - schedulers_beta_start: float = None, - schedulers_beta_end: float = None, - schedulers_shift: float = None, - schedulers_dynamic_shift: bool = None, - schedulers_base_shift: float = None, - schedulers_max_shift: float = None, - schedulers_rescale_betas: bool = None, - schedulers_timestep_spacing: str = None, - schedulers_timesteps_range: int = None, - schedulers_sigma_adjust: float = None, - schedulers_sigma_adjust_min: float = None, - schedulers_sigma_adjust_max: float = None, - scheduler_eta: float = None, - eta_noise_seed_delta: int = None, - enable_batch_seeds: bool = None, - diffusers_generator_device: str = None, - nan_skip: bool = None, - sequential_seed: bool = None, + schedulers_prediction_type: str | None = None, + schedulers_beta_schedule: str | None = None, + schedulers_timesteps: str | None = None, + schedulers_sigma: str | None = None, + schedulers_use_thresholding: bool | None = None, + schedulers_use_loworder: bool | None = None, + schedulers_solver_order: int | None = None, + uni_pc_variant: str | None = None, + schedulers_beta_start: float | None = None, + schedulers_beta_end: float | None = None, + schedulers_shift: float | None = None, + schedulers_dynamic_shift: bool | None = None, + schedulers_base_shift: float | None = None, + schedulers_max_shift: float | None = None, + schedulers_rescale_betas: bool | None = None, + schedulers_timestep_spacing: str | None = None, + schedulers_timesteps_range: int | None = None, + schedulers_sigma_adjust: float | None = None, + schedulers_sigma_adjust_min: float | None = None, + schedulers_sigma_adjust_max: float | None = None, + scheduler_eta: float | None = None, + eta_noise_seed_delta: int | None = None, + enable_batch_seeds: bool | None = None, + diffusers_generator_device: str | None = None, + nan_skip: bool | None = None, + sequential_seed: bool | None = None, # prompt/attention overrides - prompt_attention: str = None, - prompt_mean_norm: bool = None, - diffusers_zeros_prompt_pad: bool = None, - te_pooled_embeds: bool = None, - lora_apply_te: bool = None, - te_complex_human_instruction: str = None, - te_use_mask: bool = None, + prompt_attention: str | None = None, + prompt_mean_norm: bool | None = None, + diffusers_zeros_prompt_pad: bool | None = None, + te_pooled_embeds: bool | None = None, + lora_apply_te: bool | None = None, + te_complex_human_instruction: str | None = None, + te_use_mask: bool | None = None, # generation modifier overrides (hijack) - freeu_enabled: bool = None, - freeu_b1: float = None, - freeu_b2: float = None, - freeu_s1: float = None, - freeu_s2: float = None, - hypertile_unet_enabled: bool = None, - hypertile_hires_only: bool = None, - hypertile_unet_tile: int = None, - hypertile_unet_min_tile: int = None, - hypertile_unet_swap_size: int = None, - hypertile_unet_depth: int = None, - hypertile_vae_enabled: bool = None, - hypertile_vae_tile: int = None, - hypertile_vae_swap_size: int = None, - teacache_enabled: bool = None, - teacache_thresh: float = None, - token_merging_method: str = None, - tome_ratio: float = None, - todo_ratio: float = None, + freeu_enabled: bool | None = None, + freeu_b1: float | None = None, + freeu_b2: float | None = None, + freeu_s1: float | None = None, + freeu_s2: float | None = None, + hypertile_unet_enabled: bool | None = None, + hypertile_hires_only: bool | None = None, + hypertile_unet_tile: int | None = None, + hypertile_unet_min_tile: int | None = None, + hypertile_unet_swap_size: int | None = None, + hypertile_unet_depth: int | None = None, + hypertile_vae_enabled: bool | None = None, + hypertile_vae_tile: int | None = None, + hypertile_vae_swap_size: int | None = None, + teacache_enabled: bool | None = None, + teacache_thresh: float | None = None, + token_merging_method: str | None = None, + tome_ratio: float | None = None, + todo_ratio: float | None = None, # overrides - override_settings: dict[str, Any] = None, override_settings_restore_afterwards: bool = True, + override_settings: dict[str, Any] | None = None, # metadata # extra_generation_params: Dict[Any, Any] = {}, # task_args: Dict[str, Any] = {}, diff --git a/modules/processing_helpers.py b/modules/processing_helpers.py index ed3e546a0..f93bcea89 100644 --- a/modules/processing_helpers.py +++ b/modules/processing_helpers.py @@ -155,7 +155,7 @@ def images_tensor_to_samples(image, approximation=None, model=None): # pylint: d return x_latent -def get_sampler_name(sampler_index: int, img: bool = False) -> str: +def get_sampler_name(sampler_index: int | None = None, img: bool = False) -> str: sampler_index = sampler_index or 0 if len(sd_samplers.samplers) > sampler_index: sampler_name = sd_samplers.samplers[sampler_index].name