MCPcopy Create free account
hub / github.com/AMAP-ML/Eevee / forward

Method forward

models/vae.py:569–617  ·  view source on GitHub ↗
(self, x, feat_cache=None, feat_idx=[0])

Source from the content-addressed store, hash-verified

567 CausalConv3d(out_dim, z_dim, 3, padding=1))
568
569 def forward(self, x, feat_cache=None, feat_idx=[0]):
570 if feat_cache is not None:
571 idx = feat_idx[0]
572 cache_x = x[:, :, -CACHE_T:, :, :].clone()
573 if cache_x.shape[2] < 2 and feat_cache[idx] is not None:
574 # cache last frame of last two chunk
575 cache_x = torch.cat([
576 feat_cache[idx][:, :, -1, :, :].unsqueeze(2).to(
577 cache_x.device), cache_x
578 ],
579 dim=2)
580 x = self.conv1(x, feat_cache[idx])
581 feat_cache[idx] = cache_x
582 feat_idx[0] += 1
583 else:
584 x = self.conv1(x)
585
586 ## downsamples
587 for layer in self.downsamples:
588 if feat_cache is not None:
589 x = layer(x, feat_cache, feat_idx)
590 else:
591 x = layer(x)
592
593 ## middle
594 for layer in self.middle:
595 if check_is_instance(layer, ResidualBlock) and feat_cache is not None:
596 x = layer(x, feat_cache, feat_idx)
597 else:
598 x = layer(x)
599
600 ## head
601 for layer in self.head:
602 if check_is_instance(layer, CausalConv3d) and feat_cache is not None:
603 idx = feat_idx[0]
604 cache_x = x[:, :, -CACHE_T:, :, :].clone()
605 if cache_x.shape[2] < 2 and feat_cache[idx] is not None:
606 # cache last frame of last two chunk
607 cache_x = torch.cat([
608 feat_cache[idx][:, :, -1, :, :].unsqueeze(2).to(
609 cache_x.device), cache_x
610 ],
611 dim=2)
612 x = layer(x, feat_cache[idx])
613 feat_cache[idx] = cache_x
614 feat_idx[0] += 1
615 else:
616 x = layer(x)
617 return x
618
619
620class Encoder3d_38(nn.Module):

Callers

nothing calls this directly

Calls 2

check_is_instanceFunction · 0.85
toMethod · 0.45

Tested by

no test coverage detected