Revert "much stricter ruff linting"

This reverts commit 310dbf1574.
This commit is contained in:
Vladimir Mandic
2026-05-11 08:13:57 +02:00
parent 8296d07ff8
commit c8d6fd5cf8
132 changed files with 363 additions and 292 deletions
+2 -2
View File
@@ -361,7 +361,7 @@ def get_deletefile(file: str):
return {"deleted": f"{file}"}
except Exception as e:
log.error(f'Delete: file="{file}" error: {e}')
raise HTTPException(status_code=500, detail=f"error deleting file {file}: {e!s}") from e
raise HTTPException(status_code=500, detail=f"error deleting file {file}: {str(e)}") from e
def get_deleteimage(file: str):
import os
@@ -383,7 +383,7 @@ def get_deleteimage(file: str):
return {"deleted": f"{file}"}
except Exception as e:
log.error(f'Delete: file="{file}" error: {e}')
raise HTTPException(status_code=500, detail=f"error deleting file {file}: {e!s}") from e
raise HTTPException(status_code=500, detail=f"error deleting file {file}: {str(e)}") from e
def get_pnginfo(file: str):
"""Extract generation parameters from a image file path. Returns raw info string and parsed parameters dict."""
+1 -1
View File
@@ -44,7 +44,7 @@ def setup_middleware(app: FastAPI, cmd_opts):
client = req.scope.get('client', ('0:0.0.0', 0))[0]
token = req.cookies.get("access-token") or req.cookies.get("access-token-unsecure")
validate_request(client, endpoint)
if cmd_opts.api_log:
if (cmd_opts.api_log):
if not validate_log(client, endpoint):
return res
log.info('API user={user} code={code} {prot}/{ver} {method} {endpoint} {client} {duration}'.format( # pylint: disable=consider-using-f-string, logging-format-interpolation
-1
View File
@@ -9,7 +9,6 @@ request_cost = {
"/run/predict": 0,
"/sdapi/v1/browser/thumb": 0,
"/sdapi/v1/network/thumb": 0,
"/sdapi/v1/gpu-smi": 0,
"/sdapi/v1/txt2img": 5,
"/sdapi/v1/img2img": 5,
"/sdapi/v1/control": 5,
+1 -1
View File
@@ -65,7 +65,7 @@ def load(repo: str | None = None):
if llava_model is None or opts.repo != repo:
opts.repo = repo
llava_model = None
log.info(f'Caption: type=vlm model="JoyCaption" {opts!s}')
log.info(f'Caption: type=vlm model="JoyCaption" {str(opts)}')
processor = AutoProcessor.from_pretrained(repo, max_pixels=1024*1024, cache_dir=shared.opts.hfcache_dir)
quant_args = model_quant.create_config(module='LLM')
llava_model = LlavaForConditionalGeneration.from_pretrained(
+1 -1
View File
@@ -402,7 +402,7 @@ def predict(question: str, image: Image.Image, repo: str, model_name: str | None
except Exception as e:
from modules import errors
errors.display(e, 'Moondream3')
return f"Error: {e!s}"
return f"Error: {str(e)}"
finally:
offload_aux('moondream3')
+1 -1
View File
@@ -13,7 +13,7 @@ from modules import shared, devices, errors, model_quant, sd_models, sd_models_c
from modules.sd_offload_aux import register_aux, deregister_aux, move_aux_to_gpu, offload_aux
from modules.logger import log, console
from modules.caption import vqa_detection
from modules.caption.models_def import vlm_models, vlm_prefill, vlm_prompt_mapping, vlm_prompt_placeholders, vlm_prompts_common, vlm_prompts_florence, vlm_prompts_moondream, vlm_prompts_moondream2, vlm_prompts_promptgen, get_vlm_repo
from modules.caption.models_def import vlm_models, vlm_system, vlm_default, vlm_prefill, vlm_prompts, vlm_prompt_mapping, vlm_prompt_placeholders, vlm_prompts_common, vlm_prompts_florence, vlm_prompts_moondream, vlm_prompts_moondream2, vlm_prompts_promptgen, get_vlm_repo
# Debug logging - function-based to avoid circular import
debug_enabled = os.environ.get('SD_CAPTION_DEBUG', None) is not None
+1 -1
View File
@@ -191,7 +191,7 @@ class CogView4CFGZeroPipeline(DiffusionPipeline, CogView4LoraLoaderMixin):
def _get_glm_embeds(
self,
prompt: Union[str, List[str]] | None = None,
prompt: Union[str, List[str]] = None,
max_sequence_length: int = 1024,
device: Optional[torch.device] = None,
dtype: Optional[torch.dtype] = None,
+4 -4
View File
@@ -217,7 +217,7 @@ class FluxCFGZeroPipeline(
def _get_t5_prompt_embeds(
self,
prompt: Union[str, List[str]] | None = None,
prompt: Union[str, List[str]] = None,
num_images_per_prompt: int = 1,
max_sequence_length: int = 512,
device: Optional[torch.device] = None,
@@ -535,7 +535,7 @@ class FluxCFGZeroPipeline(
@staticmethod
def _unpack_latents(latents, height, width, vae_scale_factor):
batch_size, _num_patches, channels = latents.shape
batch_size, num_patches, channels = latents.shape
# VAE applies 8x compression on images but we must also account for packing which requires
# latent height and width to be divisible by 2.
@@ -637,9 +637,9 @@ class FluxCFGZeroPipeline(
@replace_example_docstring(EXAMPLE_DOC_STRING)
def __call__(
self,
prompt: Union[str, List[str]] | None = None,
prompt: Union[str, List[str]] = None,
prompt_2: Optional[Union[str, List[str]]] = None,
negative_prompt: Union[str, List[str]] | None = None,
negative_prompt: Union[str, List[str]] = None,
negative_prompt_2: Optional[Union[str, List[str]]] = None,
true_cfg_scale: float = 1.0,
height: Optional[int] = None,
+3 -3
View File
@@ -211,7 +211,7 @@ class HiDreamImageCFGZeroPipeline(DiffusionPipeline, HiDreamImageLoraLoaderMixin
def _get_t5_prompt_embeds(
self,
prompt: Union[str, List[str]] | None = None,
prompt: Union[str, List[str]] = None,
max_sequence_length: int = 128,
device: Optional[torch.device] = None,
dtype: Optional[torch.dtype] = None,
@@ -285,7 +285,7 @@ class HiDreamImageCFGZeroPipeline(DiffusionPipeline, HiDreamImageLoraLoaderMixin
def _get_llama3_prompt_embeds(
self,
prompt: Union[str, List[str]] | None = None,
prompt: Union[str, List[str]] = None,
max_sequence_length: int = 128,
device: Optional[torch.device] = None,
dtype: Optional[torch.dtype] = None,
@@ -545,7 +545,7 @@ class HiDreamImageCFGZeroPipeline(DiffusionPipeline, HiDreamImageLoraLoaderMixin
@torch.no_grad()
def __call__(
self,
prompt: Union[str, List[str]] | None = None,
prompt: Union[str, List[str]] = None,
prompt_2: Optional[Union[str, List[str]]] = None,
prompt_3: Optional[Union[str, List[str]]] = None,
prompt_4: Optional[Union[str, List[str]]] = None,
+6 -6
View File
@@ -317,7 +317,7 @@ class HunyuanVideoCFGZeroPipeline(DiffusionPipeline, HunyuanVideoLoraLoaderMixin
def encode_prompt(
self,
prompt: Union[str, List[str]],
prompt_2: Union[str, List[str]] | None = None,
prompt_2: Union[str, List[str]] = None,
prompt_template: Dict[str, Any] = DEFAULT_PROMPT_TEMPLATE,
num_videos_per_prompt: int = 1,
prompt_embeds: Optional[torch.Tensor] = None,
@@ -481,15 +481,15 @@ class HunyuanVideoCFGZeroPipeline(DiffusionPipeline, HunyuanVideoLoraLoaderMixin
@replace_example_docstring(EXAMPLE_DOC_STRING)
def __call__(
self,
prompt: Union[str, List[str]] | None = None,
prompt_2: Union[str, List[str]] | None = None,
negative_prompt: Union[str, List[str]] | None = None,
negative_prompt_2: Union[str, List[str]] | None = None,
prompt: Union[str, List[str]] = None,
prompt_2: Union[str, List[str]] = None,
negative_prompt: Union[str, List[str]] = None,
negative_prompt_2: Union[str, List[str]] = None,
height: int = 720,
width: int = 1280,
num_frames: int = 129,
num_inference_steps: int = 50,
sigmas: List[float] | None = None,
sigmas: List[float] = None,
true_cfg_scale: float = 1.0,
guidance_scale: float = 6.0,
num_videos_per_prompt: Optional[int] = 1,
+3 -3
View File
@@ -246,7 +246,7 @@ class StableDiffusion3CFGZeroPipeline(DiffusionPipeline, SD3LoraLoaderMixin, Fro
def _get_t5_prompt_embeds(
self,
prompt: Union[str, List[str]] | None = None,
prompt: Union[str, List[str]] = None,
num_images_per_prompt: int = 1,
max_sequence_length: int = 256,
device: Optional[torch.device] = None,
@@ -786,7 +786,7 @@ class StableDiffusion3CFGZeroPipeline(DiffusionPipeline, SD3LoraLoaderMixin, Fro
@replace_example_docstring(EXAMPLE_DOC_STRING)
def __call__(
self,
prompt: Union[str, List[str]] | None = None,
prompt: Union[str, List[str]] = None,
prompt_2: Optional[Union[str, List[str]]] = None,
prompt_3: Optional[Union[str, List[str]]] = None,
height: Optional[int] = None,
@@ -813,7 +813,7 @@ class StableDiffusion3CFGZeroPipeline(DiffusionPipeline, SD3LoraLoaderMixin, Fro
callback_on_step_end: Optional[Callable[[int, int, Dict], None]] = None,
callback_on_step_end_tensor_inputs: List[str] = ["latents"],
max_sequence_length: int = 256,
skip_guidance_layers: List[int] | None = None,
skip_guidance_layers: List[int] = None,
skip_layer_guidance_scale: float = 2.8,
skip_layer_guidance_stop: float = 0.2,
skip_layer_guidance_start: float = 0.01,
+3 -3
View File
@@ -153,7 +153,7 @@ class WanCFGZeroPipeline(DiffusionPipeline, WanLoraLoaderMixin):
def _get_t5_prompt_embeds(
self,
prompt: Union[str, List[str]] | None = None,
prompt: Union[str, List[str]] = None,
num_videos_per_prompt: int = 1,
max_sequence_length: int = 226,
device: Optional[torch.device] = None,
@@ -374,8 +374,8 @@ class WanCFGZeroPipeline(DiffusionPipeline, WanLoraLoaderMixin):
@replace_example_docstring(EXAMPLE_DOC_STRING)
def __call__(
self,
prompt: Union[str, List[str]] | None = None,
negative_prompt: Union[str, List[str]] | None = None,
prompt: Union[str, List[str]] = None,
negative_prompt: Union[str, List[str]] = None,
height: int = 480,
width: int = 832,
num_frames: int = 81,
+1 -1
View File
@@ -93,7 +93,7 @@ def civit_update_metadata(raw: bool = False):
model.latest_name = f.get('name', '')
if model.vername == model.latest:
model.status = 'Latest version'
elif any(map(lambda v: v in model.latest_hashes, all_hashes)): # pylint: disable=cell-var-from-loop
elif any(map(lambda v: v in model.latest_hashes, all_hashes)): # pylint: disable=cell-var-from-loop # noqa: C417
model.status = 'Update downloaded'
else:
model.status = 'Update available'
+1 -1
View File
@@ -7,7 +7,7 @@ from modules.control.util import HWC3, resize_image
class CannyDetector:
def __call__(self, input_image=None, low_threshold=100, high_threshold=200, detect_resolution=512, image_resolution=512, output_type=None, **kwargs):
if "img" in kwargs:
warnings.warn("img is deprecated, please use `input_image=...` instead.", DeprecationWarning, stacklevel=2)
warnings.warn("img is deprecated, please use `input_image=...` instead.", DeprecationWarning)
input_image = kwargs.pop("img")
if input_image is None:
raise ValueError("input_image must be defined.")
@@ -1,4 +1,7 @@
import random
from PIL import Image, ImageOps, ImageFilter
import torch
from torchvision import transforms
import torch.nn.functional as F
import numpy as np
+1 -1
View File
@@ -16,7 +16,7 @@ class DepthProDetector:
self.processor = processor
@classmethod
def from_pretrained(cls, pretrained_model_or_path: str = "apple/DepthPro-hf", cache_dir: str | None = None, local_files_only = False) -> "DepthProDetector":
def from_pretrained(cls, pretrained_model_or_path: str = "apple/DepthPro-hf", cache_dir: str = None, local_files_only = False) -> "DepthProDetector":
from transformers import AutoImageProcessor, DepthProForDepthEstimation
processor = AutoImageProcessor.from_pretrained(pretrained_model_or_path, cache_dir=cache_dir, local_files_only=local_files_only)
+1 -1
View File
@@ -33,7 +33,7 @@ class EdgeDetector:
params.PFmode = pf
ed.setParams(params)
if "img" in kwargs:
warnings.warn("img is deprecated, please use `input_image=...` instead.", DeprecationWarning, stacklevel=2)
warnings.warn("img is deprecated, please use `input_image=...` instead.", DeprecationWarning)
input_image = kwargs.pop("img")
if input_image is None:
raise ValueError("input_image must be defined.")
@@ -5,7 +5,7 @@ import torch.nn as nn
try:
from urllib import urlretrieve
except ImportError:
pass
from urllib.request import urlretrieve
__all__ = ['resnext101_32x8d']
@@ -1,3 +1,4 @@
import torch
import torch.nn as nn
from . import network_auxi as network
@@ -384,7 +384,7 @@ class SenceUnderstand(nn.Module):
self.initial_params()
def forward(self, x):
n, _c, h, w = x.size()
n, c, h, w = x.size()
x = self.conv1(x)
x = self.pool(x)
x = x.view(n, -1)
@@ -1,8 +1,8 @@
import argparse
import os
from ...pix2pix.util import util # noqa: TID252
from ...pix2pix.util import util
# import torch
from ...pix2pix import models # noqa: TID252
from ...pix2pix import models
# import pix2pix.data
import numpy as np
@@ -113,7 +113,7 @@ class MarigoldPipeline(DiffusionPipeline):
batch_size: int = 0,
color_map: str = "Spectral",
show_progress_bar: bool = True,
ensemble_kwargs: Dict | None = None,
ensemble_kwargs: Dict = None,
) -> MarigoldDepthOutput:
"""
Function invoked when calling the pipeline.
@@ -43,7 +43,7 @@ def ensemble_depths(
max_iter: int = 2,
tol: float = 1e-3,
reduction: str = "median",
max_res: int | None = None,
max_res: int = None,
):
"""
To ensemble multiple affine-invariant depth images (up to scale and shift),
@@ -28,6 +28,6 @@ def seed_all(seed: int = 0):
Set random seeds of all components.
"""
random.seed(seed)
np.random.seed(seed)
np.random.seed(seed) # noqa
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
+1
View File
@@ -16,6 +16,7 @@ def check_dependencies():
if not installed(pkg[1], quiet=True):
install(pkg[0], pkg[1], ignore=False)
try:
import mediapipe as mp # pylint: disable=unused-import
checked_ok = True
return True
except Exception as e:
+1
View File
@@ -2,6 +2,7 @@
import cv2
import os
import torch
import torch.nn as nn
from torchvision.transforms import Compose
@@ -5,6 +5,7 @@ from .vit import (
_make_pretrained_vitb_rn50_384,
_make_pretrained_vitl16_384,
_make_pretrained_vitb16_384,
forward_vit,
)
def _make_encoder(backbone, features, use_pretrained, groups=1, expand=False, exportable=True, hooks=None, use_vit_only=False, use_readout="ignore",):
@@ -1,8 +1,10 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
from .base_model import BaseModel
from .blocks import (
FeatureFusionBlock,
FeatureFusionBlock_custom,
Interpolate,
_make_encoder,
@@ -6,7 +6,7 @@ import torch
import torch.nn as nn
from .base_model import BaseModel
from .blocks import FeatureFusionBlock_custom, Interpolate, _make_encoder
from .blocks import FeatureFusionBlock, FeatureFusionBlock_custom, Interpolate, _make_encoder
class MidasNet_small(BaseModel):
+2 -2
View File
@@ -54,7 +54,7 @@ class Transpose(nn.Module):
def forward_vit(pretrained, x):
_b, _c, h, w = x.shape
b, c, h, w = x.shape
pretrained.model.forward_flex(x)
@@ -115,7 +115,7 @@ def _resize_pos_embed(self, posemb, gs_h, gs_w):
def forward_flex(self, x):
_b, _c, h, w = x.shape
b, c, h, w = x.shape
pos_embed = self._resize_pos_embed(
self.pos_embed, h // self.patch_size[1], w // self.patch_size[0]
+2 -2
View File
@@ -75,7 +75,7 @@ def write_pfm(path, image, scale=1):
if len(image.shape) == 3 and image.shape[2] == 3: # color image
color = True
elif (
len(image.shape) == 2 or (len(image.shape) == 3 and image.shape[2] == 1)
len(image.shape) == 2 or len(image.shape) == 3 and image.shape[2] == 1
): # greyscale
color = False
else:
@@ -86,7 +86,7 @@ def write_pfm(path, image, scale=1):
endian = image.dtype.byteorder
if endian == "<" or (endian == "=" and sys.byteorder == "little"):
if endian == "<" or endian == "=" and sys.byteorder == "little":
scale = -scale
file.write("%f\n".encode() % scale)
@@ -1,3 +1,5 @@
import os
import sys
import torch
import torch.nn as nn
import torch.utils.model_zoo as model_zoo
@@ -1,3 +1,5 @@
import os
import sys
import torch
import torch.nn as nn
import torch.utils.model_zoo as model_zoo
+4 -3
View File
@@ -9,6 +9,7 @@ Copyright 2021-present NAVER Corp.
Apache License v2.0
'''
import os
import numpy as np
import cv2
import torch
@@ -21,7 +22,7 @@ def deccode_output_score_and_ptss(tpMap, topk_n = 200, ksize = 5):
center: tpMap[1, 0, :, :]
displacement: tpMap[1, 1:5, :, :]
'''
b, _c, _h, w = tpMap.shape
b, c, h, w = tpMap.shape
assert b==1, 'only support bsize==1'
displacement = tpMap[:, 1:5, :, :][0]
center = tpMap[:, 0, :, :]
@@ -470,9 +471,9 @@ def pred_squares(image,
square[end_idx]
# check whether outside or inside
_start_position, start_min, start_cover_param, start_peri_param = check_outside_inside(start_segments,
start_position, start_min, start_cover_param, start_peri_param = check_outside_inside(start_segments,
connect_idx)
_end_position, end_min, end_cover_param, end_peri_param = check_outside_inside(end_segments, connect_idx)
end_position, end_min, end_cover_param, end_peri_param = check_outside_inside(end_segments, connect_idx)
cover += dist_segments[connect_idx] + start_cover_param * start_min + end_cover_param * end_min
perimeter += dist_segments[connect_idx] + start_peri_param * start_min + end_peri_param * end_min
+3 -3
View File
@@ -194,14 +194,14 @@ class OpenposeDetector:
def __call__(self, input_image, detect_resolution=512, image_resolution=512, include_body=True, include_hand=False, include_face=False, hand_and_face=None, output_type="pil", **kwargs):
self.to(devices.device)
if hand_and_face is not None:
warnings.warn("hand_and_face is deprecated. Use include_hand and include_face instead.", DeprecationWarning, stacklevel=2)
warnings.warn("hand_and_face is deprecated. Use include_hand and include_face instead.", DeprecationWarning)
include_hand = hand_and_face
include_face = hand_and_face
if "return_pil" in kwargs:
warnings.warn("return_pil is deprecated. Use output_type instead.", DeprecationWarning, stacklevel=2)
warnings.warn("return_pil is deprecated. Use output_type instead.", DeprecationWarning)
output_type = "pil" if kwargs["return_pil"] else "np"
if type(output_type) is bool:
warnings.warn("Passing `True` or `False` to `output_type` is deprecated and will raise an error in future versions", stacklevel=2)
warnings.warn("Passing `True` or `False` to `output_type` is deprecated and will raise an error in future versions")
if output_type:
output_type = "pil"
if not isinstance(input_image, np.ndarray):
+1 -1
View File
@@ -328,7 +328,7 @@ class Face(object):
def __call__(self, face_img):
device = next(iter(self.model.parameters())).device
H, W, _C = face_img.shape
H, W, C = face_img.shape
w_size = 384
x_data = torch.from_numpy(util.smart_resize(face_img, (w_size, w_size))).permute([2, 0, 1]) / 256.0 - 0.5
+1 -1
View File
@@ -32,7 +32,7 @@ class Hand(object):
wsize = 128
heatmap_avg = np.zeros((wsize, wsize, 22))
Hr, Wr, _Cr = oriImgRaw.shape
Hr, Wr, Cr = oriImgRaw.shape
oriImg = cv2.GaussianBlur(oriImgRaw, (0, 0), 0.8)
@@ -53,7 +53,7 @@ class SamDetector:
def __call__(self, input_image: Union[np.ndarray, Image.Image]=None, detect_resolution=512, image_resolution=512, output_type="pil", **kwargs) -> Image.Image:
if "image" in kwargs:
warnings.warn("image is deprecated, please use `input_image=...` instead.", DeprecationWarning, stacklevel=2)
warnings.warn("image is deprecated, please use `input_image=...` instead.", DeprecationWarning)
input_image = kwargs.pop("image")
if input_image is None:
raise ValueError("input_image must be defined.")
@@ -25,8 +25,8 @@ class Sam(nn.Module):
image_encoder: Union[ImageEncoderViT, TinyViT],
prompt_encoder: PromptEncoder,
mask_decoder: MaskDecoder,
pixel_mean: List[float] | None = None,
pixel_std: List[float] | None = None,
pixel_mean: List[float] = None,
pixel_std: List[float] = None,
) -> None:
"""
SAM predicts object masks from an image and input prompts.
@@ -79,7 +79,7 @@ class TwoWayTransformer(nn.Module):
torch.Tensor: the processed image_embedding
"""
# BxCxHxW -> BxHWxC == B x N_image_tokens x C
_bs, _c, _h, _w = image_embedding.shape
bs, c, h, w = image_embedding.shape
image_embedding = image_embedding.flatten(2).permute(0, 2, 1)
image_pe = image_pe.flatten(2).permute(0, 2, 1)
@@ -10,7 +10,7 @@ from torch.nn import functional as F
from typing import Tuple
from ..modeling import Sam # noqa: TID252
from ..modeling import Sam
from .amg import calculate_stability_score
+5 -5
View File
@@ -10,10 +10,10 @@ from modules.control.util import HWC3, img2mask, make_noise_disk, resize_image
class ContentShuffleDetector:
def __call__(self, input_image, h=None, w=None, f=None, detect_resolution=512, image_resolution=512, output_type="pil", **kwargs):
if "return_pil" in kwargs:
warnings.warn("return_pil is deprecated. Use output_type instead.", DeprecationWarning, stacklevel=2)
warnings.warn("return_pil is deprecated. Use output_type instead.", DeprecationWarning)
output_type = "pil" if kwargs["return_pil"] else "np"
if type(output_type) is bool:
warnings.warn("Passing `True` or `False` to `output_type` is deprecated and will raise an error in future versions", stacklevel=2)
warnings.warn("Passing `True` or `False` to `output_type` is deprecated and will raise an error in future versions")
if output_type:
output_type = "pil"
@@ -49,7 +49,7 @@ class ContentShuffleDetector:
class ColorShuffleDetector:
def __call__(self, img):
H, W, C = img.shape
F = np.random.randint(64, 384)
F = np.random.randint(64, 384) # noqa
A = make_noise_disk(H, W, 3, F)
B = make_noise_disk(H, W, 3, F)
C = (A + B) / 2.0
@@ -82,11 +82,11 @@ class DownSampleDetector:
def __call__(self, img, level=3, k=16.0):
h = img.astype(np.float32)
for _ in range(level):
h += np.random.normal(loc=0.0, scale=k, size=h.shape)
h += np.random.normal(loc=0.0, scale=k, size=h.shape) # noqa
h = cv2.pyrDown(h)
for _ in range(level):
h = cv2.pyrUp(h)
h += np.random.normal(loc=0.0, scale=k, size=h.shape)
h += np.random.normal(loc=0.0, scale=k, size=h.shape) # noqa
return h.clip(0, 255).astype(np.uint8)
@@ -66,7 +66,7 @@ def attention_forward(self, x, resolution, shared_rel_pos_bias: Optional[torch.T
"""
Modification of timm.models.beit.py: Attention.forward to support arbitrary window sizes.
"""
B, N, _C = x.shape
B, N, C = x.shape
qkv_bias = torch.cat((self.q_bias, self.k_bias, self.v_bias)) if self.q_bias is not None else None
qkv = F.linear(input=x, weight=self.qkv.weight, bias=qkv_bias)
@@ -81,7 +81,7 @@ def forward_default(pretrained, x, function_name="forward_features"):
def forward_adapted_unflatten(pretrained, x, function_name="forward_features"):
_b, _c, h, w = x.shape
b, c, h, w = x.shape
exec(f"glob = pretrained.model.{function_name}(x)")
@@ -31,7 +31,7 @@ def _resize_pos_embed(self, posemb, gs_h, gs_w):
def forward_flex(self, x):
_b, _c, h, w = x.shape
b, c, h, w = x.shape
pos_embed = self._resize_pos_embed(
self.pos_embed, h // self.patch_size[1], w // self.patch_size[0]
@@ -5,6 +5,10 @@ from .backbones.beit import (
_make_pretrained_beitl16_512,
_make_pretrained_beitl16_384,
_make_pretrained_beitb16_384,
forward_beit,
)
from .backbones.swin_common import (
forward_swin,
)
from .backbones.swin2 import (
_make_pretrained_swin2l24_384,
@@ -16,11 +20,13 @@ from .backbones.swin import (
)
from .backbones.levit import (
_make_pretrained_levit_384,
forward_levit,
)
from .backbones.vit import (
_make_pretrained_vitb_rn50_384,
_make_pretrained_vitl16_384,
_make_pretrained_vitb16_384,
forward_vit,
)
def _make_encoder(backbone, features, use_pretrained, groups=1, expand=False, exportable=True, hooks=None,
@@ -6,7 +6,7 @@ import torch
import torch.nn as nn
from .base_model import BaseModel
from .blocks import FeatureFusionBlock_custom, Interpolate, _make_encoder
from .blocks import FeatureFusionBlock, FeatureFusionBlock_custom, Interpolate, _make_encoder
class MidasNet_small(BaseModel):
@@ -100,7 +100,7 @@ class AttractorLayer(nn.Module):
A = self._net(x)
eps = 1e-3
A = A + eps
n, _c, h, w = A.shape
n, c, h, w = A.shape
A = A.view(n, self.n_attractors, 2, h, w)
A_normed = A / A.sum(dim=2, keepdim=True) # n, a, 2, h, w
A_normed = A[:, :, 0, ...] # n, na, h, w
@@ -177,7 +177,7 @@ class AttractorLayerUnnormed(nn.Module):
x = x + prev_b_embedding
A = self._net(x)
_n, _c, h, w = A.shape
n, c, h, w = A.shape
b_prev = nn.functional.interpolate(
b_prev, (h, w), mode='bilinear', align_corners=True)
@@ -146,7 +146,7 @@ class LinearSplitter(nn.Module):
S = self._net(x)
eps = 1e-3
S = S + eps
n, _c, h, w = S.shape
n, c, h, w = S.shape
S = S.view(n, self.prev_nbins, self.split_factor, h, w)
S_normed = S / S.sum(dim=2, keepdim=True) # fractional splits
@@ -26,13 +26,13 @@ import itertools
import torch
import torch.nn as nn
from ..depth_model import DepthModel # noqa: TID252
from ..base_models.midas import MidasCore # noqa: TID252
from ..layers.attractor import AttractorLayer, AttractorLayerUnnormed # noqa: TID252
from ..layers.dist_layers import ConditionalLogBinomial # noqa: TID252
from ..layers.localbins_layers import (Projector, SeedBinRegressor, # noqa: TID252
from ..depth_model import DepthModel
from ..base_models.midas import MidasCore
from ..layers.attractor import AttractorLayer, AttractorLayerUnnormed
from ..layers.dist_layers import ConditionalLogBinomial
from ..layers.localbins_layers import (Projector, SeedBinRegressor,
SeedBinRegressorUnnormed)
from ..model_io import load_state_from_resource # noqa: TID252
from ..model_io import load_state_from_resource
class ZoeDepth(DepthModel):
@@ -139,7 +139,7 @@ class ZoeDepth(DepthModel):
- probs (torch.Tensor): Output probability distribution of shape (B, n_bins, H, W). Present only if return_probs is True
"""
b, _c, h, w = x.shape
b, c, h, w = x.shape
# print("input shape ", x.shape)
self.orig_input_width = w
self.orig_input_height = h
@@ -27,14 +27,14 @@ import itertools
import torch
import torch.nn as nn
from ..depth_model import DepthModel # noqa: TID252
from ..base_models.midas import MidasCore # noqa: TID252
from ..layers.attractor import AttractorLayer, AttractorLayerUnnormed # noqa: TID252
from ..layers.dist_layers import ConditionalLogBinomial # noqa: TID252
from ..layers.localbins_layers import (Projector, SeedBinRegressor, # noqa: TID252
from ..depth_model import DepthModel
from ..base_models.midas import MidasCore
from ..layers.attractor import AttractorLayer, AttractorLayerUnnormed
from ..layers.dist_layers import ConditionalLogBinomial
from ..layers.localbins_layers import (Projector, SeedBinRegressor,
SeedBinRegressorUnnormed)
from ..layers.patch_transformer import PatchTransformerEncoder # noqa: TID252
from ..model_io import load_state_from_resource # noqa: TID252
from ..layers.patch_transformer import PatchTransformerEncoder
from ..model_io import load_state_from_resource
class ZoeDepthNK(DepthModel):
def __init__(self, core, bin_conf, bin_centers_type="softplus", bin_embedding_dim=128,
@@ -173,10 +173,10 @@ class ZoeDepthNK(DepthModel):
- "bin_centers": Bin centers of shape (B, N, H, W). Present only if return_final_centers is True
- "probs": Bin probabilities of shape (B, N, H, W). Present only if return_probs is True
"""
b, _c, h, w = x.shape
b, c, h, w = x.shape
self.orig_input_width = w
self.orig_input_height = h
_rel_depth, out = self.core(x, denorm=denorm, return_rel_depth=True)
rel_depth, out = self.core(x, denorm=denorm, return_rel_depth=True)
outconv_activation = out[0]
btlnck = out[1]
+4 -4
View File
@@ -5,7 +5,7 @@ from typing import Union
from diffusers import StableDiffusionPipeline, StableDiffusionXLPipeline, FluxPipeline, StableDiffusion3Pipeline, ControlNetModel
from modules.control.units import detect
from modules.shared import log, opts, cmd_opts, state, listdir
from modules import errors, sd_models, devices
from modules import errors, sd_models, devices, model_quant
from modules.processing import StableDiffusionProcessingControl
@@ -163,7 +163,7 @@ def find_models():
find_models()
def api_list_models(model_type: str | None = None):
def api_list_models(model_type: str = None):
import modules.shared
model_type = model_type or modules.shared.sd_model_type
model_list = []
@@ -215,7 +215,7 @@ def list_models(refresh=False):
class ControlNet():
def __init__(self, model_id: str | None = None, device = None, dtype = None, load_config = None):
def __init__(self, model_id: str = None, device = None, dtype = None, load_config = None):
self.model: ControlNetModel = None
self.model_id: str = model_id
self.device = device
@@ -311,7 +311,7 @@ class ControlNet():
self.load_config['original_config_file '] = config_path
self.model = cls.from_single_file(model_path, config=config, **self.load_config)
def load(self, model_id: str | None = None, force: bool = False) -> str:
def load(self, model_id: str = None, force: bool = False) -> str:
with load_lock:
try:
t0 = time.time()
+2 -2
View File
@@ -63,7 +63,7 @@ def list_models(refresh=False):
class ControlLLLite():
def __init__(self, model_id: str | None = None, device = None, dtype = None, load_config = None):
def __init__(self, model_id: str = None, device = None, dtype = None, load_config = None):
self.model: ControlNetLLLite = None
self.model_id: str = model_id
self.device = device
@@ -83,7 +83,7 @@ class ControlLLLite():
self.model = None
self.model_id = None
def load(self, model_id: str | None = None, force: bool = True) -> str:
def load(self, model_id: str = None, force: bool = True) -> str:
with load_lock:
try:
t0 = time.time()
+2 -2
View File
@@ -71,7 +71,7 @@ class AdapterModel(T2IAdapter):
class Adapter():
def __init__(self, model_id: str | None = None, device = None, dtype = None, load_config = None):
def __init__(self, model_id: str = None, device = None, dtype = None, load_config = None):
self.model: AdapterModel = None
self.model_id: str = model_id
self.device = device
@@ -91,7 +91,7 @@ class Adapter():
self.model = None
self.model_id = None
def load(self, model_id: str | None = None, force: bool = True) -> str:
def load(self, model_id: str = None, force: bool = True) -> str:
with load_lock:
try:
t0 = time.time()
+2 -2
View File
@@ -59,7 +59,7 @@ def list_models(refresh=False):
class ControlNetXS():
def __init__(self, model_id: str | None = None, device = None, dtype = None, load_config = None):
def __init__(self, model_id: str = None, device = None, dtype = None, load_config = None):
self.model: ControlNetXSModel = None
self.model_id: str = model_id
self.device = device
@@ -79,7 +79,7 @@ class ControlNetXS():
self.model = None
self.model_id = None
def load(self, model_id: str | None = None, time_embedding_mix: float = 0.0, force: bool = True) -> str:
def load(self, model_id: str = None, time_embedding_mix: float = 0.0, force: bool = True) -> str:
with load_lock:
try:
t0 = time.time()
+6 -6
View File
@@ -64,9 +64,9 @@ class ControlNetXSOutput(BaseOutput):
class ControlNetConditioningEmbedding(nn.Module):
"""
Quoting from https://arxiv.org/abs/2302.05543: "Stable Diffusion uses a pre-processing method similar to VQ-GAN
[11] to convert the entire dataset of 512 x 512 images into smaller 64 x 64 latent images for stabilized
training. This requires ControlNets to convert image-based conditions to 64 x 64 feature space to match the
convolution size. We use a tiny network E(·) of four convolution layers with 4 x 4 kernels and 2 x 2 strides
[11] to convert the entire dataset of 512 × 512 images into smaller 64 × 64 latent images for stabilized
training. This requires ControlNets to convert image-based conditions to 64 × 64 feature space to match the
convolution size. We use a tiny network E(·) of four convolution layers with 4 × 4 kernels and 2 × 2 strides
(activated by ReLU, channels are 16, 32, 64, 128, initialized with Gaussian weights, trained jointly with the full
model) to encode image-space conditions ... into feature maps ..."
"""
@@ -657,7 +657,7 @@ class ControlNetXSModel(ModelMixin, ConfigMixin):
if base_model.config.addition_embed_type == "text":
aug_emb = base_model.add_embedding(encoder_hidden_states)
elif base_model.config.addition_embed_type == "text_image":
raise NotImplementedError
raise NotImplementedError()
elif base_model.config.addition_embed_type == "text_time":
# SDXL - style
if "text_embeds" not in added_cond_kwargs:
@@ -676,9 +676,9 @@ class ControlNetXSModel(ModelMixin, ConfigMixin):
add_embeds = add_embeds.to(temb.dtype)
aug_emb = base_model.add_embedding(add_embeds)
elif base_model.config.addition_embed_type == "image":
raise NotImplementedError
raise NotImplementedError()
elif base_model.config.addition_embed_type == "image_hint":
raise NotImplementedError
raise NotImplementedError()
temb = temb + aug_emb if aug_emb is not None else temb
+8 -8
View File
@@ -518,8 +518,8 @@ class StableDiffusionXLControlNetXSPipeline(
)
if (
isinstance(self.controlnet, ControlNetXSModel)
or (is_compiled
and isinstance(self.controlnet._orig_mod, ControlNetXSModel))
or is_compiled
and isinstance(self.controlnet._orig_mod, ControlNetXSModel)
):
self.check_image(image, prompt, prompt_embeds)
else:
@@ -528,8 +528,8 @@ class StableDiffusionXLControlNetXSPipeline(
# Check `controlnet_conditioning_scale`
if (
isinstance(self.controlnet, ControlNetXSModel)
or (is_compiled
and isinstance(self.controlnet._orig_mod, ControlNetXSModel))
or is_compiled
and isinstance(self.controlnet._orig_mod, ControlNetXSModel)
):
if not isinstance(controlnet_conditioning_scale, float):
raise TypeError("For single controlnet: `controlnet_conditioning_scale` must be type `float`.")
@@ -1521,8 +1521,8 @@ class StableDiffusionControlNetXSPipeline(
)
if (
isinstance(self.controlnet, ControlNetXSModel)
or (is_compiled
and isinstance(self.controlnet._orig_mod, ControlNetXSModel))
or is_compiled
and isinstance(self.controlnet._orig_mod, ControlNetXSModel)
):
self.check_image(image, prompt, prompt_embeds)
else:
@@ -1531,8 +1531,8 @@ class StableDiffusionControlNetXSPipeline(
# Check `controlnet_conditioning_scale`
if (
isinstance(self.controlnet, ControlNetXSModel)
or (is_compiled
and isinstance(self.controlnet._orig_mod, ControlNetXSModel))
or is_compiled
and isinstance(self.controlnet._orig_mod, ControlNetXSModel)
):
if not isinstance(controlnet_conditioning_scale, float):
raise TypeError("For single controlnet: `controlnet_conditioning_scale` must be type `float`.")
+3 -1
View File
@@ -2,8 +2,10 @@ from __future__ import annotations
from contextlib import contextmanager
from threading import Lock
from typing import ClassVar
from typing import TYPE_CHECKING, ClassVar
if TYPE_CHECKING:
from collections.abc import Iterable
_instance_id = 0
_lock = Lock()
@@ -832,7 +832,7 @@ class HunyuanVideoTransformer3DModelPacked(ModelMixin, ConfigMixin, PeftAdapterM
clean_latents_4x=None, clean_latent_4x_indices=None
):
hidden_states = self.gradient_checkpointing_method(self.x_embedder.proj, latents)
B, _C, T, H, W = hidden_states.shape
B, C, T, H, W = hidden_states.shape
if latent_indices is None:
latent_indices = torch.arange(0, T).unsqueeze(0).expand(B, -1)
@@ -897,7 +897,7 @@ class HunyuanVideoTransformer3DModelPacked(ModelMixin, ConfigMixin, PeftAdapterM
if attention_kwargs is None:
attention_kwargs = {}
batch_size, _num_channels, num_frames, height, width = hidden_states.shape
batch_size, num_channels, num_frames, height, width = hidden_states.shape
p, p_t = self.config['patch_size'], self.config['patch_size_t']
post_patch_num_frames = num_frames // p_t
post_patch_height = height // p
+1 -1
View File
@@ -18,7 +18,7 @@ torch_linalg_solve = None
def test_solver():
from modules import devices
from modules import devices, shared
try:
a = torch.randn(50, 50).to(device=devices.device, dtype=torch.float32)
b = torch.randn(50, 2).to(device=devices.device, dtype=torch.float32)
+1 -1
View File
@@ -107,7 +107,7 @@ def make_diffusers_transformer_block(block_class: Type[torch.nn.Module]) -> Type
encoder_hidden_states: Optional[torch.FloatTensor] = None,
encoder_attention_mask: Optional[torch.FloatTensor] = None,
timestep: Optional[torch.LongTensor] = None,
cross_attention_kwargs: Dict[str, Any] | None = None,
cross_attention_kwargs: Dict[str, Any] = None,
class_labels: Optional[torch.LongTensor] = None,
added_cond_kwargs: Optional[Dict[str, torch.Tensor]] = None,
) -> torch.FloatTensor:
@@ -272,7 +272,7 @@ def make_diffusers_sdxl_contrtolnet_ppl(block_class):
@torch.no_grad()
def __call__(
self,
prompt: Union[str, List[str]] | None = None,
prompt: Union[str, List[str]] = None,
prompt_2: Optional[Union[str, List[str]]] = None,
image: PipelineImageInput = None,
control_image: PipelineImageInput = None,
@@ -298,9 +298,9 @@ def make_diffusers_sdxl_contrtolnet_ppl(block_class):
guess_mode: bool = False,
control_guidance_start: Union[float, List[float]] = 0.0,
control_guidance_end: Union[float, List[float]] = 1.0,
original_size: Tuple[int, int] | None = None,
original_size: Tuple[int, int] = None,
crops_coords_top_left: Tuple[int, int] = (0, 0),
target_size: Tuple[int, int] | None = None,
target_size: Tuple[int, int] = None,
negative_original_size: Optional[Tuple[int, int]] = None,
negative_crops_coords_top_left: Tuple[int, int] = (0, 0),
negative_target_size: Optional[Tuple[int, int]] = None,
+6 -6
View File
@@ -6,21 +6,21 @@ from modules.image.grid import Grid, image_grid, check_grid_size, get_grid_size,
from modules.image.util import draw_text, flatten
__all__ = [
'FilenameGenerator',
'Grid',
'check_grid_size',
'combine_grid',
'draw_grid_annotations',
'draw_prompt_matrix',
'draw_text',
'flatten',
'get_font',
'FilenameGenerator',
'get_grid_size',
'get_next_sequence_number',
'Grid',
'image_data',
'image_grid',
'read_info_from_image',
'resize_image',
'sanitize_filename_part',
'save_image',
'get_font',
'get_next_sequence_number',
'draw_text',
'flatten',
]
+1 -1
View File
@@ -50,7 +50,7 @@ def hidream_rope(pos: torch.Tensor, dim: int, theta: int) -> torch.Tensor:
scale = torch.arange(0, dim, 2, dtype=torch.float64, device=pos.device) / dim
omega = 1.0 / (theta**scale)
batch_size, _seq_length = pos.shape
batch_size, seq_length = pos.shape
out = torch.einsum("...n,d->...nd", pos, omega)
cos_out = torch.cos(out)
sin_out = torch.sin(out)
+1 -1
View File
@@ -52,7 +52,7 @@ def autocast_init(self, device_type=None, dtype=None, enabled=True, cache_enable
original_grad_scaler_init = torch.amp.grad_scaler.GradScaler.__init__
@wraps(torch.amp.grad_scaler.GradScaler.__init__)
def GradScaler_init(self, device: str | None = None, init_scale: float = 2.0**16, growth_factor: float = 2.0, backoff_factor: float = 0.5, growth_interval: int = 2000, enabled: bool = True):
def GradScaler_init(self, device: str = None, init_scale: float = 2.0**16, growth_factor: float = 2.0, backoff_factor: float = 0.5, growth_interval: int = 2000, enabled: bool = True):
if device is None or check_cuda(device):
return original_grad_scaler_init(self, device=return_xpu(device), init_scale=init_scale, growth_factor=growth_factor, backoff_factor=backoff_factor, growth_interval=growth_interval, enabled=enabled)
else:
+5 -2
View File
@@ -75,7 +75,7 @@ except Exception:
pass
try:
pass # pylint: disable=unused-import,ungrouped-imports
import torch.distributed.distributed_c10d as _c10d # pylint: disable=unused-import,ungrouped-imports
except Exception:
log.warning('Loader: torch is not built with distributed support')
@@ -96,6 +96,7 @@ warnings.filterwarnings(action="ignore", category=UserWarning, module="torchvisi
torchvision = None
try:
import torchvision # pylint: disable=W0611,C0411
import pytorch_lightning # pytorch_lightning should be imported after torch, but it re-enables warnings on import so import once to disable them # pylint: disable=W0611,C0411
except Exception as e:
report(f'torchvision=={torchvision.__version__ if torchvision is not None else None}', e)
@@ -126,6 +127,7 @@ if ".dev" in torch.__version__ or "+git" in torch.__version__:
timer.startup.record("torch")
try:
import bitsandbytes # pylint: disable=unused-import
_bnb = True
except Exception:
_bnb = False
@@ -209,9 +211,10 @@ except Exception as e:
sys.exit(1)
try:
pass # pylint: disable=W0611,C0411
import pillow_jxl # pylint: disable=W0611,C0411
except Exception:
pass
from PIL import Image # pylint: disable=W0611,C0411
timer.startup.record("pillow")
+2 -2
View File
@@ -354,7 +354,7 @@ def network_load(names, te_multipliers=None, unet_multipliers=None, dyn_dims=Non
sd_model.set_adapters(adapter_names=lora_diffusers.diffuser_loaded, adapter_weights=lora_diffusers.diffuser_scales)
except Exception as e:
if str(e) not in exclude_errors:
log.error(f'Network load: type=LoRA action=strength {e!s}')
log.error(f'Network load: type=LoRA action=strength {str(e)}')
if l.debug:
errors.display(e, 'LoRA')
try:
@@ -363,7 +363,7 @@ def network_load(names, te_multipliers=None, unet_multipliers=None, dyn_dims=Non
sd_model.unload_lora_weights()
l.timer.activate += time.time() - t1
except Exception as e:
log.error(f'Network load: type=LoRA action=fuse {e!s}')
log.error(f'Network load: type=LoRA action=fuse {str(e)}')
if l.debug:
errors.display(e, 'LoRA')
shared.sd_model = sd_models.apply_balanced_offload(shared.sd_model, force=True, silent=True) # some layers may end up on cpu without hook
+1 -1
View File
@@ -149,7 +149,7 @@ def run_ltx(task_id,
extra_networks.deactivate(p)
shared.state.end()
progress.finish_task(task_id)
yield None, f'LTX Error: {e!s}'
yield None, f'LTX Error: {str(e)}'
if model is None or len(model) == 0 or model == 'None':
yield from abort('Video: no model selected', ok=True)
+8 -8
View File
@@ -4,18 +4,18 @@ import torch
from torch import Tensor
__all__ = [
"weighted_sum",
"weighted_subtraction",
"tensor_sum",
"add_difference",
"distribution_crossover",
"sum_twice",
"triple_sum",
"euclidean_add_difference",
"multiply_difference",
"similarity_add_difference",
"sum_twice",
"tensor_sum",
"ties_add_difference",
"top_k_tensor_sum",
"triple_sum",
"weighted_subtraction",
"weighted_sum",
"similarity_add_difference",
"distribution_crossover",
"ties_add_difference",
]
+1 -1
View File
@@ -96,7 +96,7 @@ def get_provider() -> tuple:
def install_execution_provider(ep: ExecutionProvider):
import importlib # pylint: disable=deprecated-module
from installer import install, uninstall
from installer import installed, install, uninstall
res = "<br><pre>"
res += uninstall(["onnxruntime", "onnxruntime-directml", "onnxruntime-gpu", "onnxruntime-training", "onnxruntime-openvino"], quiet=True)
packages = ["onnxruntime"] # Failed to load olive: cannot import name '__version__' from 'onnxruntime'
+2 -2
View File
@@ -238,7 +238,7 @@ class SwinTransformerBlock(nn.Module):
def forward(self, x, x_size):
H, W = x_size
B, _L, C = x.shape
B, L, C = x.shape
# assert L == H * W, "input feature has wrong size"
shortcut = x
@@ -559,7 +559,7 @@ class PatchUnEmbed(nn.Module):
self.embed_dim = embed_dim
def forward(self, x, x_size):
B, _HW, _C = x.shape
B, HW, C = x.shape
x = x.transpose(1, 2).view(B, self.embed_dim, x_size[0], x_size[1]) # B Ph*Pw C
return x
+3 -3
View File
@@ -266,7 +266,7 @@ class SwinTransformerBlock(nn.Module):
def forward(self, x, x_size):
H, W = x_size
B, _L, C = x.shape
B, L, C = x.shape
#assert L == H * W, "input feature has wrong size"
shortcut = x
@@ -476,7 +476,7 @@ class PatchEmbed(nn.Module):
self.norm = None
def forward(self, x):
_B, _C, _H, _W = x.shape
B, C, H, W = x.shape
# FIXME look at relaxing size constraints
# assert H == self.img_size[0] and W == self.img_size[1],
# f"Input image size ({H}*{W}) doesn't match model ({self.img_size[0]}*{self.img_size[1]})."
@@ -591,7 +591,7 @@ class PatchUnEmbed(nn.Module):
self.embed_dim = embed_dim
def forward(self, x, x_size):
B, _HW, _C = x.shape
B, HW, C = x.shape
x = x.transpose(1, 2).view(B, self.embed_dim, x_size[0], x_size[1]) # B Ph*Pw C
return x
+4
View File
@@ -8,6 +8,10 @@ from modules.logger import log
from modules.sd_hijack_hypertile import context_hypertile_vae, context_hypertile_unet
from modules.processing_class import ( # pylint: disable=unused-import
StableDiffusionProcessing,
StableDiffusionProcessingTxt2Img,
StableDiffusionProcessingImg2Img,
StableDiffusionProcessingVideo,
StableDiffusionProcessingControl,
)
from modules.processing_info import create_infotext
+1 -1
View File
@@ -19,7 +19,7 @@ def apply(pipe, p: processing.StableDiffusionProcessing):
MANAGER.width = p.width
MANAGER.height = p.height
MANAGER.error_reset_steps = [int(1*p.steps/3), int(2*p.steps/3)]
log.info(f'RAS: scheduler={pipe.scheduler.__class__.__name__} {MANAGER!s}')
log.info(f'RAS: scheduler={pipe.scheduler.__class__.__name__} {str(MANAGER)}')
MANAGER.reset_cache()
MANAGER.generate_skip_token_list()
pipe.transformer.old_forward = pipe.transformer.forward
+1 -1
View File
@@ -304,7 +304,7 @@ class RESUnifiedScheduler(SchedulerMixin, ConfigMixin):
return SchedulerOutput(prev_sample=x_next)
# GET COEFFICIENTS
b, _h_val = self._get_coefficients(sigma, sigma_next)
b, h_val = self._get_coefficients(sigma, sigma_next)
if len(b) == 1:
res = b[0] * x0
+8 -7
View File
@@ -126,7 +126,7 @@ class DCSolverMultistepScheduler(SchedulerMixin, ConfigMixin):
Any other scheduler that if specified, the algorithm becomes `solver_p + UniC`.
use_karras_sigmas (`bool`, *optional*, defaults to `False`):
Whether to use Karras sigmas for step sizes in the noise schedule during the sampling process. If `True`,
the sigmas are determined according to a sequence of noise levels {sigma_i}.
the sigmas are determined according to a sequence of noise levels {σi}.
timestep_spacing (`str`, defaults to `"linspace"`):
The way the timesteps should be scaled. Refer to Table 2 of the [Common Diffusion Noise Schedules and
Sample Steps are Flawed](https://huggingface.co/papers/2305.08891) for more information.
@@ -449,7 +449,7 @@ class DCSolverMultistepScheduler(SchedulerMixin, ConfigMixin):
model_output: torch.FloatTensor = None,
*args,
sample: torch.FloatTensor = None,
order: int | None = None,
order: int = None,
**kwargs,
) -> torch.FloatTensor:
"""
@@ -488,12 +488,13 @@ class DCSolverMultistepScheduler(SchedulerMixin, ConfigMixin):
)
model_output_list = self.model_outputs
s0 = self.timestep_list[-1]
m0 = model_output_list[-1]
assert m0 is not None
x = sample
if self.solver_p:
raise NotImplementedError
raise NotImplementedError()
sigma_t, sigma_s0 = self.sigmas[self.step_index + 1], self.sigmas[self.step_index]
alpha_t, sigma_t = self._sigma_to_alpha_sigma_t(sigma_t)
@@ -533,7 +534,7 @@ class DCSolverMultistepScheduler(SchedulerMixin, ConfigMixin):
elif self.config.solver_type == "bh2":
B_h = torch.expm1(hh)
else:
raise NotImplementedError
raise NotImplementedError()
for i in range(1, order + 1):
R.append(torch.pow(rks, i - 1))
@@ -578,7 +579,7 @@ class DCSolverMultistepScheduler(SchedulerMixin, ConfigMixin):
*args,
last_sample: torch.FloatTensor = None,
this_sample: torch.FloatTensor = None,
order: int | None = None,
order: int = None,
**kwargs,
) -> torch.FloatTensor:
"""
@@ -668,7 +669,7 @@ class DCSolverMultistepScheduler(SchedulerMixin, ConfigMixin):
elif self.config.solver_type == "bh2":
B_h = torch.expm1(hh)
else:
raise NotImplementedError
raise NotImplementedError()
for i in range(1, order + 1):
R.append(torch.pow(rks, i - 1))
@@ -810,7 +811,7 @@ class DCSolverMultistepScheduler(SchedulerMixin, ConfigMixin):
return loss
optimizer = torch.optim.AdamW([ratio_param], lr=0.1)
for _ in range(self.num_iters):
for iter_ in range(self.num_iters):
optimizer.zero_grad()
loss = closure(ratio_param)
loss.backward()
@@ -170,7 +170,7 @@ class FlowMatchDPMSolverMultistepScheduler(SchedulerMixin, ConfigMixin):
from installer import install
install('torchsde==0.2.6', 'torchsde', quiet=True)
try:
pass
import torchsde
except Exception as e:
raise ImportError("Failed to import torchsde. Please make sure it is installed correctly.") from e
@@ -234,7 +234,7 @@ class FlowMatchDPMSolverMultistepScheduler(SchedulerMixin, ConfigMixin):
return math.exp(mu) / (math.exp(mu) + (1 / t - 1) ** sigma)
def set_timesteps(self,
num_inference_steps: int | None = None,
num_inference_steps: int = None,
device: Union[str, torch.device] = None,
sigmas: Optional[List[float]] = None,
mu: Optional[float] = None,
+1 -1
View File
@@ -395,7 +395,7 @@ class TDDScheduler(DPMSolverSinglestepScheduler):
model_output_list: List[torch.FloatTensor],
*args,
sample: torch.FloatTensor = None,
order: int | None = None,
order: int = None,
**kwargs,
) -> torch.FloatTensor:
timestep_list = args[0] if len(args) > 0 else kwargs.pop("timestep_list", None)
@@ -54,7 +54,7 @@ class FlowUniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
Any other scheduler that if specified, the algorithm becomes `solver_p + UniC`.
use_karras_sigmas (`bool`, *optional*, defaults to `False`):
Whether to use Karras sigmas for step sizes in the noise schedule during the sampling process. If `True`,
the sigmas are determined according to a sequence of noise levels {sigma_i}.
the sigmas are determined according to a sequence of noise levels {σi}.
use_exponential_sigmas (`bool`, *optional*, defaults to `False`):
Whether to use exponential sigmas for step sizes in the noise schedule during the sampling process.
timestep_spacing (`str`, defaults to `"linspace"`):
@@ -311,7 +311,7 @@ class FlowUniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
)
sigma = self.sigmas[self.step_index]
_alpha_t, sigma_t = self._sigma_to_alpha_sigma_t(sigma)
alpha_t, sigma_t = self._sigma_to_alpha_sigma_t(sigma)
if self.predict_x0:
if self.config.prediction_type == "flow_prediction":
@@ -350,7 +350,7 @@ class FlowUniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
model_output: torch.Tensor,
*args,
sample: torch.Tensor = None,
order: int | None = None, # pyright: ignore
order: int = None, # pyright: ignore
**kwargs,
) -> torch.Tensor:
"""
@@ -439,7 +439,7 @@ class FlowUniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
elif self.config.solver_type == "bh2":
B_h = torch.expm1(hh)
else:
raise NotImplementedError
raise NotImplementedError()
for i in range(1, order + 1):
R.append(torch.pow(rks, i - 1))
@@ -487,7 +487,7 @@ class FlowUniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
*args,
last_sample: torch.Tensor = None,
this_sample: torch.Tensor = None,
order: int | None = None, # pyright: ignore
order: int = None, # pyright: ignore
**kwargs,
) -> torch.Tensor:
"""
@@ -582,7 +582,7 @@ class FlowUniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
elif self.config.solver_type == "bh2":
B_h = torch.expm1(hh)
else:
raise NotImplementedError
raise NotImplementedError()
for i in range(1, order + 1):
R.append(torch.pow(rks, i - 1))
+3 -2
View File
@@ -15,9 +15,9 @@ from modules import timer, paths, shared, shared_items, modelloader, devices, sc
from modules.memstats import memory_stats
from modules.shared_helpers import walk_files
from modules.modeldata import model_data
from modules.sd_checkpoint import CheckpointInfo, select_checkpoint, list_models, checkpoint_titles, get_closest_checkpoint_match # pylint: disable=unused-import
from modules.sd_checkpoint import CheckpointInfo, select_checkpoint, list_models, checkpoint_titles, get_closest_checkpoint_match, update_model_hashes, write_metadata, checkpoints_list # pylint: disable=unused-import
from modules.sd_offload import get_module_names, disable_offload, set_diffuser_offload, apply_balanced_offload, set_accelerate # pylint: disable=unused-import
from modules.sd_models_utils import NoWatermark, get_signature, path_to_repo, apply_function_to_model # pylint: disable=unused-import
from modules.sd_models_utils import NoWatermark, get_signature, get_call, path_to_repo, apply_function_to_model, read_state_dict, get_state_dict_from_checkpoint # pylint: disable=unused-import
model_dir = "Stable-diffusion"
@@ -331,6 +331,7 @@ def load_diffuser_initial(diffusers_load_config, op='model'):
def load_diffuser_force(detected_model_type, checkpoint_info, diffusers_load_config, op='model'):
from modules import sdnq # pylint: disable=unused-import
sd_model = None
global allow_post_quant # pylint: disable=global-statement
unload_model_weights(op=op)
+1 -1
View File
@@ -28,7 +28,7 @@ class SDNQLayer(torch.nn.Module):
return self.forward_func(self, *args, **kwargs)
def __repr__(self):
return f"{self.__class__.__name__}(original_class={self.original_class} forward_func={self.forward_func} sdnq_dequantizer={getattr(self, 'sdnq_dequantizer', None)!r})"
return f"{self.__class__.__name__}(original_class={self.original_class} forward_func={self.forward_func} sdnq_dequantizer={repr(getattr(self, 'sdnq_dequantizer', None))})"
class SDNQLinear(SDNQLayer, torch.nn.Linear):
+1 -1
View File
@@ -2,8 +2,8 @@ import torch
from PIL import Image
from torch import Tensor
from torch.nn import functional as F
from ..common.half_precision_fixes import safe_pad_operation, safe_interpolate_operation
from torchvision.transforms import ToTensor, ToPILImage
from modules.seedvr.src.common.half_precision_fixes import safe_pad_operation, safe_interpolate_operation
def adain_color_fix(target: Image.Image, source: Image.Image):
# Convert images to tensors
+8 -2
View File
@@ -15,17 +15,21 @@ log.debug('Initializing: shared module')
import modules.memmon
import modules.paths as paths
from modules.json_helpers import readfile # pylint: disable=W0611
from modules.shared_helpers import listdir # pylint: disable=W0611
from modules import errors, devices, shared_state, cmd_args, history, files_cache # pylint: disable=unused-import
from modules.shared_helpers import listdir, req # pylint: disable=W0611
from modules import errors, devices, shared_state, cmd_args, theme, history, files_cache # pylint: disable=unused-import
from modules.shared_defaults import get_default_modes
from modules.memstats import memory_stats # pylint: disable=unused-import
log.debug('Initializing: pipelines')
from modules import shared_items # pylint: disable=unused-import
from modules.caption.openclip import get_clip_models, refresh_clip_models # pylint: disable=unused-import
from modules.caption.vqa import vlm_models, vlm_prompts, vlm_system, vlm_default # pylint: disable=unused-import
if TYPE_CHECKING:
# Behavior modified by __future__.annotations
from diffusers import DiffusionPipeline
from modules.shared_legacy import LegacyOption
from modules.ui_extra_networks import ExtraNetworksPage
@@ -77,6 +81,7 @@ data_path = paths.data_path
backend = Backend.DIFFUSERS
if cmd_opts.use_openvino: # override for openvino
os.environ.setdefault('PYTORCH_TRACING_MODE', 'TORCHFX')
from modules.intel.openvino import get_device_list as get_openvino_device_list # pylint: disable=ungrouped-imports,unused-import
elif cmd_opts.use_ipex or devices.has_xpu():
from modules.intel.ipex import ipex_init
ok, e = ipex_init()
@@ -152,6 +157,7 @@ startup_offload_mode, startup_offload_min_gpu, startup_offload_max_gpu, startup_
log.debug('Initializing: settings')
from modules import ui_definitions
from modules.ui_definitions import OptionInfo, options_section # pylint: disable=unused-import
options_templates = ui_definitions.create_settings(cmd_opts)
from modules.shared_legacy import get_legacy_options
options_templates.update(get_legacy_options())
+1 -1
View File
@@ -131,7 +131,7 @@ def apply_srgb(
flags=flags
)
else:
img = cast('Image', profileToProfile(
img = cast(Image, profileToProfile(
img,
profile,
_SRGB,
+1 -1
View File
@@ -1,6 +1,6 @@
from typing import Any, Dict, List, Optional, Tuple
from diffusers.models.modeling_outputs import Transformer2DModelOutput
from diffusers.utils import deprecate, USE_PEFT_BACKEND, logging, scale_lora_layers, unscale_lora_layers
from diffusers.utils import logging, deprecate, USE_PEFT_BACKEND, logging, scale_lora_layers, unscale_lora_layers
import torch
import numpy as np
+1 -1
View File
@@ -222,7 +222,7 @@ def create_ui(gr_status, gr_file):
if param.name == 'self' or param.name == 'args' or param.name == 'kwargs':
continue
component = Component(param)
debug_log(f'Model component: {component!s}')
debug_log(f'Model component: {str(component)}')
components.append(component)
return components
+1 -1
View File
@@ -6,7 +6,7 @@ import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
from PIL import Image
from installer import install
from installer import install, reload
from modules.logger import log
+1
View File
@@ -30,6 +30,7 @@ def load_custom(model_name: str):
def load_model(selected: models_def.Model):
from modules import sdnq # pylint: disable=unused-import
if selected is None or selected.repo is None:
return ''
global loaded_model # pylint: disable=global-statement
+1 -1
View File
@@ -64,7 +64,7 @@ def run_video(*args):
selected = get_selected(engine, model)
if not selected or engine is None or model is None or engine == 'None' or model == 'None':
return video_utils.queue_err('model not selected')
debug(f'Video run: {selected!s}')
debug(f'Video run: {str(selected)}')
if selected and 'Hunyuan' in selected.name:
return video_run.generate(*args)
elif selected and 'LTX' in selected.name: