





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     ,					_a     ,					_a=99     ,					_a=13     ,					_a=16     ,					_a=7     ,					_a=True     ,					_a=True     ,					_a=True     ,					_a=False     ,					_a=True     ,					_a=2     ,					_a=32     ,					_a=4     ,					_a=4     ,					_a=30     ,					_a=0     ,					_a=1     ,					_a=2     ,					_a=None     ,					)       -> Any:
							lowerCAmelCase_				=							parent
							lowerCAmelCase_				=							batch_size
							lowerCAmelCase_				=							decoder_seq_length
							# For common tests
							lowerCAmelCase_				=							self.decoder_seq_length
							lowerCAmelCase_				=							is_training
							lowerCAmelCase_				=							use_attention_mask
							lowerCAmelCase_				=							use_labels

							lowerCAmelCase_				=							vocab_size
							lowerCAmelCase_				=							d_model
							lowerCAmelCase_				=							d_model
							lowerCAmelCase_				=							decoder_layers
							lowerCAmelCase_				=							decoder_layers
							lowerCAmelCase_				=							decoder_ffn_dim
							lowerCAmelCase_				=							decoder_attention_heads
							lowerCAmelCase_				=							decoder_attention_heads
							lowerCAmelCase_				=							eos_token_id
							lowerCAmelCase_				=							bos_token_id
							lowerCAmelCase_				=							pad_token_id
							lowerCAmelCase_				=							decoder_start_token_id
							lowerCAmelCase_				=							use_cache
							lowerCAmelCase_				=							max_position_embeddings

							lowerCAmelCase_				=							None
							lowerCAmelCase_				=							decoder_seq_length
							lowerCAmelCase_				=							2
							lowerCAmelCase_				=							1




					def  __a			(    self		)       -> List[str]:
							lowerCAmelCase_				=							ids_tensor([self.batch_size, self.decoder_seq_length]     ,					self.vocab_size		)

							lowerCAmelCase_				=							None
							if self.use_attention_mask:
									lowerCAmelCase_				=							ids_tensor([self.batch_size, self.decoder_seq_length]     ,					vocab_size=2		)

							lowerCAmelCase_				=							None
							if self.use_labels:
									lowerCAmelCase_				=							ids_tensor([self.batch_size, self.decoder_seq_length]     ,					self.vocab_size		)

							lowerCAmelCase_				=							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     ,					_a     ,					_a     ,					_a     ,					_a     ,					)       -> Dict:
							lowerCAmelCase_				=							True
							lowerCAmelCase_				=							SpeechaTextaDecoder(config=__SCREAMING_SNAKE_CASE		).to(__SCREAMING_SNAKE_CASE		).eval()
							lowerCAmelCase_				=							input_ids[:2]

							input_ids[input_ids == 0] += 1
							# first forward pass
							lowerCAmelCase_				=							model(__SCREAMING_SNAKE_CASE     ,					use_cache=__SCREAMING_SNAKE_CASE		)
							lowerCAmelCase_				=							model(__SCREAMING_SNAKE_CASE		)
							lowerCAmelCase_				=							model(__SCREAMING_SNAKE_CASE     ,					use_cache=__SCREAMING_SNAKE_CASE		)

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

							lowerCAmelCase_				=							outputs["past_key_values"]

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

							# append to next input_ids and
							lowerCAmelCase_				=							torch.cat([input_ids, next_tokens]     ,					dim=-1		)

							print(__SCREAMING_SNAKE_CASE		)

							lowerCAmelCase_				=							model(__SCREAMING_SNAKE_CASE		)["last_hidden_state"]
							lowerCAmelCase_				=							model(__SCREAMING_SNAKE_CASE     ,					past_key_values=__SCREAMING_SNAKE_CASE		)["last_hidden_state"]

							# select random slice
							lowerCAmelCase_				=							ids_tensor((1,)     ,					output_from_past.shape[-1]		).item()
							lowerCAmelCase_				=							output_from_no_past[:, next_input_ids.shape[-1] - 1, random_slice_idx].detach()
							lowerCAmelCase_				=							output_from_past[:, 0, random_slice_idx].detach()

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




					def  __a			(    self		)       -> List[str]:
							lowerCAmelCase_				=							self.prepare_config_and_inputs()
							(
							    (
							    lowerCAmelCase_    
							)		,   (
							    lowerCAmelCase_    
							)		,   (
							    lowerCAmelCase_    
							)		,   (
							    lowerCAmelCase_    
							)		,       
							)				=							config_and_inputs

							lowerCAmelCase_				=							{
							    "input_ids": input_ids,
							    "attention_mask": attention_mask,
							}
							return config, inputs_dict





@require_torch
class      __magic_name__       (_A ,						_A ,						_A ,						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     ,					)       -> Tuple:
							lowerCAmelCase_				=							SpeechaTextaStandaloneDecoderModelTester(self     ,					is_training=__SCREAMING_SNAKE_CASE		)
							lowerCAmelCase_				=							ConfigTester(self     ,					config_class=__SCREAMING_SNAKE_CASE		)




					def  __a			(    self		)       -> Optional[Any]:
							pass




					def  __a			(    self		)       -> Union[str, Any]:
							pass




					def  __a			(    self		)       -> Optional[Any]:
							pass




					def  __a			(    self		)       -> str:
							self.config_tester.run_common_tests()




					def  __a			(    self		)       -> Optional[Any]:
							lowerCAmelCase_				=							self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_decoder_model_past(*__SCREAMING_SNAKE_CASE		)




					def  __a			(    self		)       -> Union[str, Any]:
							return




"""simple docstring"""




def    __SCREAMING_SNAKE_CASE						(						lowercase__ = 1_000      ):
					"""simple docstring"""
					return sum(i for i in range(lowercase__      ) if i % 3 == 0 or i % 5 == 0      )


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





