code: def _get_ln_factory(
      d_model: int,
      residual_norm_style: Optional[ResidualNormStyle],
      use_triton: bool,
      residual: bool,
      normalization: NormalizationType = NormalizationType.LayerNorm,
      residual_scale: float = 1.0,
  ):
      """
      Handle all the supported residual path configurations.
  
      ..Note: we return the appropriate constructor, not an actual layer
      """
  
      def get_layer_wrapper(
          d_model: int,
          sublayer: nn.Module,
          residual_norm_style: Optional[ResidualNormStyle],
          residual: bool,
          residual_scale: float,
      ):
          if residual:
              if residual_norm_style == ResidualNormStyle.Pre:
                  return Residual(
                      layer=PreNorm(
                          d_model, sublayer, normalization, use_triton
                      ),
                      scale=None,
                  )
              elif residual_norm_style == ResidualNormStyle.Post:
                  return PostNorm(
                      d_model,
                      Residual(layer=sublayer, scale=None),
                      normalization,
                      use_triton,
                  )
              elif residual_norm_style == ResidualNormStyle.DeepNorm:
                  return PostNorm(
                      d_model,
                      Residual(layer=sublayer, scale=residual_scale),
                      normalization,
                      use_triton=use_triton,
                  )
              else:
                  raise ValueError
  
          return (
              PreNorm(d_model, sublayer, normalization, use_triton)
              if residual_norm_style == ResidualNormStyle.Pre
              else PostNorm(
                  d_model, sublayer, normalization, use_triton
              )
          )
  
      def ln_factory(sublayer: nn.Module):
          return get_layer_wrapper(
              d_model,
              sublayer,
              residual_norm_style,
              residual,
              residual_scale,
          )
  
      return ln_factory
  
imports: import logging
  from dataclasses import asdict
  from typing import Optional, Tuple, Union
  import torch
  import torch.nn
  from xformers._deprecation_warning import deprecated_function
  from xformers.components import PatchEmbeddingConfig, PostNorm, PreNorm, Residual, ResidualNormStyle, build_multi_head_attention, build_patch_embedding
  from xformers.components.attention import AttentionMask
  from xformers.components.feedforward import build_feedforward
  from xformers.components.positional_embedding import build_positional_embedding
  from xformers.components.residual import get_deepnorm_coefficients
  from xformers.components.simplicial_embedding import SimplicialEmbedding
  from xformers.factory.block_configs import NormalizationType, xFormerDecoderConfig, xFormerEncoderConfig
label_desc: Use image node_id 1 for calling a global function with example usage: _get_ln_factory(d_model, residual_norm_style, use_triton, residual, normalization, residual_scale) and returns: ln_factory, unknown, get_layer_wrapper, Residual, PostNorm, PostNorm