MCPcopy Create free account
hub / github.com/tdrussell/diffusion-pipe / CausalContinuousVideoTokenizer

Class CausalContinuousVideoTokenizer

tools/cosmos_vae_test.py:32–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30
31
32class CausalContinuousVideoTokenizer(nn.Module):
33 def __init__(self, z_channels: int, z_factor: int, embedding_dim: int, **kwargs) -> None:
34 super().__init__()
35 self.name = kwargs.get("name", "CausalContinuousVideoTokenizer")
36 self.embedding_dim = embedding_dim
37 self.sigma_data = 0.5
38 self.encoder = EncoderFactorized(z_channels=z_factor * z_channels, **kwargs)
39 self.decoder = DecoderFactorized(z_channels=z_channels, **kwargs)
40
41 self.quant_conv = CausalConv3d(z_factor * z_channels, embedding_dim, kernel_size=1, padding=0)
42 self.post_quant_conv = CausalConv3d(embedding_dim, z_channels, kernel_size=1, padding=0)
43
44 latent_temporal_chunk = 16
45 self.latent_mean = nn.Parameter(torch.zeros([self.embedding_dim * latent_temporal_chunk], dtype=torch.float32))
46 self.latent_std = nn.Parameter(torch.ones([self.embedding_dim * latent_temporal_chunk], dtype=torch.float32))
47
48
49 def encode(self, x):
50 h = self.encoder(x)
51 z = self.quant_conv(h)
52 latent_ch = z.shape[1]
53 latent_t = z.shape[2]
54 dtype = z.dtype
55 mean = self.latent_mean.view(latent_ch, -1)[:, : latent_t].reshape([1, latent_ch, -1, 1, 1]).to(dtype=dtype, device=z.device)
56 std = self.latent_std.view(latent_ch, -1)[:, : latent_t].reshape([1, latent_ch, -1, 1, 1]).to(dtype=dtype, device=z.device)
57 return ((z - mean) / std) * self.sigma_data
58
59 def decode(self, z):
60 in_dtype = z.dtype
61 latent_ch = z.shape[1]
62 latent_t = z.shape[2]
63 mean = self.latent_mean.view(latent_ch, -1)[:, : latent_t].reshape([1, latent_ch, -1, 1, 1]).to(dtype=in_dtype, device=z.device)
64 std = self.latent_std.view(latent_ch, -1)[:, : latent_t].reshape([1, latent_ch, -1, 1, 1]).to(dtype=in_dtype, device=z.device)
65 z = z / self.sigma_data
66 z = z * std + mean
67 z = self.post_quant_conv(z)
68 return self.decoder(z)
69
70
71def load_official_video_vae():

Callers 1

load_custom_video_vaeFunction · 0.70

Calls

no outgoing calls

Tested by 1

load_custom_video_vaeFunction · 0.56