A DiT block with parallel linear layers as described in https://arxiv.org/abs/2302.05442 and adapted modulation interface.
| 377 | return x |
| 378 | |
| 379 | class SingleStreamBlockC(SingleStreamBlock): |
| 380 | """ |
| 381 | A DiT block with parallel linear layers as described in |
| 382 | https://arxiv.org/abs/2302.05442 and adapted modulation interface. |
| 383 | """ |
| 384 | |
| 385 | def __init__(self, hidden_size: int, |
| 386 | num_heads: int, |
| 387 | mlp_ratio: float = 4.0, |
| 388 | qk_scale: float | None = None, |
| 389 | backend='pytorch', |
| 390 | abondon_cond = False): |
| 391 | super().__init__(hidden_size, num_heads, mlp_ratio, |
| 392 | qk_scale, backend) |
| 393 | self.abondon_cond = abondon_cond |
| 394 | |
| 395 | def forward(self, x: Tensor, vec: Tensor, pe: Tensor, mask: Tensor = None, |
| 396 | uncondi_length = None, uncondi_pe = None, mask_uncond = None) -> Tensor: |
| 397 | if self.abondon_cond: |
| 398 | x = [ix[:u_l, :] for ix, u_l in zip(x, uncondi_length)] |
| 399 | x = pad_sequence(x, batch_first=True) |
| 400 | if not x.shape[1] == pe.shape[2]: |
| 401 | pe = uncondi_pe |
| 402 | mask = mask_uncond |
| 403 | # print("single stream block", x.shape, pe.shape) |
| 404 | x = super().forward(x, vec, pe, mask) |
| 405 | return x |
| 406 | |
| 407 | |
| 408 | class DoubleStreamBlockD(DoubleStreamBlock): |
nothing calls this directly
no outgoing calls
no test coverage detected