





'''simple docstring'''



import logging
import os
import threading
import time


try:
 import warnings
except ImportError:
 __magic_name__   :						Tuple    =			None

try:
 import msvcrt
except ImportError:
 __magic_name__   :						List[str]    =			None

try:
 import fcntl
except ImportError:
 __magic_name__   :						int    =			None


# Backward compatibility
# ------------------------------------------------
try:
 TimeoutError
except NameError:
 __magic_name__   :						Optional[int]    =			OSError


# Data
# ------------------------------------------------
__magic_name__   :						int    =			[
    "Timeout",
    "BaseFileLock",
    "WindowsFileLock",
    "UnixFileLock",
    "SoftFileLock",
    "FileLock",
]

__magic_name__   :						List[str]    =			"3.0.12"


__magic_name__   :						str    =			None




def 				snake_case_      (		):







  '''simple docstring'''



  global _logger
  _snake_case     		=				_logger or logging.getLogger(__name__       )
  return _logger




class       __SCREAMING_SNAKE_CASE	(						_SCREAMING_SNAKE_CASE			):



     '''simple docstring'''






     def __init__(					self						,   lowerCamelCase	):
       _snake_case     		=				lock_file
       return None






     def __str__(					self	):
       _snake_case     		=				F'''The file lock \'{self.lock_file}\' could not be acquired.'''
       return temp







class       __SCREAMING_SNAKE_CASE	:



     '''simple docstring'''






     def __init__(					self						,   lowerCamelCase	):
       _snake_case     		=				lock
       return None

     def __enter__(					self	):
       return self.lock






     def __exit__(					self						,   lowerCamelCase						,   lowerCamelCase						,   lowerCamelCase	):
       self.lock.release()
       return None







class       __SCREAMING_SNAKE_CASE	:



     '''simple docstring'''






     def __init__(					self						,   lowerCamelCase						,   lowerCamelCase=-1						,   lowerCamelCase=None	):
       _snake_case     		=				max_filename_length if max_filename_length is not None else 255
       # Hash the filename if it's too long
       _snake_case     		=				self.hash_filename_if_too_long(A_						,   A_	)
       # The path to the lock file.
       _snake_case     		=				lock_file

       # The file descriptor for the *_lock_file* as it is returned by the
       # os.open() function.
       # This file lock is only NOT None, if the object currently holds the
       # lock.
       _snake_case     		=				None

       # The default timeout value.
       _snake_case     		=				timeout

       # We use this lock primarily for the lock counter.
       _snake_case     		=				threading.Lock()

       # The lock counter is used for implementing the nested locking
       # mechanism. Whenever the lock is acquired, the counter is increased and
       # the lock is only released, when this value is 0 again.
       _snake_case     		=				0
       return None

     @property
     def 	UpperCamelCase(					self	):
       return self._lock_file

     @property
     def 	UpperCamelCase(					self	):
       return self._timeout

     @timeout.setter
     def 	UpperCamelCase(					self						,   lowerCamelCase	):
       _snake_case     		=				float(A_	)
       return None

     def 	UpperCamelCase(					self	):
       raise NotImplementedError()

     def 	UpperCamelCase(					self	):
       raise NotImplementedError()

     @property
     def 	UpperCamelCase(					self	):
       return self._lock_file_fd is not None

     def 	UpperCamelCase(					self						,   lowerCamelCase=None						,   lowerCamelCase=0.05	):
       # Use the default timeout, if no timeout is provided.
       if timeout is None:
         _snake_case     		=				self.timeout

       # Increment the number right at the beginning.
       # We can still undo it, if something fails.
       with self._thread_lock:
         self._lock_counter += 1

       _snake_case     		=				id(self	)
       _snake_case     		=				self._lock_file
       _snake_case     		=				time.time()
       try:
         while True:
           with self._thread_lock:
             if not self.is_locked:
               logger().debug(F'''Attempting to acquire lock {lock_id} on {lock_filename}'''	)
               self._acquire()

           if self.is_locked:
             logger().debug(F'''Lock {lock_id} acquired on {lock_filename}'''	)
             break
           elif timeout >= 0 and time.time() - start_time > timeout:
             logger().debug(F'''Timeout on acquiring lock {lock_id} on {lock_filename}'''	)
             raise Timeout(self._lock_file	)
           else:
             logger().debug(
                 F'''Lock {lock_id} not acquired on {lock_filename}, waiting {poll_intervall} seconds ...'''	)
             time.sleep(A_	)
       except:  # noqa
         # Something did go wrong, so decrement the counter.
         with self._thread_lock:
           _snake_case     		=				max(0						,   self._lock_counter - 1	)

         raise
       return _Acquire_ReturnProxy(lock=self	)

     def 	UpperCamelCase(					self						,   lowerCamelCase=False	):
       with self._thread_lock:
         if self.is_locked:
           self._lock_counter -= 1

           if self._lock_counter == 0 or force:
             _snake_case     		=				id(self	)
             _snake_case     		=				self._lock_file

             logger().debug(F'''Attempting to release lock {lock_id} on {lock_filename}'''	)
             self._release()
             _snake_case     		=				0
             logger().debug(F'''Lock {lock_id} released on {lock_filename}'''	)

       return None

     def __enter__(					self	):
       self.acquire()
       return self

     def __exit__(					self						,   lowerCamelCase						,   lowerCamelCase						,   lowerCamelCase	):
       self.release()
       return None

     def __del__(					self	):
       self.release(force=A_	)
       return None






     def 	UpperCamelCase(					self						,   lowerCamelCase						,   lowerCamelCase	):
       _snake_case     		=				os.path.basename(A_	)
       if len(A_	) > max_length and max_length > 0:
         _snake_case     		=				os.path.dirname(A_	)
         _snake_case     		=				str(hash(A_	)	)
         _snake_case     		=				filename[: max_length - len(A_	) - 8] + "..." + hashed_filename + ".lock"
         return os.path.join(A_						,   A_	)
       else:
         return path







class       __SCREAMING_SNAKE_CASE	(						_SCREAMING_SNAKE_CASE			):



     '''simple docstring'''






     def __init__(					self						,   lowerCamelCase						,   lowerCamelCase=-1						,   lowerCamelCase=None	):
       from .file_utils import relative_to_absolute_path

       super().__init__(A_						,   timeout=A_						,   max_filename_length=A_	)
       _snake_case     		=				"\\\\?\\" + relative_to_absolute_path(self.lock_file	)

     def 	UpperCamelCase(					self	):
       _snake_case     		=				os.O_RDWR | os.O_CREAT | os.O_TRUNC

       try:
         _snake_case     		=				os.open(self._lock_file						,   A_	)
       except OSError:
         pass
       else:
         try:
           msvcrt.locking(A_						,   msvcrt.LK_NBLCK						,   1	)
         except OSError:
           os.close(A_	)
         else:
           _snake_case     		=				fd
       return None






     def 	UpperCamelCase(					self	):
       _snake_case     		=				self._lock_file_fd
       _snake_case     		=				None
       msvcrt.locking(A_						,   msvcrt.LK_UNLCK						,   1	)
       os.close(A_	)

       try:
         os.remove(self._lock_file	)
       # Probably another instance of the application
       # that acquired the file lock.
       except OSError:
         pass
       return None







class       __SCREAMING_SNAKE_CASE	(						_SCREAMING_SNAKE_CASE			):



     '''simple docstring'''






     def __init__(					self						,   lowerCamelCase						,   lowerCamelCase=-1						,   lowerCamelCase=None	):
       _snake_case     		=				os.statvfs(os.path.dirname(A_	)	).f_namemax
       super().__init__(A_						,   timeout=A_						,   max_filename_length=A_	)

     def 	UpperCamelCase(					self	):
       _snake_case     		=				os.O_RDWR | os.O_CREAT | os.O_TRUNC
       _snake_case     		=				os.open(self._lock_file						,   A_	)

       try:
         fcntl.flock(A_						,   fcntl.LOCK_EX | fcntl.LOCK_NB	)
       except OSError:
         os.close(A_	)
       else:
         _snake_case     		=				fd
       return None






     def 	UpperCamelCase(					self	):
       _snake_case     		=				self._lock_file_fd
       _snake_case     		=				None
       fcntl.flock(A_						,   fcntl.LOCK_UN	)
       os.close(A_	)
       return None







class       __SCREAMING_SNAKE_CASE	(						_SCREAMING_SNAKE_CASE			):



     '''simple docstring'''






     def 	UpperCamelCase(					self	):
       _snake_case     		=				os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
       try:
         _snake_case     		=				os.open(self._lock_file						,   A_	)
       except OSError:
         pass
       else:
         _snake_case     		=				fd
       return None






     def 	UpperCamelCase(					self	):
       os.close(self._lock_file_fd	)
       _snake_case     		=				None

       try:
         os.remove(self._lock_file	)
       # The file is already deleted and that's what we want.
       except OSError:
         pass
       return None







__magic_name__   :						str    =			None

if msvcrt:
 __magic_name__   :						Tuple    =			WindowsFileLock
elif fcntl:
 __magic_name__   :						Any    =			UnixFileLock
else:
 __magic_name__   :						int    =			SoftFileLock

 if warnings is not None:
  warnings.warn("""only soft file lock is available""")









'''simple docstring'''



from collections import OrderedDict
from typing import Mapping

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


__magic_name__   :						int    =			logging.get_logger(__name__)

__magic_name__   :						Tuple    =			{
    """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       __SCREAMING_SNAKE_CASE	(						__UpperCamelCase			):



     '''simple docstring'''






     UpperCAmelCase__       :						Union[str, Any]      =   '''xlm'''
     UpperCAmelCase__       :						Dict      =   {
         '''hidden_size''': '''emb_dim''',
         '''num_attention_heads''': '''n_heads''',
         '''num_hidden_layers''': '''n_layers''',
         '''n_words''': '''vocab_size''',  # For backward compatibility
     }

     def __init__(					self						,   lowerCamelCase=30_145						,   lowerCamelCase=2_048						,   lowerCamelCase=12						,   lowerCamelCase=16						,   lowerCamelCase=0.1						,   lowerCamelCase=0.1						,   lowerCamelCase=True						,   lowerCamelCase=False						,   lowerCamelCase=False						,   lowerCamelCase=False						,   lowerCamelCase=1						,   lowerCamelCase=True						,   lowerCamelCase=512						,   lowerCamelCase=2_048**-0.5						,   lowerCamelCase=1e-12						,   lowerCamelCase=0.02						,   lowerCamelCase=0						,   lowerCamelCase=1						,   lowerCamelCase=2						,   lowerCamelCase=3						,   lowerCamelCase=5						,   lowerCamelCase=True						,   lowerCamelCase="first"						,   lowerCamelCase=True						,   lowerCamelCase=None						,   lowerCamelCase=True						,   lowerCamelCase=0.1						,   lowerCamelCase=5						,   lowerCamelCase=5						,   lowerCamelCase=0						,   lowerCamelCase=0						,   lowerCamelCase=2						,   lowerCamelCase=0						,   **lowerCamelCase						,   ):
       _snake_case     		=				vocab_size
       _snake_case     		=				emb_dim
       _snake_case     		=				n_layers
       _snake_case     		=				n_heads
       _snake_case     		=				dropout
       _snake_case     		=				attention_dropout
       _snake_case     		=				gelu_activation
       _snake_case     		=				sinusoidal_embeddings
       _snake_case     		=				causal
       _snake_case     		=				asm
       _snake_case     		=				n_langs
       _snake_case     		=				use_lang_emb
       _snake_case     		=				layer_norm_eps
       _snake_case     		=				bos_index
       _snake_case     		=				eos_index
       _snake_case     		=				pad_index
       _snake_case     		=				unk_index
       _snake_case     		=				mask_index
       _snake_case     		=				is_encoder
       _snake_case     		=				max_position_embeddings
       _snake_case     		=				embed_init_std
       _snake_case     		=				init_std
       _snake_case     		=				summary_type
       _snake_case     		=				summary_use_proj
       _snake_case     		=				summary_activation
       _snake_case     		=				summary_proj_to_labels
       _snake_case     		=				summary_first_dropout
       _snake_case     		=				start_n_top
       _snake_case     		=				end_n_top
       _snake_case     		=				mask_token_id
       _snake_case     		=				lang_id

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

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







class       __SCREAMING_SNAKE_CASE	(						__UpperCamelCase			):



     '''simple docstring'''






     @property
     def 	UpperCamelCase(					self	):
       if self.task == "multiple-choice":
         _snake_case     		=				{0: "batch", 1: "choice", 2: "sequence"}
       else:
         _snake_case     		=				{0: "batch", 1: "sequence"}
       return OrderedDict(
           [
               ("input_ids", dynamic_axis),
               ("attention_mask", dynamic_axis),
               ("token_type_ids", dynamic_axis),
           ]	)


