
import unittest

from transformers import SpeechaTextaConfig
from transformers.testing_utils import is_torch_available, require_torch, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers.models.speech_to_text_a.modeling_speech_to_text_a import (
		    SpeechaTextaDecoder,
		    SpeechaTextaForCausalLM,
		)


@require_torch
class 						__magic_name__				:





		def __init__(							self      :		Union[str, Any]  ,					lowerCamelCase__      :		str  ,					lowerCamelCase__      :		Tuple=9_9  ,					lowerCamelCase__      :		List[Any]=1_3  ,					lowerCamelCase__      :		Dict=1_6  ,					lowerCamelCase__      :		Dict=7  ,					lowerCamelCase__      :		Tuple=True  ,					lowerCamelCase__      :		Optional[Any]=True  ,					lowerCamelCase__      :		List[Any]=True  ,					lowerCamelCase__      :		str=False  ,					lowerCamelCase__      :		Tuple=True  ,					lowerCamelCase__      :		Optional[int]=2  ,					lowerCamelCase__      :		Optional[Any]=3_2  ,					lowerCamelCase__      :		Dict=4  ,					lowerCamelCase__      :		List[str]=4  ,					lowerCamelCase__      :		str=3_0  ,					lowerCamelCase__      :		Optional[Any]=0  ,					lowerCamelCase__      :		Dict=1  ,					lowerCamelCase__      :		Optional[Any]=2  ,					lowerCamelCase__      :		List[str]=None  ,					):
							lowerCAmelCase						:   List[str]							=       parent
							lowerCAmelCase						:   Union[str, Any]							=       batch_size
							lowerCAmelCase						:   str							=       decoder_seq_length
							# For common tests
							lowerCAmelCase						:   Any							=       self.decoder_seq_length
							lowerCAmelCase						:   Union[str, Any]							=       is_training
							lowerCAmelCase						:   str							=       use_attention_mask
							lowerCAmelCase						:   str							=       use_labels

							lowerCAmelCase						:   int							=       vocab_size
							lowerCAmelCase						:   Union[str, Any]							=       d_model
							lowerCAmelCase						:   Optional[int]							=       d_model
							lowerCAmelCase						:   Optional[Any]							=       decoder_layers
							lowerCAmelCase						:   Optional[int]							=       decoder_layers
							lowerCAmelCase						:   Optional[int]							=       decoder_ffn_dim
							lowerCAmelCase						:   Dict							=       decoder_attention_heads
							lowerCAmelCase						:   List[str]							=       decoder_attention_heads
							lowerCAmelCase						:   Union[str, Any]							=       eos_token_id
							lowerCAmelCase						:   str							=       bos_token_id
							lowerCAmelCase						:   Tuple							=       pad_token_id
							lowerCAmelCase						:   Optional[Any]							=       decoder_start_token_id
							lowerCAmelCase						:   Dict							=       use_cache
							lowerCAmelCase						:   Optional[int]							=       max_position_embeddings

							lowerCAmelCase						:   Union[str, Any]							=       None
							lowerCAmelCase						:   List[Any]							=       decoder_seq_length
							lowerCAmelCase						:   Optional[int]							=       2
							lowerCAmelCase						:   Optional[Any]							=       1





		def  _A							(							self      :		Union[str, Any]			):
							lowerCAmelCase						:   int							=       ids_tensor([self.batch_size, self.decoder_seq_length]  ,					self.vocab_size			)

							lowerCAmelCase						:   Optional[Any]							=       None
							if self.use_attention_mask:
												lowerCAmelCase						:   int							=       ids_tensor([self.batch_size, self.decoder_seq_length]  ,					vocab_size=2			)

							lowerCAmelCase						:   str							=       None
							if self.use_labels:
												lowerCAmelCase						:   List[Any]							=       ids_tensor([self.batch_size, self.decoder_seq_length]  ,					self.vocab_size			)

							lowerCAmelCase						:   str							=       SpeechaTextaConfig(
							    vocab_size=self.vocab_size  ,					d_model=self.d_model  ,					decoder_layers=self.decoder_layers  ,					decoder_ffn_dim=self.decoder_ffn_dim  ,					decoder_attention_heads=self.decoder_attention_heads  ,					eos_token_id=self.eos_token_id  ,					bos_token_id=self.bos_token_id  ,					use_cache=self.use_cache  ,					pad_token_id=self.pad_token_id  ,					decoder_start_token_id=self.decoder_start_token_id  ,					max_position_embeddings=self.max_position_embeddings  ,					)

							return (
							    config,
							    input_ids,
							    attention_mask,
							    lm_labels,
							)





		def  _A							(							self      :		int  ,					lowerCamelCase__      :		Any  ,					lowerCamelCase__      :		Any  ,					lowerCamelCase__      :		Optional[int]  ,					lowerCamelCase__      :		Optional[int]  ,					):
							lowerCAmelCase						:   Optional[Any]							=       True
							lowerCAmelCase						:   List[str]							=       SpeechaTextaDecoder(config=lowerCamelCase__			).to(lowerCamelCase__			).eval()
							lowerCAmelCase						:   str							=       input_ids[:2]

							input_ids[input_ids == 0] += 1
							# first forward pass
							lowerCAmelCase						:   Any							=       model(lowerCamelCase__  ,					use_cache=lowerCamelCase__			)
							lowerCAmelCase						:   int							=       model(lowerCamelCase__			)
							lowerCAmelCase						:   str							=       model(lowerCamelCase__  ,					use_cache=lowerCamelCase__			)

							self.parent.assertTrue(len(lowerCamelCase__			) == len(lowerCamelCase__			)			)
							self.parent.assertTrue(len(lowerCamelCase__			) == len(lowerCamelCase__			) + 1			)

							lowerCAmelCase						:   Union[str, Any]							=       outputs["past_key_values"]

							# create hypothetical next token and extent to next_input_ids
							lowerCAmelCase						:   Dict							=       ids_tensor((2, 1)  ,					config.vocab_size - 1			) + 1

							# append to next input_ids and
							lowerCAmelCase						:   List[str]							=       torch.cat([input_ids, next_tokens]  ,					dim=-1			)

							print(lowerCamelCase__			)

							lowerCAmelCase						:   Optional[Any]							=       model(lowerCamelCase__			)["last_hidden_state"]
							lowerCAmelCase						:   int							=       model(lowerCamelCase__  ,					past_key_values=lowerCamelCase__			)["last_hidden_state"]

							# select random slice
							lowerCAmelCase						:   Tuple							=       ids_tensor((1,)  ,					output_from_past.shape[-1]			).item()
							lowerCAmelCase						:   Optional[int]							=       output_from_no_past[:, next_input_ids.shape[-1] - 1, random_slice_idx].detach()
							lowerCAmelCase						:   Optional[Any]							=       output_from_past[:, 0, random_slice_idx].detach()

							# test that outputs are equal for slice
							assert torch.allclose(lowerCamelCase__  ,					lowerCamelCase__  ,					atol=1E-3			)





		def  _A							(							self      :		Optional[Any]			):
							lowerCAmelCase						:   Tuple							=       self.prepare_config_and_inputs()
							(
							    lowerCAmelCase						
							)						:   List[Any]							=       config_and_inputs

							lowerCAmelCase						:   Union[str, Any]							=       {
							    "input_ids": input_ids,
							    "attention_mask": attention_mask,
							}
							return config, inputs_dict



@require_torch
class 						__magic_name__				(  snake_case,			snake_case,			snake_case,			unittest.TestCase      ):
		_lowerCAmelCase						=		(SpeechaTextaDecoder, SpeechaTextaForCausalLM) if is_torch_available() else ()
		_lowerCAmelCase						=		(SpeechaTextaForCausalLM,) if is_torch_available() else ()
		_lowerCAmelCase						=		{'text-generation': SpeechaTextaForCausalLM} if is_torch_available() else {}
		_lowerCAmelCase						=		True
		_lowerCAmelCase						=		False





		def  _A							(							self      :		str  ,					):
							lowerCAmelCase						:   Union[str, Any]							=       SpeechaTextaStandaloneDecoderModelTester(self  ,					is_training=lowerCamelCase__			)
							lowerCAmelCase						:   Optional[int]							=       ConfigTester(self  ,					config_class=lowerCamelCase__			)





		def  _A							(							self      :		List[str]			):
							pass





		def  _A							(							self      :		Optional[Any]			):
							pass





		def  _A							(							self      :		Union[str, Any]			):
							pass





		def  _A							(							self      :		Optional[Any]			):
							self.config_tester.run_common_tests()





		def  _A							(							self      :		Dict			):
							lowerCAmelCase						:   int							=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_decoder_model_past(*lowerCamelCase__			)





		def  _A							(							self      :		Optional[int]			):
							return


def       UpperCAmelCase__							(    __magic_name__  :       int = 99_80_01					):


					'''simple docstring'''

					lowerCAmelCase						:   Tuple							=       0
					for i in range(9_99							,					99							,					-1					):  # 3 digit numbers range from 999 down to 100
										for j in range(9_99							,					99							,					-1					):
															lowerCAmelCase						:   Any							=       str(i * j					)
															if product_string == product_string[::-1] and i * j < n:
																				lowerCAmelCase						:   Optional[int]							=       max(__magic_name__							,					i * j					)
					return answer


if __name__ == "__main__":
		print(f"""{solution() = }""")
