class_docstr: Implements feed-forward networks (FFNs) with identity connection.
  
  Args:
      embed_dims (int): The feature dimension. Same as
          `MultiheadAttention`. Defaults: 256.
      feedforward_channels (int): The hidden dimension of FFNs.
          Defaults: 1024.
      num_fcs (int, optional): The number of fully-connected layers in
          FFNs. Default: 2.
      act_cfg (dict, optional): The activation config for FFNs.
          Default: dict(type='ReLU')
      ffn_drop (float, optional): Probability of an element to be
          zeroed in FFN. Default 0.0.
      add_identity (bool, optional): Whether to add the
          identity connection. Default: `True`.
      dropout_layer (obj:`ConfigDict`): The dropout_layer used
          when adding the shortcut.
      init_cfg (obj:`mmcv.ConfigDict`): The Config for initialization.
          Default: None.
class_docstr_tok: ["Implements","feed-forward","networks","(","FFNs",")","with","identity","connection",".","Args",":","embed_dims","(","int",")",":","The","feature","dimension",".","Same","as","`","MultiheadAttention","`",".","Defaults",":","256.","feedforward_channels","(","int",")",":","The","hidden","dimension","of","FFNs",".","Defaults",":","1024.","num_fcs","(","int",",","optional",")",":","The","number","of","fully-connected","layers","in","FFNs",".","Default",":","2.","act_cfg","(","dict",",","optional",")",":","The","activation","config","for","FFNs",".","Default",":","dict","(","type='ReLU","'",")","ffn_drop","(","float",",","optional",")",":","Probability","of","an","element","to","be","zeroed","in","FFN",".","Default","0.0.","add_identity","(","bool",",","optional",")",":","Whether","to","add","the","identity","connection",".","Default",":","`","True","`",".","dropout_layer","(","obj",":","`","ConfigDict","`",")",":","The","dropout_layer","used","when","adding","the","shortcut",".","init_cfg","(","obj",":","`","mmcv.ConfigDict","`",")",":","The","Config","for","initialization",".","Default",":","None","."]
code: def __init__(
      self,
      embed_dims=256,
      feedforward_channels=1024,
      num_fcs=2,
      act_cfg=dict(type="ReLU", inplace=True),
      ffn_drop=0.0,
      dropout_layer=None,
      add_identity=True,
      init_cfg=None,
      **kwargs,
  ):
      super(FFN, self).__init__(init_cfg)
      assert num_fcs >= 2, (
          "num_fcs should be no less " f"than 2. got {num_fcs}."
      )
      self.embed_dims = embed_dims
      self.feedforward_channels = feedforward_channels
      self.num_fcs = num_fcs
      self.act_cfg = act_cfg
      self.activate = build_activation_layer(act_cfg)
  
      layers = []
      in_channels = embed_dims
      for _ in range(num_fcs - 1):
          layers.append(
              Sequential(
                  Linear(in_channels, feedforward_channels),
                  self.activate,
                  nn.Dropout(ffn_drop),
              )
          )
          in_channels = feedforward_channels
      layers.append(Linear(feedforward_channels, embed_dims))
      layers.append(nn.Dropout(ffn_drop))
      self.layers = Sequential(*layers)
      self.dropout_layer = (
          build_dropout(dropout_layer)
          if dropout_layer
          else torch.nn.Identity()
      )
      self.add_identity = add_identity
  
imports: import copy
  import warnings
  import torch
  import torch.nn
  from annotator.uniformer.mmcv import ConfigDict, deprecated_api_warning
  from annotator.uniformer.mmcv.cnn import Linear, build_activation_layer, build_norm_layer
  from annotator.uniformer.mmcv.runner.base_module import BaseModule, ModuleList, Sequential
  from annotator.uniformer.mmcv.utils import build_from_cfg
  from .drop import build_dropout
  from .registry import ATTENTION, FEEDFORWARD_NETWORK, POSITIONAL_ENCODING, TRANSFORMER_LAYER, TRANSFORMER_LAYER_SEQUENCE
label_desc: Use image node_id 1 to create a new FFN object from inherited base classes: BaseModule with example: obj = FFN(embed_dims, feedforward_channels, num_fcs, act_cfg, ffn_drop, dropout_layer, add_identity, init_cfg)