




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







							def __init__(    self			:    Any				,     lowerCAmelCase_			:    str				,     lowerCAmelCase_			:    Optional[Any]=12				,     lowerCAmelCase_			:    str=7				,     lowerCAmelCase_			:    Tuple=True				,     lowerCAmelCase_			:    List[str]=True				,     lowerCAmelCase_			:    Tuple=True				,     lowerCAmelCase_			:    Dict=99				,     lowerCAmelCase_			:    Tuple=32				,     lowerCAmelCase_			:    Dict=32				,     lowerCAmelCase_			:    int=2				,     lowerCAmelCase_			:    str=4				,     lowerCAmelCase_			:    List[str]=37				,     lowerCAmelCase_			:    List[str]=0.1				,     lowerCAmelCase_			:    Union[str, Any]=0.1				,     lowerCAmelCase_			:    List[Any]=5_12				,     lowerCAmelCase_			:    Dict=0.0_2				,     lowerCAmelCase_			:    str=0				,     lowerCAmelCase_			:    Dict=None				,     )     ->				Optional[int]:


														"""simple docstring"""


														_a      	=							parent
														_a      	=							batch_size
														_a      	=							seq_length
														_a      	=							is_training
														_a      	=							use_input_mask
														_a      	=							use_labels
														_a      	=							vocab_size
														_a      	=							hidden_size
														_a      	=							projection_dim
														_a      	=							num_hidden_layers
														_a      	=							num_attention_heads
														_a      	=							intermediate_size
														_a      	=							dropout
														_a      	=							attention_dropout
														_a      	=							max_position_embeddings
														_a      	=							initializer_range
														_a      	=							scope
														_a      	=							bos_token_id







							def   __lowerCAmelCase     (    self			:    Optional[Any]   )     ->				str:


														"""simple docstring"""


														_a      	=							ids_tensor([self.batch_size, self.seq_length]				,     self.vocab_size   )

														_a      	=							None
														if self.use_input_mask:
																					_a      	=							random_attention_mask([self.batch_size, self.seq_length]   )

														if input_mask is not None:
																					_a      	=							input_mask.numpy()
																					_a	,				_a      	=							input_mask.shape
																					_a      	=							np.random.randint(1				,     seq_length - 1				,     size=(batch_size,)   )
																					for batch_idx, start_index in enumerate(lowerCAmelCase_   ):
																												_a      	=							1
																												_a      	=							0

														_a      	=							self.get_config()

														return config, input_ids, tf.convert_to_tensor(lowerCAmelCase_   )







							def   __lowerCAmelCase     (    self			:    int   )     ->				Dict:


														"""simple docstring"""


														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			:    str				,     lowerCAmelCase_			:    Dict				,     lowerCAmelCase_			:    Optional[Any]				,     lowerCAmelCase_			:    Optional[Any]   )     ->				int:


														"""simple docstring"""


														_a      	=							TFBlipTextModel(config=lowerCAmelCase_   )
														_a      	=							model(lowerCAmelCase_				,     attention_mask=lowerCAmelCase_				,     training=lowerCAmelCase_   )
														_a      	=							model(lowerCAmelCase_				,     training=lowerCAmelCase_   )
														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			:    Optional[Any]   )     ->				Tuple:


														"""simple docstring"""


														_a      	=							self.prepare_config_and_inputs()
														_a	,				_a	,				_a      	=							config_and_inputs
														_a      	=							{'''input_ids''': input_ids, '''attention_mask''': input_mask}
														return config, inputs_dict



@require_tf
class      A       (						_a	,unittest.TestCase       ):
							lowercase_							     =							(TFBlipTextModel,) if is_tf_available() else ()
							lowercase_							     =							False
							lowercase_							     =							False
							lowercase_							     =							False







							def   __lowerCAmelCase     (    self			:    Tuple   )     ->				int:


														"""simple docstring"""


														_a      	=							BlipTextModelTester(self   )
														_a      	=							ConfigTester(self				,     config_class=lowerCAmelCase_				,     hidden_size=37   )







							def   __lowerCAmelCase     (    self			:    Union[str, Any]   )     ->				str:


														"""simple docstring"""


														self.config_tester.run_common_tests()







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


														"""simple docstring"""


														_a      	=							self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*lowerCAmelCase_   )







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


														"""simple docstring"""


														pass







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


														"""simple docstring"""


														pass







							@unittest.skip(reason='''Blip does not use inputs_embeds'''   )
							def   __lowerCAmelCase     (    self			:    Union[str, Any]   )     ->				Any:


														"""simple docstring"""


														pass







							@unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING'''   )
							def   __lowerCAmelCase     (    self			:    Any   )     ->				Optional[Any]:


														"""simple docstring"""


														pass







							@unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING'''   )
							def   __lowerCAmelCase     (    self			:    Any   )     ->				List[Any]:


														"""simple docstring"""


														pass







							@slow
							def   __lowerCAmelCase     (    self			:    Optional[int]   )     ->				Dict:


														"""simple docstring"""


														for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					_a      	=							TFBlipTextModel.from_pretrained(lowerCAmelCase_   )
																					self.assertIsNotNone(lowerCAmelCase_   )







							def   __lowerCAmelCase     (    self			:    Union[str, Any]				,     lowerCAmelCase_			:    Union[str, Any]=True   )     ->				str:


														"""simple docstring"""


														super().test_pt_tf_model_equivalence(allow_missing_keys=lowerCAmelCase_   )



"""simple docstring"""






import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_funnel import FunnelTokenizer


__SCREAMING_SNAKE_CASE							=     logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE							=     {'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

__SCREAMING_SNAKE_CASE							=     [
    'small',
    'small-base',
    'medium',
    'medium-base',
    'intermediate',
    'intermediate-base',
    'large',
    'large-base',
    'xlarge',
    'xlarge-base',
]

__SCREAMING_SNAKE_CASE							=     {
    'vocab_file': {
        'funnel-transformer/small': 'https://huggingface.co/funnel-transformer/small/resolve/main/vocab.txt',
        'funnel-transformer/small-base': 'https://huggingface.co/funnel-transformer/small-base/resolve/main/vocab.txt',
        'funnel-transformer/medium': 'https://huggingface.co/funnel-transformer/medium/resolve/main/vocab.txt',
        'funnel-transformer/medium-base': (
            'https://huggingface.co/funnel-transformer/medium-base/resolve/main/vocab.txt'
        ),
        'funnel-transformer/intermediate': (
            'https://huggingface.co/funnel-transformer/intermediate/resolve/main/vocab.txt'
        ),
        'funnel-transformer/intermediate-base': (
            'https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/vocab.txt'
        ),
        'funnel-transformer/large': 'https://huggingface.co/funnel-transformer/large/resolve/main/vocab.txt',
        'funnel-transformer/large-base': 'https://huggingface.co/funnel-transformer/large-base/resolve/main/vocab.txt',
        'funnel-transformer/xlarge': 'https://huggingface.co/funnel-transformer/xlarge/resolve/main/vocab.txt',
        'funnel-transformer/xlarge-base': (
            'https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/vocab.txt'
        ),
    },
    'tokenizer_file': {
        'funnel-transformer/small': 'https://huggingface.co/funnel-transformer/small/resolve/main/tokenizer.json',
        'funnel-transformer/small-base': (
            'https://huggingface.co/funnel-transformer/small-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/medium': 'https://huggingface.co/funnel-transformer/medium/resolve/main/tokenizer.json',
        'funnel-transformer/medium-base': (
            'https://huggingface.co/funnel-transformer/medium-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/intermediate': (
            'https://huggingface.co/funnel-transformer/intermediate/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/intermediate-base': (
            'https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/large': 'https://huggingface.co/funnel-transformer/large/resolve/main/tokenizer.json',
        'funnel-transformer/large-base': (
            'https://huggingface.co/funnel-transformer/large-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/xlarge': 'https://huggingface.co/funnel-transformer/xlarge/resolve/main/tokenizer.json',
        'funnel-transformer/xlarge-base': (
            'https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/tokenizer.json'
        ),
    },
}
__SCREAMING_SNAKE_CASE							=     {F"""funnel-transformer/{name}""": 512 for name in _model_names}
__SCREAMING_SNAKE_CASE							=     {F"""funnel-transformer/{name}""": {'do_lower_case': True} for name in _model_names}





class 				a__					(						A__       ):
     UpperCAmelCase__         =      VOCAB_FILES_NAMES
     UpperCAmelCase__         =      PRETRAINED_VOCAB_FILES_MAP
     UpperCAmelCase__         =      PRETRAINED_INIT_CONFIGURATION
     UpperCAmelCase__         =      FunnelTokenizer
     UpperCAmelCase__         =      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     UpperCAmelCase__         =      2



     def __init__(							self :str      ,  _lowerCamelCase :int=None      ,  _lowerCamelCase :List[Any]=None      ,  _lowerCamelCase :Dict=True      ,  _lowerCamelCase :Optional[Any]="<unk>"      ,  _lowerCamelCase :Optional[Any]="<sep>"      ,  _lowerCamelCase :List[Any]="<pad>"      ,  _lowerCamelCase :List[Any]="<cls>"      ,  _lowerCamelCase :Union[str, Any]="<mask>"      ,  _lowerCamelCase :Any="<s>"      ,  _lowerCamelCase :Union[str, Any]="</s>"      ,  _lowerCamelCase :str=True      ,  _lowerCamelCase :Dict=True      ,  _lowerCamelCase :Tuple=None      ,  _lowerCamelCase :Tuple="##"      ,  **_lowerCamelCase :int      ,  ):







      '''simple docstring'''



      super().__init__(
          _lowerCamelCase      ,  tokenizer_file=_lowerCamelCase      ,  do_lower_case=_lowerCamelCase      ,  unk_token=_lowerCamelCase      ,  sep_token=_lowerCamelCase      ,  pad_token=_lowerCamelCase      ,  cls_token=_lowerCamelCase      ,  mask_token=_lowerCamelCase      ,  bos_token=_lowerCamelCase      ,  eos_token=_lowerCamelCase      ,  clean_text=_lowerCamelCase      ,  tokenize_chinese_chars=_lowerCamelCase      ,  strip_accents=_lowerCamelCase      ,  wordpieces_prefix=_lowerCamelCase      ,  **_lowerCamelCase      ,  )

      UpperCamelCase_     :					str   	=json.loads(self.backend_tokenizer.normalizer.__getstate__()   )
      if (
          normalizer_state.get('lowercase'      ,  _lowerCamelCase   ) != do_lower_case
          or normalizer_state.get('strip_accents'      ,  _lowerCamelCase   ) != strip_accents
          or normalizer_state.get('handle_chinese_chars'      ,  _lowerCamelCase   ) != tokenize_chinese_chars
      ):
       UpperCamelCase_     :					int   	=getattr(_lowerCamelCase      ,  normalizer_state.pop('type'   )   )
       UpperCamelCase_     :					Dict   	=do_lower_case
       UpperCamelCase_     :					Tuple   	=strip_accents
       UpperCamelCase_     :					int   	=tokenize_chinese_chars
       UpperCamelCase_     :					Tuple   	=normalizer_class(**_lowerCamelCase   )

      UpperCamelCase_     :					Dict   	=do_lower_case



     def  lowerCamelCase_						(							self :Optional[int]      ,  _lowerCamelCase :str      ,  _lowerCamelCase :Optional[int]=None   ):







      '''simple docstring'''



      UpperCamelCase_     :					Optional[Any]   	=[self.cls_token_id] + token_ids_a + [self.sep_token_id]

      if token_ids_a:
       output += token_ids_a + [self.sep_token_id]

      return output



     def  lowerCamelCase_						(							self :List[Any]      ,  _lowerCamelCase :List[int]      ,  _lowerCamelCase :Optional[List[int]] = None   ):







      '''simple docstring'''



      UpperCamelCase_     :					Optional[int]   	=[self.sep_token_id]
      UpperCamelCase_     :					List[Any]   	=[self.cls_token_id]
      if token_ids_a is None:
       return len(cls   ) * [self.cls_token_type_id] + len(token_ids_a + sep   ) * [0]
      return len(cls   ) * [self.cls_token_type_id] + len(token_ids_a + sep   ) * [0] + len(token_ids_a + sep   ) * [1]




     def  lowerCamelCase_						(							self :Optional[Any]      ,  _lowerCamelCase :str      ,  _lowerCamelCase :Optional[str] = None   ):







      '''simple docstring'''



      UpperCamelCase_     :					int   	=self._tokenizer.model.save(_lowerCamelCase      ,  name=_lowerCamelCase   )
      return tuple(_lowerCamelCase   )
