


'''simple docstring'''






from __future__ import annotations

import unittest

from transformers import AutoTokenizer, MBartConfig, is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow
from transformers.utils import cached_property

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


if is_tf_available():
							import tensorflow as tf

							from transformers import TFAutoModelForSeqaSeqLM, TFMBartForConditionalGeneration, TFMBartModel
@require_tf
class 						__UpperCamelCase	:
							lowercase			:		Optional[Any]   		=  MBartConfig
							lowercase			:		List[str]   		=  {}
							lowercase			:		Dict   		=  'gelu'





							def __init__(  self		:Any  ,_UpperCamelCase		:Union[str, Any]  ,_UpperCamelCase		:int=1_3  ,_UpperCamelCase		:List[Any]=7  ,_UpperCamelCase		:List[Any]=True  ,_UpperCamelCase		:Optional[Any]=False  ,_UpperCamelCase		:Any=9_9  ,_UpperCamelCase		:Any=3_2  ,_UpperCamelCase		:Optional[Any]=2  ,_UpperCamelCase		:Any=4  ,_UpperCamelCase		:Any=3_7  ,_UpperCamelCase		:List[str]=0.1  ,_UpperCamelCase		:List[str]=0.1  ,_UpperCamelCase		:Optional[int]=2_0  ,_UpperCamelCase		:Tuple=2  ,_UpperCamelCase		:int=1  ,_UpperCamelCase		:List[Any]=0  ,):
									snake_case_		:							Optional[int]			       =						parent
									snake_case_		:							List[Any]			       =						batch_size
									snake_case_		:							str			       =						seq_length
									snake_case_		:							Any			       =						is_training
									snake_case_		:							str			       =						use_labels
									snake_case_		:							Dict			       =						vocab_size
									snake_case_		:							Optional[int]			       =						hidden_size
									snake_case_		:							Dict			       =						num_hidden_layers
									snake_case_		:							Union[str, Any]			       =						num_attention_heads
									snake_case_		:							int			       =						intermediate_size
									snake_case_		:							Any			       =						hidden_dropout_prob
									snake_case_		:							Dict			       =						attention_probs_dropout_prob
									snake_case_		:							Dict			       =						max_position_embeddings
									snake_case_		:							Tuple			       =						eos_token_id
									snake_case_		:							Dict			       =						pad_token_id
									snake_case_		:							str			       =						bos_token_id





							def 		a__   (  self		:Dict			):
									snake_case_		:							List[Any]			       =						ids_tensor([self.batch_size, self.seq_length - 1]  ,self.vocab_size			)
									snake_case_		:							int			       =						tf.expand_dims(tf.constant([self.eos_token_id] * self.batch_size			)  ,1			)
									snake_case_		:							Tuple			       =						tf.concat([input_ids, eos_tensor]  ,axis=1			)

									snake_case_		:							Optional[int]			       =						ids_tensor([self.batch_size, self.seq_length]  ,self.vocab_size			)

									snake_case_		:							Tuple			       =						self.config_cls(
									    vocab_size=self.vocab_size  ,d_model=self.hidden_size  ,encoder_layers=self.num_hidden_layers  ,decoder_layers=self.num_hidden_layers  ,encoder_attention_heads=self.num_attention_heads  ,decoder_attention_heads=self.num_attention_heads  ,encoder_ffn_dim=self.intermediate_size  ,decoder_ffn_dim=self.intermediate_size  ,dropout=self.hidden_dropout_prob  ,attention_dropout=self.attention_probs_dropout_prob  ,max_position_embeddings=self.max_position_embeddings  ,eos_token_ids=[2]  ,bos_token_id=self.bos_token_id  ,pad_token_id=self.pad_token_id  ,decoder_start_token_id=self.pad_token_id  ,**self.config_updates  ,)
									snake_case_		:							Dict			       =						prepare_mbart_inputs_dict(_UpperCamelCase  ,_UpperCamelCase  ,_UpperCamelCase			)
									return config, inputs_dict





							def 		a__   (  self		:Optional[int]  ,_UpperCamelCase		:int  ,_UpperCamelCase		:str			):
									snake_case_		:							Optional[int]			       =						TFMBartModel(config=_UpperCamelCase			).get_decoder()
									snake_case_		:							Dict			       =						inputs_dict["""input_ids"""]

									snake_case_		:							List[str]			       =						input_ids[:1, :]
									snake_case_		:							Optional[int]			       =						inputs_dict["""attention_mask"""][:1, :]
									snake_case_		:							str			       =						inputs_dict["""head_mask"""]
									snake_case_		:							Dict			       =						1

									# first forward pass
									snake_case_		:							Any			       =						model(_UpperCamelCase  ,attention_mask=_UpperCamelCase  ,head_mask=_UpperCamelCase  ,use_cache=_UpperCamelCase			)

									snake_case_       ,      snake_case_		:							str			       =						outputs.to_tuple()
									snake_case_		:							str			       =						past_key_values[1]





def      UpperCAmelCase      (		lowerCamelCase_  :Dict				,      lowerCamelCase_  :int				,      lowerCamelCase_  :Dict				,      lowerCamelCase_  :Optional[int]=None				,      lowerCamelCase_  :Union[str, Any]=None				,      lowerCamelCase_  :List[Any]=None				,      lowerCamelCase_  :Tuple=None				,      lowerCamelCase_  :Any=None				,      ):







		'''simple docstring'''
		if attention_mask is None:
				snake_case_		:							List[str]			       =						tf.cast(tf.math.not_equal(lowerCamelCase_				,      config.pad_token_id )				,      tf.inta )
		if decoder_attention_mask is None:
				snake_case_		:							Optional[int]			       =						tf.concat(
				    [
				        tf.ones(decoder_input_ids[:, :1].shape				,      dtype=tf.inta ),
				        tf.cast(tf.math.not_equal(decoder_input_ids[:, 1:]				,      config.pad_token_id )				,      tf.inta ),
				    ]				,      axis=-1				,      )
		if head_mask is None:
				snake_case_		:							Any			       =						tf.ones((config.encoder_layers, config.encoder_attention_heads) )
		if decoder_head_mask is None:
				snake_case_		:							Union[str, Any]			       =						tf.ones((config.decoder_layers, config.decoder_attention_heads) )
		if cross_attn_head_mask is None:
				snake_case_		:							Optional[int]			       =						tf.ones((config.decoder_layers, config.decoder_attention_heads) )
		return {
		    "input_ids": input_ids,
		    "decoder_input_ids": decoder_input_ids,
		    "attention_mask": attention_mask,
		    "decoder_attention_mask": decoder_attention_mask,
		    "head_mask": head_mask,
		    "decoder_head_mask": decoder_head_mask,
		    "cross_attn_head_mask": cross_attn_head_mask,
		}
@require_tf
class 						__UpperCamelCase	(						lowercase__						,  lowercase__						,  unittest.TestCase							):
							lowercase			:		int   		=  (TFMBartForConditionalGeneration, TFMBartModel) if is_tf_available() else ()
							lowercase			:		int   		=  (TFMBartForConditionalGeneration,) if is_tf_available() else ()
							lowercase			:		Any   		=  (
							    {
							        'conversational': TFMBartForConditionalGeneration,
							        'feature-extraction': TFMBartModel,
							        'summarization': TFMBartForConditionalGeneration,
							        'text2text-generation': TFMBartForConditionalGeneration,
							        'translation': TFMBartForConditionalGeneration,
							    }
							    if is_tf_available()
							    else {}
							)
							lowercase			:		str   		=  True
							lowercase			:		Optional[Any]   		=  False
							lowercase			:		Union[str, Any]   		=  False





							def 		a__   (  self		:List[str]  ,_UpperCamelCase		:Any  ,_UpperCamelCase		:Optional[Any]  ,_UpperCamelCase		:Union[str, Any]  ,_UpperCamelCase		:List[str]  ,_UpperCamelCase		:List[str]			):
									if pipeline_test_casse_name != "FeatureExtractionPipelineTests":
											# Exception encountered when calling layer '...'
											return True

									return False





							def 		a__   (  self		:int			):
									snake_case_		:							Tuple			       =						TFMBartModelTester(self			)
									snake_case_		:							Tuple			       =						ConfigTester(self  ,config_class=_UpperCamelCase			)





							def 		a__   (  self		:List[Any]			):
									self.config_tester.run_common_tests()





							def 		a__   (  self		:Optional[Any]			):
									snake_case_		:							List[str]			       =						self.model_tester.prepare_config_and_inputs_for_common()
									self.model_tester.check_decoder_model_past_large_inputs(*_UpperCamelCase			)





@require_sentencepiece
@require_tokenizers
@require_tf
class 						__UpperCamelCase	(						unittest.TestCase							):
							lowercase			:		Dict   		=  [
							    ' UN Chief Says There Is No Military Solution in Syria',
							]
							lowercase			:		Optional[Any]   		=  [
							    'Şeful ONU declară că nu există o soluţie militară în Siria',
							]
							lowercase			:		Tuple   		=  'facebook/mbart-large-en-ro'





							@cached_property
							def 		a__   (  self		:Any			):
									return AutoTokenizer.from_pretrained(self.model_name			)





							@cached_property
							def 		a__   (  self		:List[Any]			):
									snake_case_		:							int			       =						TFAutoModelForSeqaSeqLM.from_pretrained(self.model_name			)
									return model





							def 		a__   (  self		:List[str]  ,**_UpperCamelCase		:Any			):
									snake_case_		:							Tuple			       =						self.translate_src_text(**_UpperCamelCase			)
									self.assertListEqual(self.expected_text  ,_UpperCamelCase			)





							def 		a__   (  self		:Dict  ,**_UpperCamelCase		:Union[str, Any]			):
									snake_case_		:							List[Any]			       =						self.tokenizer(self.src_text  ,**_UpperCamelCase  ,return_tensors="""tf"""			)
									snake_case_		:							str			       =						self.model.generate(
									    model_inputs.input_ids  ,attention_mask=model_inputs.attention_mask  ,num_beams=2			)
									snake_case_		:							Optional[int]			       =						self.tokenizer.batch_decode(_UpperCamelCase  ,skip_special_tokens=_UpperCamelCase			)
									return generated_words





							@slow
							def 		a__   (  self		:int			):
									self._assert_generated_batch_equal_expected()



'''simple docstring'''






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_speech_available, is_torch_available


__A	:	Tuple     =     {
    'configuration_audio_spectrogram_transformer': [
        'AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'ASTConfig',
    ]
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__A	:	Tuple     =     [
							    'AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'ASTForAudioClassification',
							    'ASTModel',
							    'ASTPreTrainedModel',
							]

try:
							if not is_speech_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__A	:	int     =     ['ASTFeatureExtractor']

if TYPE_CHECKING:
							from .configuration_audio_spectrogram_transformer import (
							    AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    ASTConfig,
							)

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_audio_spectrogram_transformer import (
														    AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
														    ASTForAudioClassification,
														    ASTModel,
														    ASTPreTrainedModel,
														)

							try:
														if not is_speech_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .feature_extraction_audio_spectrogram_transformer import ASTFeatureExtractor


else:
							import sys

							__A	:	Union[str, Any]     =     _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)