



'''simple docstring'''


import logging
import os
import threading
import time


try:
      import warnings
except ImportError:
      lowercase							       =			None

try:
      import msvcrt
except ImportError:
      lowercase							       =			None

try:
      import fcntl
except ImportError:
      lowercase							       =			None


# Backward compatibility
# ------------------------------------------------
try:
      TimeoutError
except NameError:
      lowercase							       =			OSError


# Data
# ------------------------------------------------
lowercase							       =			[
    '''Timeout''',
    '''BaseFileLock''',
    '''WindowsFileLock''',
    '''UnixFileLock''',
    '''SoftFileLock''',
    '''FileLock''',
]

lowercase							       =			'''3.0.12'''


lowercase							       =			None






def  UpperCAmelCase_       (		):


     '''simple docstring'''







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







class 	UpperCAmelCase	(		__a):


 '''simple docstring'''




 def __init__(   self							,  lowerCAmelCase_) ->      Optional[Any]:



      """simple docstring"""







      a_       		=lock_file
      return None




 def __str__(   self) ->      List[str]:



      """simple docstring"""







      a_       		=f"""The file lock '{self.lock_file}' could not be acquired."""
      return temp







class 	UpperCAmelCase	:


 '''simple docstring'''




 def __init__(   self							,  lowerCAmelCase_) ->      int:



      """simple docstring"""







      a_       		=lock
      return None




 def __enter__(   self) ->      Optional[int]:



      """simple docstring"""







      return self.lock




 def __exit__(   self							,  lowerCAmelCase_							,  lowerCAmelCase_							,  lowerCAmelCase_) ->      Optional[int]:



      """simple docstring"""







      self.lock.release()
      return None







class 	UpperCAmelCase	:


 '''simple docstring'''




 def __init__(   self							,  lowerCAmelCase_							,  lowerCAmelCase_=-1							,  lowerCAmelCase_=None) ->      Union[str, Any]:



      """simple docstring"""







      a_       		=max_filename_length if max_filename_length is not None else 2_5_5
      # Hash the filename if it's too long
      a_       		=self.hash_filename_if_too_long(lowerCAmelCase_							,  lowerCAmelCase_)
      # The path to the lock file.
      a_       		=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.
      a_       		=None

      # The default timeout value.
      a_       		=timeout

      # We use this lock primarily for the lock counter.
      a_       		=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.
      a_       		=0
      return None




 @property
 def       lowercase_  (   self) ->      Any:



      """simple docstring"""







      return self._lock_file




 @property
 def       lowercase_  (   self) ->      List[str]:



      """simple docstring"""







      return self._timeout




 @timeout.setter
 def       lowercase_  (   self							,  lowerCAmelCase_) ->      Optional[Any]:



      """simple docstring"""







      a_       		=float(lowerCAmelCase_)
      return None




 def       lowercase_  (   self) ->      int:



      """simple docstring"""







      raise NotImplementedError()




 def       lowercase_  (   self) ->      int:



      """simple docstring"""







      raise NotImplementedError()




 @property
 def       lowercase_  (   self) ->      Dict:



      """simple docstring"""







      return self._lock_file_fd is not None




 def       lowercase_  (   self							,  lowerCAmelCase_=None							,  lowerCAmelCase_=0.0_5) ->      Union[str, Any]:



      """simple docstring"""







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

      a_       		=id(self)
      a_       		=self._lock_file
      a_       		=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(lowerCAmelCase_)
      except:  # noqa
           # Something did go wrong, so decrement the counter.
           with self._thread_lock:
                a_       		=max(0							,  self._lock_counter - 1)

           raise
      return _Acquire_ReturnProxy(lock=self)




 def       lowercase_  (   self							,  lowerCAmelCase_=False) ->      Tuple:



      """simple docstring"""







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

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

                     logger().debug(f"""Attempting to release lock {lock_id} on {lock_filename}""")
                     self._release()
                     a_       		=0
                     logger().debug(f"""Lock {lock_id} released on {lock_filename}""")

      return None




 def __enter__(   self) ->      Optional[int]:



      """simple docstring"""







      self.acquire()
      return self




 def __exit__(   self							,  lowerCAmelCase_							,  lowerCAmelCase_							,  lowerCAmelCase_) ->      Any:



      """simple docstring"""







      self.release()
      return None




 def __del__(   self) ->      List[str]:



      """simple docstring"""







      self.release(force=lowerCAmelCase_)
      return None




 def       lowercase_  (   self							,  lowerCAmelCase_							,  lowerCAmelCase_) ->      str:



      """simple docstring"""







      a_       		=os.path.basename(lowerCAmelCase_)
      if len(lowerCAmelCase_) > max_length and max_length > 0:
           a_       		=os.path.dirname(lowerCAmelCase_)
           a_       		=str(hash(lowerCAmelCase_))
           a_       		=filename[: max_length - len(lowerCAmelCase_) - 8] + "..." + hashed_filename + ".lock"
           return os.path.join(lowerCAmelCase_							,  lowerCAmelCase_)
      else:
           return path







class 	UpperCAmelCase	(		__a):


 '''simple docstring'''




 def __init__(   self							,  lowerCAmelCase_							,  lowerCAmelCase_=-1							,  lowerCAmelCase_=None) ->      Tuple:



      """simple docstring"""







      from .file_utils import relative_to_absolute_path

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




 def       lowercase_  (   self) ->      Optional[int]:



      """simple docstring"""







      a_       		=os.O_RDWR | os.O_CREAT | os.O_TRUNC

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




 def       lowercase_  (   self) ->      List[str]:



      """simple docstring"""







      a_       		=self._lock_file_fd
      a_       		=None
      msvcrt.locking(lowerCAmelCase_							,  msvcrt.LK_UNLCK							,  1)
      os.close(lowerCAmelCase_)

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







class 	UpperCAmelCase	(		__a):


 '''simple docstring'''




 def __init__(   self							,  lowerCAmelCase_							,  lowerCAmelCase_=-1							,  lowerCAmelCase_=None) ->      List[Any]:



      """simple docstring"""







      a_       		=os.statvfs(os.path.dirname(lowerCAmelCase_)).f_namemax
      super().__init__(lowerCAmelCase_							,  timeout=lowerCAmelCase_							,  max_filename_length=lowerCAmelCase_)




 def       lowercase_  (   self) ->      Optional[Any]:



      """simple docstring"""







      a_       		=os.O_RDWR | os.O_CREAT | os.O_TRUNC
      a_       		=os.open(self._lock_file							,  lowerCAmelCase_)

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




 def       lowercase_  (   self) ->      Any:



      """simple docstring"""







      a_       		=self._lock_file_fd
      a_       		=None
      fcntl.flock(lowerCAmelCase_							,  fcntl.LOCK_UN)
      os.close(lowerCAmelCase_)
      return None







class 	UpperCAmelCase	(		__a):


 '''simple docstring'''




 def       lowercase_  (   self) ->      List[str]:



      """simple docstring"""







      a_       		=os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
      try:
           a_       		=os.open(self._lock_file							,  lowerCAmelCase_)
      except OSError:
           pass
      else:
           a_       		=fd
      return None




 def       lowercase_  (   self) ->      List[str]:



      """simple docstring"""







      os.close(self._lock_file_fd)
      a_       		=None

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



lowercase							       =			None

if msvcrt:
      lowercase							       =			WindowsFileLock
elif fcntl:
      lowercase							       =			UnixFileLock
else:
      lowercase							       =			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


lowercase							       =			{
    '''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 	UpperCAmelCase	(		__a):


 '''simple docstring'''




 __magic_name__					: int  =      "albert"




 def __init__(   self							,  lowerCAmelCase_=3_0_0_0_0							,  lowerCAmelCase_=1_2_8							,  lowerCAmelCase_=4_0_9_6							,  lowerCAmelCase_=1_2							,  lowerCAmelCase_=1							,  lowerCAmelCase_=6_4							,  lowerCAmelCase_=1_6_3_8_4							,  lowerCAmelCase_=1							,  lowerCAmelCase_="gelu_new"							,  lowerCAmelCase_=0							,  lowerCAmelCase_=0							,  lowerCAmelCase_=5_1_2							,  lowerCAmelCase_=2							,  lowerCAmelCase_=0.0_2							,  lowerCAmelCase_=1e-12							,  lowerCAmelCase_=0.1							,  lowerCAmelCase_="absolute"							,  lowerCAmelCase_=0							,  lowerCAmelCase_=2							,  lowerCAmelCase_=3							,  **lowerCAmelCase_							,  ) ->      Any:



      """simple docstring"""







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

      a_       		=vocab_size
      a_       		=embedding_size
      a_       		=hidden_size
      a_       		=num_hidden_layers
      a_       		=num_hidden_groups
      a_       		=num_attention_heads
      a_       		=inner_group_num
      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_       		=classifier_dropout_prob
      a_       		=position_embedding_type







class 	UpperCAmelCase	(		__a):


 '''simple docstring'''




 @property
 def       lowercase_  (   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),
              ("token_type_ids", dynamic_axis),
          ])


