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

Class AttnUpBlock1D

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

Source from the content-addressed store, hash-verified

520
521
522class AttnUpBlock1D(nn.Module):
523 def __init__(self, in_channels: int, out_channels: int, mid_channels: int | None = None):
524 super().__init__()
525 mid_channels = out_channels if mid_channels is None else mid_channels
526
527 resnets = [
528 ResConvBlock(2 * in_channels, mid_channels, mid_channels),
529 ResConvBlock(mid_channels, mid_channels, mid_channels),
530 ResConvBlock(mid_channels, mid_channels, out_channels),
531 ]
532 attentions = [
533 SelfAttention1d(mid_channels, mid_channels // 32),
534 SelfAttention1d(mid_channels, mid_channels // 32),
535 SelfAttention1d(out_channels, out_channels // 32),
536 ]
537
538 self.attentions = nn.ModuleList(attentions)
539 self.resnets = nn.ModuleList(resnets)
540 self.up = Upsample1d(kernel="cubic")
541
542 def forward(
543 self,
544 hidden_states: torch.Tensor,
545 res_hidden_states_tuple: tuple[torch.Tensor, ...],
546 temb: torch.Tensor | None = None,
547 ) -> torch.Tensor:
548 res_hidden_states = res_hidden_states_tuple[-1]
549 hidden_states = torch.cat([hidden_states, res_hidden_states], dim=1)
550
551 for resnet, attn in zip(self.resnets, self.attentions):
552 hidden_states = resnet(hidden_states)
553 hidden_states = attn(hidden_states)
554
555 hidden_states = self.up(hidden_states)
556
557 return hidden_states
558
559
560class UpBlock1D(nn.Module):

Callers 1

get_up_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…