MCPcopy Create free account
hub / github.com/OpenImagingLab/FlashVSR / forward

Method forward

diffsynth/models/wan_video_vae.py:329–377  ·  view source on GitHub ↗
(self, x, feat_cache=None, feat_idx=[0])

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

check_is_instanceFunction · 0.85
toMethod · 0.45

Tested by

no test coverage detected