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

Method forward

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

Source from the content-addressed store, hash-verified

425 CausalConv3d(out_dim, 3, 3, padding=1))
426
427 def forward(self, x, feat_cache=None, feat_idx=[0]):
428 ## conv1
429 if feat_cache is not None:
430 idx = feat_idx[0]
431 cache_x = x[:, :, -CACHE_T:, :, :].clone()
432 if cache_x.shape[2] < 2 and feat_cache[idx] is not None:
433 # cache last frame of last two chunk
434 cache_x = torch.cat([
435 feat_cache[idx][:, :, -1, :, :].unsqueeze(2).to(
436 cache_x.device), cache_x
437 ],
438 dim=2)
439 x = self.conv1(x, feat_cache[idx])
440 feat_cache[idx] = cache_x
441 feat_idx[0] += 1
442 else:
443 x = self.conv1(x)
444
445 ## middle
446 for layer in self.middle:
447 if isinstance(layer, ResidualBlock) and feat_cache is not None:
448 x = layer(x, feat_cache, feat_idx)
449 else:
450 x = layer(x)
451
452 ## upsamples
453 for layer in self.upsamples:
454 if feat_cache is not None:
455 x = layer(x, feat_cache, feat_idx)
456 else:
457 x = layer(x)
458
459 ## head
460 for layer in self.head:
461 if isinstance(layer, CausalConv3d) and feat_cache is not None:
462 idx = feat_idx[0]
463 cache_x = x[:, :, -CACHE_T:, :, :].clone()
464 if cache_x.shape[2] < 2 and feat_cache[idx] is not None:
465 # cache last frame of last two chunk
466 cache_x = torch.cat([
467 feat_cache[idx][:, :, -1, :, :].unsqueeze(2).to(
468 cache_x.device), cache_x
469 ],
470 dim=2)
471 x = layer(x, feat_cache[idx])
472 feat_cache[idx] = cache_x
473 feat_idx[0] += 1
474 else:
475 x = layer(x)
476 return x
477
478
479def count_conv3d(model):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected