Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
Vladimir Mandic
2025-10-11 18:51:07 -04:00
parent eaa7dc119b
commit 8d36a5aebb
9 changed files with 40 additions and 45 deletions
+2 -2
View File
@@ -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
+4 -4
View File
@@ -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)
"""
-1
View File
@@ -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)
+4 -4
View File
@@ -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'
]
]
'''
+12 -12
View File
@@ -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
@@ -90,4 +90,3 @@ class FlashAttentionVarlen(nn.Module):
return flash_attn_varlen_func(*args, **kwargs)
except ImportError:
return pytorch_varlen_attention(*args, **kwargs)
@@ -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
"""
+15 -18
View File
@@ -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