


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

from tqdm import auto as tqdm_lib


SCREAMING_SNAKE_CASE       :		str         =				{
    "debug": logging.DEBUG,
    "info": logging.INFO,
    "warning": logging.WARNING,
    "error": logging.ERROR,
    "critical": logging.CRITICAL,
}

SCREAMING_SNAKE_CASE       :		Dict         =				logging.WARNING




def     UpperCamelCase    (      )					->							Tuple:
     '''simple docstring'''





     lowercase_       :int     =       os.getenv('''DATASETS_VERBOSITY'''       ,		_a		)
     if env_level_str:
          if env_level_str in log_levels:
               return log_levels[env_level_str]
          else:
               logging.getLogger().warning(
                   f"Unknown option DATASETS_VERBOSITY={env_level_str}, "
                   f"has to be one of: { ', '.join(log_levels.keys()		) }"		)
     return _default_log_level




def     UpperCamelCase    (      )					->							str:
     '''simple docstring'''





     return __name__.split('''.'''		)[0]




def     UpperCamelCase    (      )					->							logging.Logger:
     '''simple docstring'''





     return logging.getLogger(_get_library_name()		)




def     UpperCamelCase    (      )					->							None:
     '''simple docstring'''





     lowercase_       :Dict     =       _get_library_root_logger()
     library_root_logger.setLevel(_get_default_logging_level()		)




def     UpperCamelCase    (      )					->							None:
     '''simple docstring'''





     lowercase_       :List[str]     =       _get_library_root_logger()
     library_root_logger.setLevel(logging.NOTSET		)




def     UpperCamelCase    (      _a = None		)					->							logging.Logger:
     '''simple docstring'''





     if name is None:
          lowercase_       :Union[str, Any]     =       _get_library_name()
     return logging.getLogger(_a		)




def     UpperCamelCase    (      )					->							int:
     '''simple docstring'''





     return _get_library_root_logger().getEffectiveLevel()




def     UpperCamelCase    (      _a		)					->							None:
     '''simple docstring'''





     _get_library_root_logger().setLevel(_a		)




def     UpperCamelCase    (      )					->							Optional[int]:
     '''simple docstring'''





     return set_verbosity(_a		)




def     UpperCamelCase    (      )					->							List[Any]:
     '''simple docstring'''





     return set_verbosity(_a		)




def     UpperCamelCase    (      )					->							int:
     '''simple docstring'''





     return set_verbosity(_a		)




def     UpperCamelCase    (      )					->							Dict:
     '''simple docstring'''





     return set_verbosity(_a		)




def     UpperCamelCase    (      )					->							None:
     '''simple docstring'''





     lowercase_       :int     =       False




def     UpperCamelCase    (      )					->							None:
     '''simple docstring'''





     lowercase_       :Optional[int]     =       True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()






class      UpperCamelCase					:


   '''simple docstring'''







   def __init__(     self   ,							*UpperCamelCase_   ,							**UpperCamelCase_		):  # pylint: disable=unused-argument
        lowercase_       :Tuple     =       args[0] if args else None
   def __iter__(     self		):
        return iter(self._iterator		)
   def __getattr__(     self   ,							UpperCamelCase_		):

        def empty_fn(*UpperCamelCase_   ,							**UpperCamelCase_		):  # pylint: disable=unused-argument
             return

        return empty_fn
   def __enter__(     self		):
        return self




   def __exit__(     self   ,							UpperCamelCase_   ,							UpperCamelCase_   ,							UpperCamelCase_		):
        return
SCREAMING_SNAKE_CASE       :		Optional[int]         =				True






class      UpperCamelCase					:


   '''simple docstring'''







   def __call__(     self   ,							*UpperCamelCase_   ,							UpperCamelCase_=False   ,							**UpperCamelCase_		):
        if _tqdm_active and not disable:
             return tqdm_lib.tqdm(*UpperCamelCase_   ,							**UpperCamelCase_		)
        else:
             return EmptyTqdm(*UpperCamelCase_   ,							**UpperCamelCase_		)
   def 		UpperCamelCase  (     self   ,							*UpperCamelCase_   ,							**UpperCamelCase_		):
        lowercase_       :int     =       None
        if _tqdm_active:
             return tqdm_lib.tqdm.set_lock(*UpperCamelCase_   ,							**UpperCamelCase_		)




   def 		UpperCamelCase  (     self		):
        if _tqdm_active:
             return tqdm_lib.tqdm.get_lock()
SCREAMING_SNAKE_CASE       :		Optional[int]         =				_tqdm_cls()




def     UpperCamelCase    (      )					->							bool:
     '''simple docstring'''





     global _tqdm_active
     return bool(_tqdm_active		)




def     UpperCamelCase    (      )					->							str:
     '''simple docstring'''





     global _tqdm_active
     lowercase_       :str     =       True




def     UpperCamelCase    (      )					->							str:
     '''simple docstring'''





     global _tqdm_active
     lowercase_       :Optional[int]     =       False





import unittest

import numpy as np

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

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
   from transformers.models.bert.modeling_flax_bert import (
       FlaxBertForMaskedLM,
       FlaxBertForMultipleChoice,
       FlaxBertForNextSentencePrediction,
       FlaxBertForPreTraining,
       FlaxBertForQuestionAnswering,
       FlaxBertForSequenceClassification,
       FlaxBertForTokenClassification,
       FlaxBertModel,
   )






class      UpperCamelCase					(		unittest.TestCase     ):


   '''simple docstring'''







   def __init__(     self   ,							UpperCamelCase_   ,							UpperCamelCase_=13   ,							UpperCamelCase_=7   ,							UpperCamelCase_=True   ,							UpperCamelCase_=True   ,							UpperCamelCase_=True   ,							UpperCamelCase_=True   ,							UpperCamelCase_=99   ,							UpperCamelCase_=32   ,							UpperCamelCase_=5   ,							UpperCamelCase_=4   ,							UpperCamelCase_=37   ,							UpperCamelCase_="gelu"   ,							UpperCamelCase_=0.1   ,							UpperCamelCase_=0.1   ,							UpperCamelCase_=512   ,							UpperCamelCase_=16   ,							UpperCamelCase_=2   ,							UpperCamelCase_=0.02   ,							UpperCamelCase_=4   ,							):
        lowercase_       :Union[str, Any]     =       parent
        lowercase_       :int     =       batch_size
        lowercase_       :int     =       seq_length
        lowercase_       :str     =       is_training
        lowercase_       :Dict     =       use_attention_mask
        lowercase_       :List[Any]     =       use_token_type_ids
        lowercase_       :str     =       use_labels
        lowercase_       :str     =       vocab_size
        lowercase_       :Optional[int]     =       hidden_size
        lowercase_       :Dict     =       num_hidden_layers
        lowercase_       :List[str]     =       num_attention_heads
        lowercase_       :int     =       intermediate_size
        lowercase_       :Union[str, Any]     =       hidden_act
        lowercase_       :Optional[int]     =       hidden_dropout_prob
        lowercase_       :Tuple     =       attention_probs_dropout_prob
        lowercase_       :int     =       max_position_embeddings
        lowercase_       :List[Any]     =       type_vocab_size
        lowercase_       :Any     =       type_sequence_label_size
        lowercase_       :Tuple     =       initializer_range
        lowercase_       :Any     =       num_choices
   def 		UpperCamelCase  (     self		):
        lowercase_       :Optional[int]     =       ids_tensor([self.batch_size, self.seq_length]   ,							self.vocab_size		)

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

        lowercase_       :List[Any]     =       None
        if self.use_token_type_ids:
             lowercase_       :Union[str, Any]     =       ids_tensor([self.batch_size, self.seq_length]   ,							self.type_vocab_size		)

        lowercase_       :Union[str, Any]     =       BertConfig(
            vocab_size=self.vocab_size   ,							hidden_size=self.hidden_size   ,							num_hidden_layers=self.num_hidden_layers   ,							num_attention_heads=self.num_attention_heads   ,							intermediate_size=self.intermediate_size   ,							hidden_act=self.hidden_act   ,							hidden_dropout_prob=self.hidden_dropout_prob   ,							attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,							max_position_embeddings=self.max_position_embeddings   ,							type_vocab_size=self.type_vocab_size   ,							is_decoder=UpperCamelCase_   ,							initializer_range=self.initializer_range   ,							)

        return config, input_ids, token_type_ids, attention_mask
   def 		UpperCamelCase  (     self		):
        lowercase_       :Optional[Any]     =       self.prepare_config_and_inputs()
        lowercase_    ,      lowercase_    ,      lowercase_    ,      lowercase_       :List[str]     =       config_and_inputs
        lowercase_       :Union[str, Any]     =       {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
        return config, inputs_dict




   def 		UpperCamelCase  (     self		):
        lowercase_       :Dict     =       self.prepare_config_and_inputs()
        lowercase_    ,      lowercase_    ,      lowercase_    ,      lowercase_       :Dict     =       config_and_inputs

        lowercase_       :str     =       True
        lowercase_       :Dict     =       floats_tensor([self.batch_size, self.seq_length, self.hidden_size]		)
        lowercase_       :Optional[Any]     =       ids_tensor([self.batch_size, self.seq_length]   ,							vocab_size=2		)

        return (
            config,
            input_ids,
            attention_mask,
            encoder_hidden_states,
            encoder_attention_mask,
        )






@require_flax
class      UpperCamelCase					(		lowercase__						,      unittest.TestCase     ):


   '''simple docstring'''







   lowercase					:	int									=True

   lowercase					:	Dict									=(
       (
           FlaxBertModel,
           FlaxBertForPreTraining,
           FlaxBertForMaskedLM,
           FlaxBertForMultipleChoice,
           FlaxBertForQuestionAnswering,
           FlaxBertForNextSentencePrediction,
           FlaxBertForSequenceClassification,
           FlaxBertForTokenClassification,
           FlaxBertForQuestionAnswering,
       )
       if is_flax_available()
       else ()
   )
   def 		UpperCamelCase  (     self		):
        lowercase_       :Union[str, Any]     =       FlaxBertModelTester(self		)




   @slow
   def 		UpperCamelCase  (     self		):
        # Only check this for base model, not necessary for all model classes.
        # This will also help speed-up tests.
        lowercase_       :Dict     =       FlaxBertModel.from_pretrained('''bert-base-cased'''		)
        lowercase_       :str     =       model(np.ones((1, 1)		)		)
        self.assertIsNotNone(UpperCamelCase_		)

