'''simple docstring'''






import gc
import random
import unittest

import torch

from diffusers import (
    IFImgaImgPipeline,
    IFImgaImgSuperResolutionPipeline,
    IFInpaintingPipeline,
    IFInpaintingSuperResolutionPipeline,
    IFPipeline,
    IFSuperResolutionPipeline,
)
from diffusers.models.attention_processor import AttnAddedKVProcessor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import floats_tensor, load_numpy, require_torch_gpu, skip_mps, slow, torch_device

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference
from . import IFPipelineTesterMixin







@skip_mps
class lowercase_       (		_UpperCamelCase    ,    _UpperCamelCase    ,    unittest.TestCase			):







   """simple docstring"""

   __lowerCAmelCase         =   IFPipeline
   __lowerCAmelCase         =   TEXT_TO_IMAGE_PARAMS - {"width", "height", "latents"}
   __lowerCAmelCase         =   TEXT_TO_IMAGE_BATCH_PARAMS
   __lowerCAmelCase         =   PipelineTesterMixin.required_optional_params - {"latents"}
   def 	__UpperCAmelCase   (      self      :			int     )  ->			Tuple:
        return self._get_dummy_components()
   def 	__UpperCAmelCase   (      self      :			Dict, UpperCamelCase__      :			str, UpperCamelCase__      :			Any=0     )  ->			List[str]:
        if str(UpperCamelCase__     ).startswith('mps'     ):
             _A    		=  torch.manual_seed(UpperCamelCase__     )
        else:
             _A    		=  torch.Generator(device=UpperCamelCase__     ).manual_seed(UpperCamelCase__     )

        _A    		=  {
            'prompt': 'A painting of a squirrel eating a burger',
            'generator': generator,
            'num_inference_steps': 2,
            'output_type': 'numpy',
        }

        return inputs
   def 	__UpperCAmelCase   (      self      :			List[Any]     )  ->			int:
        self._test_save_load_optional_components()
   @unittest.skipIf(torch_device != 'cuda', reason='float16 requires CUDA'     )
   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			Optional[Any]:
        # Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
        super().test_save_load_floataa(expected_max_diff=1e-1     )
   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			List[str]:
        self._test_attention_slicing_forward_pass(expected_max_diff=1e-2     )
   def 	__UpperCAmelCase   (      self      :			str     )  ->			str:
        self._test_save_load_local()
   def 	__UpperCAmelCase   (      self      :			Union[str, Any]     )  ->			Optional[int]:
        self._test_inference_batch_single_identical(
            expected_max_diff=1e-2, )

   @unittest.skipIf(
       torch_device != 'cuda' or not is_xformers_available(), reason='XFormers attention is only available with CUDA and `xformers` installed', )
   def 	__UpperCAmelCase   (      self      :			Optional[int]     )  ->			List[str]:
        self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3     )







@slow
@require_torch_gpu
class lowercase_       (		unittest.TestCase			):







   """simple docstring"""

   def 	__UpperCAmelCase   (      self      :			List[str]     )  ->			Tuple:
        # clean up the VRAM after each test
        super().tearDown()
        gc.collect()
        torch.cuda.empty_cache()
   def 	__UpperCAmelCase   (      self      :			Dict     )  ->			Dict:
        # if

        _A    		=  IFPipeline.from_pretrained('DeepFloyd/IF-I-XL-v1.0', variant='fp16', torch_dtype=torch.floataa     )

        _A    		=  IFSuperResolutionPipeline.from_pretrained(
            'DeepFloyd/IF-II-L-v1.0', variant='fp16', torch_dtype=torch.floataa, text_encoder=UpperCamelCase__, tokenizer=UpperCamelCase__     )

        # pre compute text embeddings and remove T5 to save memory

        pipe_a.text_encoder.to('cuda'     )

        _A		,       _A    		=  pipe_a.encode_prompt('anime turtle', device='cuda'     )

        del pipe_a.tokenizer
        del pipe_a.text_encoder
        gc.collect()

        _A    		=  None
        _A    		=  None

        pipe_a.enable_model_cpu_offload()
        pipe_a.enable_model_cpu_offload()

        pipe_a.unet.set_attn_processor(AttnAddedKVProcessor()     )
        pipe_a.unet.set_attn_processor(AttnAddedKVProcessor()     )

        self._test_if(UpperCamelCase__, UpperCamelCase__, UpperCamelCase__, UpperCamelCase__     )

        pipe_a.remove_all_hooks()
        pipe_a.remove_all_hooks()

        # img2img

        _A    		=  IFImgaImgPipeline(**pipe_a.components     )
        _A    		=  IFImgaImgSuperResolutionPipeline(**pipe_a.components     )

        pipe_a.enable_model_cpu_offload()
        pipe_a.enable_model_cpu_offload()

        pipe_a.unet.set_attn_processor(AttnAddedKVProcessor()     )
        pipe_a.unet.set_attn_processor(AttnAddedKVProcessor()     )

        self._test_if_imgaimg(UpperCamelCase__, UpperCamelCase__, UpperCamelCase__, UpperCamelCase__     )

        pipe_a.remove_all_hooks()
        pipe_a.remove_all_hooks()

        # inpainting

        _A    		=  IFInpaintingPipeline(**pipe_a.components     )
        _A    		=  IFInpaintingSuperResolutionPipeline(**pipe_a.components     )

        pipe_a.enable_model_cpu_offload()
        pipe_a.enable_model_cpu_offload()

        pipe_a.unet.set_attn_processor(AttnAddedKVProcessor()     )
        pipe_a.unet.set_attn_processor(AttnAddedKVProcessor()     )

        self._test_if_inpainting(UpperCamelCase__, UpperCamelCase__, UpperCamelCase__, UpperCamelCase__     )
   def 	__UpperCAmelCase   (      self      :			Tuple, UpperCamelCase__      :			Dict, UpperCamelCase__      :			int, UpperCamelCase__      :			Dict, UpperCamelCase__      :			Dict     )  ->			List[Any]:
        # pipeline 1

        _start_torch_memory_measurement()

        _A    		=  torch.Generator(device='cpu'     ).manual_seed(0     )
        _A    		=  pipe_a(
            prompt_embeds=UpperCamelCase__, negative_prompt_embeds=UpperCamelCase__, num_inference_steps=2, generator=UpperCamelCase__, output_type='np', )

        _A    		=  output.images[0]

        assert image.shape == (64, 64, 3)

        _A    		=  torch.cuda.max_memory_allocated()
        assert mem_bytes < 13 * 10**9

        _A    		=  load_numpy(
            'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/if/test_if.npy'     )
        assert_mean_pixel_difference(UpperCamelCase__, UpperCamelCase__     )

        # pipeline 2

        _start_torch_memory_measurement()

        _A    		=  torch.Generator(device='cpu'     ).manual_seed(0     )

        _A    		=  floats_tensor((1, 3, 64, 64), rng=random.Random(0     )     ).to(UpperCamelCase__     )

        _A    		=  pipe_a(
            prompt_embeds=UpperCamelCase__, negative_prompt_embeds=UpperCamelCase__, image=UpperCamelCase__, generator=UpperCamelCase__, num_inference_steps=2, output_type='np', )

        _A    		=  output.images[0]

        assert image.shape == (2_56, 2_56, 3)

        _A    		=  torch.cuda.max_memory_allocated()
        assert mem_bytes < 4 * 10**9

        _A    		=  load_numpy(
            'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/if/test_if_superresolution_stage_II.npy'     )
        assert_mean_pixel_difference(UpperCamelCase__, UpperCamelCase__     )
   def 	__UpperCAmelCase   (      self      :			List[Any], UpperCamelCase__      :			List[Any], UpperCamelCase__      :			List[str], UpperCamelCase__      :			Optional[Any], UpperCamelCase__      :			int     )  ->			str:
        # pipeline 1

        _start_torch_memory_measurement()

        _A    		=  floats_tensor((1, 3, 64, 64), rng=random.Random(0     )     ).to(UpperCamelCase__     )

        _A    		=  torch.Generator(device='cpu'     ).manual_seed(0     )

        _A    		=  pipe_a(
            prompt_embeds=UpperCamelCase__, negative_prompt_embeds=UpperCamelCase__, image=UpperCamelCase__, num_inference_steps=2, generator=UpperCamelCase__, output_type='np', )

        _A    		=  output.images[0]

        assert image.shape == (64, 64, 3)

        _A    		=  torch.cuda.max_memory_allocated()
        assert mem_bytes < 10 * 10**9

        _A    		=  load_numpy(
            'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/if/test_if_img2img.npy'     )
        assert_mean_pixel_difference(UpperCamelCase__, UpperCamelCase__     )

        # pipeline 2

        _start_torch_memory_measurement()

        _A    		=  torch.Generator(device='cpu'     ).manual_seed(0     )

        _A    		=  floats_tensor((1, 3, 2_56, 2_56), rng=random.Random(0     )     ).to(UpperCamelCase__     )
        _A    		=  floats_tensor((1, 3, 64, 64), rng=random.Random(0     )     ).to(UpperCamelCase__     )

        _A    		=  pipe_a(
            prompt_embeds=UpperCamelCase__, negative_prompt_embeds=UpperCamelCase__, image=UpperCamelCase__, original_image=UpperCamelCase__, generator=UpperCamelCase__, num_inference_steps=2, output_type='np', )

        _A    		=  output.images[0]

        assert image.shape == (2_56, 2_56, 3)

        _A    		=  torch.cuda.max_memory_allocated()
        assert mem_bytes < 4 * 10**9

        _A    		=  load_numpy(
            'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/if/test_if_img2img_superresolution_stage_II.npy'     )
        assert_mean_pixel_difference(UpperCamelCase__, UpperCamelCase__     )

   def 	__UpperCAmelCase   (      self      :			Optional[Any], UpperCamelCase__      :			Union[str, Any], UpperCamelCase__      :			Union[str, Any], UpperCamelCase__      :			Union[str, Any], UpperCamelCase__      :			List[str]     )  ->			Tuple:
        # pipeline 1

        _start_torch_memory_measurement()

        _A    		=  floats_tensor((1, 3, 64, 64), rng=random.Random(0     )     ).to(UpperCamelCase__     )
        _A    		=  floats_tensor((1, 3, 64, 64), rng=random.Random(1     )     ).to(UpperCamelCase__     )

        _A    		=  torch.Generator(device='cpu'     ).manual_seed(0     )
        _A    		=  pipe_a(
            prompt_embeds=UpperCamelCase__, negative_prompt_embeds=UpperCamelCase__, image=UpperCamelCase__, mask_image=UpperCamelCase__, num_inference_steps=2, generator=UpperCamelCase__, output_type='np', )

        _A    		=  output.images[0]

        assert image.shape == (64, 64, 3)

        _A    		=  torch.cuda.max_memory_allocated()
        assert mem_bytes < 10 * 10**9

        _A    		=  load_numpy(
            'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/if/test_if_inpainting.npy'     )
        assert_mean_pixel_difference(UpperCamelCase__, UpperCamelCase__     )

        # pipeline 2

        _start_torch_memory_measurement()

        _A    		=  torch.Generator(device='cpu'     ).manual_seed(0     )

        _A    		=  floats_tensor((1, 3, 64, 64), rng=random.Random(0     )     ).to(UpperCamelCase__     )
        _A    		=  floats_tensor((1, 3, 2_56, 2_56), rng=random.Random(0     )     ).to(UpperCamelCase__     )
        _A    		=  floats_tensor((1, 3, 2_56, 2_56), rng=random.Random(1     )     ).to(UpperCamelCase__     )

        _A    		=  pipe_a(
            prompt_embeds=UpperCamelCase__, negative_prompt_embeds=UpperCamelCase__, image=UpperCamelCase__, mask_image=UpperCamelCase__, original_image=UpperCamelCase__, generator=UpperCamelCase__, num_inference_steps=2, output_type='np', )

        _A    		=  output.images[0]

        assert image.shape == (2_56, 2_56, 3)

        _A    		=  torch.cuda.max_memory_allocated()
        assert mem_bytes < 4 * 10**9

        _A    		=  load_numpy(
            'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/if/test_if_inpainting_superresolution_stage_II.npy'     )
        assert_mean_pixel_difference(UpperCamelCase__, UpperCamelCase__     )






def  _SCREAMING_SNAKE_CASE		(      ):
     torch.cuda.empty_cache()
     torch.cuda.reset_max_memory_allocated()
     torch.cuda.reset_peak_memory_stats()








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 				_a				:

			def __init__(self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_=13,   SCREAMING_SNAKE_CASE_=7,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=True,   SCREAMING_SNAKE_CASE_=99,   SCREAMING_SNAKE_CASE_=[1, 1, 2],   SCREAMING_SNAKE_CASE_=1,   SCREAMING_SNAKE_CASE_=32,   SCREAMING_SNAKE_CASE_=4,   SCREAMING_SNAKE_CASE_=8,   SCREAMING_SNAKE_CASE_=37,   SCREAMING_SNAKE_CASE_="gelu_new",   SCREAMING_SNAKE_CASE_=0.1,   SCREAMING_SNAKE_CASE_=0.1,   SCREAMING_SNAKE_CASE_=0.0,   SCREAMING_SNAKE_CASE_=512,   SCREAMING_SNAKE_CASE_=3,   SCREAMING_SNAKE_CASE_=0.0_2,   SCREAMING_SNAKE_CASE_=3,   SCREAMING_SNAKE_CASE_=4,   SCREAMING_SNAKE_CASE_=None,   SCREAMING_SNAKE_CASE_=False,   )       ->   Tuple:
						UpperCAmelCase_:		Any							      =     parent
						UpperCAmelCase_:		Optional[Any]							      =     batch_size
						UpperCAmelCase_:		Dict							      =     seq_length
						UpperCAmelCase_:		Union[str, Any]							      =     is_training
						UpperCAmelCase_:		Optional[Any]							      =     use_input_mask
						UpperCAmelCase_:		Optional[Any]							      =     use_token_type_ids
						UpperCAmelCase_:		int							      =     use_labels
						UpperCAmelCase_:		List[str]							      =     vocab_size
						UpperCAmelCase_:		Optional[int]							      =     block_sizes
						UpperCAmelCase_:		Tuple							      =     num_decoder_layers
						UpperCAmelCase_:		List[Any]							      =     d_model
						UpperCAmelCase_:		Dict							      =     n_head
						UpperCAmelCase_:		Optional[Any]							      =     d_head
						UpperCAmelCase_:		Optional[Any]							      =     d_inner
						UpperCAmelCase_:		str							      =     hidden_act
						UpperCAmelCase_:		str							      =     hidden_dropout
						UpperCAmelCase_:		Union[str, Any]							      =     attention_dropout
						UpperCAmelCase_:		Dict							      =     activation_dropout
						UpperCAmelCase_:		str							      =     max_position_embeddings
						UpperCAmelCase_:		Dict							      =     type_vocab_size
						UpperCAmelCase_:		str							      =     2
						UpperCAmelCase_:		Dict							      =     num_labels
						UpperCAmelCase_:		Optional[int]							      =     num_choices
						UpperCAmelCase_:		Optional[int]							      =     scope
						UpperCAmelCase_:		List[Any]							      =     initializer_std

						# Used in the tests to check the size of the first attention layer
						UpperCAmelCase_:		Tuple							      =     n_head
						# Used in the tests to check the size of the first hidden state
						UpperCAmelCase_:		Union[str, Any]							      =     self.d_model
						# Used in the tests to check the number of output hidden states/attentions
						UpperCAmelCase_:		str							      =     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:
									UpperCAmelCase_:		Dict							      =     self.num_hidden_layers + 2

			def      __snake_case       (self					)       ->   Union[str, Any]:
						UpperCAmelCase_:		Dict							      =     ids_tensor([self.batch_size, self.seq_length],   self.vocab_size					)

						UpperCAmelCase_:		Dict							      =     None
						if self.use_input_mask:
									UpperCAmelCase_:		List[str]							      =     random_attention_mask([self.batch_size, self.seq_length]					)

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

						UpperCAmelCase_:		Any							      =     None
						UpperCAmelCase_:		str							      =     None
						UpperCAmelCase_:		Any							      =     None
						if self.use_labels:
									UpperCAmelCase_:		Dict							      =     ids_tensor([self.batch_size],   self.type_sequence_label_size					)
									UpperCAmelCase_:		Optional[Any]							      =     ids_tensor([self.batch_size, self.seq_length],   self.num_labels					)
									UpperCAmelCase_:		str							      =     ids_tensor([self.batch_size],   self.num_choices					)

						UpperCAmelCase_:		Dict							      =     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      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   int:
						UpperCAmelCase_:		str							      =     TFFunnelModel(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		List[Any]							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		Tuple							      =     model(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		int							      =     [input_ids, input_mask]
						UpperCAmelCase_:		Dict							      =     model(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		Union[str, Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, self.seq_length, self.d_model)					)

						UpperCAmelCase_:		Union[str, Any]							      =     False
						UpperCAmelCase_:		int							      =     TFFunnelModel(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		List[Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, self.seq_length, self.d_model)					)

						UpperCAmelCase_:		Optional[Any]							      =     False
						UpperCAmelCase_:		str							      =     TFFunnelModel(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		List[Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, self.seq_length, self.d_model)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   Any:
						UpperCAmelCase_:		Dict							      =     TFFunnelBaseModel(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Tuple							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		Tuple							      =     model(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		Optional[int]							      =     [input_ids, input_mask]
						UpperCAmelCase_:		List[str]							      =     model(SCREAMING_SNAKE_CASE_					)

						UpperCAmelCase_:		int							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, 2, self.d_model)					)

						UpperCAmelCase_:		List[str]							      =     False
						UpperCAmelCase_:		str							      =     TFFunnelBaseModel(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Any							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, 3, self.d_model)					)

						UpperCAmelCase_:		List[Any]							      =     False
						UpperCAmelCase_:		List[Any]							      =     TFFunnelBaseModel(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		List[Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.last_hidden_state.shape,   (self.batch_size, 2, self.d_model)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   Dict:
						UpperCAmelCase_:		List[Any]							      =     TFFunnelForPreTraining(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Union[str, Any]							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		List[Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.seq_length)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   str:
						UpperCAmelCase_:		Union[str, Any]							      =     TFFunnelForMaskedLM(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		List[str]							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		List[Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.seq_length, self.vocab_size)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   int:
						UpperCAmelCase_:		Tuple							      =     self.num_labels
						UpperCAmelCase_:		Optional[int]							      =     TFFunnelForSequenceClassification(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Union[str, Any]							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		Dict							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.num_labels)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   int:
						UpperCAmelCase_:		Tuple							      =     self.num_choices
						UpperCAmelCase_:		List[str]							      =     TFFunnelForMultipleChoice(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		int							      =     tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_,   1					),   (1, self.num_choices, 1)					)
						UpperCAmelCase_:		Any							      =     tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_,   1					),   (1, self.num_choices, 1)					)
						UpperCAmelCase_:		int							      =     tf.tile(tf.expand_dims(SCREAMING_SNAKE_CASE_,   1					),   (1, self.num_choices, 1)					)
						UpperCAmelCase_:		Tuple							      =     {
						    """input_ids""": multiple_choice_inputs_ids,
						    """attention_mask""": multiple_choice_input_mask,
						    """token_type_ids""": multiple_choice_token_type_ids,
						}
						UpperCAmelCase_:		Tuple							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.num_choices)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   int:
						UpperCAmelCase_:		List[Any]							      =     self.num_labels
						UpperCAmelCase_:		Dict							      =     TFFunnelForTokenClassification(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Tuple							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		Union[str, Any]							      =     model(SCREAMING_SNAKE_CASE_					)
						self.parent.assertEqual(result.logits.shape,   (self.batch_size, self.seq_length, self.num_labels)					)

			def      __snake_case       (self,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   SCREAMING_SNAKE_CASE_,   )       ->   str:
						UpperCAmelCase_:		Any							      =     TFFunnelForQuestionAnswering(config=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Dict							      =     {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
						UpperCAmelCase_:		Union[str, Any]							      =     model(SCREAMING_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      __snake_case       (self					)       ->   int:
						UpperCAmelCase_:		Optional[Any]							      =     self.prepare_config_and_inputs()
						(
						    (
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							(
						    UpperCAmelCase_
						)      ,							
						):		Tuple							      =     config_and_inputs
						UpperCAmelCase_:		Tuple							      =     {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
						return config, inputs_dict







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

			def      __snake_case       (self					)       ->   Tuple:
						UpperCAmelCase_:		Union[str, Any]							      =     TFFunnelModelTester(self					)
						UpperCAmelCase_:		List[str]							      =     ConfigTester(self,   config_class=SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Any:
						self.config_tester.run_common_tests()

			def      __snake_case       (self					)       ->   int:
						UpperCAmelCase_:		List[str]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   int:
						UpperCAmelCase_:		Union[str, Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_pretraining(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Optional[int]:
						UpperCAmelCase_:		Union[str, Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Optional[Any]:
						UpperCAmelCase_:		Tuple							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   List[Any]:
						UpperCAmelCase_:		Union[str, Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*SCREAMING_SNAKE_CASE_					)







@require_tf
class 				_a				(   _lowerCAmelCase ,		unittest.TestCase					):
			A      		=	(
			    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
			)
			A      		=	False
			A      		=	False

			def      __snake_case       (self					)       ->   Dict:
						UpperCAmelCase_:		List[Any]							      =     TFFunnelModelTester(self,   base=SCREAMING_SNAKE_CASE_					)
						UpperCAmelCase_:		Dict							      =     ConfigTester(self,   config_class=SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Union[str, Any]:
						self.config_tester.run_common_tests()

			def      __snake_case       (self					)       ->   Union[str, Any]:
						UpperCAmelCase_:		Optional[Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_base_model(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Union[str, Any]:
						UpperCAmelCase_:		Union[str, Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*SCREAMING_SNAKE_CASE_					)

			def      __snake_case       (self					)       ->   Tuple:
						UpperCAmelCase_:		Optional[Any]							      =     self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*SCREAMING_SNAKE_CASE_					)






