



from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


a_			=					logging.get_logger(__name__)

a_			=					{
    """Helsinki-NLP/opus-mt-en-de""": """https://huggingface.co/Helsinki-NLP/opus-mt-en-de/resolve/main/config.json""",
    # See all Marian models at https://huggingface.co/models?filter=marian
}



class  __lowerCAmelCase     (	lowerCAmelCase__   ):
 lowerCAmelCase__       					=  """marian"""
 lowerCAmelCase__       					=  ["""past_key_values"""]
 lowerCAmelCase__       					=  {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}




 def __init__(						self	,				__UpperCAmelCase=58101	,				__UpperCAmelCase=None	,				__UpperCAmelCase=1024	,				__UpperCAmelCase=12	,				__UpperCAmelCase=4096	,				__UpperCAmelCase=16	,				__UpperCAmelCase=12	,				__UpperCAmelCase=4096	,				__UpperCAmelCase=16	,				__UpperCAmelCase=0.0	,				__UpperCAmelCase=0.0	,				__UpperCAmelCase=True	,				__UpperCAmelCase=True	,				__UpperCAmelCase="gelu"	,				__UpperCAmelCase=1024	,				__UpperCAmelCase=0.1	,				__UpperCAmelCase=0.0	,				__UpperCAmelCase=0.0	,				__UpperCAmelCase=0.02	,				__UpperCAmelCase=58100	,				__UpperCAmelCase=False	,				__UpperCAmelCase=58100	,				__UpperCAmelCase=0	,				__UpperCAmelCase=0	,				__UpperCAmelCase=True	,				**__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    vocab_size
    __lowerCamelCase													=    decoder_vocab_size or vocab_size
    __lowerCamelCase													=    max_position_embeddings
    __lowerCamelCase													=    d_model
    __lowerCamelCase													=    encoder_ffn_dim
    __lowerCamelCase													=    encoder_layers
    __lowerCamelCase													=    encoder_attention_heads
    __lowerCamelCase													=    decoder_ffn_dim
    __lowerCamelCase													=    decoder_layers
    __lowerCamelCase													=    decoder_attention_heads
    __lowerCamelCase													=    dropout
    __lowerCamelCase													=    attention_dropout
    __lowerCamelCase													=    activation_dropout
    __lowerCamelCase													=    activation_function
    __lowerCamelCase													=    init_std
    __lowerCamelCase													=    encoder_layerdrop
    __lowerCamelCase													=    decoder_layerdrop
    __lowerCamelCase													=    use_cache
    __lowerCamelCase													=    encoder_layers
    __lowerCamelCase													=    scale_embedding  # scale factor will be sqrt(d_model) if True
    __lowerCamelCase													=    share_encoder_decoder_embeddings
    super().__init__(
        pad_token_id=__UpperCAmelCase	,				eos_token_id=__UpperCAmelCase	,				is_encoder_decoder=__UpperCAmelCase	,				decoder_start_token_id=__UpperCAmelCase	,				forced_eos_token_id=__UpperCAmelCase	,				**__UpperCAmelCase	,				)



class  __lowerCAmelCase     (	lowerCAmelCase__   ):




 @property
 # Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.inputs
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    if self.task in ["default", "seq2seq-lm"]:
       __lowerCamelCase													=    OrderedDict(
           [
               ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
               ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
           ]				)

       if self.use_past:
          __lowerCamelCase													=    {0: '''batch'''}
          __lowerCamelCase													=    {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
       else:
          __lowerCamelCase													=    {0: '''batch''', 1: '''decoder_sequence'''}
          __lowerCamelCase													=    {0: '''batch''', 1: '''decoder_sequence'''}

       if self.use_past:
          self.fill_with_past_key_values_(__UpperCAmelCase	,				direction='''inputs'''				)
    elif self.task == "causal-lm":
       # TODO: figure this case out.
       __lowerCamelCase													=    OrderedDict(
           [
               ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
               ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
           ]				)
       if self.use_past:
          __lowerCamelCase							,__lowerCamelCase													=    self.num_layers
          for i in range(__UpperCAmelCase				):
             __lowerCamelCase													=    {0: '''batch''', 2: '''past_sequence + sequence'''}
             __lowerCamelCase													=    {0: '''batch''', 2: '''past_sequence + sequence'''}
    else:
       __lowerCamelCase													=    OrderedDict(
           [
               ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
               ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
               ('''decoder_input_ids''', {0: '''batch''', 1: '''decoder_sequence'''}),
               ('''decoder_attention_mask''', {0: '''batch''', 1: '''decoder_sequence'''}),
           ]				)

    return common_inputs




 @property
 # Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    if self.task in ["default", "seq2seq-lm"]:
       __lowerCamelCase													=    super().outputs
    else:
       __lowerCamelCase													=    super(__UpperCAmelCase	,				self				).outputs
       if self.use_past:
          __lowerCamelCase							,__lowerCamelCase													=    self.num_layers
          for i in range(__UpperCAmelCase				):
             __lowerCamelCase													=    {0: '''batch''', 2: '''past_sequence + sequence'''}
             __lowerCamelCase													=    {0: '''batch''', 2: '''past_sequence + sequence'''}
    return common_outputs




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase = -1	,				__UpperCAmelCase = -1	,				__UpperCAmelCase = False	,				__UpperCAmelCase = None	,				):



    '''simple docstring'''
    __lowerCamelCase													=    self._generate_dummy_inputs_for_encoder_and_decoder(
        __UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase				)

    # Generate decoder inputs
    __lowerCamelCase													=    seq_length if not self.use_past else 1
    __lowerCamelCase													=    self._generate_dummy_inputs_for_encoder_and_decoder(
        __UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase				)
    __lowerCamelCase													=    {F"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
    __lowerCamelCase													=    dict(**__UpperCAmelCase	,				**__UpperCAmelCase				)

    if self.use_past:
       if not is_torch_available():
          raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''				)
       else:
          import torch
       __lowerCamelCase							,__lowerCamelCase													=    common_inputs['''input_ids'''].shape
       __lowerCamelCase													=    common_inputs['''decoder_input_ids'''].shape[1]
       __lowerCamelCase							,__lowerCamelCase													=    self.num_attention_heads
       __lowerCamelCase													=    (
           batch,
           num_encoder_attention_heads,
           encoder_seq_length,
           self._config.hidden_size // num_encoder_attention_heads,
       )
       __lowerCamelCase													=    decoder_seq_length + 3
       __lowerCamelCase													=    (
           batch,
           num_decoder_attention_heads,
           decoder_past_length,
           self._config.hidden_size // num_decoder_attention_heads,
       )

       __lowerCamelCase													=    torch.cat(
           [common_inputs['''decoder_attention_mask'''], torch.ones(__UpperCAmelCase	,				__UpperCAmelCase				)]	,				dim=1				)

       __lowerCamelCase													=    []
       # If the number of encoder and decoder layers are present in the model configuration, both are considered
       __lowerCamelCase							,__lowerCamelCase													=    self.num_layers
       __lowerCamelCase													=    min(__UpperCAmelCase	,				__UpperCAmelCase				)
       __lowerCamelCase													=    max(__UpperCAmelCase	,				__UpperCAmelCase				) - min_num_layers
       __lowerCamelCase													=    '''encoder''' if num_encoder_layers > num_decoder_layers else '''decoder'''

       for _ in range(__UpperCAmelCase				):
          common_inputs["past_key_values"].append(
              (
                  torch.zeros(__UpperCAmelCase				),
                  torch.zeros(__UpperCAmelCase				),
                  torch.zeros(__UpperCAmelCase				),
                  torch.zeros(__UpperCAmelCase				),
              )				)
       # TODO: test this.
       __lowerCamelCase													=    encoder_shape if remaining_side_name == '''encoder''' else decoder_shape
       for _ in range(__UpperCAmelCase	,				__UpperCAmelCase				):
          common_inputs["past_key_values"].append((torch.zeros(__UpperCAmelCase				), torch.zeros(__UpperCAmelCase				))				)
    return common_inputs




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase = -1	,				__UpperCAmelCase = -1	,				__UpperCAmelCase = False	,				__UpperCAmelCase = None	,				):



    '''simple docstring'''
    __lowerCamelCase													=    self._generate_dummy_inputs_for_encoder_and_decoder(
        __UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase				)

    if self.use_past:
       if not is_torch_available():
          raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''				)
       else:
          import torch
       __lowerCamelCase							,__lowerCamelCase													=    common_inputs['''input_ids'''].shape
       # Not using the same length for past_key_values
       __lowerCamelCase													=    seqlen + 2
       __lowerCamelCase							,__lowerCamelCase													=    self.num_layers
       __lowerCamelCase							,__lowerCamelCase													=    self.num_attention_heads
       __lowerCamelCase													=    (
           batch,
           num_encoder_attention_heads,
           past_key_values_length,
           self._config.hidden_size // num_encoder_attention_heads,
       )

       __lowerCamelCase													=    common_inputs['''attention_mask'''].dtype
       __lowerCamelCase													=    torch.cat(
           [common_inputs['''attention_mask'''], torch.ones(__UpperCAmelCase	,				__UpperCAmelCase	,				dtype=__UpperCAmelCase				)]	,				dim=1				)
       __lowerCamelCase													=    [
           (torch.zeros(__UpperCAmelCase				), torch.zeros(__UpperCAmelCase				)) for _ in range(__UpperCAmelCase				)
       ]
    return common_inputs




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase = -1	,				__UpperCAmelCase = -1	,				__UpperCAmelCase = False	,				__UpperCAmelCase = None	,				):



    '''simple docstring'''
    __lowerCamelCase													=    compute_effective_axis_dimension(
        __UpperCAmelCase	,				fixed_dimension=OnnxConfig.default_fixed_batch	,				num_token_to_add=0				)

    # If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
    __lowerCamelCase													=    tokenizer.num_special_tokens_to_add(__UpperCAmelCase				)
    __lowerCamelCase													=    compute_effective_axis_dimension(
        __UpperCAmelCase	,				fixed_dimension=OnnxConfig.default_fixed_sequence	,				num_token_to_add=__UpperCAmelCase				)

    # Generate dummy inputs according to compute batch and sequence
    __lowerCamelCase													=    [''' '''.join([tokenizer.unk_token]				) * seq_length] * batch_size
    __lowerCamelCase													=    dict(tokenizer(__UpperCAmelCase	,				return_tensors=__UpperCAmelCase				)				)
    return common_inputs




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				__UpperCAmelCase = -1	,				__UpperCAmelCase = -1	,				__UpperCAmelCase = False	,				__UpperCAmelCase = None	,				):



    '''simple docstring'''
    if self.task in ["default", "seq2seq-lm"]:
       __lowerCamelCase													=    self._generate_dummy_inputs_for_default_and_seqaseq_lm(
           __UpperCAmelCase	,				batch_size=__UpperCAmelCase	,				seq_length=__UpperCAmelCase	,				is_pair=__UpperCAmelCase	,				framework=__UpperCAmelCase				)

    else:
       __lowerCamelCase													=    self._generate_dummy_inputs_for_causal_lm(
           __UpperCAmelCase	,				batch_size=__UpperCAmelCase	,				seq_length=__UpperCAmelCase	,				is_pair=__UpperCAmelCase	,				framework=__UpperCAmelCase				)

    return common_inputs




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



    '''simple docstring'''
    if self.task in ["default", "seq2seq-lm"]:
       __lowerCamelCase													=    super()._flatten_past_key_values_(__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase				)
    else:
       __lowerCamelCase													=    super(__UpperCAmelCase	,				self				)._flatten_past_key_values_(
           __UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase				)




 @property
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    return 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				)






