class_docstr: The `Encoder` layer of a variational autoencoder that encodes its input into a latent representation.
  
  Args:
      in_channels (`int`, *optional*, defaults to 3):
          The number of input channels.
      out_channels (`int`, *optional*, defaults to 3):
          The number of output channels.
      down_block_types (`Tuple[str, ...]`, *optional*, defaults to `("DownEncoderBlock2D",)`):
          The types of down blocks to use. See `~diffusers.models.unet_2d_blocks.get_down_block` for available
          options.
      block_out_channels (`Tuple[int, ...]`, *optional*, defaults to `(64,)`):
          The number of output channels for each block.
      layers_per_block (`int`, *optional*, defaults to 2):
          The number of layers per block.
      norm_num_groups (`int`, *optional*, defaults to 32):
          The number of groups for normalization.
      act_fn (`str`, *optional*, defaults to `"silu"`):
          The activation function to use. See `~diffusers.models.activations.get_activation` for available options.
      double_z (`bool`, *optional*, defaults to `True`):
          Whether to double the number of output channels for the last block.
code: def __init__(
      self,
      in_channels: int = 3,
      out_channels: int = 3,
      down_block_types: Tuple[str, ...] = ("DownEncoderBlock2D",),
      block_out_channels: Tuple[int, ...] = (64,),
      layers_per_block: int = 2,
      norm_num_groups: int = 32,
      act_fn: str = "silu",
      double_z: bool = True,
      mid_block_add_attention=True,
  ):
      super().__init__()
      self.layers_per_block = layers_per_block
  
      self.conv_in = nn.Conv2d(
          in_channels,
          block_out_channels[0],
          kernel_size=3,
          stride=1,
          padding=1,
      )
  
      self.mid_block = None
      self.down_blocks = nn.ModuleList([])
  
      # down
      output_channel = block_out_channels[0]
      for i, down_block_type in enumerate(down_block_types):
          input_channel = output_channel
          output_channel = block_out_channels[i]
          is_final_block = i == len(block_out_channels) - 1
  
          down_block = get_down_block(
              down_block_type,
              num_layers=self.layers_per_block,
              in_channels=input_channel,
              out_channels=output_channel,
              add_downsample=not is_final_block,
              resnet_eps=1e-6,
              downsample_padding=0,
              resnet_act_fn=act_fn,
              resnet_groups=norm_num_groups,
              attention_head_dim=output_channel,
              temb_channels=None,
          )
          self.down_blocks.append(down_block)
  
      # mid
      self.mid_block = UNetMidBlock2D(
          in_channels=block_out_channels[-1],
          resnet_eps=1e-6,
          resnet_act_fn=act_fn,
          output_scale_factor=1,
          resnet_time_scale_shift="default",
          attention_head_dim=block_out_channels[-1],
          resnet_groups=norm_num_groups,
          temb_channels=None,
          add_attention=mid_block_add_attention,
      )
  
      # out
      self.conv_norm_out = nn.GroupNorm(
          num_channels=block_out_channels[-1],
          num_groups=norm_num_groups,
          eps=1e-6,
      )
      self.conv_act = nn.SiLU()
  
      conv_out_channels = 2 * out_channels if double_z else out_channels
      self.conv_out = nn.Conv2d(
          block_out_channels[-1], conv_out_channels, 3, padding=1
      )
  
      self.gradient_checkpointing = False
  
imports: from dataclasses import dataclass
  from typing import Optional, Tuple
  import numpy
  import torch
  import torch.nn
  from ...utils import BaseOutput, is_torch_version
  from ...utils.torch_utils import randn_tensor
  from ..activations import get_activation
  from ..attention_processor import SpatialNorm
  from ..unet_2d_blocks import AutoencoderTinyBlock, UNetMidBlock2D, get_down_block, get_up_block
label_desc: Use image node_id 1 to create a new Encoder object from inherited base classes: nn with example: obj = Encoder(in_channels, out_channels, down_block_types, block_out_channels, layers_per_block, norm_num_groups, act_fn, double_z, mid_block_add_attention)