MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / UNetMidBlock1D

Class UNetMidBlock1D

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

Source from the content-addressed store, hash-verified

407
408
409class UNetMidBlock1D(nn.Module):
410 def __init__(self, mid_channels: int, in_channels: int, out_channels: Optional[int] = None):
411 super().__init__()
412
413 out_channels = in_channels if out_channels is None else out_channels
414
415 # there is always at least one resnet
416 self.down = Downsample1d("cubic")
417 resnets = [
418 ResConvBlock(in_channels, mid_channels, mid_channels),
419 ResConvBlock(mid_channels, mid_channels, mid_channels),
420 ResConvBlock(mid_channels, mid_channels, mid_channels),
421 ResConvBlock(mid_channels, mid_channels, mid_channels),
422 ResConvBlock(mid_channels, mid_channels, mid_channels),
423 ResConvBlock(mid_channels, mid_channels, out_channels),
424 ]
425 attentions = [
426 SelfAttention1d(mid_channels, mid_channels // 32),
427 SelfAttention1d(mid_channels, mid_channels // 32),
428 SelfAttention1d(mid_channels, mid_channels // 32),
429 SelfAttention1d(mid_channels, mid_channels // 32),
430 SelfAttention1d(mid_channels, mid_channels // 32),
431 SelfAttention1d(out_channels, out_channels // 32),
432 ]
433 self.up = Upsample1d(kernel="cubic")
434
435 self.attentions = nn.ModuleList(attentions)
436 self.resnets = nn.ModuleList(resnets)
437
438 def forward(self, hidden_states: torch.Tensor, temb: Optional[torch.Tensor] = None) -> torch.Tensor:
439 hidden_states = self.down(hidden_states)
440 for attn, resnet in zip(self.attentions, self.resnets):
441 hidden_states = resnet(hidden_states)
442 hidden_states = attn(hidden_states)
443
444 hidden_states = self.up(hidden_states)
445
446 return hidden_states
447
448
449class AttnDownBlock1D(nn.Module):

Callers 1

get_mid_blockFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected