code: 
  """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 A_			:
  
  
  
  
    '''simple docstring'''
  
  
  
  
  
  
  
    def __init__(	self       ,     lowercase_       ,     lowercase_=99       ,     lowercase_=13       ,     lowercase_=16       ,     lowercase_=7       ,     lowercase_=True       ,     lowercase_=True       ,     lowercase_=True       ,     lowercase_=False       ,     lowercase_=True       ,     lowercase_=2       ,     lowercase_=32       ,     lowercase_=4       ,     lowercase_=4       ,     lowercase_=30       ,     lowercase_=0       ,     lowercase_=1       ,     lowercase_=2       ,     lowercase_=None       ,     ):
  
       """simple docstring"""
       UpperCAmelCase_      :      Dict      =					parent
       UpperCAmelCase_      :      Optional[Any]      =					batch_size
       UpperCAmelCase_      :      Optional[int]      =					decoder_seq_length
       # For common tests
       UpperCAmelCase_      :      Any      =					self.decoder_seq_length
       UpperCAmelCase_      :      Optional[Any]      =					is_training
       UpperCAmelCase_      :      List[str]      =					use_attention_mask
       UpperCAmelCase_      :      List[str]      =					use_labels
  
       UpperCAmelCase_      :      str      =					vocab_size
       UpperCAmelCase_      :      str      =					d_model
       UpperCAmelCase_      :      List[Any]      =					d_model
       UpperCAmelCase_      :      List[str]      =					decoder_layers
       UpperCAmelCase_      :      List[str]      =					decoder_layers
       UpperCAmelCase_      :      List[Any]      =					decoder_ffn_dim
       UpperCAmelCase_      :      Dict      =					decoder_attention_heads
       UpperCAmelCase_      :      Optional[Any]      =					decoder_attention_heads
       UpperCAmelCase_      :      str      =					eos_token_id
       UpperCAmelCase_      :      Optional[int]      =					bos_token_id
       UpperCAmelCase_      :      List[Any]      =					pad_token_id
       UpperCAmelCase_      :      Optional[Any]      =					decoder_start_token_id
       UpperCAmelCase_      :      List[Any]      =					use_cache
       UpperCAmelCase_      :      Dict      =					max_position_embeddings
  
       UpperCAmelCase_      :      Any      =					None
       UpperCAmelCase_      :      int      =					decoder_seq_length
       UpperCAmelCase_      :      List[str]      =					2
       UpperCAmelCase_      :      Optional[Any]      =					1
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Dict      =					ids_tensor([self.batch_size, self.decoder_seq_length]       ,     self.vocab_size						)
  
       UpperCAmelCase_      :      Any      =					None
       if self.use_attention_mask:
          UpperCAmelCase_      :      int      =					ids_tensor([self.batch_size, self.decoder_seq_length]       ,     vocab_size=2						)
  
       UpperCAmelCase_      :      List[str]      =					None
       if self.use_labels:
          UpperCAmelCase_      :      Dict      =					ids_tensor([self.batch_size, self.decoder_seq_length]       ,     self.vocab_size						)
  
       UpperCAmelCase_      :      Tuple      =					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  UpperCamelCase__      (	self       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     ):
  
       """simple docstring"""
       UpperCAmelCase_      :      int      =					True
       UpperCAmelCase_      :      Optional[int]      =					SpeechaTextaDecoder(config=lowercase_						).to(lowercase_						).eval()
       UpperCAmelCase_      :      Dict      =					input_ids[:2]
  
       input_ids[input_ids == 0] += 1
       # first forward pass
       UpperCAmelCase_      :      int      =					model(lowercase_       ,     use_cache=lowercase_						)
       UpperCAmelCase_      :      str      =					model(lowercase_						)
       UpperCAmelCase_      :      List[Any]      =					model(lowercase_       ,     use_cache=lowercase_						)
  
       self.parent.assertTrue(len(lowercase_						) == len(lowercase_						)						)
       self.parent.assertTrue(len(lowercase_						) == len(lowercase_						) + 1						)
  
       UpperCAmelCase_      :      Any      =					outputs["past_key_values"]
  
       # create hypothetical next token and extent to next_input_ids
       UpperCAmelCase_      :      Union[str, Any]      =					ids_tensor((2, 1)       ,     config.vocab_size - 1						) + 1
  
       # append to next input_ids and
       UpperCAmelCase_      :      Union[str, Any]      =					torch.cat([input_ids, next_tokens]       ,     dim=-1						)
  
       print(lowercase_						)
  
       UpperCAmelCase_      :      int      =					model(lowercase_						)["last_hidden_state"]
       UpperCAmelCase_      :      Any      =					model(lowercase_       ,     past_key_values=lowercase_						)["last_hidden_state"]
  
       # select random slice
       UpperCAmelCase_      :      Any      =					ids_tensor((1,)       ,     output_from_past.shape[-1]						).item()
       UpperCAmelCase_      :      Any      =					output_from_no_past[:, next_input_ids.shape[-1] - 1, random_slice_idx].detach()
       UpperCAmelCase_      :      str      =					output_from_past[:, 0, random_slice_idx].detach()
  
       # test that outputs are equal for slice
       assert torch.allclose(lowercase_       ,     lowercase_       ,     atol=1E-3						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Optional[int]      =					self.prepare_config_and_inputs()
       (
           (
           UpperCAmelCase_
       )  ,     (
           UpperCAmelCase_
       )  ,     (
           UpperCAmelCase_
       )  ,     (
           UpperCAmelCase_
       )  ,     
       )      :      Optional[Any]      =					config_and_inputs
  
       UpperCAmelCase_      :      str      =					{
           "input_ids": input_ids,
           "attention_mask": attention_mask,
       }
       return config, inputs_dict
  
  
  
  
  @require_torch
  class A_			(lowercase__       ,lowercase__       ,lowercase__       ,unittest.TestCase   ):
  
  
  
  
    '''simple docstring'''
    SCREAMING_SNAKE_CASE__    :		str						  =	(SpeechaTextaDecoder, SpeechaTextaForCausalLM) if is_torch_available() else ()
    SCREAMING_SNAKE_CASE__    :		List[Any]						  =	(SpeechaTextaForCausalLM,) if is_torch_available() else ()
    SCREAMING_SNAKE_CASE__    :		Optional[int]						  =	{"""text-generation""": SpeechaTextaForCausalLM} if is_torch_available() else {}
    SCREAMING_SNAKE_CASE__    :		Optional[int]						  =	True
    SCREAMING_SNAKE_CASE__    :		str						  =	False
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self       ,     ):
  
       """simple docstring"""
       UpperCAmelCase_      :      List[str]      =					SpeechaTextaStandaloneDecoderModelTester(self       ,     is_training=lowercase_						)
       UpperCAmelCase_      :      Optional[Any]      =					ConfigTester(self       ,     config_class=lowercase_						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       pass
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       pass
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       pass
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       self.config_tester.run_common_tests()
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      int      =					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_decoder_model_past(*lowercase_						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       return
  
  
  
style_context: 
  """simple docstring"""
  
  
  
  
  
  from .hash_table import HashTable
  
  
  class A_			(lowercase__   ):
  
  
  
  
    '''simple docstring'''
  
  
  
  
  
  
  
    def __init__(	self       ,     *lowercase_       ,     **lowercase_						):
  
       """simple docstring"""
       super().__init__(*lowercase_       ,     **lowercase_						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self       ,     lowercase_       ,     lowercase_=None						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Tuple      =					1
       UpperCAmelCase_      :      List[str]      =					self.hash_function(key + i * i						)
  
       while self.values[new_key] is not None and self.values[new_key] != key:
          i += 1
          UpperCAmelCase_      :      List[Any]      =					(
              self.hash_function(key + i * i						)
              if not self.balanced_factor() >= self.lim_charge
              else None
          )
  
          if new_key is None:
             break
  
       return new_key
  
  
  