MCPcopy Create free account
hub / github.com/Francis-Rings/FlashPortrait / forward

Method forward

wan/models/wan_vae.py:322–370  ·  view source on GitHub ↗
(self, x, feat_cache=None, feat_idx=[0])

Source from the content-addressed store, hash-verified

320 CausalConv3d(out_dim, z_dim, 3, padding=1))
321
322 def forward(self, x, feat_cache=None, feat_idx=[0]):
323 if feat_cache is not None:
324 idx = feat_idx[0]
325 cache_x = x[:, :, -CACHE_T:, :, :].clone()
326 if cache_x.shape[2] < 2 and feat_cache[idx] is not None:
327 # cache last frame of last two chunk
328 cache_x = torch.cat([
329 feat_cache[idx][:, :, -1, :, :].unsqueeze(2).to(
330 cache_x.device), cache_x
331 ],
332 dim=2)
333 x = self.conv1(x, feat_cache[idx])
334 feat_cache[idx] = cache_x
335 feat_idx[0] += 1
336 else:
337 x = self.conv1(x)
338
339 ## downsamples
340 for layer in self.downsamples:
341 if feat_cache is not None:
342 x = layer(x, feat_cache, feat_idx)
343 else:
344 x = layer(x)
345
346 ## middle
347 for layer in self.middle:
348 if isinstance(layer, ResidualBlock) and feat_cache is not None:
349 x = layer(x, feat_cache, feat_idx)
350 else:
351 x = layer(x)
352
353 ## head
354 for layer in self.head:
355 if isinstance(layer, CausalConv3d) and feat_cache is not None:
356 idx = feat_idx[0]
357 cache_x = x[:, :, -CACHE_T:, :, :].clone()
358 if cache_x.shape[2] < 2 and feat_cache[idx] is not None:
359 # cache last frame of last two chunk
360 cache_x = torch.cat([
361 feat_cache[idx][:, :, -1, :, :].unsqueeze(2).to(
362 cache_x.device), cache_x
363 ],
364 dim=2)
365 x = layer(x, feat_cache[idx])
366 feat_cache[idx] = cache_x
367 feat_idx[0] += 1
368 else:
369 x = layer(x)
370 return x
371
372
373class Decoder3d(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected