code: 
  
  
  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					:
  
  
         def __init__(self   ,       lowerCAmelCase   ,       lowerCAmelCase=9_9   ,       lowerCAmelCase=1_3   ,       lowerCAmelCase=1_6   ,       lowerCAmelCase=7   ,       lowerCAmelCase=True   ,       lowerCAmelCase=True   ,       lowerCAmelCase=True   ,       lowerCAmelCase=False   ,       lowerCAmelCase=True   ,       lowerCAmelCase=2   ,       lowerCAmelCase=3_2   ,       lowerCAmelCase=4   ,       lowerCAmelCase=4   ,       lowerCAmelCase=3_0   ,       lowerCAmelCase=0   ,       lowerCAmelCase=1   ,       lowerCAmelCase=2   ,       lowerCAmelCase=None   ,       ):
           __lowercase=    parent
           __lowercase=    batch_size
           __lowercase=    decoder_seq_length
           # For common tests
           __lowercase=    self.decoder_seq_length
           __lowercase=    is_training
           __lowercase=    use_attention_mask
           __lowercase=    use_labels
  
           __lowercase=    vocab_size
           __lowercase=    d_model
           __lowercase=    d_model
           __lowercase=    decoder_layers
           __lowercase=    decoder_layers
           __lowercase=    decoder_ffn_dim
           __lowercase=    decoder_attention_heads
           __lowercase=    decoder_attention_heads
           __lowercase=    eos_token_id
           __lowercase=    bos_token_id
           __lowercase=    pad_token_id
           __lowercase=    decoder_start_token_id
           __lowercase=    use_cache
           __lowercase=    max_position_embeddings
  
           __lowercase=    None
           __lowercase=    decoder_seq_length
           __lowercase=    2
           __lowercase=    1
  
  
         def     _A (self      ):
           __lowercase=    ids_tensor([self.batch_size, self.decoder_seq_length]   ,       self.vocab_size      )
  
           __lowercase=    None
           if self.use_attention_mask:
             __lowercase=    ids_tensor([self.batch_size, self.decoder_seq_length]   ,       vocab_size=2      )
  
           __lowercase=    None
           if self.use_labels:
             __lowercase=    ids_tensor([self.batch_size, self.decoder_seq_length]   ,       self.vocab_size      )
  
           __lowercase=    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   ,       lowerCAmelCase   ,       lowerCAmelCase   ,       lowerCAmelCase   ,       lowerCAmelCase   ,       ):
           __lowercase=    True
           __lowercase=    SpeechaTextaDecoder(config=__lowerCamelCase      ).to(__lowerCamelCase      ).eval()
           __lowercase=    input_ids[:2]
  
           input_ids[input_ids == 0] += 1
           # first forward pass
           __lowercase=    model(__lowerCamelCase   ,       use_cache=__lowerCamelCase      )
           __lowercase=    model(__lowerCamelCase      )
           __lowercase=    model(__lowerCamelCase   ,       use_cache=__lowerCamelCase      )
  
           self.parent.assertTrue(len(__lowerCamelCase      ) == len(__lowerCamelCase      )      )
           self.parent.assertTrue(len(__lowerCamelCase      ) == len(__lowerCamelCase      ) + 1      )
  
           __lowercase=    outputs["past_key_values"]
  
           # create hypothetical next token and extent to next_input_ids
           __lowercase=    ids_tensor((2, 1)   ,       config.vocab_size - 1      ) + 1
  
           # append to next input_ids and
           __lowercase=    torch.cat([input_ids, next_tokens]   ,       dim=-1      )
  
           print(__lowerCamelCase      )
  
           __lowercase=    model(__lowerCamelCase      )["last_hidden_state"]
           __lowercase=    model(__lowerCamelCase   ,       past_key_values=__lowerCamelCase      )["last_hidden_state"]
  
           # select random slice
           __lowercase=    ids_tensor((1,)   ,       output_from_past.shape[-1]      ).item()
           __lowercase=    output_from_no_past[:, next_input_ids.shape[-1] - 1, random_slice_idx].detach()
           __lowercase=    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      ):
           __lowercase=    self.prepare_config_and_inputs()
           (
               __lowercase    
           )=    config_and_inputs
  
           __lowercase=    {
               "input_ids": input_ids,
               "attention_mask": attention_mask,
           }
           return config, inputs_dict
  
  
  
  
  
  @require_torch
  class    A					(     A_      ,       A_      ,       A_      ,       unittest.TestCase				):
         UpperCamelCase_     :							List[Any] =(SpeechaTextaDecoder, SpeechaTextaForCausalLM) if is_torch_available() else ()
         UpperCamelCase_     :							List[str] =(SpeechaTextaForCausalLM,) if is_torch_available() else ()
         UpperCamelCase_     :							Union[str, Any] ={'''text-generation''': SpeechaTextaForCausalLM} if is_torch_available() else {}
         UpperCamelCase_     :							Union[str, Any] =True
         UpperCamelCase_     :							str =False
  
  
         def     _A (self   ,       ):
           __lowercase=    SpeechaTextaStandaloneDecoderModelTester(self   ,       is_training=__lowerCamelCase      )
           __lowercase=    ConfigTester(self   ,       config_class=__lowerCamelCase      )
  
  
         def     _A (self      ):
           pass
  
  
         def     _A (self      ):
           pass
  
  
         def     _A (self      ):
           pass
  
  
         def     _A (self      ):
           self.config_tester.run_common_tests()
  
  
         def     _A (self      ):
           __lowercase=    self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_decoder_model_past(*__lowerCamelCase      )
  
  
  
  
  
  
  
         def     _A (self      ):
           return
  
  
  
  
  
  
  
style_context: 
  
  
  from typing import Dict, List, Optional, Tuple
  
  from ...tokenization_utils import AddedToken, PreTrainedTokenizer
  from ...utils import logging
  
  
  lowerCAmelCase					 =	logging.get_logger(__name__)
  
  
  
  
  
  class    A					(     A_				):
  							UpperCamelCase_     :							Any =['''input_ids''', '''attention_mask''']
  
  
  							def __init__(self   ,       lowerCAmelCase="[PAD]"   ,       lowerCAmelCase="[BOS]"   ,       lowerCAmelCase="[EOS]"   ,       lowerCAmelCase="[MASK]"   ,       lowerCAmelCase="[CLS]"   ,       lowerCAmelCase="[SEP]"   ,       lowerCAmelCase=2_0_4_8   ,       **lowerCAmelCase   ,       ):
  									__lowercase=    AddedToken(lowerCAmelCase   ,       lstrip=lowerCAmelCase   ,       rstrip=lowerCAmelCase      ) if isinstance(lowerCAmelCase   ,       lowerCAmelCase      ) else pad_token
  									__lowercase=    AddedToken(lowerCAmelCase   ,       lstrip=lowerCAmelCase   ,       rstrip=lowerCAmelCase      ) if isinstance(lowerCAmelCase   ,       lowerCAmelCase      ) else bos_token
  									__lowercase=    AddedToken(lowerCAmelCase   ,       lstrip=lowerCAmelCase   ,       rstrip=lowerCAmelCase      ) if isinstance(lowerCAmelCase   ,       lowerCAmelCase      ) else eos_token
  									__lowercase=    AddedToken(lowerCAmelCase   ,       lstrip=lowerCAmelCase   ,       rstrip=lowerCAmelCase      ) if isinstance(lowerCAmelCase   ,       lowerCAmelCase      ) else mask_token
  									__lowercase=    AddedToken(lowerCAmelCase   ,       lstrip=lowerCAmelCase   ,       rstrip=lowerCAmelCase      ) if isinstance(lowerCAmelCase   ,       lowerCAmelCase      ) else cls_token
  									__lowercase=    AddedToken(lowerCAmelCase   ,       lstrip=lowerCAmelCase   ,       rstrip=lowerCAmelCase      ) if isinstance(lowerCAmelCase   ,       lowerCAmelCase      ) else sep_token
  
  									super().__init__(
  									    pad_token=lowerCAmelCase   ,       bos_token=lowerCAmelCase   ,       eos_token=lowerCAmelCase   ,       mask_token=lowerCAmelCase   ,       cls_token=lowerCAmelCase   ,       sep_token=lowerCAmelCase   ,       model_max_length=lowerCAmelCase   ,       **lowerCAmelCase   ,       )
  
  									__lowercase=    2**8  # utf is 8 bits
  
  									# define special tokens dict
  									__lowercase=    {
  									    self.pad_token: 0,
  									    self.bos_token: 1,
  									    self.eos_token: 2,
  									    self.mask_token: 3,
  									    self.cls_token: 4,
  									    self.sep_token: 5,
  									}
  									__lowercase=    len(self.special_tokens_encoder      )
  									__lowercase=    {v: k for k, v in self.special_tokens_encoder.items()}
  
  
  							def     _A (self      ):
  									__lowercase=    self.special_tokens_encoder.copy()
  									vocab.update(self.added_tokens_encoder      )
  									for i in range(self._utf_vocab_size      ):
  											__lowercase=    chr(lowerCAmelCase      )
  											__lowercase=    i + len(self.special_tokens_encoder      )
  									return vocab
  
  
  							@property
  							def     _A (self      ):
  									return self._utf_vocab_size + self._num_special_tokens
  
  
  							def     _A (self   ,       lowerCAmelCase   ,       lowerCAmelCase = None   ,       lowerCAmelCase = False      ):
  									if already_has_special_tokens:
  											return super().get_special_tokens_mask(
  											    token_ids_a=lowerCAmelCase   ,       token_ids_a=lowerCAmelCase   ,       already_has_special_tokens=lowerCAmelCase      )
  
  									# normal case: some special tokens
  									if token_ids_a is None:
  											return [1] + [0] * len(lowerCAmelCase      ) + [1]
  									return [1] + ([0] * len(lowerCAmelCase      )) + [1] + ([0] * len(lowerCAmelCase      )) + [1]
  
  
  							def     _A (self   ,       lowerCAmelCase   ,       lowerCAmelCase = None      ):
  									if token_ids_a is None:
  											return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
  									else:
  											return [self.cls_token_id] + token_ids_a + [self.sep_token_id] + token_ids_a + [self.sep_token_id]
  
  
  							def     _A (self   ,       lowerCAmelCase      ):
  									__lowercase=    [chr(lowerCAmelCase      ) for i in text.encode('utf-8'      )]
  									return tokens
  
  
  							def     _A (self   ,       lowerCAmelCase      ):
  									if token in self.special_tokens_encoder:
  											__lowercase=    self.special_tokens_encoder[token]
  									elif token in self.added_tokens_encoder:
  											__lowercase=    self.added_tokens_encoder[token]
  									elif len(lowerCAmelCase      ) != 1:
  											__lowercase=    self.unk_token_id
  									else:
  											__lowercase=    ord(lowerCAmelCase      ) + self._num_special_tokens
  									return token_id
  
  
  							def     _A (self   ,       lowerCAmelCase      ):
  									if index in self.special_tokens_decoder:
  											__lowercase=    self.special_tokens_decoder[index]
  									elif index in self.added_tokens_decoder:
  											__lowercase=    self.added_tokens_decoder[index]
  									else:
  											__lowercase=    chr(index - self._num_special_tokens      )
  									return token
  
  
  							def     _A (self   ,       lowerCAmelCase      ):
  									__lowercase=    B''
  									for token in tokens:
  											if token in self.special_tokens_decoder:
  													__lowercase=    self.special_tokens_decoder[token].encode('utf-8'      )
  											elif token in self.added_tokens_decoder:
  													__lowercase=    self.special_tokens_decoder[token].encode('utf-8'      )
  											elif token in self.special_tokens_encoder:
  													__lowercase=    token.encode('utf-8'      )
  											elif token in self.added_tokens_encoder:
  													__lowercase=    token.encode('utf-8'      )
  											else:
  													__lowercase=    bytes([ord(lowerCAmelCase      )]      )
  											bstring += tok_string
  									__lowercase=    bstring.decode('utf-8'   ,       errors='replace'      )
  									return string
  
  
  
  
  
  
  
  							def     _A (self   ,       lowerCAmelCase   ,       lowerCAmelCase = None      ):
  									return ()
  
  
  
  
  
  
  