code: def transformer_weights_init(
      module, std_init_range=0.02, xavier=True
  ):
      """
      Initialize different weights in Transformer model.
  
      Args:
          module: torch.nn.Module to be initialized
          std_init_range: standard deviation of normal initializer
          xavier: if True, xavier initializer will be used in Linear layers
              as was proposed in AIAYN paper, otherwise normal initializer
              will be used (like in BERT paper)
      """
  
      if isinstance(module, nn.Linear):
          if xavier:
              nn.init.xavier_uniform_(module.weight)
          else:
              nn.init.normal_(
                  module.weight, mean=0.0, std=std_init_range
              )
          if module.bias is not None:
              nn.init.constant_(module.bias, 0.0)
      elif isinstance(module, nn.Embedding):
          nn.init.normal_(module.weight, mean=0.0, std=std_init_range)
      elif isinstance(module, nn.LayerNorm):
          nn.init.constant_(module.weight, 1.0)
          nn.init.constant_(module.bias, 0.0)
  
imports: import torch
  import torch.nn
label_desc: Use image node_id 2 for calling a global function with example usage: transformer_weights_init(module, std_init_range, xavier) without return types