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

Class UNetMidBlock1D

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

Source from the content-addressed store, hash-verified

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

Callers 1

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