MCPcopy Create free account
hub / github.com/huggingface/diffusers / AttnDownBlock1D

Class AttnDownBlock1D

src/diffusers/models/unets/unet_1d_blocks.py:448–475  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

446
447
448class AttnDownBlock1D(nn.Module):
449 def __init__(self, out_channels: int, in_channels: int, mid_channels: int | None = None):
450 super().__init__()
451 mid_channels = out_channels if mid_channels is None else mid_channels
452
453 self.down = Downsample1d("cubic")
454 resnets = [
455 ResConvBlock(in_channels, mid_channels, mid_channels),
456 ResConvBlock(mid_channels, mid_channels, mid_channels),
457 ResConvBlock(mid_channels, mid_channels, out_channels),
458 ]
459 attentions = [
460 SelfAttention1d(mid_channels, mid_channels // 32),
461 SelfAttention1d(mid_channels, mid_channels // 32),
462 SelfAttention1d(out_channels, out_channels // 32),
463 ]
464
465 self.attentions = nn.ModuleList(attentions)
466 self.resnets = nn.ModuleList(resnets)
467
468 def forward(self, hidden_states: torch.Tensor, temb: torch.Tensor | None = None) -> torch.Tensor:
469 hidden_states = self.down(hidden_states)
470
471 for resnet, attn in zip(self.resnets, self.attentions):
472 hidden_states = resnet(hidden_states)
473 hidden_states = attn(hidden_states)
474
475 return hidden_states, (hidden_states,)
476
477
478class DownBlock1D(nn.Module):

Callers 1

get_down_blockFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…