code: def __init__(self, config):
      super().__init__()
      self.config = config
      # stochastic depth decay rule
      dpr = [
          x.item()
          for x in torch.linspace(
              0, config.drop_path_rate, sum(config.depths)
          )
      ]
  
      # patch embeddings
      embeddings = []
      for i in range(config.num_encoder_blocks):
          embeddings.append(
              PoolFormerEmbeddings(
                  patch_size=config.patch_sizes[i],
                  stride=config.strides[i],
                  padding=config.padding[i],
                  num_channels=config.num_channels
                  if i == 0
                  else config.hidden_sizes[i - 1],
                  hidden_size=config.hidden_sizes[i],
              )
          )
      self.patch_embeddings = nn.ModuleList(embeddings)
  
      # Transformer blocks
      blocks = []
      cur = 0
      for i in range(config.num_encoder_blocks):
          # each block consists of layers
          layers = []
          if i != 0:
              cur += config.depths[i - 1]
          for j in range(config.depths[i]):
              layers.append(
                  PoolFormerLayer(
                      config,
                      num_channels=config.hidden_sizes[i],
                      pool_size=config.pool_size,
                      hidden_size=config.hidden_sizes[i],
                      intermediate_size=int(
                          config.hidden_sizes[i] * config.mlp_ratio
                      ),
                      drop_path=dpr[cur + j],
                  )
              )
          blocks.append(nn.ModuleList(layers))
  
      self.block = nn.ModuleList(blocks)
  
imports: import collections.abc
  from typing import Optional, Tuple, Union
  import torch
  import torch.utils.checkpoint
  from torch import nn
  from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
  from ...activations import ACT2FN
  from ...modeling_outputs import BaseModelOutputWithNoAttention, ImageClassifierOutputWithNoAttention
  from ...modeling_utils import PreTrainedModel
  from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
  from .configuration_poolformer import PoolFormerConfig
label_desc: Use image node_id 1 to create a new PoolFormerEncoder object from inherited base classes: nn with example: obj = PoolFormerEncoder(config)