From 8d36a5aebb5fdf8db71982b4d584cebd4dfbb744 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sat, 11 Oct 2025 18:51:07 -0400 Subject: [PATCH] lint Signed-off-by: Vladimir Mandic --- modules/sd_detect.py | 2 +- modules/seedvr/src/__init__.py | 4 +-- modules/seedvr/src/common/config.py | 8 ++--- modules/seedvr/src/common/seed.py | 1 - modules/seedvr/src/core/__init__.py | 8 ++--- modules/seedvr/src/core/generation.py | 24 +++++++------- modules/seedvr/src/models/dit_v2/attention.py | 1 - .../seedvr/src/optimization/memory_manager.py | 4 +-- .../seedvr/src/optimization/performance.py | 33 +++++++++---------- 9 files changed, 40 insertions(+), 45 deletions(-) diff --git a/modules/sd_detect.py b/modules/sd_detect.py index 9996537c1..0b2d3d19c 100644 --- a/modules/sd_detect.py +++ b/modules/sd_detect.py @@ -146,7 +146,7 @@ def guess_by_diffusers(fn, current_guess): if folder.endswith('quantization_config.json'): is_quant = True break - elif os.path.isdir(folder): + if os.path.isdir(folder): for f in os.listdir(folder): if f.endswith('quantization_config.json'): is_quant = True diff --git a/modules/seedvr/src/__init__.py b/modules/seedvr/src/__init__.py index ebff00ffb..a374bbd24 100644 --- a/modules/seedvr/src/__init__.py +++ b/modules/seedvr/src/__init__.py @@ -7,7 +7,7 @@ Version: 2.0.0 - Modular Available Modules: - utils: Download and path utilities -- optimization: Memory, performance, and compatibility optimizations +- optimization: Memory, performance, and compatibility optimizations - core: Model management and generation pipeline (NEW) - processing: Video and tensor processing (coming next) - interfaces: ComfyUI integration @@ -17,7 +17,7 @@ Available Modules: MODULES_AVAILABLE = { 'downloads': True, # ✅ Module 1 - Downloads and model management 'memory_manager': True, # ✅ Module 2 - Memory optimization - 'performance': True, # ✅ Module 3 - Performance optimizations + 'performance': True, # ✅ Module 3 - Performance optimizations 'compatibility': True, # ✅ Module 4 - FP8/FP16 compatibility 'model_manager': True, # ✅ Module 5 - Model configuration and loading 'generation': True, # ✅ Module 6 - Generation loop and inference diff --git a/modules/seedvr/src/common/config.py b/modules/seedvr/src/common/config.py index 3667b4d2b..653685ccd 100644 --- a/modules/seedvr/src/common/config.py +++ b/modules/seedvr/src/common/config.py @@ -71,15 +71,15 @@ def resolve_inheritance(config: Union[DictConfig, ListConfig]) -> Any: def import_item(path: Union[str, List[str]], name: str) -> Any: """ Import a python item with fallback support. - + Args: path: Single path string or list of paths to try (fallback order) name: Class/function name to import - + Returns: Imported object - - Example: + + Example: import_item("path.to.file", "MyClass") -> MyClass import_item(["path1.to.file", "path2.to.file"], "MyClass") -> MyClass (first working path) """ diff --git a/modules/seedvr/src/common/seed.py b/modules/seedvr/src/common/seed.py index f00e33db6..f3e77f2bf 100644 --- a/modules/seedvr/src/common/seed.py +++ b/modules/seedvr/src/common/seed.py @@ -27,4 +27,3 @@ def set_seed(seed: Optional[int], same_across_ranks: bool = False): random.seed(seed) np.random.seed(seed) torch.manual_seed(seed) - diff --git a/modules/seedvr/src/core/__init__.py b/modules/seedvr/src/core/__init__.py index 271ba39b8..e284d32ed 100644 --- a/modules/seedvr/src/core/__init__.py +++ b/modules/seedvr/src/core/__init__.py @@ -29,13 +29,13 @@ from .infer import VideoDiffusionInfer __all__ = [ # Model management 'configure_runner', - 'load_quantized_state_dict', + 'load_quantized_state_dict', 'configure_dit_model_inference', 'configure_vae_model_inference', - + # Generation logic 'generation_step', - 'generation_loop', + 'generation_loop', 'cut_videos', 'prepare_video_transforms', 'load_text_embeddings', @@ -43,5 +43,5 @@ __all__ = [ # Infer 'VideoDiffusionInfer' -] +] ''' diff --git a/modules/seedvr/src/core/generation.py b/modules/seedvr/src/core/generation.py index daac4020f..5f871cfe7 100644 --- a/modules/seedvr/src/core/generation.py +++ b/modules/seedvr/src/core/generation.py @@ -12,16 +12,16 @@ from src.utils.color_fix import wavelet_reconstruction def generation_step(runner, text_embeds_dict, cond_latents, temporal_overlap, device): """ Execute a single generation step with adaptive dtype handling - + Args: runner: VideoDiffusionInfer instance text_embeds_dict (dict): Text embeddings for positive and negative prompts cond_latents (list): Conditional latents for generation temporal_overlap (int): Number of frames for temporal overlap - + Returns: tuple: (samples, last_latents) for potential temporal continuation - + Features: - Adaptive dtype detection (FP8/FP16/BFloat16) - Optimal autocast configuration for each model type @@ -111,7 +111,7 @@ def cut_videos(videos): def generation_loop(runner, images, cfg_scale=1.0, seed=666, res_w=720, batch_size=90, temporal_overlap=0, progress_callback=None, device:str='cpu'): """ Main generation loop with context-aware temporal processing - + Args: runner: VideoDiffusionInfer instance images (torch.Tensor): Input images for upscaling @@ -121,10 +121,10 @@ def generation_loop(runner, images, cfg_scale=1.0, seed=666, res_w=720, batch_si batch_size (int): Batch size for processing temporal_overlap (int): Frames for temporal continuity progress_callback (callable): Optional callback for progress reporting - + Returns: torch.Tensor: Generated video frames - + Features: - Context-aware generation with temporal overlap - Adaptive dtype pipeline (FP8/FP16/BFloat16) @@ -300,13 +300,13 @@ def generation_loop(runner, images, cfg_scale=1.0, seed=666, res_w=720, batch_si def prepare_video_transforms(res_w): """ Prepare optimized video transformation pipeline - + Args: res_w (int): Target resolution width - + Returns: Compose: Configured transformation pipeline - + Features: - Resolution-aware upscaling (no downsampling) - Proper normalization for model compatibility @@ -328,15 +328,15 @@ def prepare_video_transforms(res_w): def calculate_optimal_batch_params(total_frames, batch_size, temporal_overlap): """ Calculate optimal batch processing parameters - + Args: total_frames (int): Total number of frames batch_size (int): Desired batch size temporal_overlap (int): Temporal overlap frames - + Returns: dict: Optimized parameters and recommendations - + Features: - 4n+1 constraint optimization - Padding waste calculation diff --git a/modules/seedvr/src/models/dit_v2/attention.py b/modules/seedvr/src/models/dit_v2/attention.py index 5a93ba30a..a88fd7d13 100644 --- a/modules/seedvr/src/models/dit_v2/attention.py +++ b/modules/seedvr/src/models/dit_v2/attention.py @@ -90,4 +90,3 @@ class FlashAttentionVarlen(nn.Module): return flash_attn_varlen_func(*args, **kwargs) except ImportError: return pytorch_varlen_attention(*args, **kwargs) - diff --git a/modules/seedvr/src/optimization/memory_manager.py b/modules/seedvr/src/optimization/memory_manager.py index 47bc52101..3be323f67 100644 --- a/modules/seedvr/src/optimization/memory_manager.py +++ b/modules/seedvr/src/optimization/memory_manager.py @@ -16,7 +16,7 @@ from src.models.dit_v2.rope import RotaryEmbeddingBase def preinitialize_rope_cache(runner) -> None: """ 🚀 Pre-initialize RoPE cache to avoid OOM at first launch - + Args: runner: The model runner containing DiT and VAE models """ @@ -93,7 +93,7 @@ def preinitialize_rope_cache(runner) -> None: def clear_rope_cache(runner) -> None: """ 🧹 Clear RoPE cache to free VRAM - + Args: runner: The model runner containing the cache """ diff --git a/modules/seedvr/src/optimization/performance.py b/modules/seedvr/src/optimization/performance.py index 73a95fe4d..83cba0462 100644 --- a/modules/seedvr/src/optimization/performance.py +++ b/modules/seedvr/src/optimization/performance.py @@ -13,16 +13,16 @@ def optimized_video_rearrange(video_tensors: List[torch.Tensor]) -> List[torch.T """ 🚀 OPTIMIZED version of video rearrangement Replaces slow loops with vectorized operations - + Transforms: - - 3D: c h w -> t c h w (with t=1) + - 3D: c h w -> t c h w (with t=1) - 4D: c t h w -> t c h w - + Expected gains: 5-10x faster than naive loops - + Args: video_tensors: List of video tensors to rearrange - + Returns: List of rearranged tensors in t c h w format """ @@ -81,16 +81,16 @@ def optimized_single_video_rearrange(video: torch.Tensor) -> torch.Tensor: """ 🚀 OPTIMIZED version for single video tensor Replaces rearrange() with native PyTorch operations - + Transforms: - 3D: c h w -> 1 c h w (add temporal dimension) - 4D: c t h w -> t c h w (permute dimensions) - + Expected gains: 2-5x faster than rearrange() - + Args: video: Input video tensor - + Returns: Rearranged tensor with temporal dimension first """ @@ -106,16 +106,16 @@ def optimized_sample_to_image_format(sample: torch.Tensor) -> torch.Tensor: """ 🚀 OPTIMIZED version to convert sample to image format Replaces rearrange() with native PyTorch operations - + Transforms: - 3D: c h w -> 1 h w c (add temporal dimension + permute to image format) - 4D: t c h w -> t h w c (permute to image format) - + Expected gains: 2-5x faster than rearrange() - + Args: sample: Input sample tensor - + Returns: Tensor in image format (channels last) """ @@ -130,12 +130,12 @@ def optimized_sample_to_image_format(sample: torch.Tensor) -> torch.Tensor: def temporal_latent_blending(latents1: torch.Tensor, latents2: torch.Tensor, blend_frames: int) -> torch.Tensor: """ 🎨 Temporal blending in latent space to avoid discontinuities - + Args: latents1: Latents from previous batch (end frames) latents2: Latents from current batch (start frames) blend_frames: Number of frames to blend - + Returns: Blended latents for smooth transition """ @@ -155,6 +155,3 @@ def temporal_latent_blending(latents1: torch.Tensor, latents2: torch.Tensor, ble blended_latents = weights1 * latents1 + weights2 * latents2 return blended_latents - - -