"""simple docstring"""






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     snake_case	:




					"""simple docstring"""

					def __init__(    self       :     Union[str, Any]   ,lowerCamelCase__       :     Dict   ,lowerCamelCase__       :     Union[str, Any]=99   ,lowerCamelCase__       :     List[str]=13   ,lowerCamelCase__       :     List[str]=16   ,lowerCamelCase__       :     List[str]=7   ,lowerCamelCase__       :     List[Any]=True   ,lowerCamelCase__       :     Any=True   ,lowerCamelCase__       :     Dict=True   ,lowerCamelCase__       :     Dict=False   ,lowerCamelCase__       :     Any=True   ,lowerCamelCase__       :     Any=2   ,lowerCamelCase__       :     int=32   ,lowerCamelCase__       :     Tuple=4   ,lowerCamelCase__       :     Optional[Any]=4   ,lowerCamelCase__       :     Any=30   ,lowerCamelCase__       :     List[Any]=0   ,lowerCamelCase__       :     Tuple=1   ,lowerCamelCase__       :     Optional[int]=2   ,lowerCamelCase__       :     Union[str, Any]=None   ,):
									UpperCAmelCase__					=							parent
									UpperCAmelCase__					=							batch_size
									UpperCAmelCase__					=							decoder_seq_length
									# For common tests
									UpperCAmelCase__					=							self.decoder_seq_length
									UpperCAmelCase__					=							is_training
									UpperCAmelCase__					=							use_attention_mask
									UpperCAmelCase__					=							use_labels

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

									UpperCAmelCase__					=							None
									UpperCAmelCase__					=							decoder_seq_length
									UpperCAmelCase__					=							2
									UpperCAmelCase__					=							1







					def 		__lowerCAmelCase						(    self       :     Union[str, Any]      ):
									UpperCAmelCase__					=							ids_tensor([self.batch_size, self.decoder_seq_length]   ,self.vocab_size      )

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

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

									UpperCAmelCase__					=							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 		__lowerCAmelCase						(    self       :     Tuple   ,lowerCamelCase__       :     Union[str, Any]   ,lowerCamelCase__       :     Any   ,lowerCamelCase__       :     Optional[Any]   ,lowerCamelCase__       :     Optional[int]   ,):
									UpperCAmelCase__					=							True
									UpperCAmelCase__					=							SpeechaTextaDecoder(config=lowerCamelCase__      ).to(lowerCamelCase__      ).eval()
									UpperCAmelCase__					=							input_ids[:2]

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

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

									UpperCAmelCase__					=							outputs['past_key_values']

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

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

									print(lowerCamelCase__      )

									UpperCAmelCase__					=							model(lowerCamelCase__      )['last_hidden_state']
									UpperCAmelCase__					=							model(lowerCamelCase__   ,past_key_values=lowerCamelCase__      )['last_hidden_state']

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

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







					def 		__lowerCAmelCase						(    self       :     Optional[int]      ):
									UpperCAmelCase__					=							self.prepare_config_and_inputs()
									(
									    (
									    UpperCAmelCase__
									)				,     (
									    UpperCAmelCase__
									)				,     (
									    UpperCAmelCase__
									)				,     (
									    UpperCAmelCase__
									)				,     
									)					=							config_and_inputs

									UpperCAmelCase__					=							{
									    'input_ids': input_ids,
									    'attention_mask': attention_mask,
									}
									return config, inputs_dict






@require_torch
class     snake_case	(			__UpperCAmelCase				,   __UpperCAmelCase				,   __UpperCAmelCase				,   unittest.TestCase    ):




					"""simple docstring"""

					snake_case__       =			(SpeechaTextaDecoder, SpeechaTextaForCausalLM) if is_torch_available() else ()
					snake_case__       =			(SpeechaTextaForCausalLM,) if is_torch_available() else ()
					snake_case__       =			{"text-generation": SpeechaTextaForCausalLM} if is_torch_available() else {}
					snake_case__       =			True
					snake_case__       =			False







					def 		__lowerCAmelCase						(    self       :     Tuple   ,):
									UpperCAmelCase__					=							SpeechaTextaStandaloneDecoderModelTester(self   ,is_training=lowerCamelCase__      )
									UpperCAmelCase__					=							ConfigTester(self   ,config_class=lowerCamelCase__      )







					def 		__lowerCAmelCase						(    self       :     Optional[int]      ):
									pass







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







					def 		__lowerCAmelCase						(    self       :     List[Any]      ):
									pass







					def 		__lowerCAmelCase						(    self       :     Any      ):
									self.config_tester.run_common_tests()







					def 		__lowerCAmelCase						(    self       :     int      ):
									UpperCAmelCase__					=							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_decoder_model_past(*lowerCamelCase__      )







					def 		__lowerCAmelCase						(    self       :     int      ):
									return




"""simple docstring"""






import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


lowerCAmelCase__  :  List[Any]											=     '\nHugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.\n\nIn March 2021, Hugging Face raised $40 million in a Series B funding round.[3]\n\nOn April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]\n'
class     snake_case	(			unittest.TestCase				,   __UpperCAmelCase    ):




					"""simple docstring"""

					def 		__lowerCAmelCase						(    self       :     Tuple      ):
									UpperCAmelCase__					=							load_tool('summarization'      )
									self.tool.setup()
									UpperCAmelCase__					=							load_tool('summarization'   ,remote=lowerCamelCase__      )







					def 		__lowerCAmelCase						(    self       :     Union[str, Any]      ):
									UpperCAmelCase__					=							self.tool(lowerCamelCase__      )
									self.assertEqual(
									    lowerCamelCase__   ,'Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'   ,)







					def 		__lowerCAmelCase						(    self       :     Tuple      ):
									UpperCAmelCase__					=							self.remote_tool(lowerCamelCase__      )
									self.assertEqual(
									    lowerCamelCase__   ,'Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'   ,)







					def 		__lowerCAmelCase						(    self       :     List[Any]      ):
									UpperCAmelCase__					=							self.tool(text=lowerCamelCase__      )
									self.assertEqual(
									    lowerCamelCase__   ,'Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'   ,)







					def 		__lowerCAmelCase						(    self       :     Tuple      ):
									UpperCAmelCase__					=							self.remote_tool(text=lowerCamelCase__      )
									self.assertEqual(
									    lowerCamelCase__   ,'Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'   ,)



