



"""simple docstring"""






from typing import Callable, List, Optional, Tuple, Union

import torch
from transformers import CLIPTextModel, CLIPTokenizer

from ...configuration_utils import ConfigMixin, register_to_config
from ...models import ModelMixin, TransformeraDModel, VQModel
from ...schedulers import VQDiffusionScheduler
from ...utils import logging
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput


_lowercase			:			Optional[Any]										=						logging.get_logger(__name__)  # pylint: disable=invalid-name

class 	__SCREAMING_SNAKE_CASE     (				lowerCAmelCase_		,       lowerCAmelCase_       ):


					'''simple docstring'''





					@register_to_config
					def __init__(	self							:  str,  lowerCamelCase							:  bool,  lowerCamelCase							:  Optional[int] = None,  lowerCamelCase							:  Optional[int] = None					)-> Any:
								super().__init__()

								lowerCamelCase__		:		Optional[int]		     =learnable

								if self.learnable:
											assert hidden_size is not None, "learnable=True requires `hidden_size` to be set"
											assert length is not None, "learnable=True requires `length` to be set"

											lowerCamelCase__		:		Tuple		     =torch.zeros(lowerCamelCase,  lowerCamelCase					)
								else:
											lowerCamelCase__		:		List[str]		     =None

								lowerCamelCase__		:		str		     =torch.nn.Parameter(lowerCamelCase					)





class 	__SCREAMING_SNAKE_CASE     (				lowerCAmelCase_       ):


					'''simple docstring'''





					_a             =							42
					_a             =							42
					_a             =							42
					_a             =							42
					_a             =							42
					_a             =							42



					def __init__(	self							:  List[str],  lowerCamelCase							:  VQModel,  lowerCamelCase							:  CLIPTextModel,  lowerCamelCase							:  CLIPTokenizer,  lowerCamelCase							:  TransformeraDModel,  lowerCamelCase							:  VQDiffusionScheduler,  lowerCamelCase							:  LearnedClassifierFreeSamplingEmbeddings,  )-> List[str]:
								super().__init__()

								self.register_modules(
								    vqvae=lowerCamelCase,  transformer=lowerCamelCase,  text_encoder=lowerCamelCase,  tokenizer=lowerCamelCase,  scheduler=lowerCamelCase,  learned_classifier_free_sampling_embeddings=lowerCamelCase,  )



					def 		snake_case	(	self							:  List[str],  lowerCamelCase							:  List[Any],  lowerCamelCase							:  Dict,  lowerCamelCase							:  List[Any]					)-> int:
								lowerCamelCase__		:		Optional[int]		     =len(lowerCamelCase					) if isinstance(lowerCamelCase,  lowerCamelCase					) else 1

								# get prompt text embeddings
								lowerCamelCase__		:		Tuple		     =self.tokenizer(
								    lowerCamelCase,  padding='''max_length''',  max_length=self.tokenizer.model_max_length,  return_tensors='''pt''',  )
								lowerCamelCase__		:		Any		     =text_inputs.input_ids

								if text_input_ids.shape[-1] > self.tokenizer.model_max_length:
											lowerCamelCase__		:		List[Any]		     =self.tokenizer.batch_decode(text_input_ids[:, self.tokenizer.model_max_length :]					)
											logger.warning(
											    '''The following part of your input was truncated because CLIP can only handle sequences up to'''
											    F''' {self.tokenizer.model_max_length} tokens: {removed_text}'''					)
											lowerCamelCase__		:		List[str]		     =text_input_ids[:, : self.tokenizer.model_max_length]
								lowerCamelCase__		:		Tuple		     =self.text_encoder(text_input_ids.to(self.device					)					)[0]

								# NOTE: This additional step of normalizing the text embeddings is from VQ-Diffusion.
								# While CLIP does normalize the pooled output of the text transformer when combining
								# the image and text embeddings, CLIP does not directly normalize the last hidden state.
								#
								# CLIP normalizing the pooled output.
								# https://github.com/huggingface/transformers/blob/d92e22d1f28324f513f3080e5c47c071a3916721/src/transformers/models/clip/modeling_clip.py#L1052-L1053
								lowerCamelCase__		:		Any		     =prompt_embeds / prompt_embeds.norm(dim=-1,  keepdim=lowerCamelCase					)

								# duplicate text embeddings for each generation per prompt
								lowerCamelCase__		:		Dict		     =prompt_embeds.repeat_interleave(lowerCamelCase,  dim=0					)

								if do_classifier_free_guidance:
											if self.learned_classifier_free_sampling_embeddings.learnable:
														lowerCamelCase__		:		Dict		     =self.learned_classifier_free_sampling_embeddings.embeddings
														lowerCamelCase__		:		Union[str, Any]		     =negative_prompt_embeds.unsqueeze(0					).repeat(lowerCamelCase,  1,  1					)
											else:
														lowerCamelCase__		:		Optional[Any]		     =[''''''] * batch_size

														lowerCamelCase__		:		Union[str, Any]		     =text_input_ids.shape[-1]
														lowerCamelCase__		:		List[str]		     =self.tokenizer(
														    lowerCamelCase,  padding='''max_length''',  max_length=lowerCamelCase,  truncation=lowerCamelCase,  return_tensors='''pt''',  )
														lowerCamelCase__		:		Optional[int]		     =self.text_encoder(uncond_input.input_ids.to(self.device					)					)[0]
														# See comment for normalizing text embeddings
														lowerCamelCase__		:		List[Any]		     =negative_prompt_embeds / negative_prompt_embeds.norm(dim=-1,  keepdim=lowerCamelCase					)

											# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
											lowerCamelCase__		:		int		     =negative_prompt_embeds.shape[1]
											lowerCamelCase__		:		Optional[Any]		     =negative_prompt_embeds.repeat(1,  lowerCamelCase,  1					)
											lowerCamelCase__		:		int		     =negative_prompt_embeds.view(batch_size * num_images_per_prompt,  lowerCamelCase,  -1					)

											# For classifier free guidance, we need to do two forward passes.
											# Here we concatenate the unconditional and text embeddings into a single batch
											# to avoid doing two forward passes
											lowerCamelCase__		:		Union[str, Any]		     =torch.cat([negative_prompt_embeds, prompt_embeds]					)

								return prompt_embeds



					@torch.no_grad()
					def __call__(	self							:  str,  lowerCamelCase							:  Union[str, List[str]],  lowerCamelCase							:  int = 100,  lowerCamelCase							:  float = 5.0,  lowerCamelCase							:  float = 1.0,  lowerCamelCase							:  int = 1,  lowerCamelCase							:  Optional[Union[torch.Generator, List[torch.Generator]]] = None,  lowerCamelCase							:  Optional[torch.FloatTensor] = None,  lowerCamelCase							:  Optional[str] = "pil",  lowerCamelCase							:  bool = True,  lowerCamelCase							:  Optional[Callable[[int, int, torch.FloatTensor], None]] = None,  lowerCamelCase							:  int = 1,  )-> Union[ImagePipelineOutput, Tuple]:
								if isinstance(lowerCamelCase,  lowerCamelCase					):
											lowerCamelCase__		:		Union[str, Any]		     =1
								elif isinstance(lowerCamelCase,  lowerCamelCase					):
											lowerCamelCase__		:		List[Any]		     =len(lowerCamelCase					)
								else:
											raise ValueError(F'''`prompt` has to be of type `str` or `list` but is {type(lowerCamelCase					)}'''					)

								lowerCamelCase__		:		Tuple		     =batch_size * num_images_per_prompt

								lowerCamelCase__		:		Optional[Any]		     =guidance_scale > 1.0

								lowerCamelCase__		:		Dict		     =self._encode_prompt(lowerCamelCase,  lowerCamelCase,  lowerCamelCase					)

								if (callback_steps is None) or (
								    callback_steps is not None and (not isinstance(lowerCamelCase,  lowerCamelCase					) or callback_steps <= 0)
								):
											raise ValueError(
											    F'''`callback_steps` has to be a positive integer but is {callback_steps} of type'''
											    F''' {type(lowerCamelCase					)}.'''					)

								# get the initial completely masked latents unless the user supplied it

								lowerCamelCase__		:		Any		     =(batch_size, self.transformer.num_latent_pixels)
								if latents is None:
											lowerCamelCase__		:		Union[str, Any]		     =self.transformer.num_vector_embeds - 1
											lowerCamelCase__		:		Optional[Any]		     =torch.full(lowerCamelCase,  lowerCamelCase					).to(self.device					)
								else:
											if latents.shape != latents_shape:
														raise ValueError(F'''Unexpected latents shape, got {latents.shape}, expected {latents_shape}'''					)
											if (latents < 0).any() or (latents >= self.transformer.num_vector_embeds).any():
														raise ValueError(
														    '''Unexpected latents value(s). All latents be valid embedding indices i.e. in the range 0,'''
														    F''' {self.transformer.num_vector_embeds - 1} (inclusive).'''					)
											lowerCamelCase__		:		List[Any]		     =latents.to(self.device					)

								# set timesteps
								self.scheduler.set_timesteps(lowerCamelCase,  device=self.device					)

								lowerCamelCase__		:		Optional[int]		     =self.scheduler.timesteps.to(self.device					)

								lowerCamelCase__		:		int		     =latents

								for i, t in enumerate(self.progress_bar(lowerCamelCase					)					):
											# expand the sample if we are doing classifier free guidance
											lowerCamelCase__		:		Dict		     =torch.cat([sample] * 2					) if do_classifier_free_guidance else sample

											# predict the un-noised image
											# model_output == `log_p_x_0`
											lowerCamelCase__		:		Optional[int]		     =self.transformer(lowerCamelCase,  encoder_hidden_states=lowerCamelCase,  timestep=lowerCamelCase					).sample

											if do_classifier_free_guidance:
														lowerCamelCase__     ,       lowerCamelCase__		:		str		     =model_output.chunk(2					)
														lowerCamelCase__		:		Any		     =model_output_uncond + guidance_scale * (model_output_text - model_output_uncond)
														model_output -= torch.logsumexp(lowerCamelCase,  dim=1,  keepdim=lowerCamelCase					)

											lowerCamelCase__		:		str		     =self.truncate(lowerCamelCase,  lowerCamelCase					)

											# remove `log(0)`'s (`-inf`s)
											lowerCamelCase__		:		Dict		     =model_output.clamp(-70					)

											# compute the previous noisy sample x_t -> x_t-1
											lowerCamelCase__		:		List[str]		     =self.scheduler.step(lowerCamelCase,  timestep=lowerCamelCase,  sample=lowerCamelCase,  generator=lowerCamelCase					).prev_sample

											# call the callback, if provided
											if callback is not None and i % callback_steps == 0:
														callback(lowerCamelCase,  lowerCamelCase,  lowerCamelCase					)

								lowerCamelCase__		:		Any		     =self.vqvae.config.vq_embed_dim
								lowerCamelCase__		:		int		     =(batch_size, self.transformer.height, self.transformer.width, embedding_channels)
								lowerCamelCase__		:		Tuple		     =self.vqvae.quantize.get_codebook_entry(lowerCamelCase,  shape=lowerCamelCase					)
								lowerCamelCase__		:		str		     =self.vqvae.decode(lowerCamelCase,  force_not_quantize=lowerCamelCase					).sample

								lowerCamelCase__		:		Optional[Any]		     =(image / 2 + 0.5).clamp(0,  1					)
								lowerCamelCase__		:		Dict		     =image.cpu().permute(0,  2,  3,  1					).numpy()

								if output_type == "pil":
											lowerCamelCase__		:		Dict		     =self.numpy_to_pil(lowerCamelCase					)

								if not return_dict:
											return (image,)

								return ImagePipelineOutput(images=lowerCamelCase					)




					def 		snake_case	(	self							:  List[Any],  lowerCamelCase							:  torch.FloatTensor,  lowerCamelCase							:  float					)-> torch.FloatTensor:
								lowerCamelCase__     ,       lowerCamelCase__		:		Optional[Any]		     =torch.sort(lowerCamelCase,  1,  descending=lowerCamelCase					)
								lowerCamelCase__		:		Optional[Any]		     =torch.exp(lowerCamelCase					)
								lowerCamelCase__		:		Optional[Any]		     =sorted_p_x_0.cumsum(dim=1					) < truncation_rate

								# Ensure that at least the largest probability is not zeroed out
								lowerCamelCase__		:		int		     =torch.full_like(keep_mask[:, 0:1, :],  lowerCamelCase					)
								lowerCamelCase__		:		Any		     =torch.cat((all_true, keep_mask),  dim=1					)
								lowerCamelCase__		:		str		     =keep_mask[:, :-1, :]

								lowerCamelCase__		:		List[str]		     =keep_mask.gather(1,  indices.argsort(1					)					)

								lowerCamelCase__		:		Optional[int]		     =log_p_x_0.clone()

								lowerCamelCase__		:		Union[str, Any]		     =-torch.inf  # -inf = log(0)

								return rv









"""simple docstring"""






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


					'''simple docstring'''





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

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



					def 		snake_case	(	self							:  int					)-> List[Any]:
								lowerCamelCase__		:		Dict		     =ids_tensor([self.batch_size, self.seq_length],  self.vocab_size					)

								lowerCamelCase__		:		Union[str, Any]		     =None
								if self.use_input_mask:
											lowerCamelCase__		:		Any		     =random_attention_mask([self.batch_size, self.seq_length]					)

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

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

								lowerCamelCase__		:		Optional[int]		     =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							:  List[Any],  lowerCamelCase							:  Optional[Any],  lowerCamelCase							:  Optional[int],  lowerCamelCase							:  int,  lowerCamelCase							:  int,  lowerCamelCase							:  str,  lowerCamelCase							:  List[str],  lowerCamelCase							:  Dict,  )-> Union[str, Any]:
								lowerCamelCase__		:		Tuple		     =TFFunnelModel(config=lowerCamelCase					)
								lowerCamelCase__		:		Dict		     ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
								lowerCamelCase__		:		Tuple		     =model(lowerCamelCase					)

								lowerCamelCase__		:		Optional[Any]		     =[input_ids, input_mask]
								lowerCamelCase__		:		List[Any]		     =model(lowerCamelCase					)

								lowerCamelCase__		:		Any		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.last_hidden_state.shape,  (self.batch_size, self.seq_length, self.d_model)					)

								lowerCamelCase__		:		int		     =False
								lowerCamelCase__		:		Any		     =TFFunnelModel(config=lowerCamelCase					)
								lowerCamelCase__		:		str		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.last_hidden_state.shape,  (self.batch_size, self.seq_length, self.d_model)					)

								lowerCamelCase__		:		Dict		     =False
								lowerCamelCase__		:		Optional[int]		     =TFFunnelModel(config=lowerCamelCase					)
								lowerCamelCase__		:		Tuple		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.last_hidden_state.shape,  (self.batch_size, self.seq_length, self.d_model)					)



					def 		snake_case	(	self							:  Tuple,  lowerCamelCase							:  List[Any],  lowerCamelCase							:  Union[str, Any],  lowerCamelCase							:  Union[str, Any],  lowerCamelCase							:  str,  lowerCamelCase							:  Optional[Any],  lowerCamelCase							:  Tuple,  lowerCamelCase							:  Dict,  )-> Optional[Any]:
								lowerCamelCase__		:		List[str]		     =TFFunnelBaseModel(config=lowerCamelCase					)
								lowerCamelCase__		:		str		     ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
								lowerCamelCase__		:		Union[str, Any]		     =model(lowerCamelCase					)

								lowerCamelCase__		:		Tuple		     =[input_ids, input_mask]
								lowerCamelCase__		:		Any		     =model(lowerCamelCase					)

								lowerCamelCase__		:		Optional[Any]		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.last_hidden_state.shape,  (self.batch_size, 2, self.d_model)					)

								lowerCamelCase__		:		List[Any]		     =False
								lowerCamelCase__		:		Dict		     =TFFunnelBaseModel(config=lowerCamelCase					)
								lowerCamelCase__		:		int		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.last_hidden_state.shape,  (self.batch_size, 3, self.d_model)					)

								lowerCamelCase__		:		Union[str, Any]		     =False
								lowerCamelCase__		:		Optional[Any]		     =TFFunnelBaseModel(config=lowerCamelCase					)
								lowerCamelCase__		:		str		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.last_hidden_state.shape,  (self.batch_size, 2, self.d_model)					)



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



					def 		snake_case	(	self							:  str,  lowerCamelCase							:  Tuple,  lowerCamelCase							:  str,  lowerCamelCase							:  List[Any],  lowerCamelCase							:  List[Any],  lowerCamelCase							:  str,  lowerCamelCase							:  Tuple,  lowerCamelCase							:  int,  )-> List[Any]:
								lowerCamelCase__		:		Union[str, Any]		     =TFFunnelForMaskedLM(config=lowerCamelCase					)
								lowerCamelCase__		:		Tuple		     ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
								lowerCamelCase__		:		List[Any]		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.logits.shape,  (self.batch_size, self.seq_length, self.vocab_size)					)



					def 		snake_case	(	self							:  Optional[int],  lowerCamelCase							:  Tuple,  lowerCamelCase							:  Any,  lowerCamelCase							:  List[str],  lowerCamelCase							:  Union[str, Any],  lowerCamelCase							:  str,  lowerCamelCase							:  Optional[int],  lowerCamelCase							:  Dict,  )-> Union[str, Any]:
								lowerCamelCase__		:		Optional[Any]		     =self.num_labels
								lowerCamelCase__		:		Tuple		     =TFFunnelForSequenceClassification(config=lowerCamelCase					)
								lowerCamelCase__		:		Tuple		     ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
								lowerCamelCase__		:		List[str]		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.logits.shape,  (self.batch_size, self.num_labels)					)



					def 		snake_case	(	self							:  Union[str, Any],  lowerCamelCase							:  str,  lowerCamelCase							:  Dict,  lowerCamelCase							:  Dict,  lowerCamelCase							:  Dict,  lowerCamelCase							:  Optional[Any],  lowerCamelCase							:  int,  lowerCamelCase							:  Tuple,  )-> int:
								lowerCamelCase__		:		int		     =self.num_choices
								lowerCamelCase__		:		List[Any]		     =TFFunnelForMultipleChoice(config=lowerCamelCase					)
								lowerCamelCase__		:		int		     =tf.tile(tf.expand_dims(lowerCamelCase,  1					),  (1, self.num_choices, 1)					)
								lowerCamelCase__		:		Union[str, Any]		     =tf.tile(tf.expand_dims(lowerCamelCase,  1					),  (1, self.num_choices, 1)					)
								lowerCamelCase__		:		Optional[Any]		     =tf.tile(tf.expand_dims(lowerCamelCase,  1					),  (1, self.num_choices, 1)					)
								lowerCamelCase__		:		Union[str, Any]		     ={
								    '''input_ids''': multiple_choice_inputs_ids,
								    '''attention_mask''': multiple_choice_input_mask,
								    '''token_type_ids''': multiple_choice_token_type_ids,
								}
								lowerCamelCase__		:		str		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.logits.shape,  (self.batch_size, self.num_choices)					)



					def 		snake_case	(	self							:  str,  lowerCamelCase							:  Dict,  lowerCamelCase							:  Optional[Any],  lowerCamelCase							:  Any,  lowerCamelCase							:  str,  lowerCamelCase							:  Union[str, Any],  lowerCamelCase							:  Union[str, Any],  lowerCamelCase							:  Dict,  )-> Optional[int]:
								lowerCamelCase__		:		Optional[Any]		     =self.num_labels
								lowerCamelCase__		:		Optional[Any]		     =TFFunnelForTokenClassification(config=lowerCamelCase					)
								lowerCamelCase__		:		Tuple		     ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
								lowerCamelCase__		:		Union[str, Any]		     =model(lowerCamelCase					)
								self.parent.assertEqual(result.logits.shape,  (self.batch_size, self.seq_length, self.num_labels)					)



					def 		snake_case	(	self							:  Optional[int],  lowerCamelCase							:  Dict,  lowerCamelCase							:  str,  lowerCamelCase							:  Union[str, Any],  lowerCamelCase							:  Union[str, Any],  lowerCamelCase							:  Union[str, Any],  lowerCamelCase							:  str,  lowerCamelCase							:  Optional[int],  )-> Tuple:
								lowerCamelCase__		:		Tuple		     =TFFunnelForQuestionAnswering(config=lowerCamelCase					)
								lowerCamelCase__		:		Union[str, Any]		     ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
								lowerCamelCase__		:		Optional[int]		     =model(lowerCamelCase					)
								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					)-> List[str]:
								lowerCamelCase__		:		List[Any]		     =self.prepare_config_and_inputs()
								(
								    (
								    lowerCamelCase__
								)     ,       (
								    lowerCamelCase__
								)     ,       (
								    lowerCamelCase__
								)     ,       (
								    lowerCamelCase__
								)     ,       (
								    lowerCamelCase__
								)     ,       (
								    lowerCamelCase__
								)     ,       (
								    lowerCamelCase__
								)     ,       
								)		:		Tuple		     =config_and_inputs
								lowerCamelCase__		:		str		     ={'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
								return config, inputs_dict





@require_tf
class 	__SCREAMING_SNAKE_CASE     (				lowerCAmelCase_		,       lowerCAmelCase_		,       unittest.TestCase       ):


					'''simple docstring'''





					_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							:  str					)-> Tuple:
								lowerCamelCase__		:		Any		     =TFFunnelModelTester(self					)
								lowerCamelCase__		:		Any		     =ConfigTester(self,  config_class=lowerCamelCase					)



					def 		snake_case	(	self							:  List[str]					)-> Tuple:
								self.config_tester.run_common_tests()



					def 		snake_case	(	self							:  str					)-> List[Any]:
								lowerCamelCase__		:		Optional[Any]		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*lowerCamelCase					)



					def 		snake_case	(	self							:  str					)-> Dict:
								lowerCamelCase__		:		int		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_pretraining(*lowerCamelCase					)



					def 		snake_case	(	self							:  int					)-> List[Any]:
								lowerCamelCase__		:		Tuple		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_lm(*lowerCamelCase					)



					def 		snake_case	(	self							:  Dict					)-> Any:
								lowerCamelCase__		:		str		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_token_classification(*lowerCamelCase					)




					def 		snake_case	(	self							:  Tuple					)-> Optional[Any]:
								lowerCamelCase__		:		Optional[Any]		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_question_answering(*lowerCamelCase					)





@require_tf
class 	__SCREAMING_SNAKE_CASE     (				lowerCAmelCase_		,       unittest.TestCase       ):


					'''simple docstring'''





					_a             =							(
					    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
					)
					_a             =							False
					_a             =							False



					def 		snake_case	(	self							:  int					)-> Tuple:
								lowerCamelCase__		:		Union[str, Any]		     =TFFunnelModelTester(self,  base=lowerCamelCase					)
								lowerCamelCase__		:		Tuple		     =ConfigTester(self,  config_class=lowerCamelCase					)



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



					def 		snake_case	(	self							:  Optional[Any]					)-> Optional[Any]:
								lowerCamelCase__		:		Any		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_base_model(*lowerCamelCase					)



					def 		snake_case	(	self							:  Union[str, Any]					)-> int:
								lowerCamelCase__		:		Tuple		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase					)




					def 		snake_case	(	self							:  List[str]					)-> Optional[int]:
								lowerCamelCase__		:		List[Any]		     =self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_multiple_choice(*lowerCamelCase					)




