class_docstr: The configuration structure to define a Transformer block.
  This base class is applicable to both encoder and decoder definitions.
  
  This completely defines each of the blocks, for instance in terms of dimensions,
  position encoding, pre or post layer norms or reversibility.
class_docstr_tok: ["The","configuration","structure","to","define","a","Transformer","block",".","This","base","class","is","applicable","to","both","encoder","and","decoder","definitions",".","This","completely","defines","each","of","the","blocks",",","for","instance","in","terms","of","dimensions",",","position","encoding",",","pre","or","post","layer","norms","or","reversibility","."]
code: def __init__(
      self,
      dim_model: int,
      feedforward_config: Dict[str, Any],
      position_encoding_config: Optional[Dict[str, Any]],
      block_type: BlockType,
      residual_norm_style: ResidualNormStyle = ResidualNormStyle(
          "post"
      ),
      normalization: NormalizationType = NormalizationType.LayerNorm,
      reversible: bool = False,
      num_layers: int = 1,
      layer_position: Optional[LayerPosition] = None,
  ):
      self.dim_model = dim_model
      self.block_type = block_type
      self.residual_norm_style = residual_norm_style
      self.reversible = reversible
      self.num_layers = num_layers
      self.normalization = normalization
  
      # Fill in possible gaps in the config for subparts of the block
      self.feedforward_config = generate_matching_config(
          feedforward_config,
          FEEDFORWARD_REGISTRY[feedforward_config["name"]].config,
      )
  
      self.position_encoding_config = (
          generate_matching_config(
              position_encoding_config,
              POSITION_EMBEDDING_REGISTRY[
                  position_encoding_config["name"]
              ].config,
          )
          if position_encoding_config is not None
          else None
      )
  
      # Default is that this layer is the only one, so both first and last
      if layer_position:
          self.layer_position = layer_position
      else:
          self.layer_position = LayerPosition()
  
imports: from dataclasses import dataclass
  from enum import Enum
  from typing import Any, Dict, Optional
  from xformers.components import NormalizationType, ResidualNormStyle
  from xformers.components.feedforward import FEEDFORWARD_REGISTRY, FeedforwardConfig
  from xformers.components.positional_embedding import POSITION_EMBEDDING_REGISTRY, PositionEmbeddingConfig
  from xformers.utils import generate_matching_config
label_desc: Use image node_id 1 to create a new xFormerBlockConfig object  with example: obj = xFormerBlockConfig(dim_model, feedforward_config, position_encoding_config, block_type, residual_norm_style, normalization, reversible, num_layers, layer_position)