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,
      with_cp=False,
      **kwargs,
  ):
      super().__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)
      self.with_cp = with_cp
      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 math
  import warnings
  from typing import Sequence
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils.checkpoint
  from mmcv.cnn import Linear, build_activation_layer, build_norm_layer, xavier_init
  from mmcv.cnn.bricks.drop import build_dropout
  from mmcv.cnn.bricks.registry import FEEDFORWARD_NETWORK, TRANSFORMER_LAYER, TRANSFORMER_LAYER_SEQUENCE
  from mmcv.cnn.bricks.transformer import BaseTransformerLayer, TransformerLayerSequence, build_transformer_layer_sequence
  from mmcv.runner.base_module import BaseModule, Sequential
  from mmcv.utils import deprecated_api_warning, to_2tuple
  from torch.nn.init import normal_
  from ..builder import TRANSFORMER
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, with_cp)