'''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


_A								=   threading.Lock()
_A								=   None

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

_A								=   logging.WARNING

_A								=   True

def _UpperCamelCase   (       ):
     lowercase_					:       Optional[Any]     				=					os.getenv('TRANSFORMERS_VERBOSITY'  ,       SCREAMING_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
          lowercase_					:       Any     				=					logging.StreamHandler()  # Set sys.stderr as stream.
          lowercase_					:       str     				=					sys.stderr.flush

          # Apply our default configuration to the library root logger.
          lowercase_					:       int     				=					_get_library_root_logger()
          library_root_logger.addHandler(_default_handler							)
          library_root_logger.setLevel(_get_default_logging_level()							)
          lowercase_					:       str     				=					False

def _UpperCamelCase   (       ):
     global _default_handler

     with _lock:
          if not _default_handler:
               return

          lowercase_					:       Any     				=					_get_library_root_logger()
          library_root_logger.removeHandler(_default_handler							)
          library_root_logger.setLevel(logging.NOTSET							)
          lowercase_					:       List[str]     				=					None

def _UpperCamelCase   (       ):
     return log_levels

def _UpperCamelCase   (       SCREAMING_SNAKE_CASE_ = None							):

     if name is None:
          lowercase_					:       Optional[int]     				=					_get_library_name()

     _configure_library_root_logger()
     return logging.getLogger(SCREAMING_SNAKE_CASE_							)

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

def _UpperCamelCase   (       SCREAMING_SNAKE_CASE_							):
     _configure_library_root_logger()
     _get_library_root_logger().setLevel(SCREAMING_SNAKE_CASE_							)

def _UpperCamelCase   (       ):
     return set_verbosity(SCREAMING_SNAKE_CASE_							)

def _UpperCamelCase   (       ):
     return set_verbosity(SCREAMING_SNAKE_CASE_							)

def _UpperCamelCase   (       ):
     return set_verbosity(SCREAMING_SNAKE_CASE_							)

def _UpperCamelCase   (       ):
     return set_verbosity(SCREAMING_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   (       SCREAMING_SNAKE_CASE_							):
     _configure_library_root_logger()

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

def _UpperCamelCase   (       SCREAMING_SNAKE_CASE_							):
     _configure_library_root_logger()

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

def _UpperCamelCase   (       ):
     _configure_library_root_logger()
     lowercase_					:       List[Any]     				=					False

def _UpperCamelCase   (       ):
     _configure_library_root_logger()
     lowercase_					:       List[str]     				=					True

def _UpperCamelCase   (       ):
     lowercase_					:       Optional[int]     				=					_get_library_root_logger().handlers

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

def _UpperCamelCase   (       ):
     lowercase_					:       List[Any]     				=					_get_library_root_logger().handlers

     for handler in handlers:
          handler.setFormatter(SCREAMING_SNAKE_CASE_							)

def _UpperCamelCase   (       self  ,       *SCREAMING_SNAKE_CASE_  ,       **SCREAMING_SNAKE_CASE_							):
     lowercase_					:       Dict     				=					os.getenv('TRANSFORMERS_NO_ADVISORY_WARNINGS'  ,       SCREAMING_SNAKE_CASE_							)
     if no_advisory_warnings:
          return
     self.warning(*SCREAMING_SNAKE_CASE_  ,       **SCREAMING_SNAKE_CASE_							)


_A								=   warning_advice

@functools.lru_cache(SCREAMING_SNAKE_CASE_							)
def _UpperCamelCase   (       self  ,       *SCREAMING_SNAKE_CASE_  ,       **SCREAMING_SNAKE_CASE_							):
     self.warning(*SCREAMING_SNAKE_CASE_  ,       **SCREAMING_SNAKE_CASE_							)


_A								=   warning_once


class       UpperCAmelCase__  :






   """simple docstring"""
   def __init__(self       ,				*_a       ,				**_a				)    ->     Any:  # pylint: disable=unused-argument
        lowercase_					:       Optional[int]     				=					args[0] if args else None
   def __iter__(self				)    ->     Optional[Any]:
        return iter(self._iterator				)
   def __getattr__(self       ,				_a				)    ->     Dict:

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

        return empty_fn
   def __enter__(self				)    ->     Dict:
        return self





   def __exit__(self       ,				_a       ,				_a       ,				_a				)    ->     List[Any]:
        return



class       UpperCAmelCase__  :






   """simple docstring"""
   def __call__(self       ,				*_a       ,				**_a				)    ->     Union[str, Any]:
        if _tqdm_active:
             return tqdm_lib.tqdm(*_a       ,				**_a				)
        else:
             return EmptyTqdm(*_a       ,				**_a				)
   def 		_lowerCamelCase (self       ,				*_a       ,				**_a				)    ->     Any:
        lowercase_					:       List[str]     				=					None
        if _tqdm_active:
             return tqdm_lib.tqdm.set_lock(*_a       ,				**_a				)





   def 		_lowerCamelCase (self				)    ->     Dict:
        if _tqdm_active:
             return tqdm_lib.tqdm.get_lock()



_A								=   _tqdm_cls()

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

def _UpperCamelCase   (       ):
     global _tqdm_active
     lowercase_					:       List[Any]     				=					True
     hf_hub_utils.enable_progress_bars()






def _UpperCamelCase   (       ):
     global _tqdm_active
     lowercase_					:       Any     				=					False
     hf_hub_utils.disable_progress_bars()





'''simple docstring'''




from __future__ import annotations

import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_tf, slow
from transformers.utils import is_tf_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask


if is_tf_available():
 import tensorflow as tf

 from transformers import TFBlipTextModel
 from transformers.models.blip.modeling_tf_blip import TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST


class       UpperCAmelCase__  :






   """simple docstring"""
   def __init__(self       ,				_a       ,				_a=12       ,				_a=7       ,				_a=True       ,				_a=True       ,				_a=True       ,				_a=99       ,				_a=32       ,				_a=32       ,				_a=2       ,				_a=4       ,				_a=37       ,				_a=0.1       ,				_a=0.1       ,				_a=512       ,				_a=0.02       ,				_a=0       ,				_a=None       ,				)    ->     Optional[Any]:
        lowercase_					:       List[Any]     				=					parent
        lowercase_					:       List[Any]     				=					batch_size
        lowercase_					:       Optional[Any]     				=					seq_length
        lowercase_					:       Optional[Any]     				=					is_training
        lowercase_					:       Optional[int]     				=					use_input_mask
        lowercase_					:       Any     				=					use_labels
        lowercase_					:       Union[str, Any]     				=					vocab_size
        lowercase_					:       Union[str, Any]     				=					hidden_size
        lowercase_					:       str     				=					projection_dim
        lowercase_					:       str     				=					num_hidden_layers
        lowercase_					:       List[str]     				=					num_attention_heads
        lowercase_					:       List[str]     				=					intermediate_size
        lowercase_					:       Optional[Any]     				=					dropout
        lowercase_					:       Tuple     				=					attention_dropout
        lowercase_					:       Optional[Any]     				=					max_position_embeddings
        lowercase_					:       Any     				=					initializer_range
        lowercase_					:       List[str]     				=					scope
        lowercase_					:       Optional[Any]     				=					bos_token_id
   def 		_lowerCamelCase (self				)    ->     Tuple:
        lowercase_					:       Optional[Any]     				=					ids_tensor([self.batch_size, self.seq_length]       ,				self.vocab_size				)

        lowercase_					:       Optional[int]     				=					None
        if self.use_input_mask:
             lowercase_					:       Dict     				=					random_attention_mask([self.batch_size, self.seq_length]				)

        if input_mask is not None:
             lowercase_					:       Dict     				=					input_mask.numpy()
             lowercase_				,lowercase_					:       int     				=					input_mask.shape
             lowercase_					:       int     				=					np.random.randint(1       ,				seq_length - 1       ,				size=(batch_size,)				)
             for batch_idx, start_index in enumerate(_a				):
                  lowercase_					:       Tuple     				=					1
                  lowercase_					:       List[Any]     				=					0

        lowercase_					:       List[Any]     				=					self.get_config()

        return config, input_ids, tf.convert_to_tensor(_a				)
   def 		_lowerCamelCase (self				)    ->     Any:
        return BlipTextConfig(
            vocab_size=self.vocab_size       ,				hidden_size=self.hidden_size       ,				projection_dim=self.projection_dim       ,				num_hidden_layers=self.num_hidden_layers       ,				num_attention_heads=self.num_attention_heads       ,				intermediate_size=self.intermediate_size       ,				dropout=self.dropout       ,				attention_dropout=self.attention_dropout       ,				max_position_embeddings=self.max_position_embeddings       ,				initializer_range=self.initializer_range       ,				bos_token_id=self.bos_token_id       ,				)
   def 		_lowerCamelCase (self       ,				_a       ,				_a       ,				_a				)    ->     List[Any]:
        lowercase_					:       List[Any]     				=					TFBlipTextModel(config=_a				)
        lowercase_					:       List[str]     				=					model(_a       ,				attention_mask=_a       ,				training=_a				)
        lowercase_					:       Union[str, Any]     				=					model(_a       ,				training=_a				)
        self.parent.assertEqual(result.last_hidden_state.shape       ,				(self.batch_size, self.seq_length, self.hidden_size)				)
        self.parent.assertEqual(result.pooler_output.shape       ,				(self.batch_size, self.hidden_size)				)





   def 		_lowerCamelCase (self				)    ->     Dict:
        lowercase_					:       Optional[Any]     				=					self.prepare_config_and_inputs()
        lowercase_				,lowercase_				,lowercase_					:       Dict     				=					config_and_inputs
        lowercase_					:       Optional[int]     				=					{'input_ids': input_ids, 'attention_mask': input_mask}
        return config, inputs_dict



@require_tf
class       UpperCAmelCase__  (       _snake_case					,     unittest.TestCase			):






   """simple docstring"""
   A							:       Any     =    (TFBlipTextModel,) if is_tf_available() else ()
   A							:       Union[str, Any]     =    False
   A							:       int     =    False
   A							:       str     =    False
   def 		_lowerCamelCase (self				)    ->     int:
        lowercase_					:       Tuple     				=					BlipTextModelTester(self				)
        lowercase_					:       str     				=					ConfigTester(self       ,				config_class=_a       ,				hidden_size=37				)
   def 		_lowerCamelCase (self				)    ->     Optional[int]:
        self.config_tester.run_common_tests()
   def 		_lowerCamelCase (self				)    ->     List[Any]:
        lowercase_					:       str     				=					self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*_a				)
   def 		_lowerCamelCase (self				)    ->     Dict:
        pass
   def 		_lowerCamelCase (self				)    ->     Optional[int]:
        pass
   @unittest.skip(reason='Blip does not use inputs_embeds'				)
   def 		_lowerCamelCase (self				)    ->     List[Any]:
        pass
   @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'				)
   def 		_lowerCamelCase (self				)    ->     Any:
        pass
   @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'				)
   def 		_lowerCamelCase (self				)    ->     Optional[int]:
        pass
   @slow
   def 		_lowerCamelCase (self				)    ->     Optional[Any]:
        for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             lowercase_					:       List[str]     				=					TFBlipTextModel.from_pretrained(_a				)
             self.assertIsNotNone(_a				)





   def 		_lowerCamelCase (self       ,				_a=True				)    ->     Optional[int]:
        super().test_pt_tf_model_equivalence(allow_missing_keys=_a				)




