MCPcopy Create free account
hub / github.com/MeiGen-AI/MultiTalk / forward

Method forward

wan/modules/vae.py:101–160  ·  view source on GitHub ↗
(self, x, feat_cache=None, feat_idx=[0])

Source from the content-addressed store, hash-verified

99 self.resample = nn.Identity()
100
101 def forward(self, x, feat_cache=None, feat_idx=[0]):
102 b, c, t, h, w = x.size()
103 if self.mode == 'upsample3d':
104 if feat_cache is not None:
105 idx = feat_idx[0]
106 if feat_cache[idx] is None:
107 feat_cache[idx] = 'Rep'
108 feat_idx[0] += 1
109 else:
110
111 cache_x = x[:, :, -CACHE_T:, :, :].clone()
112 if cache_x.shape[2] < 2 and feat_cache[
113 idx] is not None and feat_cache[idx] != 'Rep':
114 # cache last frame of last two chunk
115 cache_x = torch.cat([
116 feat_cache[idx][:, :, -1, :, :].unsqueeze(2).to(
117 cache_x.device), cache_x
118 ],
119 dim=2)
120 if cache_x.shape[2] < 2 and feat_cache[
121 idx] is not None and feat_cache[idx] == 'Rep':
122 cache_x = torch.cat([
123 torch.zeros_like(cache_x).to(cache_x.device),
124 cache_x
125 ],
126 dim=2)
127 if feat_cache[idx] == 'Rep':
128 x = self.time_conv(x)
129 else:
130 x = self.time_conv(x, feat_cache[idx])
131 feat_cache[idx] = cache_x
132 feat_idx[0] += 1
133
134 x = x.reshape(b, 2, c, t, h, w)
135 x = torch.stack((x[:, 0, :, :, :, :], x[:, 1, :, :, :, :]),
136 3)
137 x = x.reshape(b, c, t * 2, h, w)
138 t = x.shape[2]
139 x = rearrange(x, 'b c t h w -> (b t) c h w')
140 x = self.resample(x)
141 x = rearrange(x, '(b t) c h w -> b c t h w', t=t)
142
143 if self.mode == 'downsample3d':
144 if feat_cache is not None:
145 idx = feat_idx[0]
146 if feat_cache[idx] is None:
147 feat_cache[idx] = x.clone()
148 feat_idx[0] += 1
149 else:
150
151 cache_x = x[:, :, -1:, :, :].clone()
152 # if cache_x.shape[2] < 2 and feat_cache[idx] is not None and feat_cache[idx]!='Rep':
153 # # cache last frame of last two chunk
154 # cache_x = torch.cat([feat_cache[idx][:, :, -1, :, :].unsqueeze(2).to(cache_x.device), cache_x], dim=2)
155
156 x = self.time_conv(
157 torch.cat([feat_cache[idx][:, :, -1:, :, :], x], 2))
158 feat_cache[idx] = cache_x

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected