r""" A Resnet block. Parameters: in_channels (`int`): The number of channels in the input. out_channels (`int`, *optional*, default to be `None`): The number of output channels for the first conv2d layer. If None, same as `in_channels`. dropout (`float`,
| 186 | |
| 187 | |
| 188 | class ResnetBlock2D(nn.Module): |
| 189 | r""" |
| 190 | A Resnet block. |
| 191 | |
| 192 | Parameters: |
| 193 | in_channels (`int`): The number of channels in the input. |
| 194 | out_channels (`int`, *optional*, default to be `None`): |
| 195 | The number of output channels for the first conv2d layer. If None, same as `in_channels`. |
| 196 | dropout (`float`, *optional*, defaults to `0.0`): The dropout probability to use. |
| 197 | temb_channels (`int`, *optional*, default to `512`): the number of channels in timestep embedding. |
| 198 | groups (`int`, *optional*, default to `32`): The number of groups to use for the first normalization layer. |
| 199 | groups_out (`int`, *optional*, default to None): |
| 200 | The number of groups to use for the second normalization layer. if set to None, same as `groups`. |
| 201 | eps (`float`, *optional*, defaults to `1e-6`): The epsilon to use for the normalization. |
| 202 | non_linearity (`str`, *optional*, default to `"swish"`): the activation function to use. |
| 203 | time_embedding_norm (`str`, *optional*, default to `"default"` ): Time scale shift config. |
| 204 | By default, apply timestep embedding conditioning with a simple shift mechanism. Choose "scale_shift" for a |
| 205 | stronger conditioning with scale and shift. |
| 206 | kernel (`torch.Tensor`, optional, default to None): FIR filter, see |
| 207 | [`~models.resnet.FirUpsample2D`] and [`~models.resnet.FirDownsample2D`]. |
| 208 | output_scale_factor (`float`, *optional*, default to be `1.0`): the scale factor to use for the output. |
| 209 | use_in_shortcut (`bool`, *optional*, default to `True`): |
| 210 | If `True`, add a 1x1 nn.conv2d layer for skip-connection. |
| 211 | up (`bool`, *optional*, default to `False`): If `True`, add an upsample layer. |
| 212 | down (`bool`, *optional*, default to `False`): If `True`, add a downsample layer. |
| 213 | conv_shortcut_bias (`bool`, *optional*, default to `True`): If `True`, adds a learnable bias to the |
| 214 | `conv_shortcut` output. |
| 215 | conv_2d_out_channels (`int`, *optional*, default to `None`): the number of channels in the output. |
| 216 | If None, same as `out_channels`. |
| 217 | """ |
| 218 | |
| 219 | def __init__( |
| 220 | self, |
| 221 | *, |
| 222 | in_channels: int, |
| 223 | out_channels: int | None = None, |
| 224 | conv_shortcut: bool = False, |
| 225 | dropout: float = 0.0, |
| 226 | temb_channels: int = 512, |
| 227 | groups: int = 32, |
| 228 | groups_out: int | None = None, |
| 229 | pre_norm: bool = True, |
| 230 | eps: float = 1e-6, |
| 231 | non_linearity: str = "swish", |
| 232 | skip_time_act: bool = False, |
| 233 | time_embedding_norm: str = "default", # default, scale_shift, |
| 234 | kernel: torch.Tensor | None = None, |
| 235 | output_scale_factor: float = 1.0, |
| 236 | use_in_shortcut: bool | None = None, |
| 237 | up: bool = False, |
| 238 | down: bool = False, |
| 239 | conv_shortcut_bias: bool = True, |
| 240 | conv_2d_out_channels: int | None = None, |
| 241 | ): |
| 242 | super().__init__() |
| 243 | if time_embedding_norm == "ada_group": |
| 244 | raise ValueError( |
| 245 | "This class cannot be used with `time_embedding_norm==ada_group`, please use `ResnetBlockCondNorm2D` instead", |
no outgoing calls
searching dependent graphs…