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

Method __init__

diffsynth/models/wan_video_vae.py:279–327  ·  view source on GitHub ↗
(self,
                 dim=128,
                 z_dim=4,
                 dim_mult=[1, 2, 4, 4],
                 num_res_blocks=2,
                 attn_scales=[],
                 temperal_downsample=[True, True, False],
                 dropout=0.0)

Source from the content-addressed store, hash-verified

277class Encoder3d(nn.Module):
278
279 def __init__(self,
280 dim=128,
281 z_dim=4,
282 dim_mult=[1, 2, 4, 4],
283 num_res_blocks=2,
284 attn_scales=[],
285 temperal_downsample=[True, True, False],
286 dropout=0.0):
287 super().__init__()
288 self.dim = dim
289 self.z_dim = z_dim
290 self.dim_mult = dim_mult
291 self.num_res_blocks = num_res_blocks
292 self.attn_scales = attn_scales
293 self.temperal_downsample = temperal_downsample
294
295 # dimensions
296 dims = [dim * u for u in [1] + dim_mult]
297 scale = 1.0
298
299 # init block
300 self.conv1 = CausalConv3d(3, dims[0], 3, padding=1)
301
302 # downsample blocks
303 downsamples = []
304 for i, (in_dim, out_dim) in enumerate(zip(dims[:-1], dims[1:])):
305 # residual (+attention) blocks
306 for _ in range(num_res_blocks):
307 downsamples.append(ResidualBlock(in_dim, out_dim, dropout))
308 if scale in attn_scales:
309 downsamples.append(AttentionBlock(out_dim))
310 in_dim = out_dim
311
312 # downsample block
313 if i != len(dim_mult) - 1:
314 mode = 'downsample3d' if temperal_downsample[
315 i] else 'downsample2d'
316 downsamples.append(Resample(out_dim, mode=mode))
317 scale /= 2.0
318 self.downsamples = nn.Sequential(*downsamples)
319
320 # middle blocks
321 self.middle = nn.Sequential(ResidualBlock(out_dim, out_dim, dropout),
322 AttentionBlock(out_dim),
323 ResidualBlock(out_dim, out_dim, dropout))
324
325 # output blocks
326 self.head = nn.Sequential(RMS_norm(out_dim, images=False), nn.SiLU(),
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:

Callers

nothing calls this directly

Calls 6

ResidualBlockClass · 0.85
ResampleClass · 0.85
CausalConv3dClass · 0.70
AttentionBlockClass · 0.70
RMS_normClass · 0.70
__init__Method · 0.45

Tested by

no test coverage detected