FILE sources/0241/repo/configs/wan2.1/wan_civitai.yaml
SHA256 21fe4409b664385a1c1cc5c23d92506ffb05ef3c374a18de9df67b715dca07e9
LINES 1-25
    1  format: civitai
    2  pipeline: Wan
    3  transformer_additional_kwargs:
    4    transformer_subpath: ./
    5    dict_mapping:
    6      in_dim: in_channels
    7      dim: hidden_size
    8  
    9  vae_kwargs:
   10    vae_subpath: Wan2.1_VAE.pth
   11    temporal_compression_ratio: 4
   12    spatial_compression_ratio: 8
   13  
   14  text_encoder_kwargs:
   15    text_encoder_subpath: models_t5_umt5-xxl-enc-bf16.pth
   16    tokenizer_subpath: google/umt5-xxl
   17    text_length: 512
   18    vocab: 256384
   19    dim: 4096
   20    dim_attn: 4096
   21    dim_ffn: 10240
   22    num_heads: 64
   23    num_layers: 24
   24    num_buckets: 32
   25    shared_pos: False

FILE sources/0241/repo/rose/models/wan_vae.py
SHA256 2568f0d045289e3f6a0a367fec59285ea99831ba30fdb33505f321d21ffd33cc
LINES 615-640
  615  
  616      return model
  617  
  618  
  619  class AutoencoderKLWan(ModelMixin, ConfigMixin, FromOriginalModelMixin):
  620  
  621      @register_to_config
  622      def __init__(
  623          self,
  624          latent_channels=16,
  625          temporal_compression_ratio=4,
  626          spacial_compression_ratio=8
  627      ):
  628          super().__init__()
  629          mean = [
  630              -0.7571, -0.7089, -0.9113, 0.1075, -0.1745, 0.9653, -0.1517, 1.5508,
  631              0.4134, -0.0715, 0.5517, -0.3632, -0.1922, -0.9497, 0.2503, -0.2921
  632          ]
  633          std = [
  634              2.8184, 1.4541, 2.3275, 2.6558, 1.2196, 1.7708, 2.6052, 2.0743,
  635              3.2687, 2.1526, 2.8652, 1.5579, 1.6382, 1.1253, 2.8251, 1.9160
  636          ]
  637          self.mean = torch.tensor(mean, dtype=torch.float32)
  638          self.std = torch.tensor(std, dtype=torch.float32)
  639          self.scale = [self.mean, 1.0 / self.std]
  640  

FILE sources/0241/repo/rose/models/wan_transformer3d.py
SHA256 3152f9f4d59968b7af144ee272c937f7532f907ef17bdbbeef493a86a96b0219
LINES 636-650
  636      _supports_gradient_checkpointing = True
  637  
  638      @register_to_config
  639      def __init__(
  640          self,
  641          model_type='t2v',
  642          patch_size=(1, 2, 2),
  643          text_len=512,
  644          in_dim=16,
  645          dim=2048,
  646          ffn_dim=8192,
  647          freq_dim=256,
  648          text_dim=4096,
  649          out_dim=16,
  650          num_heads=16,
LINES 708-725
  708          self.num_heads = num_heads
  709          self.num_layers = num_layers
  710          self.window_size = window_size
  711          self.qk_norm = qk_norm
  712          self.cross_attn_norm = cross_attn_norm
  713          self.eps = eps
  714  
  715          # embeddings
  716          self.patch_embedding = nn.Conv3d(
  717              in_dim, dim, kernel_size=patch_size, stride=patch_size)
  718          self.text_embedding = nn.Sequential(
  719              nn.Linear(text_dim, dim), nn.GELU(approximate='tanh'),
  720              nn.Linear(dim, dim))
  721  
  722          self.time_embedding = nn.Sequential(
  723              nn.Linear(freq_dim, dim), nn.SiLU(), nn.Linear(dim, dim))
  724          self.time_projection = nn.Sequential(nn.SiLU(), nn.Linear(dim, dim * 6))
  725  
LINES 848-867
  848          device = self.patch_embedding.weight.device
  849          dtype = x.dtype
  850          if self.freqs.device != device and torch.device(type="meta") != device:
  851              self.freqs = self.freqs.to(device)
  852  
  853          if y is not None:
  854              x = [torch.cat([u, v], dim=0) for u, v in zip(x, y)]
  855  
  856          # embeddings
  857          x = [self.patch_embedding(u.unsqueeze(0)) for u in x]
  858          grid_sizes = torch.stack(
  859              [torch.tensor(u.shape[2:], dtype=torch.long) for u in x])
  860          x = [u.flatten(2).transpose(1, 2) for u in x]
  861          seq_lens = torch.tensor([u.size(1) for u in x], dtype=torch.long)
  862          if self.sp_world_size > 1:
  863              seq_len = int(math.ceil(seq_len / self.sp_world_size)) * self.sp_world_size
  864          assert seq_lens.max() <= seq_len
  865          x = torch.cat([
  866              torch.cat([u, u.new_zeros(1, seq_len - u.size(1), u.size(2))],
  867                        dim=1) for u in x
LINES 958-974
  958                              grid_sizes=grid_sizes,
  959                              freqs=self.freqs,
  960                              context=context,
  961                              context_lens=context_lens,
  962                              dtype=dtype
  963                          )
  964                          x = block(x, **kwargs)
  965  
  966                      if return_intermediate and idx in selected_layers:
  967                          intermediate_features.append(x.clone())
  968                      
  969                      if cond_flag:
  970                          self.teacache.previous_residual_cond = x.cpu() - ori_x if self.teacache.offload else x - ori_x
  971                      else:
  972                          self.teacache.previous_residual_uncond = x.cpu() - ori_x if self.teacache.offload else x - ori_x
  973          else:
  974              for idx, block in enumerate(self.blocks):
LINES 1000-1030
 1000                          grid_sizes=grid_sizes,
 1001                          freqs=self.freqs,
 1002                          context=context,
 1003                          context_lens=context_lens,
 1004                          dtype=dtype
 1005                      )
 1006                      x = block(x, **kwargs)
 1007                  
 1008                  if return_intermediate and idx in selected_layers:
 1009                      intermediate_features.append(x.clone())
 1010                      
 1011  
 1012          if self.sp_world_size > 1:
 1013              x = get_sp_group().all_gather(x, dim=1)
 1014  
 1015          # head
 1016          x = self.head(x, e)
 1017  
 1018          # unpatchify
 1019          x = self.unpatchify(x, grid_sizes)
 1020          x = torch.stack(x)
 1021  
 1022          if return_intermediate:
 1023              mid_feat = intermediate_features
 1024              return x, mid_feat
 1025          else:
 1026              return x
 1027  
 1028  
 1029      def unpatchify(self, x, grid_sizes):
 1030          r"""

FILE sources/0241/repo/rose/models/diff_mask_predictor.py
SHA256 0b4c6f34c6c9412909e80c9d0450847f579b76b3870649ee9b8bdead555f2537
LINES 1-42
    1  import torch
    2  import torch.nn as nn
    3  import torch.nn.functional as F
    4  from diffusers.configuration_utils import ConfigMixin, register_to_config
    5  
    6  class DiffMaskPredictor(nn.Module):
    7      def __init__(self, input_dim=4608, patch_grid=(10, 15, 189), output_grid=(81, 480, 720), hidden_dim=256):
    8          """
    9          Args:
   10              input_dim (int): concatenated feature dimension, e.g. 1536 * num_selected_layers
   11              patch_grid (tuple): (F_p, H_p, W_p) - patch token grid shape (e.g., from transformer block)
   12              output_grid (tuple): (F, H, W) - final full resolution shape for mask
   13              hidden_dim (int): intermediate conv/linear hidden dim
   14          """
   15          super().__init__()
   16          self.F_p, self.H_p, self.W_p = patch_grid
   17          self.F, self.H, self.W = output_grid
   18  
   19          self.project = nn.Sequential(
   20              nn.Linear(input_dim, hidden_dim),
   21              nn.GELU(),
   22              nn.Linear(hidden_dim, 1)
   23          )
   24  
   25      def forward(self, x):
   26          """
   27          Args:
   28              x (Tensor): shape [B, L, D_total], L = F_p  H_p  W_p
   29          Returns:
   30              Tensor: predicted diff mask, shape [B, 1, F, H, W]
   31          """
   32          B, L, D = x.shape
   33          assert L == self.F_p * self.H_p * self.W_p, \
   34              f"Input token length {L} doesn't match patch grid ({self.F_p}, {self.H_p}, {self.W_p})"
   35  
   36          x = self.project(x)                         # [B, L, 1]
   37          x = x.view(B, 1, self.F_p, self.H_p, self.W_p)  # [B, 1, F_p, H_p, W_p]
   38          x = F.interpolate(
   39              x, size=(self.F, self.H, self.W),
   40              mode="trilinear", align_corners=False   # upsample to match ground truth resolution
   41          )
   42          return x  # [B, 1, F, H, W]

FILE sources/0241/repo/rose/pipeline/pipeline_wan_fun_inpaint.py
SHA256 84619e82019bf4fed36ede74b8185ac3c33247948c36286e081816bde5816957
LINES 314-330
  314          self, batch_size, num_channels_latents, num_frames, height, width, dtype, device, generator, latents=None
  315      ):
  316          if isinstance(generator, list) and len(generator) != batch_size:
  317              raise ValueError(
  318                  f"You have passed a list of generators of length {len(generator)}, but requested an effective batch"
  319                  f" size of {batch_size}. Make sure the batch size matches the length of the generators."
  320              )
  321  
  322          shape = (
  323              batch_size,
  324              num_channels_latents,
  325              (num_frames - 1) // self.vae.temporal_compression_ratio + 1,
  326              height // self.vae.spacial_compression_ratio,
  327              width // self.vae.spacial_compression_ratio,
  328          )
  329  
  330          if latents is None:

FILE sources/0241/repo/utils/evaluate_video.py
SHA256 23c17843bbe6b681571185c583f05fcdd913b39fba960e23ed8dbb894f773e1c
LINES 1-133
    1  import torch
    2  import numpy as np
    3  from skimage.metrics import structural_similarity as ssim
    4  from skimage.metrics import peak_signal_noise_ratio as psnr
    5  import lpips
    6  from tqdm import tqdm
    7  import cv2
    8  
    9  class VideoQualityEvaluator:
   10      def __init__(self, device='cuda'):
   11          """Initialize video quality evaluator with specified computation device
   12          
   13          Args:
   14              device (str): Computation device ('cuda' or 'cpu')
   15          """
   16          self.device = device
   17          # Initialize LPIPS model (perceptual similarity metric)
   18          self.lpips_model = lpips.LPIPS(net='alex').to(device)
   19      
   20      def _preprocess_frame(self, frame):
   21          """Convert frame to standardized format for evaluation
   22          
   23          Args:
   24              frame: Input frame (numpy array or torch tensor)
   25              
   26          Returns:
   27              Processed frame in HWC format with values in [0,1]
   28          """
   29          if isinstance(frame, torch.Tensor):
   30              frame = frame.detach().cpu().numpy()
   31          
   32          # Normalize to [0,1] if needed
   33          if frame.max() > 1:
   34              frame = frame / 255.0
   35          # Convert CHW to HWC if needed
   36          if len(frame.shape) == 3 and frame.shape[0] == 3:
   37              frame = frame.transpose(1, 2, 0)
   38          return frame
   39      
   40      def calculate_psnr(self, vid1, vid2):
   41          """Calculate average PSNR between two videos
   42          
   43          Args:
   44              vid1: First video (list/array of frames)
   45              vid2: Second video (list/array of frames)
   46              
   47          Returns:
   48              Mean PSNR value across all frames
   49          """
   50          psnrs = []
   51          for f1, f2 in zip(vid1, vid2):
   52              f1 = self._preprocess_frame(f1)
   53              f2 = self._preprocess_frame(f2)
   54              # Calculate PSNR for this frame pair
   55              psnrs.append(psnr(f1, f2, data_range=1.0))
   56          return np.mean(psnrs)
   57      
   58      def calculate_ssim(self, vid1, vid2):
   59          """Calculate average SSIM between two videos
   60          
   61          Args:
   62              vid1: First video (list/array of frames)
   63              vid2: Second video (list/array of frames)
   64              
   65          Returns:
   66              Mean SSIM value across all frames
   67          """
   68          ssims = []
   69          for f1, f2 in zip(vid1, vid2):
   70              f1 = self._preprocess_frame(f1)
   71              f2 = self._preprocess_frame(f2)
   72              # Calculate SSIM for this frame pair (multichannel for color images)
   73              ssims.append(ssim(f1, f2, channel_axis=2, data_range=1.0))
   74          return np.mean(ssims)
   75      
   76      def calculate_lpips(self, vid1, vid2):
   77          """Calculate average LPIPS (perceptual similarity) between two videos
   78          
   79          Args:
   80              vid1: First video (list/array of frames)
   81              vid2: Second video (list/array of frames)
   82              
   83          Returns:
   84              Mean LPIPS value across all frames (lower is better)
   85          """
   86          lpips_values = []
   87          for f1, f2 in zip(vid1, vid2):
   88              # Convert to torch tensor if needed
   89              if not isinstance(f1, torch.Tensor):
   90                  f1 = torch.from_numpy(f1).permute(2, 0, 1).unsqueeze(0).float()  # HWC -> 1CHW
   91                  f2 = torch.from_numpy(f2).permute(2, 0, 1).unsqueeze(0).float()
   92              
   93              # Normalize to [-1,1] if needed
   94              if f1.max() > 1:
   95                  f1 = f1 / 127.5 - 1.0
   96                  f2 = f2 / 127.5 - 1.0
   97              
   98              f1 = f1.to(self.device)
   99              f2 = f2.to(self.device)
  100              
  101              # Calculate LPIPS with no gradients
  102              with torch.no_grad():
  103                  lpips_values.append(self.lpips_model(f1, f2).item())
  104          return np.mean(lpips_values)
  105      
  106      def evaluate_videos(self, generated_video, reference_video, metrics=['psnr','lpips','ssim']):
  107          """Comprehensive video quality evaluation between generated and reference videos
  108          
  109          Args:
  110              generated_video: Model-generated video [T,H,W,C] or [T,C,H,W]
  111              reference_video: Ground truth reference video [T,H,W,C] or [T,C,H,W]
  112              metrics: List of metrics to compute ('psnr', 'ssim', 'lpips')
  113              
  114          Returns:
  115              Dictionary containing computed metric values
  116          """
  117          results = {}
  118          
  119          # Verify video lengths match
  120          assert len(generated_video) == len(reference_video), "Videos must have same number of frames"
  121          
  122          # Calculate requested metrics
  123          if 'psnr' in metrics:
  124              results['psnr'] = self.calculate_psnr(generated_video, reference_video)
  125          
  126          if 'ssim' in metrics:
  127              results['ssim'] = self.calculate_ssim(generated_video, reference_video)
  128          
  129          if 'lpips' in metrics:
  130              results['lpips'] = self.calculate_lpips(generated_video, reference_video)
  131          
  132          return results
  133  

FILE sources/0241/checkpoint_metadata/config.json
SHA256 2489f6cd3d1f8b98422b9b88a2afb8a7ee6f8d9eb9f0801a2ebbba87fbf3c6f2
LINES 1-28
    1  {
    2    "_class_name": "WanTransformer3DModel",
    3    "_diffusers_version": "0.31.0",
    4    "cross_attn_norm": true,
    5    "dim": 1536,
    6    "eps": 1e-06,
    7    "ffn_dim": 8960,
    8    "freq_dim": 256,
    9    "hidden_size": 1536,
   10    "in_channels": 36,
   11    "in_dim": 36,
   12    "model_type": "i2v",
   13    "num_heads": 12,
   14    "num_layers": 30,
   15    "out_dim": 16,
   16    "patch_size": [
   17      1,
   18      2,
   19      2
   20    ],
   21    "qk_norm": true,
   22    "text_dim": 4096,
   23    "text_len": 512,
   24    "window_size": [
   25      -1,
   26      -1
   27    ]
   28  }

