
'''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 A				():
						global _logger
						_lowerCAmelCase  						=			_logger or logging.getLogger(__name__		)
						return _logger




class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE			):






						'''simple docstring'''






						def __init__( self   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			lock_file
												return None




						def __str__( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			F'The file lock \'{self.lock_file}\' could not be acquired.'
												return temp






class   UpperCAmelCase_					:






						'''simple docstring'''






						def __init__( self   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			lock
												return None




						def __enter__( self				):

												"""simple docstring"""



												return self.lock




						def __exit__( self   ,       _lowercase   ,       _lowercase   ,       _lowercase				):

												"""simple docstring"""



												self.lock.release()
												return None






class   UpperCAmelCase_					:






						'''simple docstring'''






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

												"""simple docstring"""



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

												# The default timeout value.
												_lowerCAmelCase  						=			timeout

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




						@property
						def  _lowercase     ( self				):

												"""simple docstring"""



												return self._lock_file




						@property
						def  _lowercase     ( self				):

												"""simple docstring"""



												return self._timeout




						@timeout.setter
						def  _lowercase     ( self   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			float(_lowercase				)
												return None




						def  _lowercase     ( self				):

												"""simple docstring"""



												raise NotImplementedError()




						def  _lowercase     ( self				):

												"""simple docstring"""



												raise NotImplementedError()




						@property
						def  _lowercase     ( self				):

												"""simple docstring"""



												return self._lock_file_fd is not None




						def  _lowercase     ( self   ,       _lowercase=None   ,       _lowercase=0.05				):

												"""simple docstring"""



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

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

																		raise
												return _Acquire_ReturnProxy(lock=self				)




						def  _lowercase     ( self   ,       _lowercase=False				):

												"""simple docstring"""



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

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

																														logger().debug(F'Attempting to release lock {lock_id} on {lock_filename}'				)
																														self._release()
																														_lowerCAmelCase  						=			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   ,       _lowercase   ,       _lowercase   ,       _lowercase				):

												"""simple docstring"""



												self.release()
												return None




						def __del__( self				):

												"""simple docstring"""



												self.release(force=_lowercase				)
												return None




						def  _lowercase     ( self   ,       _lowercase   ,       _lowercase				):

												"""simple docstring"""



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






class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE			):






						'''simple docstring'''






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

												"""simple docstring"""



												from .file_utils import relative_to_absolute_path

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




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			os.O_RDWR | os.O_CREAT | os.O_TRUNC

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




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self._lock_file_fd
												_lowerCAmelCase  						=			None
												msvcrt.locking(_lowercase   ,       msvcrt.LK_UNLCK   ,       1				)
												os.close(_lowercase				)

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






class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE			):






						'''simple docstring'''






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

												"""simple docstring"""



												_lowerCAmelCase  						=			os.statvfs(os.path.dirname(_lowercase				)				).f_namemax
												super().__init__(_lowercase   ,       timeout=_lowercase   ,       max_filename_length=_lowercase				)




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			os.O_RDWR | os.O_CREAT | os.O_TRUNC
												_lowerCAmelCase  						=			os.open(self._lock_file   ,       _lowercase				)

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




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self._lock_file_fd
												_lowerCAmelCase  						=			None
												fcntl.flock(_lowercase   ,       fcntl.LOCK_UN				)
												os.close(_lowercase				)
												return None






class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE			):






						'''simple docstring'''






						def  _lowercase     ( self				):

												"""simple docstring"""



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




						def  _lowercase     ( self				):

												"""simple docstring"""



												os.close(self._lock_file_fd				)
												_lowerCAmelCase  						=			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
from ...utils import logging


_lowercase    =		logging.get_logger(__name__)

_lowercase    =		{
    """YituTech/conv-bert-base""": """https://huggingface.co/YituTech/conv-bert-base/resolve/main/config.json""",
    """YituTech/conv-bert-medium-small""": (
        """https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/config.json"""
    ),
    """YituTech/conv-bert-small""": """https://huggingface.co/YituTech/conv-bert-small/resolve/main/config.json""",
    # See all ConvBERT models at https://huggingface.co/models?filter=convbert
}




class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE			):






						'''simple docstring'''






						_lowercase		:				List[Any]									=       '''convbert'''




						def __init__( self   ,       _lowercase=30_522   ,       _lowercase=768   ,       _lowercase=12   ,       _lowercase=12   ,       _lowercase=3_072   ,       _lowercase="gelu"   ,       _lowercase=0.1   ,       _lowercase=0.1   ,       _lowercase=512   ,       _lowercase=2   ,       _lowercase=0.02   ,       _lowercase=1e-12   ,       _lowercase=1   ,       _lowercase=0   ,       _lowercase=2   ,       _lowercase=768   ,       _lowercase=2   ,       _lowercase=9   ,       _lowercase=1   ,       _lowercase=None   ,       **_lowercase   ,       ):

												"""simple docstring"""



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

												_lowerCAmelCase  						=			vocab_size
												_lowerCAmelCase  						=			hidden_size
												_lowerCAmelCase  						=			num_hidden_layers
												_lowerCAmelCase  						=			num_attention_heads
												_lowerCAmelCase  						=			intermediate_size
												_lowerCAmelCase  						=			hidden_act
												_lowerCAmelCase  						=			hidden_dropout_prob
												_lowerCAmelCase  						=			attention_probs_dropout_prob
												_lowerCAmelCase  						=			max_position_embeddings
												_lowerCAmelCase  						=			type_vocab_size
												_lowerCAmelCase  						=			initializer_range
												_lowerCAmelCase  						=			layer_norm_eps
												_lowerCAmelCase  						=			embedding_size
												_lowerCAmelCase  						=			head_ratio
												_lowerCAmelCase  						=			conv_kernel_size
												_lowerCAmelCase  						=			num_groups
												_lowerCAmelCase  						=			classifier_dropout






class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE			):






						'''simple docstring'''






						@property
						def  _lowercase     ( self				):

												"""simple docstring"""



												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),
												    ]				)
