





"""simple docstring"""


from __future__ import annotations

import unittest

from transformers import DebertaConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

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


if is_tf_available():
   import tensorflow as tf

   from transformers import (
       TFDebertaForMaskedLM,
       TFDebertaForQuestionAnswering,
       TFDebertaForSequenceClassification,
       TFDebertaForTokenClassification,
       TFDebertaModel,
   )



class        lowercase_			:

       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=32				,   __SCREAMING_SNAKE_CASE=2				,   __SCREAMING_SNAKE_CASE=4				,   __SCREAMING_SNAKE_CASE=37				,   __SCREAMING_SNAKE_CASE="gelu"				,   __SCREAMING_SNAKE_CASE=0.1				,   __SCREAMING_SNAKE_CASE=0.1				,   __SCREAMING_SNAKE_CASE=512				,   __SCREAMING_SNAKE_CASE=16				,   __SCREAMING_SNAKE_CASE=2				,   __SCREAMING_SNAKE_CASE=0.02				,   __SCREAMING_SNAKE_CASE=3				,   __SCREAMING_SNAKE_CASE=4				,   __SCREAMING_SNAKE_CASE=None				,   ):






        '''simple docstring'''

        snake_case__      							=			parent
        snake_case__      							=			13
        snake_case__      							=			7
        snake_case__      							=			True
        snake_case__      							=			True
        snake_case__      							=			True
        snake_case__      							=			True
        snake_case__      							=			99
        snake_case__      							=			32
        snake_case__      							=			2
        snake_case__      							=			4
        snake_case__      							=			37
        snake_case__      							=			"gelu"
        snake_case__      							=			0.1
        snake_case__      							=			0.1
        snake_case__      							=			512
        snake_case__      							=			16
        snake_case__      							=			False
        snake_case__      							=			-1
        snake_case__      							=			True
        snake_case__      							=			2
        snake_case__      							=			0.02
        snake_case__      							=			3
        snake_case__      							=			4
        snake_case__      							=			None

       def 						_SCREAMING_SNAKE_CASE(     self       ):






        '''simple docstring'''

        snake_case__      							=			ids_tensor([self.batch_size, self.seq_length]				,   self.vocab_size       )

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

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

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

        snake_case__      							=			DebertaConfig(
            vocab_size=self.vocab_size				,   hidden_size=self.hidden_size				,   num_hidden_layers=self.num_hidden_layers				,   num_attention_heads=self.num_attention_heads				,   intermediate_size=self.intermediate_size				,   hidden_act=self.hidden_act				,   hidden_dropout_prob=self.hidden_dropout_prob				,   attention_probs_dropout_prob=self.attention_probs_dropout_prob				,   max_position_embeddings=self.max_position_embeddings				,   type_vocab_size=self.type_vocab_size				,   relative_attention=self.relative_attention				,   max_relative_positions=self.max_relative_positions				,   position_biased_input=self.position_biased_input				,   initializer_range=self.initializer_range				,   return_dict=__SCREAMING_SNAKE_CASE				,   )

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

       def 						_SCREAMING_SNAKE_CASE(     self				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE       ):






        '''simple docstring'''

        snake_case__      							=			TFDebertaModel(config=__SCREAMING_SNAKE_CASE       )
        snake_case__      							=			{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

        snake_case__      							=			[input_ids, input_mask]
        snake_case__      							=			model(__SCREAMING_SNAKE_CASE       )

        snake_case__      							=			model(__SCREAMING_SNAKE_CASE       )

        self.parent.assertEqual(result.last_hidden_state.shape				,   (self.batch_size, self.seq_length, self.hidden_size)       )

       def 						_SCREAMING_SNAKE_CASE(     self				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE       ):






        '''simple docstring'''

        snake_case__      							=			TFDebertaForMaskedLM(config=__SCREAMING_SNAKE_CASE       )
        snake_case__      							=			{
            "input_ids": input_ids,
            "attention_mask": input_mask,
            "token_type_ids": token_type_ids,
        }
        snake_case__      							=			model(__SCREAMING_SNAKE_CASE       )
        self.parent.assertEqual(result.logits.shape				,   (self.batch_size, self.seq_length, self.vocab_size)       )

       def 						_SCREAMING_SNAKE_CASE(     self				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE       ):






        '''simple docstring'''

        snake_case__      							=			self.num_labels
        snake_case__      							=			TFDebertaForSequenceClassification(config=__SCREAMING_SNAKE_CASE       )
        snake_case__      							=			{
            "input_ids": input_ids,
            "attention_mask": input_mask,
            "token_type_ids": token_type_ids,
        }

        snake_case__      							=			model(__SCREAMING_SNAKE_CASE       )
        self.parent.assertEqual(result.logits.shape				,   (self.batch_size, self.num_labels)       )

       def 						_SCREAMING_SNAKE_CASE(     self				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE       ):






        '''simple docstring'''

        snake_case__      							=			self.num_labels
        snake_case__      							=			TFDebertaForTokenClassification(config=__SCREAMING_SNAKE_CASE       )
        snake_case__      							=			{
            "input_ids": input_ids,
            "attention_mask": input_mask,
            "token_type_ids": token_type_ids,
        }
        snake_case__      							=			model(__SCREAMING_SNAKE_CASE       )
        self.parent.assertEqual(result.logits.shape				,   (self.batch_size, self.seq_length, self.num_labels)       )

       def 						_SCREAMING_SNAKE_CASE(     self				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE				,   __SCREAMING_SNAKE_CASE       ):






        '''simple docstring'''

        snake_case__      							=			TFDebertaForQuestionAnswering(config=__SCREAMING_SNAKE_CASE       )
        snake_case__      							=			{
            "input_ids": input_ids,
            "attention_mask": input_mask,
            "token_type_ids": token_type_ids,
        }

        snake_case__      							=			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 						_SCREAMING_SNAKE_CASE(     self       ):






        '''simple docstring'''

        snake_case__      							=			self.prepare_config_and_inputs()
        (
            (
            snake_case__				
        )							,				(
            snake_case__				
        )							,				(
            snake_case__				
        )							,				(
            snake_case__				
        )							,				(
            snake_case__				
        )							,				(
            snake_case__				
        )							,				(
            snake_case__				
        )							,								
        )      							=			config_and_inputs
        snake_case__      							=			{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
        return config, inputs_dict



@require_tf
class        lowercase_			(       __lowerCAmelCase			,__lowerCAmelCase			,unittest.TestCase							):
       snake_case__			:							List[str]										=       (
           (
               TFDebertaModel,
               TFDebertaForMaskedLM,
               TFDebertaForQuestionAnswering,
               TFDebertaForSequenceClassification,
               TFDebertaForTokenClassification,
           )
           if is_tf_available()
           else ()
       )
       snake_case__			:							Any										=       (
           {
               """feature-extraction""": TFDebertaModel,
               """fill-mask""": TFDebertaForMaskedLM,
               """question-answering""": TFDebertaForQuestionAnswering,
               """text-classification""": TFDebertaForSequenceClassification,
               """token-classification""": TFDebertaForTokenClassification,
               """zero-shot""": TFDebertaForSequenceClassification,
           }
           if is_tf_available()
           else {}
       )

       snake_case__			:							str										=       False
       snake_case__			:							str										=       False

       def 						_SCREAMING_SNAKE_CASE(     self       ):






        '''simple docstring'''

        snake_case__      							=			TFDebertaModelTester(self       )
        snake_case__      							=			ConfigTester(self				,   config_class=__SCREAMING_SNAKE_CASE				,   hidden_size=37       )

       def 						_SCREAMING_SNAKE_CASE(     self       ):






        '''simple docstring'''

        self.config_tester.run_common_tests()

       def 						_SCREAMING_SNAKE_CASE(     self       ):






        '''simple docstring'''

        snake_case__      							=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*__SCREAMING_SNAKE_CASE       )

       def 						_SCREAMING_SNAKE_CASE(     self       ):






        '''simple docstring'''

        snake_case__      							=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*__SCREAMING_SNAKE_CASE       )

       def 						_SCREAMING_SNAKE_CASE(     self       ):






        '''simple docstring'''

        snake_case__      							=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*__SCREAMING_SNAKE_CASE       )

       def 						_SCREAMING_SNAKE_CASE(     self       ):






        '''simple docstring'''

        snake_case__      							=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*__SCREAMING_SNAKE_CASE       )

       def 						_SCREAMING_SNAKE_CASE(     self       ):






        '''simple docstring'''

        snake_case__      							=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*__SCREAMING_SNAKE_CASE       )

       @slow
       def 						_SCREAMING_SNAKE_CASE(     self       ):






        '''simple docstring'''

        snake_case__      							=			TFDebertaModel.from_pretrained("kamalkraj/deberta-base"       )
        self.assertIsNotNone(__SCREAMING_SNAKE_CASE       )



@require_tf
class        lowercase_			(       unittest.TestCase							):

       @unittest.skip(reason="Model not available yet"       )
       def 						_SCREAMING_SNAKE_CASE(     self       ):






        '''simple docstring'''

        pass

       @slow
       def 						_SCREAMING_SNAKE_CASE(     self       ):






        '''simple docstring'''

        snake_case__      							=			TFDebertaModel.from_pretrained("kamalkraj/deberta-base"       )
        snake_case__      							=			tf.constant([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]       )
        snake_case__      							=			tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]       )
        snake_case__      							=			model(__SCREAMING_SNAKE_CASE				,   attention_mask=__SCREAMING_SNAKE_CASE       )[0]

        snake_case__      							=			tf.constant(
            [
                [
                    [-0.59855896, -0.80552566, -0.8462135],
                    [1.4484025, -0.93483794, -0.80593085],
                    [0.3122741, 0.00316059, -1.4131377],
                ]
            ]       )
        tf.debugging.assert_near(output[:, 1:4, 1:4]				,   __SCREAMING_SNAKE_CASE				,   atol=1e-4       )








"""simple docstring"""


import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging


a__   :       Optional[Any]   						=			logging.get_logger(__name__)

a__   :       List[str]   						=			{}



class        lowercase_			(       __lowerCAmelCase							):
       snake_case__			:							List[str]										=       """fsmt_decoder"""

       def __init__(     self				,   __SCREAMING_SNAKE_CASE=0				,   __SCREAMING_SNAKE_CASE=0       ):






        '''simple docstring'''

        super().__init__()
        snake_case__      							=			vocab_size
        snake_case__      							=			bos_token_id



class        lowercase_			(       __lowerCAmelCase							):
       snake_case__			:							str										=       """fsmt"""
       snake_case__			:							List[Any]										=       {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}

       def __init__(     self				,   __SCREAMING_SNAKE_CASE=["en", "de"]				,   __SCREAMING_SNAKE_CASE=4_2024				,   __SCREAMING_SNAKE_CASE=4_2024				,   __SCREAMING_SNAKE_CASE="relu"				,   __SCREAMING_SNAKE_CASE=1024				,   __SCREAMING_SNAKE_CASE=200				,   __SCREAMING_SNAKE_CASE=1024				,   __SCREAMING_SNAKE_CASE=4096				,   __SCREAMING_SNAKE_CASE=12				,   __SCREAMING_SNAKE_CASE=16				,   __SCREAMING_SNAKE_CASE=0.0				,   __SCREAMING_SNAKE_CASE=4096				,   __SCREAMING_SNAKE_CASE=12				,   __SCREAMING_SNAKE_CASE=16				,   __SCREAMING_SNAKE_CASE=0.0				,   __SCREAMING_SNAKE_CASE=0.0				,   __SCREAMING_SNAKE_CASE=0.1				,   __SCREAMING_SNAKE_CASE=0.0				,   __SCREAMING_SNAKE_CASE=0.02				,   __SCREAMING_SNAKE_CASE=2				,   __SCREAMING_SNAKE_CASE=True				,   __SCREAMING_SNAKE_CASE=True				,   __SCREAMING_SNAKE_CASE=False				,   __SCREAMING_SNAKE_CASE=5				,   __SCREAMING_SNAKE_CASE=1.0				,   __SCREAMING_SNAKE_CASE=False				,   __SCREAMING_SNAKE_CASE=True				,   __SCREAMING_SNAKE_CASE=1				,   __SCREAMING_SNAKE_CASE=0				,   __SCREAMING_SNAKE_CASE=2				,   __SCREAMING_SNAKE_CASE=2				,   **__SCREAMING_SNAKE_CASE				,   ):






        '''simple docstring'''

        snake_case__      							=			langs
        snake_case__      							=			src_vocab_size
        snake_case__      							=			tgt_vocab_size
        snake_case__      							=			d_model  # encoder_embed_dim and decoder_embed_dim

        snake_case__      							=			encoder_ffn_dim
        snake_case__      							=			snake_case__      							=			encoder_layers
        snake_case__      							=			encoder_attention_heads
        snake_case__      							=			encoder_layerdrop
        snake_case__      							=			decoder_layerdrop
        snake_case__      							=			decoder_ffn_dim
        snake_case__      							=			decoder_layers
        snake_case__      							=			decoder_attention_heads
        snake_case__      							=			max_position_embeddings
        snake_case__      							=			init_std  # Normal(0, this parameter)
        snake_case__      							=			activation_function

        snake_case__      							=			DecoderConfig(vocab_size=__SCREAMING_SNAKE_CASE				,   bos_token_id=__SCREAMING_SNAKE_CASE       )
        if "decoder" in common_kwargs:
         del common_kwargs["decoder"]

        snake_case__      							=			scale_embedding  # scale factor will be sqrt(d_model) if True

        # 3 Types of Dropout
        snake_case__      							=			attention_dropout
        snake_case__      							=			activation_dropout
        snake_case__      							=			dropout

        snake_case__      							=			use_cache
        super().__init__(
            pad_token_id=__SCREAMING_SNAKE_CASE				,   bos_token_id=__SCREAMING_SNAKE_CASE				,   eos_token_id=__SCREAMING_SNAKE_CASE				,   decoder_start_token_id=__SCREAMING_SNAKE_CASE				,   is_encoder_decoder=__SCREAMING_SNAKE_CASE				,   tie_word_embeddings=__SCREAMING_SNAKE_CASE				,   forced_eos_token_id=__SCREAMING_SNAKE_CASE				,   max_length=__SCREAMING_SNAKE_CASE				,   num_beams=__SCREAMING_SNAKE_CASE				,   length_penalty=__SCREAMING_SNAKE_CASE				,   early_stopping=__SCREAMING_SNAKE_CASE				,   **__SCREAMING_SNAKE_CASE				,   )

       def 						_SCREAMING_SNAKE_CASE(     self       ):






        '''simple docstring'''

        snake_case__      							=			copy.deepcopy(self.__dict__       )
        snake_case__      							=			self.decoder.to_dict()
        snake_case__      							=			self.__class__.model_type
        return output

