
import importlib
import json
import os
from collections import OrderedDict
from typing import Dict, Optional, Union

# Build the list of all image processors
from ...configuration_utils import PretrainedConfig
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
from ...image_processing_utils import ImageProcessingMixin
from ...utils import CONFIG_NAME, IMAGE_PROCESSOR_NAME, get_file_from_repo, logging
from .auto_factory import _LazyAutoMapping
from .configuration_auto import (
    CONFIG_MAPPING_NAMES,
    AutoConfig,
    model_type_to_module_name,
    replace_list_option_in_docstrings,
)


lowercase  :					Any						    =							logging.get_logger(__name__)

lowercase  :					Tuple						    =							OrderedDict(
    [
        ("""align""", """EfficientNetImageProcessor"""),
        ("""beit""", """BeitImageProcessor"""),
        ("""bit""", """BitImageProcessor"""),
        ("""blip""", """BlipImageProcessor"""),
        ("""blip-2""", """BlipImageProcessor"""),
        ("""bridgetower""", """BridgeTowerImageProcessor"""),
        ("""chinese_clip""", """ChineseCLIPImageProcessor"""),
        ("""clip""", """CLIPImageProcessor"""),
        ("""clipseg""", """ViTImageProcessor"""),
        ("""conditional_detr""", """ConditionalDetrImageProcessor"""),
        ("""convnext""", """ConvNextImageProcessor"""),
        ("""convnextv2""", """ConvNextImageProcessor"""),
        ("""cvt""", """ConvNextImageProcessor"""),
        ("""data2vec-vision""", """BeitImageProcessor"""),
        ("""deformable_detr""", """DeformableDetrImageProcessor"""),
        ("""deit""", """DeiTImageProcessor"""),
        ("""deta""", """DetaImageProcessor"""),
        ("""detr""", """DetrImageProcessor"""),
        ("""dinat""", """ViTImageProcessor"""),
        ("""donut-swin""", """DonutImageProcessor"""),
        ("""dpt""", """DPTImageProcessor"""),
        ("""efficientformer""", """EfficientFormerImageProcessor"""),
        ("""efficientnet""", """EfficientNetImageProcessor"""),
        ("""flava""", """FlavaImageProcessor"""),
        ("""focalnet""", """BitImageProcessor"""),
        ("""git""", """CLIPImageProcessor"""),
        ("""glpn""", """GLPNImageProcessor"""),
        ("""groupvit""", """CLIPImageProcessor"""),
        ("""imagegpt""", """ImageGPTImageProcessor"""),
        ("""instructblip""", """BlipImageProcessor"""),
        ("""layoutlmv2""", """LayoutLMv2ImageProcessor"""),
        ("""layoutlmv3""", """LayoutLMv3ImageProcessor"""),
        ("""levit""", """LevitImageProcessor"""),
        ("""mask2former""", """Mask2FormerImageProcessor"""),
        ("""maskformer""", """MaskFormerImageProcessor"""),
        ("""mgp-str""", """ViTImageProcessor"""),
        ("""mobilenet_v1""", """MobileNetV1ImageProcessor"""),
        ("""mobilenet_v2""", """MobileNetV2ImageProcessor"""),
        ("""mobilevit""", """MobileViTImageProcessor"""),
        ("""mobilevit""", """MobileViTImageProcessor"""),
        ("""mobilevitv2""", """MobileViTImageProcessor"""),
        ("""nat""", """ViTImageProcessor"""),
        ("""oneformer""", """OneFormerImageProcessor"""),
        ("""owlvit""", """OwlViTImageProcessor"""),
        ("""perceiver""", """PerceiverImageProcessor"""),
        ("""pix2struct""", """Pix2StructImageProcessor"""),
        ("""poolformer""", """PoolFormerImageProcessor"""),
        ("""regnet""", """ConvNextImageProcessor"""),
        ("""resnet""", """ConvNextImageProcessor"""),
        ("""sam""", """SamImageProcessor"""),
        ("""segformer""", """SegformerImageProcessor"""),
        ("""swiftformer""", """ViTImageProcessor"""),
        ("""swin""", """ViTImageProcessor"""),
        ("""swin2sr""", """Swin2SRImageProcessor"""),
        ("""swinv2""", """ViTImageProcessor"""),
        ("""table-transformer""", """DetrImageProcessor"""),
        ("""timesformer""", """VideoMAEImageProcessor"""),
        ("""tvlt""", """TvltImageProcessor"""),
        ("""upernet""", """SegformerImageProcessor"""),
        ("""van""", """ConvNextImageProcessor"""),
        ("""videomae""", """VideoMAEImageProcessor"""),
        ("""vilt""", """ViltImageProcessor"""),
        ("""vit""", """ViTImageProcessor"""),
        ("""vit_hybrid""", """ViTHybridImageProcessor"""),
        ("""vit_mae""", """ViTImageProcessor"""),
        ("""vit_msn""", """ViTImageProcessor"""),
        ("""xclip""", """CLIPImageProcessor"""),
        ("""yolos""", """YolosImageProcessor"""),
    ]
)

lowercase  :					Any						    =							_LazyAutoMapping(CONFIG_MAPPING_NAMES, IMAGE_PROCESSOR_MAPPING_NAMES)







def 						_snake_case(  SCREAMING_SNAKE_CASE__				) ->    List[str]:
       for module_name, extractors in IMAGE_PROCESSOR_MAPPING_NAMES.items():
              if class_name in extractors:
                     lowercase							:     Any       	=      model_type_to_module_name(SCREAMING_SNAKE_CASE__				)

                     lowercase							:     Optional[Any]       	=      importlib.import_module(f".{module_name}"					,	"""transformers.models"""				)
                     try:
                            return getattr(SCREAMING_SNAKE_CASE__					,	SCREAMING_SNAKE_CASE__				)
                     except AttributeError:
                            continue

       for _, extractor in IMAGE_PROCESSOR_MAPPING._extra_content.items():
              if getattr(SCREAMING_SNAKE_CASE__					,	"""__name__"""					,	SCREAMING_SNAKE_CASE__				) == class_name:
                     return extractor

    # We did not fine the class, but maybe it's because a dep is missing. In that case, the class will be in the main
    # init and we return the proper dummy to get an appropriate error message.
       lowercase							:     Optional[int]       	=      importlib.import_module("""transformers"""				)
       if hasattr(SCREAMING_SNAKE_CASE__					,	SCREAMING_SNAKE_CASE__				):
              return getattr(SCREAMING_SNAKE_CASE__					,	SCREAMING_SNAKE_CASE__				)

       return None







def 						_snake_case(  SCREAMING_SNAKE_CASE__					,	SCREAMING_SNAKE_CASE__ = None					,	SCREAMING_SNAKE_CASE__ = False					,	SCREAMING_SNAKE_CASE__ = False					,	SCREAMING_SNAKE_CASE__ = None					,	SCREAMING_SNAKE_CASE__ = None					,	SCREAMING_SNAKE_CASE__ = None					,	SCREAMING_SNAKE_CASE__ = False					,	**SCREAMING_SNAKE_CASE__					,	) ->    Optional[Any]:
       lowercase							:     List[Any]       	=      get_file_from_repo(
           SCREAMING_SNAKE_CASE__					,	SCREAMING_SNAKE_CASE__					,	cache_dir=SCREAMING_SNAKE_CASE__					,	force_download=SCREAMING_SNAKE_CASE__					,	resume_download=SCREAMING_SNAKE_CASE__					,	proxies=SCREAMING_SNAKE_CASE__					,	use_auth_token=SCREAMING_SNAKE_CASE__					,	revision=SCREAMING_SNAKE_CASE__					,	local_files_only=SCREAMING_SNAKE_CASE__					,	)
       if resolved_config_file is None:
              logger.info(
                  """Could not locate the image processor configuration file, will try to use the model config instead."""				)
              return {}

       with open(SCREAMING_SNAKE_CASE__					,	encoding="""utf-8"""				) as reader:
              return json.load(SCREAMING_SNAKE_CASE__				)




class __snake_case		:
    def __init__(  self      ):



           '''simple docstring'''







           raise EnvironmentError(
               """AutoImageProcessor is designed to be instantiated """
               """using the `AutoImageProcessor.from_pretrained(pretrained_model_name_or_path)` method."""      )
    @classmethod
    @replace_list_option_in_docstrings(snake_case      )
    def       _SCREAMING_SNAKE_CASE       (  cls		,snake_case		,**snake_case      ):



           '''simple docstring'''







           lowercase							:     int       	=      kwargs.pop("""config"""		,snake_case      )
           lowercase							:     Optional[Any]       	=      kwargs.pop("""trust_remote_code"""		,snake_case      )
           lowercase							:     str       	=      True

           lowercase	,			lowercase							:     str       	=      ImageProcessingMixin.get_image_processor_dict(snake_case		,**snake_case      )
           lowercase							:     List[str]       	=      config_dict.get("""image_processor_type"""		,snake_case      )
           lowercase							:     Dict       	=      None
           if "AutoImageProcessor" in config_dict.get("""auto_map"""		,{}      ):
                  lowercase							:     str       	=      config_dict["""auto_map"""]["""AutoImageProcessor"""]

           # If we still don't have the image processor class, check if we're loading from a previous feature extractor config
           # and if so, infer the image processor class from there.
           if image_processor_class is None and image_processor_auto_map is None:
                  lowercase							:     Dict       	=      config_dict.pop("""feature_extractor_type"""		,snake_case      )
                  if feature_extractor_class is not None:
                         logger.warning(
                             """Could not find image processor class in the image processor config or the model config. Loading"""
                             """ based on pattern matching with the model's feature extractor configuration."""      )
                         lowercase							:     List[str]       	=      feature_extractor_class.replace("""FeatureExtractor"""		,"""ImageProcessor"""      )
                  if "AutoFeatureExtractor" in config_dict.get("""auto_map"""		,{}      ):
                         lowercase							:     int       	=      config_dict["""auto_map"""]["""AutoFeatureExtractor"""]
                         lowercase							:     str       	=      feature_extractor_auto_map.replace("""FeatureExtractor"""		,"""ImageProcessor"""      )
                         logger.warning(
                             """Could not find image processor auto map in the image processor config or the model config."""
                             """ Loading based on pattern matching with the model's feature extractor configuration."""      )

        # If we don't find the image processor class in the image processor config, let's try the model config.
           if image_processor_class is None and image_processor_auto_map is None:
                  if not isinstance(snake_case		,snake_case      ):
                         lowercase							:     Tuple       	=      AutoConfig.from_pretrained(snake_case		,**snake_case      )
                  # It could be in `config.image_processor_type``
                  lowercase							:     Optional[int]       	=      getattr(snake_case		,"""image_processor_type"""		,snake_case      )
                  if hasattr(snake_case		,"""auto_map"""      ) and "AutoImageProcessor" in config.auto_map:
                         lowercase							:     Tuple       	=      config.auto_map["""AutoImageProcessor"""]

           if image_processor_class is not None:
                  lowercase							:     Union[str, Any]       	=      image_processor_class_from_name(snake_case      )

           lowercase							:     List[Any]       	=      image_processor_auto_map is not None
           lowercase							:     Optional[int]       	=      image_processor_class is not None or type(snake_case      ) in IMAGE_PROCESSOR_MAPPING
           lowercase							:     Any       	=      resolve_trust_remote_code(
               snake_case		,snake_case		,snake_case		,snake_case      )

           if has_remote_code and trust_remote_code:
                  lowercase							:     int       	=      get_class_from_dynamic_module(
                      snake_case		,snake_case		,**snake_case      )
                  lowercase							:     Dict       	=      kwargs.pop("""code_revision"""		,snake_case      )
                  if os.path.isdir(snake_case      ):
                         image_processor_class.register_for_auto_class()
                  return image_processor_class.from_dict(snake_case		,**snake_case      )
           elif image_processor_class is not None:
                  return image_processor_class.from_dict(snake_case		,**snake_case      )
           # Last try: we use the IMAGE_PROCESSOR_MAPPING.
           elif type(snake_case      ) in IMAGE_PROCESSOR_MAPPING:
                  lowercase							:     List[Any]       	=      IMAGE_PROCESSOR_MAPPING[type(snake_case      )]
                  return image_processor_class.from_dict(snake_case		,**snake_case      )

           raise ValueError(
               f"Unrecognized image processor in {pretrained_model_name_or_path}. Should have a "
               f"`image_processor_type` key in its {IMAGE_PROCESSOR_NAME} of {CONFIG_NAME}, or one of the following "
               f"`model_type` keys in its {CONFIG_NAME}: {', '.join(c for c in IMAGE_PROCESSOR_MAPPING_NAMES.keys()      )}"      )
    @staticmethod
    def       _SCREAMING_SNAKE_CASE       (  snake_case		,snake_case      ):



           '''simple docstring'''







           IMAGE_PROCESSOR_MAPPING.register(snake_case		,snake_case      )


from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow

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


if is_tf_available():
  import numpy as np
  import tensorflow as tf

  from transformers import (
      TF_FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
      FlaubertConfig,
      TFFlaubertForMultipleChoice,
      TFFlaubertForQuestionAnsweringSimple,
      TFFlaubertForSequenceClassification,
      TFFlaubertForTokenClassification,
      TFFlaubertModel,
      TFFlaubertWithLMHeadModel,
  )

class __snake_case		:
    def __init__(  self		,snake_case		,):



           '''simple docstring'''







           lowercase							:     Any       	=      parent
           lowercase							:     Tuple       	=      13
           lowercase							:     str       	=      7
           lowercase							:     Dict       	=      True
           lowercase							:     Dict       	=      True
           lowercase							:     str       	=      True
           lowercase							:     List[str]       	=      True
           lowercase							:     int       	=      True
           lowercase							:     Union[str, Any]       	=      False
           lowercase							:     Dict       	=      False
           lowercase							:     List[Any]       	=      False
           lowercase							:     List[Any]       	=      2
           lowercase							:     Optional[Any]       	=      99
           lowercase							:     int       	=      0
           lowercase							:     Tuple       	=      32
           lowercase							:     int       	=      2
           lowercase							:     Tuple       	=      4
           lowercase							:     List[Any]       	=      0.1
           lowercase							:     Tuple       	=      0.1
           lowercase							:     List[Any]       	=      512
           lowercase							:     int       	=      16
           lowercase							:     Dict       	=      2
           lowercase							:     int       	=      0.02
           lowercase							:     Union[str, Any]       	=      3
           lowercase							:     Any       	=      4
           lowercase							:     List[Any]       	=      """last"""
           lowercase							:     Tuple       	=      True
           lowercase							:     List[Any]       	=      None
           lowercase							:     Any       	=      0
    def       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







           lowercase							:     List[Any]       	=      ids_tensor([self.batch_size, self.seq_length]		,self.vocab_size      )
           lowercase							:     List[str]       	=      random_attention_mask([self.batch_size, self.seq_length]		,dtype=tf.floataa      )

           lowercase							:     Tuple       	=      None
           if self.use_input_lengths:
                  lowercase							:     List[str]       	=      (
                      ids_tensor([self.batch_size]		,vocab_size=2      ) + self.seq_length - 2
                  )  # small variation of seq_length

           lowercase							:     Tuple       	=      None
           if self.use_token_type_ids:
                  lowercase							:     Optional[int]       	=      ids_tensor([self.batch_size, self.seq_length]		,self.n_langs      )

           lowercase							:     List[str]       	=      None
           lowercase							:     List[str]       	=      None
           lowercase							:     Optional[Any]       	=      None
           if self.use_labels:
                  lowercase							:     List[str]       	=      ids_tensor([self.batch_size]		,self.type_sequence_label_size      )
                  lowercase							:     List[str]       	=      ids_tensor([self.batch_size, self.seq_length]		,self.num_labels      )
                  lowercase							:     str       	=      ids_tensor([self.batch_size]		,2		,dtype=tf.floataa      )
                  lowercase							:     Optional[Any]       	=      ids_tensor([self.batch_size]		,self.num_choices      )

           lowercase							:     str       	=      FlaubertConfig(
               vocab_size=self.vocab_size		,n_special=self.n_special		,emb_dim=self.hidden_size		,n_layers=self.num_hidden_layers		,n_heads=self.num_attention_heads		,dropout=self.hidden_dropout_prob		,attention_dropout=self.attention_probs_dropout_prob		,gelu_activation=self.gelu_activation		,sinusoidal_embeddings=self.sinusoidal_embeddings		,asm=self.asm		,causal=self.causal		,n_langs=self.n_langs		,max_position_embeddings=self.max_position_embeddings		,initializer_range=self.initializer_range		,summary_type=self.summary_type		,use_proj=self.use_proj		,bos_token_id=self.bos_token_id		,)

           return (
               config,
               input_ids,
               token_type_ids,
               input_lengths,
               sequence_labels,
               token_labels,
               is_impossible_labels,
               choice_labels,
               input_mask,
           )
    def       _SCREAMING_SNAKE_CASE       (  self		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,):



           '''simple docstring'''







           lowercase							:     Tuple       	=      TFFlaubertModel(config=snake_case      )
           lowercase							:     str       	=      {"""input_ids""": input_ids, """lengths""": input_lengths, """langs""": token_type_ids}
           lowercase							:     Optional[Any]       	=      model(snake_case      )

           lowercase							:     List[Any]       	=      [input_ids, input_mask]
           lowercase							:     int       	=      model(snake_case      )
           self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, self.seq_length, self.hidden_size)      )
    def       _SCREAMING_SNAKE_CASE       (  self		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,):



           '''simple docstring'''







           lowercase							:     List[Any]       	=      TFFlaubertWithLMHeadModel(snake_case      )

           lowercase							:     Optional[Any]       	=      {"""input_ids""": input_ids, """lengths""": input_lengths, """langs""": token_type_ids}
           lowercase							:     int       	=      model(snake_case      )

           self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.seq_length, self.vocab_size)      )
    def       _SCREAMING_SNAKE_CASE       (  self		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,):



           '''simple docstring'''







           lowercase							:     Tuple       	=      TFFlaubertForQuestionAnsweringSimple(snake_case      )

           lowercase							:     Union[str, Any]       	=      {"""input_ids""": input_ids, """lengths""": input_lengths}

           lowercase							:     Tuple       	=      model(snake_case      )

           self.parent.assertEqual(result.start_logits.shape		,(self.batch_size, self.seq_length)      )
           self.parent.assertEqual(result.end_logits.shape		,(self.batch_size, self.seq_length)      )
    def       _SCREAMING_SNAKE_CASE       (  self		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,):



           '''simple docstring'''







           lowercase							:     Union[str, Any]       	=      TFFlaubertForSequenceClassification(snake_case      )

           lowercase							:     str       	=      {"""input_ids""": input_ids, """lengths""": input_lengths}

           lowercase							:     str       	=      model(snake_case      )

           self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.type_sequence_label_size)      )
    def       _SCREAMING_SNAKE_CASE       (  self		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,):



           '''simple docstring'''







           lowercase							:     Any       	=      self.num_labels
           lowercase							:     List[str]       	=      TFFlaubertForTokenClassification(config=snake_case      )
           lowercase							:     Dict       	=      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
           lowercase							:     int       	=      model(snake_case      )
           self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.seq_length, self.num_labels)      )
    def       _SCREAMING_SNAKE_CASE       (  self		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case		,):



           '''simple docstring'''







           lowercase							:     Any       	=      self.num_choices
           lowercase							:     Dict       	=      TFFlaubertForMultipleChoice(config=snake_case      )
           lowercase							:     Any       	=      tf.tile(tf.expand_dims(snake_case		,1      )		,(1, self.num_choices, 1)      )
           lowercase							:     Optional[Any]       	=      tf.tile(tf.expand_dims(snake_case		,1      )		,(1, self.num_choices, 1)      )
           lowercase							:     Dict       	=      tf.tile(tf.expand_dims(snake_case		,1      )		,(1, self.num_choices, 1)      )
           lowercase							:     Union[str, Any]       	=      {
               """input_ids""": multiple_choice_inputs_ids,
               """attention_mask""": multiple_choice_input_mask,
               """token_type_ids""": multiple_choice_token_type_ids,
           }
           lowercase							:     int       	=      model(snake_case      )
           self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.num_choices)      )
    def       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







           lowercase							:     Any       	=      self.prepare_config_and_inputs()
           (
               (
               lowercase
           )	,			(
               lowercase
           )	,			(
               lowercase
           )	,			(
               lowercase
           )	,			(
               lowercase
           )	,			(
               lowercase
           )	,			(
               lowercase
           )	,			(
               lowercase
           )	,			(
               lowercase
           )	,			
           )							:     int       	=      config_and_inputs
           lowercase							:     List[str]       	=      {
               """input_ids""": input_ids,
               """token_type_ids""": token_type_ids,
               """langs""": token_type_ids,
               """lengths""": input_lengths,
           }
           return config, inputs_dict






@require_tf
class __snake_case		(      lowerCAmelCase					,	lowerCAmelCase					,	unittest.TestCase     ):
    _a		:						Dict=				(
        (
            TFFlaubertModel,
            TFFlaubertWithLMHeadModel,
            TFFlaubertForSequenceClassification,
            TFFlaubertForQuestionAnsweringSimple,
            TFFlaubertForTokenClassification,
            TFFlaubertForMultipleChoice,
        )
        if is_tf_available()
        else ()
    )
    _a		:						Optional[Any]=				(
        (TFFlaubertWithLMHeadModel,) if is_tf_available() else ()
    )  # TODO (PVP): Check other models whether language generation is also applicable
    _a		:						Any=				(
        {
            "feature-extraction": TFFlaubertModel,
            "fill-mask": TFFlaubertWithLMHeadModel,
            "question-answering": TFFlaubertForQuestionAnsweringSimple,
            "text-classification": TFFlaubertForSequenceClassification,
            "token-classification": TFFlaubertForTokenClassification,
            "zero-shot": TFFlaubertForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )
    _a		:						Tuple=				False
    _a		:						int=				False
    def       _SCREAMING_SNAKE_CASE       (  self		,snake_case		,snake_case		,snake_case		,snake_case		,snake_case      ):



           '''simple docstring'''







           if (
               pipeline_test_casse_name == "QAPipelineTests"
               and tokenizer_name is not None
               and not tokenizer_name.endswith("""Fast"""      )
           ):
                  # `QAPipelineTests` fails for a few models when the slower tokenizer are used.
                  # (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
                  # TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
                  return True

           return False
    def       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







           lowercase							:     str       	=      TFFlaubertModelTester(self      )
           lowercase							:     List[Any]       	=      ConfigTester(self		,config_class=snake_case		,emb_dim=37      )
    def       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







           self.config_tester.run_common_tests()
    def       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







           lowercase							:     Tuple       	=      self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_flaubert_model(*snake_case      )
    def       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







           lowercase							:     Optional[int]       	=      self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_flaubert_lm_head(*snake_case      )
    def       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







           lowercase							:     int       	=      self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_flaubert_qa(*snake_case      )
    def       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







           lowercase							:     Optional[Any]       	=      self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_flaubert_sequence_classif(*snake_case      )
    def       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







           lowercase							:     str       	=      self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_flaubert_for_token_classification(*snake_case      )
    def       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







           lowercase							:     List[str]       	=      self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_flaubert_for_multiple_choice(*snake_case      )
    @slow
    def       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







           for model_name in TF_FLAUBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                  lowercase							:     Dict       	=      TFFlaubertModel.from_pretrained(snake_case      )
                  self.assertIsNotNone(snake_case      )






@require_tf
@require_sentencepiece
@require_tokenizers
class __snake_case		(      unittest.TestCase     ):
    @slow
    def       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







           lowercase							:     List[Any]       	=      TFFlaubertModel.from_pretrained("""jplu/tf-flaubert-small-cased"""      )

           lowercase							:     int       	=      tf.convert_to_tensor(
               [[0, 158, 735, 2592, 1424, 6727, 82, 1]]		,dtype=tf.intaa		,)  # "J'aime flaubert !"

           lowercase							:     Dict       	=      model(snake_case      )[0]
           lowercase							:     Union[str, Any]       	=      tf.TensorShape((1, 8, 512)      )
           self.assertEqual(output.shape		,snake_case      )
           # compare the actual values for a slice.
           lowercase							:     Tuple       	=      tf.convert_to_tensor(
               [
                   [
                       [-1.8_768_773, -1.566_555, 0.27_072_418],
                       [-1.6_920_038, -0.5_873_505, 1.9_329_599],
                       [-2.9_563_985, -1.6_993_835, 1.7_972_052],
                   ]
               ]		,dtype=tf.floataa		,)

           self.assertTrue(np.allclose(output[:, :3, :3].numpy()		,expected_slice.numpy()		,atol=1e-4      )      )
