


"""simple docstring"""
from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, 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 (
							    TFDebertaVaForMaskedLM,
							    TFDebertaVaForQuestionAnswering,
							    TFDebertaVaForSequenceClassification,
							    TFDebertaVaForTokenClassification,
							    TFDebertaVaModel,
							)





class        __A       :





							'''simple docstring'''

							def __init__(			self							: Any						,    UpperCAmelCase_							: Tuple						,    UpperCAmelCase_							: Any=13						,    UpperCAmelCase_							: List[Any]=7						,    UpperCAmelCase_							: Union[str, Any]=True						,    UpperCAmelCase_							: List[str]=True						,    UpperCAmelCase_							: Any=True						,    UpperCAmelCase_							: Optional[Any]=True						,    UpperCAmelCase_							: Optional[int]=99						,    UpperCAmelCase_							: str=32						,    UpperCAmelCase_							: Dict=2						,    UpperCAmelCase_							: Optional[Any]=4						,    UpperCAmelCase_							: List[str]=37						,    UpperCAmelCase_							: Optional[int]="gelu"						,    UpperCAmelCase_							: Any=0.1						,    UpperCAmelCase_							: Any=0.1						,    UpperCAmelCase_							: Dict=512						,    UpperCAmelCase_							: List[str]=16						,    UpperCAmelCase_							: Any=2						,    UpperCAmelCase_							: int=0.02						,    UpperCAmelCase_							: str=False						,    UpperCAmelCase_							: Any=True						,    UpperCAmelCase_							: List[str]="None"						,    UpperCAmelCase_							: Optional[int]=3						,    UpperCAmelCase_							: List[str]=4						,    UpperCAmelCase_							: Any=None						,    )   ->List[str]:



														"""simple docstring"""



														snake_case_          =						parent
														snake_case_          =						batch_size
														snake_case_          =						seq_length
														snake_case_          =						is_training
														snake_case_          =						use_input_mask
														snake_case_          =						use_token_type_ids
														snake_case_          =						use_labels
														snake_case_          =						vocab_size
														snake_case_          =						hidden_size
														snake_case_          =						num_hidden_layers
														snake_case_          =						num_attention_heads
														snake_case_          =						intermediate_size
														snake_case_          =						hidden_act
														snake_case_          =						hidden_dropout_prob
														snake_case_          =						attention_probs_dropout_prob
														snake_case_          =						max_position_embeddings
														snake_case_          =						type_vocab_size
														snake_case_          =						type_sequence_label_size
														snake_case_          =						initializer_range
														snake_case_          =						num_labels
														snake_case_          =						num_choices
														snake_case_          =						relative_attention
														snake_case_          =						position_biased_input
														snake_case_          =						pos_att_type
														snake_case_          =						scope



							def 						lowerCAmelCase    (			self							: str    )   ->List[str]:



														"""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_          =						DebertaVaConfig(
														    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						,    position_biased_input=self.position_biased_input						,    initializer_range=self.initializer_range						,    return_dict=UpperCAmelCase_						,    )

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



							def 						lowerCAmelCase    (			self							: List[Any]						,    UpperCAmelCase_							: str						,    UpperCAmelCase_							: str						,    UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: List[str]						,    UpperCAmelCase_							: List[str]						,    UpperCAmelCase_							: int						,    UpperCAmelCase_							: Any    )   ->int:



														"""simple docstring"""



														snake_case_          =						TFDebertaVaModel(config=UpperCAmelCase_    )
														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(UpperCAmelCase_    )

														snake_case_          =						model(UpperCAmelCase_    )

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



							def 						lowerCAmelCase    (			self							: Any						,    UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: List[str]						,    UpperCAmelCase_							: Any						,    UpperCAmelCase_							: Any						,    UpperCAmelCase_							: List[Any]						,    UpperCAmelCase_							: Any						,    UpperCAmelCase_							: Union[str, Any]    )   ->Dict:



														"""simple docstring"""



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



							def 						lowerCAmelCase    (			self							: int						,    UpperCAmelCase_							: str						,    UpperCAmelCase_							: List[str]						,    UpperCAmelCase_							: int						,    UpperCAmelCase_							: Optional[int]						,    UpperCAmelCase_							: int						,    UpperCAmelCase_							: Optional[Any]						,    UpperCAmelCase_							: Tuple    )   ->Dict:



														"""simple docstring"""



														snake_case_          =						self.num_labels
														snake_case_          =						TFDebertaVaForSequenceClassification(config=UpperCAmelCase_    )
														snake_case_          =						{
														    """input_ids""": input_ids,
														    """attention_mask""": input_mask,
														    """token_type_ids""": token_type_ids,
														}

														snake_case_          =						model(UpperCAmelCase_    )
														self.parent.assertEqual(result.logits.shape						,    (self.batch_size, self.num_labels)    )



							def 						lowerCAmelCase    (			self							: List[Any]						,    UpperCAmelCase_							: str						,    UpperCAmelCase_							: Any						,    UpperCAmelCase_							: List[Any]						,    UpperCAmelCase_							: Tuple						,    UpperCAmelCase_							: List[Any]						,    UpperCAmelCase_							: Tuple						,    UpperCAmelCase_							: Any    )   ->str:



														"""simple docstring"""



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



							def 						lowerCAmelCase    (			self							: Union[str, Any]						,    UpperCAmelCase_							: List[Any]						,    UpperCAmelCase_							: Any						,    UpperCAmelCase_							: Tuple						,    UpperCAmelCase_							: Tuple						,    UpperCAmelCase_							: List[str]						,    UpperCAmelCase_							: int						,    UpperCAmelCase_							: List[Any]    )   ->Any:



														"""simple docstring"""



														snake_case_          =						TFDebertaVaForQuestionAnswering(config=UpperCAmelCase_    )
														snake_case_          =						{
														    """input_ids""": input_ids,
														    """attention_mask""": input_mask,
														    """token_type_ids""": token_type_ids,
														}

														snake_case_          =						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							: Any    )   ->int:



														"""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        __A       (snake_case__  ,						snake_case__  ,						unittest.TestCase):





							'''simple docstring'''

							__lowercase:						List[Any]							 =      (
							    (
							        TFDebertaVaModel,
							        TFDebertaVaForMaskedLM,
							        TFDebertaVaForQuestionAnswering,
							        TFDebertaVaForSequenceClassification,
							        TFDebertaVaForTokenClassification,
							    )
							    if is_tf_available()
							    else ()
							)
							__lowercase:						Tuple							 =      (
							    {
							        """feature-extraction""": TFDebertaVaModel,
							        """fill-mask""": TFDebertaVaForMaskedLM,
							        """question-answering""": TFDebertaVaForQuestionAnswering,
							        """text-classification""": TFDebertaVaForSequenceClassification,
							        """token-classification""": TFDebertaVaForTokenClassification,
							        """zero-shot""": TFDebertaVaForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)

							__lowercase:						Tuple							 =      False
							__lowercase:						Optional[Any]							 =      False



							def 						lowerCAmelCase    (			self							: List[Any]    )   ->List[Any]:



														"""simple docstring"""



														snake_case_          =						TFDebertaVaModelTester(self    )
														snake_case_          =						ConfigTester(self						,    config_class=UpperCAmelCase_						,    hidden_size=37    )



							def 						lowerCAmelCase    (			self							: List[str]    )   ->List[Any]:



														"""simple docstring"""



														self.config_tester.run_common_tests()



							def 						lowerCAmelCase    (			self							: Any    )   ->List[str]:



														"""simple docstring"""



														snake_case_          =						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*UpperCAmelCase_    )



							def 						lowerCAmelCase    (			self							: List[Any]    )   ->str:



														"""simple docstring"""



														snake_case_          =						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase_    )



							def 						lowerCAmelCase    (			self							: int    )   ->List[Any]:



														"""simple docstring"""



														snake_case_          =						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase_    )



							def 						lowerCAmelCase    (			self							: Any    )   ->Optional[int]:



														"""simple docstring"""



														snake_case_          =						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase_    )



							def 						lowerCAmelCase    (			self							: Tuple    )   ->List[str]:



														"""simple docstring"""



														snake_case_          =						self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase_    )



							@slow
							def 						lowerCAmelCase    (			self							: Dict    )   ->Any:



														"""simple docstring"""



														snake_case_          =						TFDebertaVaModel.from_pretrained("""kamalkraj/deberta-v2-xlarge"""    )
														self.assertIsNotNone(UpperCAmelCase_    )





@require_tf
class        __A       (unittest.TestCase):





							'''simple docstring'''

							@unittest.skip(reason="""Model not available yet"""    )
							def 						lowerCAmelCase    (			self							: List[str]    )   ->List[str]:



														"""simple docstring"""



														pass



							@slow
							def 						lowerCAmelCase    (			self							: Optional[Any]    )   ->str:



														"""simple docstring"""



														snake_case_          =						TFDebertaVaModel.from_pretrained("""kamalkraj/deberta-v2-xlarge"""    )
														snake_case_          =						tf.constant([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]    )
														snake_case_          =						tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]    )
														snake_case_          =						model(UpperCAmelCase_						,    attention_mask=UpperCAmelCase_    )[0]

														snake_case_          =						tf.constant(
														    [[[0.2_356, 0.1_948, 0.0_369], [-0.1_063, 0.3_586, -0.5_152], [-0.6_399, -0.0_259, -0.2_525]]]    )
														tf.debugging.assert_near(output[:, 1:4, 1:4]						,    UpperCAmelCase_						,    atol=1E-4    )







"""simple docstring"""
import shutil
import tempfile
import unittest

from transformers import ClapFeatureExtractor, ClapProcessor, RobertaTokenizer, RobertaTokenizerFast
from transformers.testing_utils import require_sentencepiece, require_torchaudio

from .test_feature_extraction_clap import floats_list





@require_torchaudio
@require_sentencepiece
class        __A       (unittest.TestCase):





							'''simple docstring'''

							def 						lowerCAmelCase    (			self							: Dict    )   ->List[Any]:



														"""simple docstring"""



														snake_case_          =						"""laion/clap-htsat-unfused"""
														snake_case_          =						tempfile.mkdtemp()



							def 						lowerCAmelCase    (			self							: List[str]						,    **UpperCAmelCase_							: Tuple    )   ->str:



														"""simple docstring"""



														return RobertaTokenizer.from_pretrained(self.checkpoint						,    **UpperCAmelCase_    )



							def 						lowerCAmelCase    (			self							: Optional[Any]						,    **UpperCAmelCase_							: Any    )   ->Optional[Any]:



														"""simple docstring"""



														return ClapFeatureExtractor.from_pretrained(self.checkpoint						,    **UpperCAmelCase_    )



							def 						lowerCAmelCase    (			self							: str    )   ->Any:



														"""simple docstring"""



														shutil.rmtree(self.tmpdirname    )



							def 						lowerCAmelCase    (			self							: Tuple    )   ->Optional[int]:



														"""simple docstring"""



														snake_case_          =						self.get_tokenizer()
														snake_case_          =						self.get_feature_extractor()

														snake_case_          =						ClapProcessor(tokenizer=UpperCAmelCase_						,    feature_extractor=UpperCAmelCase_    )

														processor.save_pretrained(self.tmpdirname    )
														snake_case_          =						ClapProcessor.from_pretrained(self.tmpdirname    )

														self.assertEqual(processor.tokenizer.get_vocab()						,    tokenizer.get_vocab()    )
														self.assertIsInstance(processor.tokenizer						,    UpperCAmelCase_    )

														self.assertEqual(processor.feature_extractor.to_json_string()						,    feature_extractor.to_json_string()    )
														self.assertIsInstance(processor.feature_extractor						,    UpperCAmelCase_    )



							def 						lowerCAmelCase    (			self							: int    )   ->List[str]:



														"""simple docstring"""



														snake_case_          =						ClapProcessor(tokenizer=self.get_tokenizer()						,    feature_extractor=self.get_feature_extractor()    )
														processor.save_pretrained(self.tmpdirname    )

														snake_case_          =						self.get_tokenizer(bos_token="""(BOS)"""						,    eos_token="""(EOS)"""    )
														snake_case_          =						self.get_feature_extractor(do_normalize=UpperCAmelCase_						,    padding_value=1.0    )

														snake_case_          =						ClapProcessor.from_pretrained(
														    self.tmpdirname						,    bos_token="""(BOS)"""						,    eos_token="""(EOS)"""						,    do_normalize=UpperCAmelCase_						,    padding_value=1.0    )

														self.assertEqual(processor.tokenizer.get_vocab()						,    tokenizer_add_kwargs.get_vocab()    )
														self.assertIsInstance(processor.tokenizer						,    UpperCAmelCase_    )

														self.assertEqual(processor.feature_extractor.to_json_string()						,    feature_extractor_add_kwargs.to_json_string()    )
														self.assertIsInstance(processor.feature_extractor						,    UpperCAmelCase_    )



							def 						lowerCAmelCase    (			self							: str    )   ->Dict:



														"""simple docstring"""



														snake_case_          =						self.get_feature_extractor()
														snake_case_          =						self.get_tokenizer()

														snake_case_          =						ClapProcessor(tokenizer=UpperCAmelCase_						,    feature_extractor=UpperCAmelCase_    )

														snake_case_          =						floats_list((3, 1_000)    )

														snake_case_          =						feature_extractor(UpperCAmelCase_						,    return_tensors="""np"""    )
														snake_case_          =						processor(audios=UpperCAmelCase_						,    return_tensors="""np"""    )

														for key in input_feat_extract.keys():
																					self.assertAlmostEqual(input_feat_extract[key].sum()						,    input_processor[key].sum()						,    delta=1E-2    )



							def 						lowerCAmelCase    (			self							: Union[str, Any]    )   ->Optional[int]:



														"""simple docstring"""



														snake_case_          =						self.get_feature_extractor()
														snake_case_          =						self.get_tokenizer()

														snake_case_          =						ClapProcessor(tokenizer=UpperCAmelCase_						,    feature_extractor=UpperCAmelCase_    )

														snake_case_          =						"""This is a test string"""

														snake_case_          =						processor(text=UpperCAmelCase_    )

														snake_case_          =						tokenizer(UpperCAmelCase_    )

														for key in encoded_tok.keys():
																					self.assertListEqual(encoded_tok[key]						,    encoded_processor[key]    )



							def 						lowerCAmelCase    (			self							: Optional[int]    )   ->Tuple:



														"""simple docstring"""



														snake_case_          =						self.get_feature_extractor()
														snake_case_          =						self.get_tokenizer()

														snake_case_          =						ClapProcessor(tokenizer=UpperCAmelCase_						,    feature_extractor=UpperCAmelCase_    )

														snake_case_          =						[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

														snake_case_          =						processor.batch_decode(UpperCAmelCase_    )
														snake_case_          =						tokenizer.batch_decode(UpperCAmelCase_    )

														self.assertListEqual(UpperCAmelCase_						,    UpperCAmelCase_    )



							def 						lowerCAmelCase    (			self							: List[str]    )   ->Union[str, Any]:



														"""simple docstring"""



														snake_case_          =						self.get_feature_extractor()
														snake_case_          =						self.get_tokenizer()

														snake_case_          =						ClapProcessor(tokenizer=UpperCAmelCase_						,    feature_extractor=UpperCAmelCase_    )

														self.assertListEqual(
														    processor.model_input_names[2:]						,    feature_extractor.model_input_names						,    msg="""`processor` and `feature_extractor` model input names do not match"""						,    )



