'''simple docstring'''


import logging
import os
import threading
import time


try:
  import warnings
except ImportError:
  snake_case__					:      List[str]				      =  None

try:
  import msvcrt
except ImportError:
  snake_case__					:      Optional[Any]				      =  None

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


# Backward compatibility
# ------------------------------------------------
try:
  TimeoutError
except NameError:
  snake_case__					:      Union[str, Any]				      =  OSError


# Data
# ------------------------------------------------
snake_case__					:      str				      =  [
    '''Timeout''',
    '''BaseFileLock''',
    '''WindowsFileLock''',
    '''UnixFileLock''',
    '''SoftFileLock''',
    '''FileLock''',
]

snake_case__					:      Any				      =  '''3.0.12'''


snake_case__					:      List[str]				      =  None


def  _lowerCamelCase   (				):



     """simple docstring"""





     global _logger
     UpperCAmelCase_							:       List[str]       =				_logger or logging.getLogger(__name__       )
     return _logger






class 					__SCREAMING_SNAKE_CASE						(	lowerCamelCase_	):







  '''simple docstring'''






  def __init__(			self				,		snake_case_						):




       '''simple docstring'''

       UpperCAmelCase_							:       Dict       =				lock_file
       return None






  def __str__(			self						):




       '''simple docstring'''

       UpperCAmelCase_							:       Union[str, Any]       =				F'''The file lock \'{self.lock_file}\' could not be acquired.'''
       return temp







class 					__SCREAMING_SNAKE_CASE						:







  '''simple docstring'''






  def __init__(			self				,		snake_case_						):




       '''simple docstring'''

       UpperCAmelCase_							:       int       =				lock
       return None


  def __enter__(			self						):




       '''simple docstring'''

       return self.lock






  def __exit__(			self				,		snake_case_				,		snake_case_				,		snake_case_						):




       '''simple docstring'''

       self.lock.release()
       return None







class 					__SCREAMING_SNAKE_CASE						:







  '''simple docstring'''






  def __init__(			self				,		snake_case_				,		snake_case_=-1				,		snake_case_=None						):




       '''simple docstring'''

       UpperCAmelCase_							:       Union[str, Any]       =				max_filename_length if max_filename_length is not None else 2_5_5
       # Hash the filename if it's too long
       UpperCAmelCase_							:       Any       =				self.hash_filename_if_too_long(snake_case_				,		snake_case_						)
       # The path to the lock file.
       UpperCAmelCase_							:       Dict       =				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.
       UpperCAmelCase_							:       Any       =				None

       # The default timeout value.
       UpperCAmelCase_							:       Optional[int]       =				timeout

       # We use this lock primarily for the lock counter.
       UpperCAmelCase_							:       Optional[Any]       =				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.
       UpperCAmelCase_							:       List[str]       =				0
       return None


  @property
  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       return self._lock_file


  @property
  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       return self._timeout


  @timeout.setter
  def _UpperCamelCase					(			self				,		snake_case_						):




       '''simple docstring'''

       UpperCAmelCase_							:       Union[str, Any]       =				float(snake_case_						)
       return None


  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       raise NotImplementedError()


  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       raise NotImplementedError()


  @property
  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       return self._lock_file_fd is not None


  def _UpperCamelCase					(			self				,		snake_case_=None				,		snake_case_=0.05						):




       '''simple docstring'''

       if timeout is None:
            UpperCAmelCase_							:       Any       =				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

       UpperCAmelCase_							:       List[str]       =				id(self						)
       UpperCAmelCase_							:       Optional[Any]       =				self._lock_file
       UpperCAmelCase_							:       Optional[Any]       =				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(snake_case_						)
       except:  # noqa
            # Something did go wrong, so decrement the counter.
            with self._thread_lock:
                 UpperCAmelCase_							:       str       =				max(0				,		self._lock_counter - 1						)

            raise
       return _Acquire_ReturnProxy(lock=self						)


  def _UpperCamelCase					(			self				,		snake_case_=False						):




       '''simple docstring'''

       with self._thread_lock:
            if self.is_locked:
                 self._lock_counter -= 1

                 if self._lock_counter == 0 or force:
                      UpperCAmelCase_							:       Optional[int]       =				id(self						)
                      UpperCAmelCase_							:       Any       =				self._lock_file

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

       return None


  def __enter__(			self						):




       '''simple docstring'''

       self.acquire()
       return self


  def __exit__(			self				,		snake_case_				,		snake_case_				,		snake_case_						):




       '''simple docstring'''

       self.release()
       return None


  def __del__(			self						):




       '''simple docstring'''

       self.release(force=snake_case_						)
       return None






  def _UpperCamelCase					(			self				,		snake_case_				,		snake_case_						):




       '''simple docstring'''

       UpperCAmelCase_							:       Tuple       =				os.path.basename(snake_case_						)
       if len(snake_case_						) > max_length and max_length > 0:
            UpperCAmelCase_							:       Dict       =				os.path.dirname(snake_case_						)
            UpperCAmelCase_							:       Any       =				str(hash(snake_case_						)						)
            UpperCAmelCase_							:       Dict       =				filename[: max_length - len(snake_case_						) - 8] + '...' + hashed_filename + '.lock'
            return os.path.join(snake_case_				,		snake_case_						)
       else:
            return path







class 					__SCREAMING_SNAKE_CASE						(	lowerCamelCase_	):







  '''simple docstring'''






  def __init__(			self				,		snake_case_				,		snake_case_=-1				,		snake_case_=None						):




       '''simple docstring'''

       from .file_utils import relative_to_absolute_path

       super().__init__(snake_case_				,		timeout=snake_case_				,		max_filename_length=snake_case_						)
       UpperCAmelCase_							:       List[Any]       =				'\\\\?\\' + relative_to_absolute_path(self.lock_file						)


  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       UpperCAmelCase_							:       List[Any]       =				os.O_RDWR | os.O_CREAT | os.O_TRUNC

       try:
            UpperCAmelCase_							:       Dict       =				os.open(self._lock_file				,		snake_case_						)
       except OSError:
            pass
       else:
            try:
                 msvcrt.locking(snake_case_				,		msvcrt.LK_NBLCK				,		1						)
            except OSError:
                 os.close(snake_case_						)
            else:
                 UpperCAmelCase_							:       List[Any]       =				fd
       return None






  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       UpperCAmelCase_							:       int       =				self._lock_file_fd
       UpperCAmelCase_							:       Union[str, Any]       =				None
       msvcrt.locking(snake_case_				,		msvcrt.LK_UNLCK				,		1						)
       os.close(snake_case_						)

       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						(	lowerCamelCase_	):







  '''simple docstring'''






  def __init__(			self				,		snake_case_				,		snake_case_=-1				,		snake_case_=None						):




       '''simple docstring'''

       UpperCAmelCase_							:       List[str]       =				os.statvfs(os.path.dirname(snake_case_						)						).f_namemax
       super().__init__(snake_case_				,		timeout=snake_case_				,		max_filename_length=snake_case_						)


  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       UpperCAmelCase_							:       int       =				os.O_RDWR | os.O_CREAT | os.O_TRUNC
       UpperCAmelCase_							:       List[str]       =				os.open(self._lock_file				,		snake_case_						)

       try:
            fcntl.flock(snake_case_				,		fcntl.LOCK_EX | fcntl.LOCK_NB						)
       except OSError:
            os.close(snake_case_						)
       else:
            UpperCAmelCase_							:       List[str]       =				fd
       return None






  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       UpperCAmelCase_							:       Union[str, Any]       =				self._lock_file_fd
       UpperCAmelCase_							:       str       =				None
       fcntl.flock(snake_case_				,		fcntl.LOCK_UN						)
       os.close(snake_case_						)
       return None







class 					__SCREAMING_SNAKE_CASE						(	lowerCamelCase_	):







  '''simple docstring'''






  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       UpperCAmelCase_							:       Union[str, Any]       =				os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
       try:
            UpperCAmelCase_							:       List[str]       =				os.open(self._lock_file				,		snake_case_						)
       except OSError:
            pass
       else:
            UpperCAmelCase_							:       Dict       =				fd
       return None






  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       os.close(self._lock_file_fd						)
       UpperCAmelCase_							:       Optional[Any]       =				None

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







snake_case__					:      List[str]				      =  None

if msvcrt:
  snake_case__					:      Any				      =  WindowsFileLock
elif fcntl:
  snake_case__					:      List[str]				      =  UnixFileLock
else:
  snake_case__					:      Optional[Any]				      =  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


snake_case__					:      Dict				      =  {
    '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/config.json''',
    '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/config.json''',
    '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/config.json''',
    '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/config.json''',
    '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/config.json''',
    '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/config.json''',
    '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/config.json''',
    '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/config.json''',
}






class 					__SCREAMING_SNAKE_CASE						(	lowerCamelCase_	):







  '''simple docstring'''






  lowerCamelCase_		:str						   =		'''albert'''


  def __init__(			self				,		snake_case_=3_0_0_0_0				,		snake_case_=1_2_8				,		snake_case_=4_0_9_6				,		snake_case_=1_2				,		snake_case_=1				,		snake_case_=6_4				,		snake_case_=1_6_3_8_4				,		snake_case_=1				,		snake_case_="gelu_new"				,		snake_case_=0				,		snake_case_=0				,		snake_case_=5_1_2				,		snake_case_=2				,		snake_case_=0.02				,		snake_case_=1E-12				,		snake_case_=0.1				,		snake_case_="absolute"				,		snake_case_=0				,		snake_case_=2				,		snake_case_=3				,		**snake_case_				,		):




       '''simple docstring'''

       super().__init__(pad_token_id=snake_case_				,		bos_token_id=snake_case_				,		eos_token_id=snake_case_				,		**snake_case_						)

       UpperCAmelCase_							:       List[Any]       =				vocab_size
       UpperCAmelCase_							:       Dict       =				embedding_size
       UpperCAmelCase_							:       str       =				hidden_size
       UpperCAmelCase_							:       Any       =				num_hidden_layers
       UpperCAmelCase_							:       Union[str, Any]       =				num_hidden_groups
       UpperCAmelCase_							:       List[str]       =				num_attention_heads
       UpperCAmelCase_							:       Any       =				inner_group_num
       UpperCAmelCase_							:       Optional[int]       =				hidden_act
       UpperCAmelCase_							:       Tuple       =				intermediate_size
       UpperCAmelCase_							:       Any       =				hidden_dropout_prob
       UpperCAmelCase_							:       List[str]       =				attention_probs_dropout_prob
       UpperCAmelCase_							:       Union[str, Any]       =				max_position_embeddings
       UpperCAmelCase_							:       Dict       =				type_vocab_size
       UpperCAmelCase_							:       Union[str, Any]       =				initializer_range
       UpperCAmelCase_							:       Optional[Any]       =				layer_norm_eps
       UpperCAmelCase_							:       Dict       =				classifier_dropout_prob
       UpperCAmelCase_							:       Tuple       =				position_embedding_type







class 					__SCREAMING_SNAKE_CASE						(	lowerCamelCase_	):







  '''simple docstring'''






  @property
  def _UpperCamelCase					(			self						):




       '''simple docstring'''

       if self.task == "multiple-choice":
            UpperCAmelCase_							:       Optional[Any]       =				{0: 'batch', 1: 'choice', 2: 'sequence'}
       else:
            UpperCAmelCase_							:       List[Any]       =				{0: 'batch', 1: 'sequence'}
       return OrderedDict(
           [
               ('input_ids', dynamic_axis),
               ('attention_mask', dynamic_axis),
               ('token_type_ids', dynamic_axis),
           ]						)






