MCPcopy Create free account
hub / github.com/ml-explore/mlx-examples / __init__

Method __init__

stable_diffusion/stable_diffusion/vae.py:96–140  ·  view source on GitHub ↗
(
        self,
        in_channels: int,
        out_channels: int,
        block_out_channels: List[int] = [64],
        layers_per_block: int = 2,
        resnet_groups: int = 32,
    )

Source from the content-addressed store, hash-verified

94 """Implements the encoder side of the Autoencoder."""
95
96 def __init__(
97 self,
98 in_channels: int,
99 out_channels: int,
100 block_out_channels: List[int] = [64],
101 layers_per_block: int = 2,
102 resnet_groups: int = 32,
103 ):
104 super().__init__()
105
106 self.conv_in = nn.Conv2d(
107 in_channels, block_out_channels[0], kernel_size=3, stride=1, padding=1
108 )
109
110 channels = [block_out_channels[0]] + list(block_out_channels)
111 self.down_blocks = [
112 EncoderDecoderBlock2D(
113 in_channels,
114 out_channels,
115 num_layers=layers_per_block,
116 resnet_groups=resnet_groups,
117 add_downsample=i < len(block_out_channels) - 1,
118 add_upsample=False,
119 )
120 for i, (in_channels, out_channels) in enumerate(zip(channels, channels[1:]))
121 ]
122
123 self.mid_blocks = [
124 ResnetBlock2D(
125 in_channels=block_out_channels[-1],
126 out_channels=block_out_channels[-1],
127 groups=resnet_groups,
128 ),
129 Attention(block_out_channels[-1], resnet_groups),
130 ResnetBlock2D(
131 in_channels=block_out_channels[-1],
132 out_channels=block_out_channels[-1],
133 groups=resnet_groups,
134 ),
135 ]
136
137 self.conv_norm_out = nn.GroupNorm(
138 resnet_groups, block_out_channels[-1], pytorch_compatible=True
139 )
140 self.conv_out = nn.Conv2d(block_out_channels[-1], out_channels, 3, padding=1)
141
142 def __call__(self, x):
143 x = self.conv_in(x)

Callers 4

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 3

ResnetBlock2DClass · 0.85
AttentionClass · 0.70

Tested by

no test coverage detected