






'''simple docstring'''



import json
import logging
import os
import socket

import git
import numpy as np
import torch


logging.basicConfig(
    format="""%(asctime)s - %(levelname)s - %(name)s - PID: %(process)d -  %(message)s""",
    datefmt="""%m/%d/%Y %H:%M:%S""",
    level=logging.INFO,
)
__UpperCamelCase      :       Union[str, Any]      			=      logging.getLogger(__name__)



def    __UpperCAmelCase	(				SCREAMING_SNAKE_CASE__:	str    )  ->			int:

   """simple docstring"""
   __a				     =    git.Repo(search_parent_directories=SCREAMING_SNAKE_CASE__    )
   __a				     =    {
       'repo_id': str(SCREAMING_SNAKE_CASE__    ),
       'repo_sha': str(repo.head.object.hexsha    ),
       'repo_branch': str(repo.active_branch    ),
   }

   with open(os.path.join(SCREAMING_SNAKE_CASE__,					'git_log.json'    ),					'w'    ) as f:
      json.dump(SCREAMING_SNAKE_CASE__,					SCREAMING_SNAKE_CASE__,					indent=4    )



def    __UpperCAmelCase	(				SCREAMING_SNAKE_CASE__:	List[str]    )  ->			str:

   """simple docstring"""
   if params.n_gpu <= 0:
      __a				     =    0
      __a				     =    -1
      __a				     =    True
      __a				     =    False
      return

   assert torch.cuda.is_available()

   logger.info('Initializing GPUs'    )
   if params.n_gpu > 1:
      assert params.local_rank != -1

      __a				     =    int(os.environ['WORLD_SIZE']    )
      __a				     =    int(os.environ['N_GPU_NODE']    )
      __a				     =    int(os.environ['RANK']    )

      # number of nodes / node ID
      __a				     =    params.world_size // params.n_gpu_per_node
      __a				     =    params.global_rank // params.n_gpu_per_node
      __a				     =    True

      assert params.n_nodes == int(os.environ['N_NODES']    )
      assert params.node_id == int(os.environ['NODE_RANK']    )

   # local job (single GPU)
   else:
      assert params.local_rank == -1

      __a				     =    1
      __a				     =    0
      __a				     =    0
      __a				     =    0
      __a				     =    1
      __a				     =    1
      __a				     =    False

   # sanity checks
   assert params.n_nodes >= 1
   assert 0 <= params.node_id < params.n_nodes
   assert 0 <= params.local_rank <= params.global_rank < params.world_size
   assert params.world_size == params.n_nodes * params.n_gpu_per_node

   # define whether this is the master process / if we are in multi-node distributed mode
   __a				     =    params.node_id == 0 and params.local_rank == 0
   __a				     =    params.n_nodes > 1

   # summary
   __a				     =    f"""--- Global rank: {params.global_rank} - """
   logger.info(PREFIX + 'Number of nodes: %i' % params.n_nodes    )
   logger.info(PREFIX + 'Node ID        : %i' % params.node_id    )
   logger.info(PREFIX + 'Local rank     : %i' % params.local_rank    )
   logger.info(PREFIX + 'World size     : %i' % params.world_size    )
   logger.info(PREFIX + 'GPUs per node  : %i' % params.n_gpu_per_node    )
   logger.info(PREFIX + 'Master         : %s' % str(params.is_master    )    )
   logger.info(PREFIX + 'Multi-node     : %s' % str(params.multi_node    )    )
   logger.info(PREFIX + 'Multi-GPU      : %s' % str(params.multi_gpu    )    )
   logger.info(PREFIX + 'Hostname       : %s' % socket.gethostname()    )

   # set GPU device
   torch.cuda.set_device(params.local_rank    )

   # initialize multi-GPU
   if params.multi_gpu:
      logger.info('Initializing PyTorch distributed'    )
      torch.distributed.init_process_group(
          init_method='env://',					backend='nccl',					)



def    __UpperCAmelCase	(				SCREAMING_SNAKE_CASE__:	Any    )  ->			Optional[Any]:

   """simple docstring"""
   np.random.seed(args.seed    )
   torch.manual_seed(args.seed    )
   if args.n_gpu > 0:
      torch.cuda.manual_seed_all(args.seed    )







'''simple docstring'''



from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__UpperCamelCase      :       Dict      			=      logging.get_logger(__name__)

__UpperCamelCase      :       Optional[int]      			=      {
    """facebook/xmod-base""": """https://huggingface.co/facebook/xmod-base/resolve/main/config.json""",
    """facebook/xmod-large-prenorm""": """https://huggingface.co/facebook/xmod-large-prenorm/resolve/main/config.json""",
    """facebook/xmod-base-13-125k""": """https://huggingface.co/facebook/xmod-base-13-125k/resolve/main/config.json""",
    """facebook/xmod-base-30-125k""": """https://huggingface.co/facebook/xmod-base-30-125k/resolve/main/config.json""",
    """facebook/xmod-base-30-195k""": """https://huggingface.co/facebook/xmod-base-30-195k/resolve/main/config.json""",
    """facebook/xmod-base-60-125k""": """https://huggingface.co/facebook/xmod-base-60-125k/resolve/main/config.json""",
    """facebook/xmod-base-60-265k""": """https://huggingface.co/facebook/xmod-base-60-265k/resolve/main/config.json""",
    """facebook/xmod-base-75-125k""": """https://huggingface.co/facebook/xmod-base-75-125k/resolve/main/config.json""",
    """facebook/xmod-base-75-269k""": """https://huggingface.co/facebook/xmod-base-75-269k/resolve/main/config.json""",
}
class 							__SCREAMING_SNAKE_CASE       (							_lowerCAmelCase     ):
      __a  					="xmod"




      def __init__(  self ,   lowerCamelCase=3_0522 ,   lowerCamelCase=768 ,   lowerCamelCase=12 ,   lowerCamelCase=12 ,   lowerCamelCase=3072 ,   lowerCamelCase="gelu" ,   lowerCamelCase=0.1 ,   lowerCamelCase=0.1 ,   lowerCamelCase=512 ,   lowerCamelCase=2 ,   lowerCamelCase=0.02 ,   lowerCamelCase=1e-12 ,   lowerCamelCase=1 ,   lowerCamelCase=0 ,   lowerCamelCase=2 ,   lowerCamelCase="absolute" ,   lowerCamelCase=True ,   lowerCamelCase=None ,   lowerCamelCase=False ,   lowerCamelCase=2 ,   lowerCamelCase=False ,   lowerCamelCase=True ,   lowerCamelCase=True ,   lowerCamelCase=("en_XX",) ,   lowerCamelCase=None ,   **lowerCamelCase ,   )							->Any:



         '''simple docstring'''
         super().__init__(pad_token_id=lowerCamelCase ,   bos_token_id=lowerCamelCase ,   eos_token_id=lowerCamelCase ,   **lowerCamelCase      )

         __a				     =    vocab_size
         __a				     =    hidden_size
         __a				     =    num_hidden_layers
         __a				     =    num_attention_heads
         __a				     =    hidden_act
         __a				     =    intermediate_size
         __a				     =    hidden_dropout_prob
         __a				     =    attention_probs_dropout_prob
         __a				     =    max_position_embeddings
         __a				     =    type_vocab_size
         __a				     =    initializer_range
         __a				     =    layer_norm_eps
         __a				     =    position_embedding_type
         __a				     =    use_cache
         __a				     =    classifier_dropout
         __a				     =    pre_norm
         __a				     =    adapter_reduction_factor
         __a				     =    adapter_layer_norm
         __a				     =    adapter_reuse_layer_norm
         __a				     =    ln_before_adapter
         __a				     =    list(lowerCamelCase      )
         __a				     =    default_language







class 							__SCREAMING_SNAKE_CASE       (							_lowerCAmelCase     ):




      @property
      def  __UpperCamelCase							(  self      )							->Mapping[str, Mapping[int, str]]:



         '''simple docstring'''
         if self.task == "multiple-choice":
            __a				     =    {0: 'batch', 1: 'choice', 2: 'sequence'}
         else:
            __a				     =    {0: 'batch', 1: 'sequence'}
         return OrderedDict(
             [
                 ('input_ids', dynamic_axis),
                 ('attention_mask', dynamic_axis),
             ]      )