MCPcopy Create free account
hub / github.com/ali-vilab/ACE_plus / DoubleStreamBlockC

Class DoubleStreamBlockC

modules/layers.py:349–377  ·  view source on GitHub ↗

A DiT block with parallel linear layers as described in https://arxiv.org/abs/2302.05442 and adapted modulation interface.

Source from the content-addressed store, hash-verified

347
348
349class DoubleStreamBlockC(DoubleStreamBlock):
350 """
351 A DiT block with parallel linear layers as described in
352 https://arxiv.org/abs/2302.05442 and adapted modulation interface.
353 """
354
355 def __init__(self, hidden_size: int, num_heads: int, mlp_ratio: float,
356 qkv_bias: bool = False, backend='pytorch',
357 abondon_cond = False):
358 super().__init__(hidden_size, num_heads, mlp_ratio,
359 qkv_bias, backend)
360 self.abondon_cond = abondon_cond
361
362 def forward(self, x: Tensor, vec: Tensor,
363 pe: Tensor, mask: Tensor = None,
364 txt_length=None,
365 uncondi_length=None,
366 uncondi_pe = None,
367 mask_uncond = None):
368 # pad_sequence(tuple(x_list), batch_first=True)
369 if self.abondon_cond:
370 x = [ix[:u_l, :] for ix, u_l in zip(x, uncondi_length)]
371 x = pad_sequence(x, batch_first=True)
372 if not x.shape[1] == pe.shape[2]:
373 pe = uncondi_pe
374 mask = mask_uncond
375 # print("double stream block", x.shape, pe.shape)
376 x = super().forward(x, vec, pe, mask, txt_length)
377 return x
378
379class SingleStreamBlockC(SingleStreamBlock):
380 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected