




"""simple docstring"""






import functools
import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

import huggingface_hub.utils as hf_hub_utils
from tqdm import auto as tqdm_lib


UpperCamelCase__						=			threading.Lock()
UpperCamelCase__						=			None

UpperCamelCase__						=			{
    '''debug''': logging.DEBUG,
    '''info''': logging.INFO,
    '''warning''': logging.WARNING,
    '''error''': logging.ERROR,
    '''critical''': logging.CRITICAL,
}

UpperCamelCase__						=			logging.WARNING

UpperCamelCase__						=			True





def 							UpperCAmelCase		(		):
					_lowerCAmelCase:Optional[int]									=  os.getenv('''TRANSFORMERS_VERBOSITY'''      ,       snake_case    )
					if env_level_str:
										if env_level_str in log_levels:
															return log_levels[env_level_str]
										else:
															logging.getLogger().warning(
															    F'Unknown option TRANSFORMERS_VERBOSITY={env_level_str}, '
															    F'has to be one of: { ", ".join(log_levels.keys()    ) }'    )
					return _default_log_level





def 							UpperCAmelCase		(		):
					return __name__.split('''.'''    )[0]





def 							UpperCAmelCase		(		):
					return logging.getLogger(_get_library_name()    )





def 							UpperCAmelCase		(		):
					global _default_handler

					with _lock:
										if _default_handler:
															# This library has already configured the library root logger.
															return
										_lowerCAmelCase:List[str]									=  logging.StreamHandler()  # Set sys.stderr as stream.
										_lowerCAmelCase:int									=  sys.stderr.flush

										# Apply our default configuration to the library root logger.
										_lowerCAmelCase:Tuple									=  _get_library_root_logger()
										library_root_logger.addHandler(_default_handler    )
										library_root_logger.setLevel(_get_default_logging_level()    )
										_lowerCAmelCase:List[Any]									=  False





def 							UpperCAmelCase		(		):
					global _default_handler

					with _lock:
										if not _default_handler:
															return

										_lowerCAmelCase:Tuple									=  _get_library_root_logger()
										library_root_logger.removeHandler(_default_handler    )
										library_root_logger.setLevel(logging.NOTSET    )
										_lowerCAmelCase:Dict									=  None





def 							UpperCAmelCase		(		):
					return log_levels





def 							UpperCAmelCase		(		snake_case			:					Optional[str] = None    ):

					if name is None:
										_lowerCAmelCase:int									=  _get_library_name()

					_configure_library_root_logger()
					return logging.getLogger(snake_case    )





def 							UpperCAmelCase		(		):
					_configure_library_root_logger()
					return _get_library_root_logger().getEffectiveLevel()





def 							UpperCAmelCase		(		snake_case			:					int    ):
					_configure_library_root_logger()
					_get_library_root_logger().setLevel(snake_case    )





def 							UpperCAmelCase		(		):
					return set_verbosity(snake_case    )





def 							UpperCAmelCase		(		):
					return set_verbosity(snake_case    )





def 							UpperCAmelCase		(		):
					return set_verbosity(snake_case    )





def 							UpperCAmelCase		(		):
					return set_verbosity(snake_case    )





def 							UpperCAmelCase		(		):
					_configure_library_root_logger()

					assert _default_handler is not None
					_get_library_root_logger().removeHandler(_default_handler    )





def 							UpperCAmelCase		(		):
					_configure_library_root_logger()

					assert _default_handler is not None
					_get_library_root_logger().addHandler(_default_handler    )





def 							UpperCAmelCase		(		snake_case			:					logging.Handler    ):
					_configure_library_root_logger()

					assert handler is not None
					_get_library_root_logger().addHandler(snake_case    )





def 							UpperCAmelCase		(		snake_case			:					logging.Handler    ):
					_configure_library_root_logger()

					assert handler is not None and handler not in _get_library_root_logger().handlers
					_get_library_root_logger().removeHandler(snake_case    )





def 							UpperCAmelCase		(		):
					_configure_library_root_logger()
					_lowerCAmelCase:List[Any]									=  False





def 							UpperCAmelCase		(		):
					_configure_library_root_logger()
					_lowerCAmelCase:Any									=  True





def 							UpperCAmelCase		(		):
					_lowerCAmelCase:List[str]									=  _get_library_root_logger().handlers

					for handler in handlers:
										_lowerCAmelCase:Optional[Any]									=  logging.Formatter('''[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s'''    )
										handler.setFormatter(snake_case    )





def 							UpperCAmelCase		(		):
					_lowerCAmelCase:str									=  _get_library_root_logger().handlers

					for handler in handlers:
										handler.setFormatter(snake_case    )





def 							UpperCAmelCase		(		self			:					Dict      ,       *snake_case			:					Optional[Any]      ,       **snake_case			:					Tuple    ):
					_lowerCAmelCase:Any									=  os.getenv('''TRANSFORMERS_NO_ADVISORY_WARNINGS'''      ,       snake_case    )
					if no_advisory_warnings:
										return
					self.warning(*snake_case      ,       **snake_case    )


UpperCamelCase__						=			warning_advice





@functools.lru_cache(snake_case    )
def 							UpperCAmelCase		(		self			:					Optional[Any]      ,       *snake_case			:					Optional[int]      ,       **snake_case			:					int    ):
					self.warning(*snake_case      ,       **snake_case    )


UpperCamelCase__						=			warning_once




class   a__			:





						def __init__(							self      :	Any     ,*a__      :	Any     ,**a__      :	str)						->       Any:  # pylint: disable=unused-argument




											"""simple docstring"""







											_lowerCAmelCase:int									=  args[0] if args else None





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




											"""simple docstring"""







											return iter(self._iterator)





						def __getattr__(							self      :	List[Any]     ,a__      :	List[str])						->       Optional[Any]:




											"""simple docstring"""







											def empty_fn(*a__      :	Optional[Any]     ,**a__      :	Optional[int]):  # pylint: disable=unused-argument
																return

											return empty_fn





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




											"""simple docstring"""







											return self







						def __exit__(							self      :	int     ,a__      :	List[str]     ,a__      :	List[str]     ,a__      :	Optional[Any])						->       List[Any]:




											"""simple docstring"""







											return




class   a__			:





						def __call__(							self      :	List[str]     ,*a__      :	Tuple     ,**a__      :	Optional[int])						->       Any:




											"""simple docstring"""







											if _tqdm_active:
																return tqdm_lib.tqdm(*a__     ,**a__)
											else:
																return EmptyTqdm(*a__     ,**a__)





						def       __UpperCamelCase     (							self      :	int     ,*a__      :	int     ,**a__      :	Union[str, Any])						->       Optional[Any]:




											"""simple docstring"""







											_lowerCAmelCase:int									=  None
											if _tqdm_active:
																return tqdm_lib.tqdm.set_lock(*a__     ,**a__)







						def       __UpperCamelCase     (							self      :	Optional[Any])						->       int:




											"""simple docstring"""







											if _tqdm_active:
																return tqdm_lib.tqdm.get_lock()



UpperCamelCase__						=			_tqdm_cls()





def 							UpperCAmelCase		(		):
					global _tqdm_active
					return bool(_tqdm_active    )





def 							UpperCAmelCase		(		):
					global _tqdm_active
					_lowerCAmelCase:List[str]									=  True
					hf_hub_utils.enable_progress_bars()





def 							UpperCAmelCase		(		):
					global _tqdm_active
					_lowerCAmelCase:str									=  False
					hf_hub_utils.disable_progress_bars()







"""simple docstring"""






import unittest

import numpy as np

from transformers import DistilBertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
				import jax.numpy as jnp

				from transformers.models.distilbert.modeling_flax_distilbert import (
				    FlaxDistilBertForMaskedLM,
				    FlaxDistilBertForMultipleChoice,
				    FlaxDistilBertForQuestionAnswering,
				    FlaxDistilBertForSequenceClassification,
				    FlaxDistilBertForTokenClassification,
				    FlaxDistilBertModel,
				)




class   a__			(       unittest.TestCase  ):





						def __init__(							self      :	Dict     ,a__      :	List[Any]     ,a__      :	Optional[int]=13     ,a__      :	Dict=7     ,a__      :	Any=True     ,a__      :	Tuple=True     ,a__      :	Union[str, Any]=True     ,a__      :	Dict=True     ,a__      :	Dict=99     ,a__      :	Optional[Any]=32     ,a__      :	Dict=5     ,a__      :	List[Any]=4     ,a__      :	Union[str, Any]=37     ,a__      :	str="gelu"     ,a__      :	Any=0.1     ,a__      :	Optional[int]=0.1     ,a__      :	Tuple=512     ,a__      :	Any=16     ,a__      :	Any=2     ,a__      :	Dict=0.02     ,a__      :	int=4     ,)						->       Union[str, Any]:




											"""simple docstring"""







											_lowerCAmelCase:Optional[int]									=  parent
											_lowerCAmelCase:List[str]									=  batch_size
											_lowerCAmelCase:Tuple									=  seq_length
											_lowerCAmelCase:List[Any]									=  is_training
											_lowerCAmelCase:Dict									=  use_attention_mask
											_lowerCAmelCase:Dict									=  use_token_type_ids
											_lowerCAmelCase:Any									=  use_labels
											_lowerCAmelCase:str									=  vocab_size
											_lowerCAmelCase:int									=  hidden_size
											_lowerCAmelCase:Union[str, Any]									=  num_hidden_layers
											_lowerCAmelCase:List[str]									=  num_attention_heads
											_lowerCAmelCase:Optional[int]									=  intermediate_size
											_lowerCAmelCase:str									=  hidden_act
											_lowerCAmelCase:Optional[int]									=  hidden_dropout_prob
											_lowerCAmelCase:Optional[int]									=  attention_probs_dropout_prob
											_lowerCAmelCase:Any									=  max_position_embeddings
											_lowerCAmelCase:Optional[int]									=  type_vocab_size
											_lowerCAmelCase:Optional[int]									=  type_sequence_label_size
											_lowerCAmelCase:Tuple									=  initializer_range
											_lowerCAmelCase:Dict									=  num_choices





						def       __UpperCamelCase     (							self      :	List[str])						->       int:




											"""simple docstring"""







											_lowerCAmelCase:int									=  ids_tensor([self.batch_size, self.seq_length]     ,self.vocab_size)

											_lowerCAmelCase:List[Any]									=  None
											if self.use_attention_mask:
																_lowerCAmelCase:str									=  random_attention_mask([self.batch_size, self.seq_length])

											_lowerCAmelCase:Dict									=  DistilBertConfig(
											    vocab_size=self.vocab_size     ,dim=self.hidden_size     ,n_layers=self.num_hidden_layers     ,n_heads=self.num_attention_heads     ,hidden_dim=self.intermediate_size     ,hidden_act=self.hidden_act     ,dropout=self.hidden_dropout_prob     ,attention_dropout=self.attention_probs_dropout_prob     ,max_position_embeddings=self.max_position_embeddings     ,initializer_range=self.initializer_range     ,tie_weights_=a__     ,)

											return config, input_ids, attention_mask







						def       __UpperCamelCase     (							self      :	Any)						->       Any:




											"""simple docstring"""







											_lowerCAmelCase:Optional[Any]									=  self.prepare_config_and_inputs()
											_lowerCAmelCase							,   _lowerCAmelCase							,   _lowerCAmelCase:Optional[Any]									=  config_and_inputs
											_lowerCAmelCase:Any									=  {'''input_ids''': input_ids, '''attention_mask''': attention_mask}
											return config, inputs_dict




@require_flax
class   a__			(       UpperCamelCase_					,	unittest.TestCase  ):
						snake_case__             = (
						    (
						        FlaxDistilBertModel,
						        FlaxDistilBertForMaskedLM,
						        FlaxDistilBertForMultipleChoice,
						        FlaxDistilBertForQuestionAnswering,
						        FlaxDistilBertForSequenceClassification,
						        FlaxDistilBertForTokenClassification,
						        FlaxDistilBertForQuestionAnswering,
						    )
						    if is_flax_available()
						    else ()
						)





						def       __UpperCamelCase     (							self      :	str)						->       Dict:




											"""simple docstring"""







											_lowerCAmelCase:str									=  FlaxDistilBertModelTester(self)







						@slow
						def       __UpperCamelCase     (							self      :	List[str])						->       int:




											"""simple docstring"""







											for model_class_name in self.all_model_classes:
																_lowerCAmelCase:List[str]									=  model_class_name.from_pretrained('''distilbert-base-uncased''')
																_lowerCAmelCase:Tuple									=  model(np.ones((1, 1)))
																self.assertIsNotNone(a__)




@require_flax
class   a__			(       unittest.TestCase  ):





						@slow
						def       __UpperCamelCase     (							self      :	Union[str, Any])						->       Optional[Any]:




											"""simple docstring"""







											_lowerCAmelCase:Any									=  FlaxDistilBertModel.from_pretrained('''distilbert-base-uncased''')
											_lowerCAmelCase:Optional[int]									=  np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]])
											_lowerCAmelCase:Tuple									=  np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
											_lowerCAmelCase:List[str]									=  model(a__     ,attention_mask=a__)[0]
											_lowerCAmelCase:List[str]									=  (1, 11, 768)
											self.assertEqual(output.shape     ,a__)
											_lowerCAmelCase:int									=  np.array([[[-0.1639, 0.3299, 0.1648], [-0.1746, 0.3289, 0.1710], [-0.1884, 0.3357, 0.1810]]])

											self.assertTrue(jnp.allclose(output[:, 1:4, 1:4]     ,a__     ,atol=1E-4))






