




from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder


# @@protoc_insertion_point(imports)

__UpperCamelCase   :			List[str]          = _symbol_database.Default()


__UpperCamelCase   :			List[Any]          = _descriptor_pool.Default().AddSerializedFile(
    B"\n\x19sentencepiece_model.proto\x12\rsentencepiece\"\x80\x0c\n\x0bTrainerSpec\x12\r\n\x05input\x18\x01 \x03(\t\x12\x14\n\x0cinput_format\x18\x07 \x01(\t\x12\x14\n\x0cmodel_prefix\x18\x02 \x01(\t\x12\x41\n\nmodel_type\x18\x03 \x01(\x0e\x32$.sentencepiece.TrainerSpec.ModelType:\x07UNIGRAM\x12\x18\n\nvocab_size\x18\x04 \x01(\x05:\x04\x38\x30\x30\x30\x12\x17\n\x0f\x61\x63\x63\x65pt_language\x18\x05 \x03(\t\x12 \n\x15self_test_sample_size\x18\x06 \x01(\x05:\x01\x30\x12*\n\x1b\x65nable_differential_privacy\x18\x32 \x01(\x08:\x05\x66\x61lse\x12+\n differential_privacy_noise_level\x18\x33 \x01(\x02:\x01\x30\x12\x32\n\'differential_privacy_clipping_threshold\x18\x34 \x01(\x04:\x01\x30\x12\"\n\x12\x63haracter_coverage\x18\n \x01(\x02:\x06\x30.9995\x12\x1e\n\x13input_sentence_size\x18\x0b \x01(\x04:\x01\x30\x12$\n\x16shuffle_input_sentence\x18\x13 \x01(\x08:\x04true\x12 \n\x14mining_sentence_size\x18\x0c \x01(\x05\x42\x02\x18\x01\x12\"\n\x16training_sentence_size\x18\r \x01(\x05\x42\x02\x18\x01\x12(\n\x17seed_sentencepiece_size\x18\x0e \x01(\x05:\x07\x31\x30\x30\x30\x30\x30\x30\x12\x1e\n\x10shrinking_factor\x18\x0f \x01(\x02:\x04\x30.75\x12!\n\x13max_sentence_length\x18\x12 \x01(\x05:\x04\x34\x31\x39\x32\x12\x17\n\x0bnum_threads\x18\x10 \x01(\x05:\x02\x31\x36\x12\x1d\n\x12num_sub_iterations\x18\x11 \x01(\x05:\x01\x32\x12$\n\x18max_sentencepiece_length\x18\x14 \x01(\x05:\x02\x31\x36\x12%\n\x17split_by_unicode_script\x18\x15 \x01(\x08:\x04true\x12\x1d\n\x0fsplit_by_number\x18\x17 \x01(\x08:\x04true\x12!\n\x13split_by_whitespace\x18\x16 \x01(\x08:\x04true\x12)\n\x1atreat_whitespace_as_suffix\x18\x18 \x01(\x08:\x05\x66\x61lse\x12+\n\x1c\x61llow_whitespace_only_pieces\x18\x1a \x01(\x08:\x05\x66\x61lse\x12\x1b\n\x0csplit_digits\x18\x19 \x01(\x08:\x05\x66\x61lse\x12#\n\x19pretokenization_delimiter\x18\x35 \x01(\t:\x00\x12\x17\n\x0f\x63ontrol_symbols\x18\x1e \x03(\t\x12\x1c\n\x14user_defined_symbols\x18\x1f \x03(\t\x12\x16\n\x0erequired_chars\x18$ \x01(\t\x12\x1c\n\rbyte_fallback\x18# \x01(\x08:\x05\x66\x61lse\x12+\n\x1dvocabulary_output_piece_score\x18  \x01(\x08:\x04true\x12\x1e\n\x10hard_vocab_limit\x18! \x01(\x08:\x04true\x12\x1c\n\ruse_all_vocab\x18\" \x01(\x08:\x05\x66\x61lse\x12\x11\n\x06unk_id\x18( \x01(\x05:\x01\x30\x12\x11\n\x06\x62os_id\x18) \x01(\x05:\x01\x31\x12\x11\n\x06\x65os_id\x18* \x01(\x05:\x01\x32\x12\x12\n\x06pad_id\x18+ \x01(\x05:\x02-1\x12\x18\n\tunk_piece\x18- \x01(\t:\x05<unk>\x12\x16\n\tbos_piece\x18. \x01(\t:\x03<s>\x12\x17\n\teos_piece\x18/ \x01(\t:\x04</s>\x12\x18\n\tpad_piece\x18\x30 \x01(\t:\x05<pad>\x12\x1a\n\x0bunk_surface\x18, \x01(\t:\x05 \xe2\x81\x87 \x12+\n\x1ctrain_extremely_large_corpus\x18\x31 \x01(\x08:\x05\x66\x61lse\"5\n\tModelType\x12\x0b\n\x07UNIGRAM\x10\x01\x12\x07\n\x03\x42PE\x10\x02\x12\x08\n\x04WORD\x10\x03\x12\x08\n\x04\x43HAR\x10\x04*\t\x08\xc8\x01\x10\x80\x80\x80\x80\x02\"\xd1\x01\n\x0eNormalizerSpec\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x1c\n\x14precompiled_charsmap\x18\x02 \x01(\x0c\x12\x1e\n\x10\x61\x64\x64_dummy_prefix\x18\x03 \x01(\x08:\x04true\x12&\n\x18remove_extra_whitespaces\x18\x04 \x01(\x08:\x04true\x12 \n\x12\x65scape_whitespaces\x18\x05 \x01(\x08:\x04true\x12\x1e\n\x16normalization_rule_tsv\x18\x06 \x01(\t*\t\x08\xc8\x01\x10\x80\x80\x80\x80\x02\"y\n\x0cSelfTestData\x12\x33\n\x07samples\x18\x01 \x03(\x0b\x32\".sentencepiece.SelfTestData.Sample\x1a)\n\x06Sample\x12\r\n\x05input\x18\x01 \x01(\t\x12\x10\n\x08\x65xpected\x18\x02 \x01(\t*\t\x08\xc8\x01\x10\x80\x80\x80\x80\x02\"\xfe\x03\n\nModelProto\x12\x37\n\x06pieces\x18\x01 \x03(\x0b\x32\'.sentencepiece.ModelProto.SentencePiece\x12\x30\n\x0ctrainer_spec\x18\x02 \x01(\x0b\x32\x1a.sentencepiece.TrainerSpec\x12\x36\n\x0fnormalizer_spec\x18\x03 \x01(\x0b\x32\x1d.sentencepiece.NormalizerSpec\x12\x33\n\x0eself_test_data\x18\x04 \x01(\x0b\x32\x1b.sentencepiece.SelfTestData\x12\x38\n\x11\x64\x65normalizer_spec\x18\x05 \x01(\x0b\x32\x1d.sentencepiece.NormalizerSpec\x1a\xd2\x01\n\rSentencePiece\x12\r\n\x05piece\x18\x01 \x01(\t\x12\r\n\x05score\x18\x02 \x01(\x02\x12\x42\n\x04type\x18\x03 \x01(\x0e\x32,.sentencepiece.ModelProto.SentencePiece.Type:\x06NORMAL\"T\n\x04Type\x12\n\n\x06NORMAL\x10\x01\x12\x0b\n\x07UNKNOWN\x10\x02\x12\x0b\n\x07\x43ONTROL\x10\x03\x12\x10\n\x0cUSER_DEFINED\x10\x04\x12\x08\n\x04\x42YTE\x10\x06\x12\n\n\x06UNUSED\x10\x05*\t\x08\xc8\x01\x10\x80\x80\x80\x80\x02*\t\x08\xc8\x01\x10\x80\x80\x80\x80\x02\x42\x02H\x03"
)

__UpperCamelCase   :			Dict          = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, "sentencepiece_model_pb2", _globals)
if _descriptor._USE_C_DESCRIPTORS is False:
		__UpperCamelCase   :			int          = None
		__UpperCamelCase   :			Optional[Any]          = B"H\003"
		# (generated by protobuf compiler, but `_TRAINERSPEC` is not defined)
		# _TRAINERSPEC.fields_by_name["mining_sentence_size"]._options = None
		# _TRAINERSPEC.fields_by_name["mining_sentence_size"]._serialized_options = b"\030\001"
		# _TRAINERSPEC.fields_by_name["training_sentence_size"]._options = None
		# _TRAINERSPEC.fields_by_name["training_sentence_size"]._serialized_options = b"\030\001"
		__UpperCamelCase   :			Optional[int]          = 45
		__UpperCamelCase   :			Dict          = 1_581
		__UpperCamelCase   :			Tuple          = 1_517
		__UpperCamelCase   :			List[str]          = 1_570
		__UpperCamelCase   :			List[str]          = 1_584
		__UpperCamelCase   :			Union[str, Any]          = 1_793
		__UpperCamelCase   :			Dict          = 1_795
		__UpperCamelCase   :			Optional[Any]          = 1_916
		__UpperCamelCase   :			Dict          = 1_864
		__UpperCamelCase   :			Optional[int]          = 1_905
		__UpperCamelCase   :			Union[str, Any]          = 1_919
		__UpperCamelCase   :			List[str]          = 2_429
		__UpperCamelCase   :			int          = 2_208
		__UpperCamelCase   :			Union[str, Any]          = 2_418
		__UpperCamelCase   :			Optional[int]          = 2_323
		__UpperCamelCase   :			Tuple          = 2_407
# @@protoc_insertion_point(module_scope)







from __future__ import annotations

import unittest

from transformers import AutoTokenizer, PegasusConfig, 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, TFPegasusForConditionalGeneration, TFPegasusModel

@require_tf
class 						__lowerCAmelCase      :
							UpperCamelCase__   	=    PegasusConfig
							UpperCamelCase__   	=    {}
							UpperCamelCase__   	=    '''gelu'''
							def __init__(		self		:int						, __magic_name__		:Optional[int]						, __magic_name__		:str=13						, __magic_name__		:List[Any]=7						, __magic_name__		:Optional[int]=True						, __magic_name__		:Optional[int]=False						, __magic_name__		:List[Any]=99						, __magic_name__		:int=32						, __magic_name__		:Tuple=2						, __magic_name__		:List[str]=4						, __magic_name__		:Dict=37						, __magic_name__		:Tuple=0.1						, __magic_name__		:Optional[Any]=0.1						, __magic_name__		:Dict=40						, __magic_name__		:Tuple=2						, __magic_name__		:Optional[Any]=1						, __magic_name__		:Dict=0						, ):







								'''simple docstring'''







								a									=				parent
								a									=				batch_size
								a									=				seq_length
								a									=				is_training
								a									=				use_labels
								a									=				vocab_size
								a									=				hidden_size
								a									=				num_hidden_layers
								a									=				num_attention_heads
								a									=				intermediate_size

								a									=				hidden_dropout_prob
								a									=				attention_probs_dropout_prob
								a									=				max_position_embeddings
								a									=				eos_token_id
								a									=				pad_token_id
								a									=				bos_token_id
							def  lowerCamelCase__				(		self		:str							):







								'''simple docstring'''







								a									=				ids_tensor([self.batch_size, self.seq_length - 1]						, self.vocab_size							)
								a									=				tf.expand_dims(tf.constant([self.eos_token_id] * self.batch_size							)						, 1							)
								a									=				tf.concat([input_ids, eos_tensor]						, axis=1							)

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

								a									=				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						, )
								a									=				prepare_pegasus_inputs_dict(__magic_name__						, __magic_name__						, __magic_name__							)
								return config, inputs_dict





							def  lowerCamelCase__				(		self		:List[Any]						, __magic_name__		:Any						, __magic_name__		:str							):







								'''simple docstring'''







								a									=				TFPegasusModel(config=__magic_name__							).get_decoder()
								a									=				inputs_dict["""input_ids"""]

								a									=				input_ids[:1, :]
								a									=				inputs_dict["""attention_mask"""][:1, :]
								a									=				inputs_dict["""head_mask"""]
								a									=				1

								# first forward pass
								a									=				model(__magic_name__						, attention_mask=__magic_name__						, head_mask=__magic_name__						, use_cache=__magic_name__							)

								a							,					a									=				outputs.to_tuple()

								# create hypothetical next token and extent to next_input_ids
								a									=				ids_tensor((self.batch_size, 3)						, config.vocab_size							)
								a									=				tf.cast(ids_tensor((self.batch_size, 3)						, 2							)						, tf.inta							)

								# append to next input_ids and
								a									=				tf.concat([input_ids, next_tokens]						, axis=-1							)
								a									=				tf.concat([attention_mask, next_attn_mask]						, axis=-1							)

								a									=				model(__magic_name__						, attention_mask=__magic_name__							)[0]
								a									=				model(__magic_name__						, attention_mask=__magic_name__						, past_key_values=__magic_name__							)[0]

								self.parent.assertEqual(next_tokens.shape[1]						, output_from_past.shape[1]							)

								# select random slice
								a									=				int(ids_tensor((1,)						, output_from_past.shape[-1]							)							)
								a									=				output_from_no_past[:, -3:, random_slice_idx]
								a									=				output_from_past[:, :, random_slice_idx]

								# test that outputs are equal for slice
								tf.debugging.assert_near(__magic_name__						, __magic_name__						, rtol=1E-3							)







def 						__A						(      __lowerCamelCase				,     __lowerCamelCase				,     __lowerCamelCase				,     __lowerCamelCase=None				,     __lowerCamelCase=None				,     __lowerCamelCase=None				,     __lowerCamelCase=None				,     __lowerCamelCase=None				,     ) ->			Tuple:
	if attention_mask is None:
		a									=				tf.cast(tf.math.not_equal(__lowerCamelCase				,     config.pad_token_id       )				,     tf.inta       )
	if decoder_attention_mask is None:
		a									=				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:
		a									=				tf.ones((config.encoder_layers, config.encoder_attention_heads)       )
	if decoder_head_mask is None:
		a									=				tf.ones((config.decoder_layers, config.decoder_attention_heads)       )
	if cross_attn_head_mask is None:
		a									=				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 						__lowerCAmelCase      (      __magic_name__ ,			__magic_name__ ,			unittest.TestCase					):
							UpperCamelCase__   	=    (TFPegasusForConditionalGeneration, TFPegasusModel) if is_tf_available() else ()
							UpperCamelCase__   	=    (TFPegasusForConditionalGeneration,) if is_tf_available() else ()
							UpperCamelCase__   	=    (
							    {
							        '''conversational''': TFPegasusForConditionalGeneration,
							        '''feature-extraction''': TFPegasusModel,
							        '''summarization''': TFPegasusForConditionalGeneration,
							        '''text2text-generation''': TFPegasusForConditionalGeneration,
							        '''translation''': TFPegasusForConditionalGeneration,
							    }
							    if is_tf_available()
							    else {}
							)
							UpperCamelCase__   	=    True
							UpperCamelCase__   	=    False
							UpperCamelCase__   	=    False
							def  lowerCamelCase__				(		self		:List[str]							):







								'''simple docstring'''







								a									=				TFPegasusModelTester(self							)
								a									=				ConfigTester(self						, config_class=__magic_name__							)
							def  lowerCamelCase__				(		self		:Any							):







								'''simple docstring'''







								self.config_tester.run_common_tests()





							def  lowerCamelCase__				(		self		:Dict							):







								'''simple docstring'''







								a									=				self.model_tester.prepare_config_and_inputs_for_common()
								self.model_tester.check_decoder_model_past_large_inputs(*__magic_name__							)







@require_sentencepiece
@require_tokenizers
@require_tf
class 						__lowerCAmelCase      (      unittest.TestCase					):
							UpperCamelCase__   	=    [
							    ''' PG&E stated it scheduled the blackouts in response to forecasts for high winds amid dry conditions. The aim is to reduce the risk of wildfires. Nearly 800 thousand customers were scheduled to be affected by the shutoffs which were expected to last through at least midday tomorrow.''',
							    ''' The London trio are up for best UK act and best album, as well as getting two nominations in the best song category."We got told like this morning \'Oh I think you\'re nominated\'", said Dappy."And I was like \'Oh yeah, which one?\' And now we\'ve got nominated for four awards. I mean, wow!"Bandmate Fazer added: "We thought it\'s best of us to come down and mingle with everyone and say hello to the cameras. And now we find we\'ve got four nominations."The band have two shots at the best song prize, getting the nod for their Tynchy Stryder collaboration Number One, and single Strong Again.Their album Uncle B will also go up against records by the likes of Beyonce and Kanye West.N-Dubz picked up the best newcomer Mobo in 2007, but female member Tulisa said they wouldn\'t be too disappointed if they didn\'t win this time around."At the end of the day we\'re grateful to be where we are in our careers."If it don\'t happen then it don\'t happen - live to fight another day and keep on making albums and hits for the fans."Dappy also revealed they could be performing live several times on the night.The group will be doing Number One and also a possible rendition of the War Child single, I Got Soul.The charity song is a  re-working of The Killers\' All These Things That I\'ve Done and is set to feature artists like Chipmunk, Ironik and Pixie Lott.This year\'s Mobos will be held outside of London for the first time, in Glasgow on 30 September.N-Dubz said they were looking forward to performing for their Scottish fans and boasted about their recent shows north of the border."We just done Edinburgh the other day," said Dappy."We smashed up an N-Dubz show over there. We done Aberdeen about three or four months ago - we smashed up that show over there! Everywhere we go we smash it up!" ''',
							]
							UpperCamelCase__   	=    [
							    '''California\'s largest electricity provider has cut power to hundreds of thousands of customers in an effort to'''
							    ''' reduce the risk of wildfires.''',
							    '''N-Dubz have revealed they\'re "grateful" to have been nominated for four Mobo Awards.''',
							]  # differs slightly from pytorch, likely due to numerical differences in linear layers
							UpperCamelCase__   	=    '''google/pegasus-xsum'''
							@cached_property
							def  lowerCamelCase__				(		self		:Union[str, Any]							):







								'''simple docstring'''







								return AutoTokenizer.from_pretrained(self.model_name							)
							@cached_property
							def  lowerCamelCase__				(		self		:List[Any]							):







								'''simple docstring'''







								a									=				TFAutoModelForSeqaSeqLM.from_pretrained(self.model_name							)
								return model
							def  lowerCamelCase__				(		self		:int						, **__magic_name__		:int							):







								'''simple docstring'''







								a									=				self.translate_src_text(**__magic_name__							)
								assert self.expected_text == generated_words
							def  lowerCamelCase__				(		self		:Union[str, Any]						, **__magic_name__		:int							):







								'''simple docstring'''







								a									=				self.tokenizer(self.src_text						, **__magic_name__						, padding=__magic_name__						, return_tensors="""tf"""							)
								a									=				self.model.generate(
								    model_inputs.input_ids						, attention_mask=model_inputs.attention_mask						, num_beams=2						, use_cache=__magic_name__						, )
								a									=				self.tokenizer.batch_decode(generated_ids.numpy()						, skip_special_tokens=__magic_name__							)
								return generated_words





							@slow
							def  lowerCamelCase__				(		self		:Union[str, Any]							):







								'''simple docstring'''







								self._assert_generated_batch_equal_expected()

