





from collections import OrderedDict
from typing import Mapping

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


A__    :       Optional[Any]              =logging.get_logger(__name__)

A__    :       Dict              ={
    '''xlm-mlm-en-2048''': '''https://huggingface.co/xlm-mlm-en-2048/resolve/main/config.json''',
    '''xlm-mlm-ende-1024''': '''https://huggingface.co/xlm-mlm-ende-1024/resolve/main/config.json''',
    '''xlm-mlm-enfr-1024''': '''https://huggingface.co/xlm-mlm-enfr-1024/resolve/main/config.json''',
    '''xlm-mlm-enro-1024''': '''https://huggingface.co/xlm-mlm-enro-1024/resolve/main/config.json''',
    '''xlm-mlm-tlm-xnli15-1024''': '''https://huggingface.co/xlm-mlm-tlm-xnli15-1024/resolve/main/config.json''',
    '''xlm-mlm-xnli15-1024''': '''https://huggingface.co/xlm-mlm-xnli15-1024/resolve/main/config.json''',
    '''xlm-clm-enfr-1024''': '''https://huggingface.co/xlm-clm-enfr-1024/resolve/main/config.json''',
    '''xlm-clm-ende-1024''': '''https://huggingface.co/xlm-clm-ende-1024/resolve/main/config.json''',
    '''xlm-mlm-17-1280''': '''https://huggingface.co/xlm-mlm-17-1280/resolve/main/config.json''',
    '''xlm-mlm-100-1280''': '''https://huggingface.co/xlm-mlm-100-1280/resolve/main/config.json''',
}




class 			UpperCAmelCase					(      snake_case_       ):
      _lowercase:      Tuple											=       '''xlm'''
      _lowercase:      str											=       {
          '''hidden_size''': '''emb_dim''',
          '''num_attention_heads''': '''n_heads''',
          '''num_hidden_layers''': '''n_layers''',
          '''n_words''': '''vocab_size''',  # For backward compatibility
      }




      def __init__(      self      :			int      ,      __snake_case      :			Tuple=3_01_45      ,      __snake_case      :			int=20_48      ,      __snake_case      :			Dict=12      ,      __snake_case      :			Optional[int]=16      ,      __snake_case      :			List[str]=0.1      ,      __snake_case      :			Optional[int]=0.1      ,      __snake_case      :			Union[str, Any]=True      ,      __snake_case      :			Optional[Any]=False      ,      __snake_case      :			Union[str, Any]=False      ,      __snake_case      :			Optional[Any]=False      ,      __snake_case      :			Tuple=1      ,      __snake_case      :			Any=True      ,      __snake_case      :			List[str]=5_12      ,      __snake_case      :			List[Any]=20_48**-0.5      ,      __snake_case      :			Union[str, Any]=1E-1_2      ,      __snake_case      :			List[str]=0.02      ,      __snake_case      :			Dict=0      ,      __snake_case      :			Optional[Any]=1      ,      __snake_case      :			List[Any]=2      ,      __snake_case      :			int=3      ,      __snake_case      :			Optional[int]=5      ,      __snake_case      :			Optional[int]=True      ,      __snake_case      :			int="first"      ,      __snake_case      :			Any=True      ,      __snake_case      :			int=None      ,      __snake_case      :			Optional[int]=True      ,      __snake_case      :			Any=0.1      ,      __snake_case      :			Tuple=5      ,      __snake_case      :			int=5      ,      __snake_case      :			Optional[Any]=0      ,      __snake_case      :			Optional[int]=0      ,      __snake_case      :			Optional[Any]=2      ,      __snake_case      :			Optional[Any]=0      ,      **__snake_case      :			Optional[Any]      ,      )    ->				Tuple:
            _lowerCAmelCase												=							vocab_size
            _lowerCAmelCase												=							emb_dim
            _lowerCAmelCase												=							n_layers
            _lowerCAmelCase												=							n_heads
            _lowerCAmelCase												=							dropout
            _lowerCAmelCase												=							attention_dropout
            _lowerCAmelCase												=							gelu_activation
            _lowerCAmelCase												=							sinusoidal_embeddings
            _lowerCAmelCase												=							causal
            _lowerCAmelCase												=							asm
            _lowerCAmelCase												=							n_langs
            _lowerCAmelCase												=							use_lang_emb
            _lowerCAmelCase												=							layer_norm_eps
            _lowerCAmelCase												=							bos_index
            _lowerCAmelCase												=							eos_index
            _lowerCAmelCase												=							pad_index
            _lowerCAmelCase												=							unk_index
            _lowerCAmelCase												=							mask_index
            _lowerCAmelCase												=							is_encoder
            _lowerCAmelCase												=							max_position_embeddings
            _lowerCAmelCase												=							embed_init_std
            _lowerCAmelCase												=							init_std
            _lowerCAmelCase												=							summary_type
            _lowerCAmelCase												=							summary_use_proj
            _lowerCAmelCase												=							summary_activation
            _lowerCAmelCase												=							summary_proj_to_labels
            _lowerCAmelCase												=							summary_first_dropout
            _lowerCAmelCase												=							start_n_top
            _lowerCAmelCase												=							end_n_top
            _lowerCAmelCase												=							mask_token_id
            _lowerCAmelCase												=							lang_id

            if "n_words" in kwargs:
                  _lowerCAmelCase												=							kwargs["""n_words"""]

            super().__init__(pad_token_id=__snake_case      ,      bos_token_id=__snake_case      ,      **__snake_case  )




class 			UpperCAmelCase					(      snake_case_       ):




      @property
      def     lowercase__   (      self      :			Optional[Any]  )    ->				Mapping[str, Mapping[int, str]]:
            if self.task == "multiple-choice":
                  _lowerCAmelCase												=							{0: """batch""", 1: """choice""", 2: """sequence"""}
            else:
                  _lowerCAmelCase												=							{0: """batch""", 1: """sequence"""}
            return OrderedDict(
                [
                    ("""input_ids""", dynamic_axis),
                    ("""attention_mask""", dynamic_axis),
                    ("""token_type_ids""", dynamic_axis),
                ]  )













'''simple docstring'''






import inspect
import os
import unittest

import torch

import accelerate
from accelerate import debug_launcher
from accelerate.test_utils import (
    execute_subprocess_async,
    require_cpu,
    require_huggingface_suite,
    require_multi_gpu,
    require_single_gpu,
)
from accelerate.utils import patch_environment




@require_huggingface_suite
class 			UpperCAmelCase					(      unittest.TestCase       ):




      def     lowercase__   (      self      :			int  )    ->				Union[str, Any]:
            _lowerCAmelCase												=							inspect.getfile(accelerate.test_utils  )
            _lowerCAmelCase												=							os.path.sep.join(
                mod_file.split(os.path.sep  )[:-1] + ["""scripts""", """external_deps""", """test_metrics.py"""]  )

            from accelerate.test_utils.scripts.external_deps import test_metrics  # noqa: F401

            _lowerCAmelCase												=							test_metrics




      @require_cpu
      def     lowercase__   (      self      :			Optional[Any]  )    ->				Optional[Any]:
            debug_launcher(self.test_metrics.main      ,      num_processes=1  )




      @require_cpu
      def     lowercase__   (      self      :			Tuple  )    ->				Tuple:
            debug_launcher(self.test_metrics.main  )




      @require_single_gpu
      def     lowercase__   (      self      :			Union[str, Any]  )    ->				str:
            self.test_metrics.main()




      @require_multi_gpu
      def     lowercase__   (      self      :			str  )    ->				List[str]:
            print(f"Found {torch.cuda.device_count()} devices."  )
            _lowerCAmelCase												=							["""torchrun""", f"--nproc_per_node={torch.cuda.device_count()}", self.test_file_path]
            with patch_environment(omp_num_threads=1  ):
                  execute_subprocess_async(__snake_case      ,      env=os.environ.copy()  )






