



import inspect
import unittest
import warnings
from math import ceil, floor

from transformers import LevitConfig
from transformers.file_utils import cached_property, is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_vision, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers import (
     MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
     MODEL_MAPPING,
     LevitForImageClassification,
     LevitForImageClassificationWithTeacher,
     LevitModel,
 )
 from transformers.models.levit.modeling_levit import LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
 from PIL import Image

 from transformers import LevitImageProcessor



class  __lowerCAmelCase     (	lowerCAmelCase__   ):




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.config_class(**self.inputs_dict				)
    self.parent.assertTrue(hasattr(lowercase_	,				'''hidden_sizes'''				)				)
    self.parent.assertTrue(hasattr(lowercase_	,				'''num_attention_heads'''				)				)



class  __lowerCAmelCase     :




 def __init__(						self	,				__UpperCAmelCase	,				__UpperCAmelCase=13	,				__UpperCAmelCase=64	,				__UpperCAmelCase=3	,				__UpperCAmelCase=3	,				__UpperCAmelCase=2	,				__UpperCAmelCase=1	,				__UpperCAmelCase=16	,				__UpperCAmelCase=[128, 256, 384]	,				__UpperCAmelCase=[4, 6, 8]	,				__UpperCAmelCase=[2, 3, 4]	,				__UpperCAmelCase=[16, 16, 16]	,				__UpperCAmelCase=0	,				__UpperCAmelCase=[2, 2, 2]	,				__UpperCAmelCase=[2, 2, 2]	,				__UpperCAmelCase=0.02	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=2	,				):



    '''simple docstring'''
    __lowerCamelCase													=    parent
    __lowerCamelCase													=    batch_size
    __lowerCamelCase													=    image_size
    __lowerCamelCase													=    num_channels
    __lowerCamelCase													=    kernel_size
    __lowerCamelCase													=    stride
    __lowerCamelCase													=    padding
    __lowerCamelCase													=    hidden_sizes
    __lowerCamelCase													=    num_attention_heads
    __lowerCamelCase													=    depths
    __lowerCamelCase													=    key_dim
    __lowerCamelCase													=    drop_path_rate
    __lowerCamelCase													=    patch_size
    __lowerCamelCase													=    attention_ratio
    __lowerCamelCase													=    mlp_ratio
    __lowerCamelCase													=    initializer_range
    __lowerCamelCase													=    [
        ['''Subsample''', key_dim[0], hidden_sizes[0] // key_dim[0], 4, 2, 2],
        ['''Subsample''', key_dim[0], hidden_sizes[1] // key_dim[0], 4, 2, 2],
    ]
    __lowerCamelCase													=    is_training
    __lowerCamelCase													=    use_labels
    __lowerCamelCase													=    num_labels
    __lowerCamelCase													=    initializer_range




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]				)

    __lowerCamelCase													=    None
    if self.use_labels:
       __lowerCamelCase													=    ids_tensor([self.batch_size]	,				self.num_labels				)

    __lowerCamelCase													=    self.get_config()
    return config, pixel_values, labels




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    return LevitConfig(
        image_size=self.image_size	,				num_channels=self.num_channels	,				kernel_size=self.kernel_size	,				stride=self.stride	,				padding=self.padding	,				patch_size=self.patch_size	,				hidden_sizes=self.hidden_sizes	,				num_attention_heads=self.num_attention_heads	,				depths=self.depths	,				key_dim=self.key_dim	,				drop_path_rate=self.drop_path_rate	,				mlp_ratio=self.mlp_ratio	,				attention_ratio=self.attention_ratio	,				initializer_range=self.initializer_range	,				down_ops=self.down_ops	,				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase				):



    '''simple docstring'''
    __lowerCamelCase													=    LevitModel(config=lowercase_				)
    model.to(lowercase_				)
    model.eval()
    __lowerCamelCase													=    model(lowercase_				)
    __lowerCamelCase													=    (self.image_size, self.image_size)
    __lowerCamelCase							,__lowerCamelCase													=    image_size[0], image_size[1]
    for _ in range(4				):
       __lowerCamelCase													=    floor(((height + 2 * self.padding - self.kernel_size) / self.stride) + 1				)
       __lowerCamelCase													=    floor(((width + 2 * self.padding - self.kernel_size) / self.stride) + 1				)
    self.parent.assertEqual(
        result.last_hidden_state.shape	,				(self.batch_size, ceil(height / 4				) * ceil(width / 4				), self.hidden_sizes[-1])	,				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase				):



    '''simple docstring'''
    __lowerCamelCase													=    self.num_labels
    __lowerCamelCase													=    LevitForImageClassification(lowercase_				)
    model.to(lowercase_				)
    model.eval()
    __lowerCamelCase													=    model(lowercase_	,				labels=lowercase_				)
    self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.num_labels)				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.prepare_config_and_inputs()
    __lowerCamelCase							,__lowerCamelCase							,__lowerCamelCase													=    config_and_inputs
    __lowerCamelCase													=    {'''pixel_values''': pixel_values}
    return config, inputs_dict



@require_torch
class  __lowerCAmelCase     (	lowerCAmelCase__  ,	lowerCAmelCase__  ,	unittest.TestCase   ):
 lowerCAmelCase__       					=  (
     (LevitModel, LevitForImageClassification, LevitForImageClassificationWithTeacher)
     if is_torch_available()
     else ()
 )
 lowerCAmelCase__       					=  (
     {
         """feature-extraction""": LevitModel,
         """image-classification""": (LevitForImageClassification, LevitForImageClassificationWithTeacher),
     }
     if is_torch_available()
     else {}
 )

 lowerCAmelCase__       					=  False
 lowerCAmelCase__       					=  False
 lowerCAmelCase__       					=  False
 lowerCAmelCase__       					=  False
 lowerCAmelCase__       					=  False




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    LevitModelTester(self				)
    __lowerCamelCase													=    ConfigTester(self	,				config_class=lowercase_	,				has_text_modality=lowercase_	,				hidden_size=37				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    self.create_and_test_config_common_properties()
    self.config_tester.create_and_test_config_to_json_string()
    self.config_tester.create_and_test_config_to_json_file()
    self.config_tester.create_and_test_config_from_and_save_pretrained()
    self.config_tester.create_and_test_config_with_num_labels()
    self.config_tester.check_config_can_be_init_without_params()
    self.config_tester.check_config_arguments_init()




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    return




 @unittest.skip(reason='''Levit does not use inputs_embeds'''				)
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    pass




 @unittest.skip(reason='''Levit does not support input and output embeddings'''				)
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    pass




 @unittest.skip(reason='''Levit does not output attentions'''				)
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    pass




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase							,__lowerCamelCase													=    self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
       __lowerCamelCase													=    model_class(lowercase_				)
       __lowerCamelCase													=    inspect.signature(model.forward				)
       # signature.parameters is an OrderedDict => so arg_names order is deterministic
       __lowerCamelCase													=    [*signature.parameters.keys()]

       __lowerCamelCase													=    ['''pixel_values''']
       self.assertListEqual(arg_names[:1]	,				lowercase_				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''







    def check_hidden_states_output(__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase				):
       __lowerCamelCase													=    model_class(lowercase_				)
       model.to(lowercase_				)
       model.eval()

       with torch.no_grad():
          __lowerCamelCase													=    model(**self._prepare_for_class(lowercase_	,				lowercase_				)				)

       __lowerCamelCase													=    outputs.hidden_states

       __lowerCamelCase													=    len(self.model_tester.depths				) + 1
       self.assertEqual(len(lowercase_				)	,				lowercase_				)

       __lowerCamelCase													=    (self.model_tester.image_size, self.model_tester.image_size)
       __lowerCamelCase							,__lowerCamelCase													=    image_size[0], image_size[1]
       for _ in range(4				):
          __lowerCamelCase													=    floor(
              (
                  (height + 2 * self.model_tester.padding - self.model_tester.kernel_size)
                  / self.model_tester.stride
              )
              + 1				)
          __lowerCamelCase													=    floor(
              (
                  (width + 2 * self.model_tester.padding - self.model_tester.kernel_size)
                  / self.model_tester.stride
              )
              + 1				)
       # verify the first hidden states (first block)
       self.assertListEqual(
           list(hidden_states[0].shape[-2:]				)	,				[
               height * width,
               self.model_tester.hidden_sizes[0],
           ]	,				)

    __lowerCamelCase							,__lowerCamelCase													=    self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
       __lowerCamelCase													=    True
       check_hidden_states_output(lowercase_	,				lowercase_	,				lowercase_				)

       # check that output_hidden_states also work using config
       del inputs_dict["output_hidden_states"]
       __lowerCamelCase													=    True

       check_hidden_states_output(lowercase_	,				lowercase_	,				lowercase_				)




 @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''				)
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    pass




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase=False				):



    '''simple docstring'''
    __lowerCamelCase													=    super()._prepare_for_class(lowercase_	,				lowercase_	,				return_labels=lowercase_				)

    if return_labels:
       if model_class.__name__ == "LevitForImageClassificationWithTeacher":
          del inputs_dict["labels"]

    return inputs_dict




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*lowercase_				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_image_classification(*lowercase_				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''







    if not self.model_tester.is_training:
       return

    __lowerCamelCase							,__lowerCamelCase													=    self.model_tester.prepare_config_and_inputs_for_common()
    __lowerCamelCase													=    True

    for model_class in self.all_model_classes:
       # LevitForImageClassificationWithTeacher supports inference-only
       if (
           model_class in get_values(lowercase_				)
           or model_class.__name__ == "LevitForImageClassificationWithTeacher"
       ):
          continue
       __lowerCamelCase													=    model_class(lowercase_				)
       model.to(lowercase_				)
       model.train()
       __lowerCamelCase													=    self._prepare_for_class(lowercase_	,				lowercase_	,				return_labels=lowercase_				)
       __lowerCamelCase													=    model(**lowercase_				).loss
       loss.backward()




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase							,__lowerCamelCase													=    self.model_tester.prepare_config_and_inputs_for_common()
    if not self.model_tester.is_training:
       return

    __lowerCamelCase													=    False
    __lowerCamelCase													=    True

    for model_class in self.all_model_classes:
       if model_class in get_values(lowercase_				) or not model_class.supports_gradient_checkpointing:
          continue
       # LevitForImageClassificationWithTeacher supports inference-only
       if model_class.__name__ == "LevitForImageClassificationWithTeacher":
          continue
       __lowerCamelCase													=    model_class(lowercase_				)
       model.gradient_checkpointing_enable()
       model.to(lowercase_				)
       model.train()
       __lowerCamelCase													=    self._prepare_for_class(lowercase_	,				lowercase_	,				return_labels=lowercase_				)
       __lowerCamelCase													=    model(**lowercase_				).loss
       loss.backward()




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase							,__lowerCamelCase													=    self.model_tester.prepare_config_and_inputs_for_common()

    __lowerCamelCase													=    [
        {'''title''': '''multi_label_classification''', '''num_labels''': 2, '''dtype''': torch.float},
        {'''title''': '''single_label_classification''', '''num_labels''': 1, '''dtype''': torch.long},
        {'''title''': '''regression''', '''num_labels''': 1, '''dtype''': torch.float},
    ]

    for model_class in self.all_model_classes:
       if (
           model_class
           not in [
               *get_values(lowercase_				),
           ]
           or model_class.__name__ == "LevitForImageClassificationWithTeacher"
       ):
          continue

       for problem_type in problem_types:
          with self.subTest(msg=F"""Testing {model_class} with {problem_type["title"]}"""				):
             __lowerCamelCase													=    problem_type['''title''']
             __lowerCamelCase													=    problem_type['''num_labels''']

             __lowerCamelCase													=    model_class(lowercase_				)
             model.to(lowercase_				)
             model.train()

             __lowerCamelCase													=    self._prepare_for_class(lowercase_	,				lowercase_	,				return_labels=lowercase_				)

             if problem_type["num_labels"] > 1:
                __lowerCamelCase													=    inputs['''labels'''].unsqueeze(1				).repeat(1	,				problem_type['''num_labels''']				)

             __lowerCamelCase													=    inputs['''labels'''].to(problem_type['''dtype''']				)

             # This tests that we do not trigger the warning form PyTorch "Using a target size that is different
             # to the input size. This will likely lead to incorrect results due to broadcasting. Please ensure
             # they have the same size." which is a symptom something in wrong for the regression problem.
             # See https://github.com/huggingface/transformers/issues/11780
             with warnings.catch_warnings(record=lowercase_				) as warning_list:
                __lowerCamelCase													=    model(**lowercase_				).loss
             for w in warning_list:
                if "Using a target size that is different to the input size" in str(w.message				):
                   raise ValueError(
                       F"""Something is going wrong in the regression problem: intercepted {w.message}"""				)

             loss.backward()




 @slow
 def        lowerCamelCase      (						self				):



    '''simple docstring'''







    for model_name in LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       __lowerCamelCase													=    LevitModel.from_pretrained(lowercase_				)
       self.assertIsNotNone(lowercase_				)





def 		a__			(		):
   __lowerCamelCase													=    Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)
   return image





@require_torch
@require_vision
class  __lowerCAmelCase     (	unittest.TestCase   ):




 @cached_property
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    return LevitImageProcessor.from_pretrained(LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[0]				)




 @slow
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    LevitForImageClassificationWithTeacher.from_pretrained(LEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[0]				).to(
        lowercase_				)

    __lowerCamelCase													=    self.default_image_processor
    __lowerCamelCase													=    prepare_img()
    __lowerCamelCase													=    image_processor(images=lowercase_	,				return_tensors='''pt'''				).to(lowercase_				)

    # forward pass
    with torch.no_grad():
       __lowerCamelCase													=    model(**lowercase_				)

    # verify the logits
    __lowerCamelCase													=    torch.Size((1, 1000)				)
    self.assertEqual(outputs.logits.shape	,				lowercase_				)

    __lowerCamelCase													=    torch.tensor([1.0_448, -0.3_745, -1.8_317]				).to(lowercase_				)

    self.assertTrue(torch.allclose(outputs.logits[0, :3]	,				lowercase_	,				atol=1E-4				)				)











from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

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 tensorflow as tf

  from transformers import (
      TFFunnelBaseModel,
      TFFunnelForMaskedLM,
      TFFunnelForMultipleChoice,
      TFFunnelForPreTraining,
      TFFunnelForQuestionAnswering,
      TFFunnelForSequenceClassification,
      TFFunnelForTokenClassification,
      TFFunnelModel,
  )



class  __lowerCAmelCase     :




 def __init__(						self	,				__UpperCAmelCase	,				__UpperCAmelCase=13	,				__UpperCAmelCase=7	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase=99	,				__UpperCAmelCase=[1, 1, 2]	,				__UpperCAmelCase=1	,				__UpperCAmelCase=32	,				__UpperCAmelCase=4	,				__UpperCAmelCase=8	,				__UpperCAmelCase=37	,				__UpperCAmelCase="gelu_new"	,				__UpperCAmelCase=0.1	,				__UpperCAmelCase=0.1	,				__UpperCAmelCase=0.0	,				__UpperCAmelCase=512	,				__UpperCAmelCase=3	,				__UpperCAmelCase=0.02	,				__UpperCAmelCase=3	,				__UpperCAmelCase=4	,				__UpperCAmelCase=None	,				__UpperCAmelCase=False	,				):



    '''simple docstring'''
    __lowerCamelCase													=    parent
    __lowerCamelCase													=    batch_size
    __lowerCamelCase													=    seq_length
    __lowerCamelCase													=    is_training
    __lowerCamelCase													=    use_input_mask
    __lowerCamelCase													=    use_token_type_ids
    __lowerCamelCase													=    use_labels
    __lowerCamelCase													=    vocab_size
    __lowerCamelCase													=    block_sizes
    __lowerCamelCase													=    num_decoder_layers
    __lowerCamelCase													=    d_model
    __lowerCamelCase													=    n_head
    __lowerCamelCase													=    d_head
    __lowerCamelCase													=    d_inner
    __lowerCamelCase													=    hidden_act
    __lowerCamelCase													=    hidden_dropout
    __lowerCamelCase													=    attention_dropout
    __lowerCamelCase													=    activation_dropout
    __lowerCamelCase													=    max_position_embeddings
    __lowerCamelCase													=    type_vocab_size
    __lowerCamelCase													=    2
    __lowerCamelCase													=    num_labels
    __lowerCamelCase													=    num_choices
    __lowerCamelCase													=    scope
    __lowerCamelCase													=    initializer_std

    # Used in the tests to check the size of the first attention layer
    __lowerCamelCase													=    n_head
    # Used in the tests to check the size of the first hidden state
    __lowerCamelCase													=    self.d_model
    # Used in the tests to check the number of output hidden states/attentions
    __lowerCamelCase													=    sum(self.block_sizes				) + (0 if base else self.num_decoder_layers)
    # FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
    # the last hidden state of the first block (which is the first hidden state of the decoder).
    if not base:
       __lowerCamelCase													=    self.num_hidden_layers + 2




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    ids_tensor([self.batch_size, self.seq_length]	,				self.vocab_size				)

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

    __lowerCamelCase													=    None
    if self.use_token_type_ids:
       __lowerCamelCase													=    ids_tensor([self.batch_size, self.seq_length]	,				self.type_vocab_size				)

    __lowerCamelCase													=    None
    __lowerCamelCase													=    None
    __lowerCamelCase													=    None
    if self.use_labels:
       __lowerCamelCase													=    ids_tensor([self.batch_size]	,				self.type_sequence_label_size				)
       __lowerCamelCase													=    ids_tensor([self.batch_size, self.seq_length]	,				self.num_labels				)
       __lowerCamelCase													=    ids_tensor([self.batch_size]	,				self.num_choices				)

    __lowerCamelCase													=    FunnelConfig(
        vocab_size=self.vocab_size	,				block_sizes=self.block_sizes	,				num_decoder_layers=self.num_decoder_layers	,				d_model=self.d_model	,				n_head=self.n_head	,				d_head=self.d_head	,				d_inner=self.d_inner	,				hidden_act=self.hidden_act	,				hidden_dropout=self.hidden_dropout	,				attention_dropout=self.attention_dropout	,				activation_dropout=self.activation_dropout	,				max_position_embeddings=self.max_position_embeddings	,				type_vocab_size=self.type_vocab_size	,				initializer_std=self.initializer_std	,				)

    return (
        config,
        input_ids,
        token_type_ids,
        input_mask,
        sequence_labels,
        token_labels,
        choice_labels,
    )




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    TFFunnelModel(config=__UpperCAmelCase				)
    __lowerCamelCase													=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    __lowerCamelCase													=    model(__UpperCAmelCase				)

    __lowerCamelCase													=    [input_ids, input_mask]
    __lowerCamelCase													=    model(__UpperCAmelCase				)

    __lowerCamelCase													=    model(__UpperCAmelCase				)
    self.parent.assertEqual(result.last_hidden_state.shape	,				(self.batch_size, self.seq_length, self.d_model)				)

    __lowerCamelCase													=    False
    __lowerCamelCase													=    TFFunnelModel(config=__UpperCAmelCase				)
    __lowerCamelCase													=    model(__UpperCAmelCase				)
    self.parent.assertEqual(result.last_hidden_state.shape	,				(self.batch_size, self.seq_length, self.d_model)				)

    __lowerCamelCase													=    False
    __lowerCamelCase													=    TFFunnelModel(config=__UpperCAmelCase				)
    __lowerCamelCase													=    model(__UpperCAmelCase				)
    self.parent.assertEqual(result.last_hidden_state.shape	,				(self.batch_size, self.seq_length, self.d_model)				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    TFFunnelBaseModel(config=__UpperCAmelCase				)
    __lowerCamelCase													=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    __lowerCamelCase													=    model(__UpperCAmelCase				)

    __lowerCamelCase													=    [input_ids, input_mask]
    __lowerCamelCase													=    model(__UpperCAmelCase				)

    __lowerCamelCase													=    model(__UpperCAmelCase				)
    self.parent.assertEqual(result.last_hidden_state.shape	,				(self.batch_size, 2, self.d_model)				)

    __lowerCamelCase													=    False
    __lowerCamelCase													=    TFFunnelBaseModel(config=__UpperCAmelCase				)
    __lowerCamelCase													=    model(__UpperCAmelCase				)
    self.parent.assertEqual(result.last_hidden_state.shape	,				(self.batch_size, 3, self.d_model)				)

    __lowerCamelCase													=    False
    __lowerCamelCase													=    TFFunnelBaseModel(config=__UpperCAmelCase				)
    __lowerCamelCase													=    model(__UpperCAmelCase				)
    self.parent.assertEqual(result.last_hidden_state.shape	,				(self.batch_size, 2, self.d_model)				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    TFFunnelForPreTraining(config=__UpperCAmelCase				)
    __lowerCamelCase													=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    __lowerCamelCase													=    model(__UpperCAmelCase				)
    self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.seq_length)				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    TFFunnelForMaskedLM(config=__UpperCAmelCase				)
    __lowerCamelCase													=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    __lowerCamelCase													=    model(__UpperCAmelCase				)
    self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.seq_length, self.vocab_size)				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    self.num_labels
    __lowerCamelCase													=    TFFunnelForSequenceClassification(config=__UpperCAmelCase				)
    __lowerCamelCase													=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    __lowerCamelCase													=    model(__UpperCAmelCase				)
    self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.num_labels)				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    self.num_choices
    __lowerCamelCase													=    TFFunnelForMultipleChoice(config=__UpperCAmelCase				)
    __lowerCamelCase													=    tf.tile(tf.expand_dims(__UpperCAmelCase	,				1				)	,				(1, self.num_choices, 1)				)
    __lowerCamelCase													=    tf.tile(tf.expand_dims(__UpperCAmelCase	,				1				)	,				(1, self.num_choices, 1)				)
    __lowerCamelCase													=    tf.tile(tf.expand_dims(__UpperCAmelCase	,				1				)	,				(1, self.num_choices, 1)				)
    __lowerCamelCase													=    {
        '''input_ids''': multiple_choice_inputs_ids,
        '''attention_mask''': multiple_choice_input_mask,
        '''token_type_ids''': multiple_choice_token_type_ids,
    }
    __lowerCamelCase													=    model(__UpperCAmelCase				)
    self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.num_choices)				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    self.num_labels
    __lowerCamelCase													=    TFFunnelForTokenClassification(config=__UpperCAmelCase				)
    __lowerCamelCase													=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    __lowerCamelCase													=    model(__UpperCAmelCase				)
    self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.seq_length, self.num_labels)				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    TFFunnelForQuestionAnswering(config=__UpperCAmelCase				)
    __lowerCamelCase													=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
    __lowerCamelCase													=    model(__UpperCAmelCase				)
    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        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.prepare_config_and_inputs()
    (
        (
        __lowerCamelCase
    )							,(
        __lowerCamelCase
    )							,(
        __lowerCamelCase
    )							,(
        __lowerCamelCase
    )							,(
        __lowerCamelCase
    )							,(
        __lowerCamelCase
    )							,(
        __lowerCamelCase
    )							,
    )													=    config_and_inputs
    __lowerCamelCase													=    {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
    return config, inputs_dict



@require_tf
class  __lowerCAmelCase     (	lowerCAmelCase__  ,	lowerCAmelCase__  ,	unittest.TestCase   ):
 lowerCAmelCase__       					=  (
     (
         TFFunnelModel,
         TFFunnelForMaskedLM,
         TFFunnelForPreTraining,
         TFFunnelForQuestionAnswering,
         TFFunnelForTokenClassification,
     )
     if is_tf_available()
     else ()
 )
 lowerCAmelCase__       					=  (
     {
         """feature-extraction""": (TFFunnelBaseModel, TFFunnelModel),
         """fill-mask""": TFFunnelForMaskedLM,
         """question-answering""": TFFunnelForQuestionAnswering,
         """text-classification""": TFFunnelForSequenceClassification,
         """token-classification""": TFFunnelForTokenClassification,
         """zero-shot""": TFFunnelForSequenceClassification,
     }
     if is_tf_available()
     else {}
 )
 lowerCAmelCase__       					=  False
 lowerCAmelCase__       					=  False




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    TFFunnelModelTester(self				)
    __lowerCamelCase													=    ConfigTester(self	,				config_class=__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    self.config_tester.run_common_tests()




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_pretraining(*__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_masked_lm(*__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_token_classification(*__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_question_answering(*__UpperCAmelCase				)



@require_tf
class  __lowerCAmelCase     (	lowerCAmelCase__  ,	unittest.TestCase   ):
 lowerCAmelCase__       					=  (
     (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
 )
 lowerCAmelCase__       					=  False
 lowerCAmelCase__       					=  False




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    TFFunnelModelTester(self	,				base=__UpperCAmelCase				)
    __lowerCamelCase													=    ConfigTester(self	,				config_class=__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    self.config_tester.run_common_tests()




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_base_model(*__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_sequence_classification(*__UpperCAmelCase				)




 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_multiple_choice(*__UpperCAmelCase				)






