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

Method forward

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

toMethod · 0.45

Tested by

no test coverage detected