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   lowerCamelCase_							:
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  					def __init__(					self,						__UpperCamelCase,						__UpperCamelCase=99,						__UpperCamelCase=13,						__UpperCamelCase=16,						__UpperCamelCase=7,						__UpperCamelCase=True,						__UpperCamelCase=True,						__UpperCamelCase=True,						__UpperCamelCase=False,						__UpperCamelCase=True,						__UpperCamelCase=2,						__UpperCamelCase=32,						__UpperCamelCase=4,						__UpperCamelCase=4,						__UpperCamelCase=30,						__UpperCamelCase=0,						__UpperCamelCase=1,						__UpperCamelCase=2,						__UpperCamelCase=None,						):
  							_snake_case			 = parent
  							_snake_case			 = batch_size
  							_snake_case			 = decoder_seq_length
  							# For common tests
  							_snake_case			 = self.decoder_seq_length
  							_snake_case			 = is_training
  							_snake_case			 = use_attention_mask
  							_snake_case			 = use_labels
  
  							_snake_case			 = vocab_size
  							_snake_case			 = d_model
  							_snake_case			 = d_model
  							_snake_case			 = decoder_layers
  							_snake_case			 = decoder_layers
  							_snake_case			 = decoder_ffn_dim
  							_snake_case			 = decoder_attention_heads
  							_snake_case			 = decoder_attention_heads
  							_snake_case			 = eos_token_id
  							_snake_case			 = bos_token_id
  							_snake_case			 = pad_token_id
  							_snake_case			 = decoder_start_token_id
  							_snake_case			 = use_cache
  							_snake_case			 = max_position_embeddings
  
  							_snake_case			 = None
  							_snake_case			 = decoder_seq_length
  							_snake_case			 = 2
  							_snake_case			 = 1
  
  
  
  
  
  
  					def        __SCREAMING_SNAKE_CASE			(					self				):
  							_snake_case			 = ids_tensor([self.batch_size, self.decoder_seq_length],						self.vocab_size				)
  
  							_snake_case			 = None
  							if self.use_attention_mask:
  									_snake_case			 = ids_tensor([self.batch_size, self.decoder_seq_length],						vocab_size=2				)
  
  							_snake_case			 = None
  							if self.use_labels:
  									_snake_case			 = ids_tensor([self.batch_size, self.decoder_seq_length],						self.vocab_size				)
  
  							_snake_case			 = 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        __SCREAMING_SNAKE_CASE			(					self,						__UpperCamelCase,						__UpperCamelCase,						__UpperCamelCase,						__UpperCamelCase,						):
  							_snake_case			 = True
  							_snake_case			 = SpeechaTextaDecoder(config=__UpperCamelCase				).to(__UpperCamelCase				).eval()
  							_snake_case			 = input_ids[:2]
  
  							input_ids[input_ids == 0] += 1
  							# first forward pass
  							_snake_case			 = model(__UpperCamelCase,						use_cache=__UpperCamelCase				)
  							_snake_case			 = model(__UpperCamelCase				)
  							_snake_case			 = model(__UpperCamelCase,						use_cache=__UpperCamelCase				)
  
  							self.parent.assertTrue(len(__UpperCamelCase				) == len(__UpperCamelCase				)				)
  							self.parent.assertTrue(len(__UpperCamelCase				) == len(__UpperCamelCase				) + 1				)
  
  							_snake_case			 = outputs["past_key_values"]
  
  							# create hypothetical next token and extent to next_input_ids
  							_snake_case			 = ids_tensor((2, 1),						config.vocab_size - 1				) + 1
  
  							# append to next input_ids and
  							_snake_case			 = torch.cat([input_ids, next_tokens],						dim=-1				)
  
  							print(__UpperCamelCase				)
  
  							_snake_case			 = model(__UpperCamelCase				)["last_hidden_state"]
  							_snake_case			 = model(__UpperCamelCase,						past_key_values=__UpperCamelCase				)["last_hidden_state"]
  
  							# select random slice
  							_snake_case			 = ids_tensor((1,),						output_from_past.shape[-1]				).item()
  							_snake_case			 = output_from_no_past[:, next_input_ids.shape[-1] - 1, random_slice_idx].detach()
  							_snake_case			 = output_from_past[:, 0, random_slice_idx].detach()
  
  							# test that outputs are equal for slice
  							assert torch.allclose(__UpperCamelCase,						__UpperCamelCase,						atol=1E-3				)
  
  
  
  
  
  
  					def        __SCREAMING_SNAKE_CASE			(					self				):
  							_snake_case			 = self.prepare_config_and_inputs()
  							(
  							    (
  							    _snake_case
  							) ,					(
  							    _snake_case
  							) ,					(
  							    _snake_case
  							) ,					(
  							    _snake_case
  							) ,					
  							)			 = config_and_inputs
  
  							_snake_case			 = {
  							    "input_ids": input_ids,
  							    "attention_mask": attention_mask,
  							}
  							return config, inputs_dict
  
  
  
  
  
  @require_torch
  class   lowerCamelCase_							( UpperCAmelCase_, UpperCAmelCase_, UpperCAmelCase_, unittest.TestCase							):
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  					lowercase__					=				(SpeechaTextaDecoder, SpeechaTextaForCausalLM) if is_torch_available() else ()
  					lowercase__					=				(SpeechaTextaForCausalLM,) if is_torch_available() else ()
  					lowercase__					=				{"""text-generation""": SpeechaTextaForCausalLM} if is_torch_available() else {}
  					lowercase__					=				True
  					lowercase__					=				False
  
  
  
  
  
  
  					def        __SCREAMING_SNAKE_CASE			(					self,						):
  							_snake_case			 = SpeechaTextaStandaloneDecoderModelTester(self,						is_training=__UpperCamelCase				)
  							_snake_case			 = ConfigTester(self,						config_class=__UpperCamelCase				)
  
  
  
  
  
  
  					def        __SCREAMING_SNAKE_CASE			(					self				):
  							pass
  
  
  
  
  
  
  					def        __SCREAMING_SNAKE_CASE			(					self				):
  							pass
  
  
  
  
  
  
  					def        __SCREAMING_SNAKE_CASE			(					self				):
  							pass
  
  
  
  
  
  
  					def        __SCREAMING_SNAKE_CASE			(					self				):
  							self.config_tester.run_common_tests()
  
  
  
  
  
  
  					def        __SCREAMING_SNAKE_CASE			(					self				):
  							_snake_case			 = self.model_tester.prepare_config_and_inputs()
  							self.model_tester.create_and_check_decoder_model_past(*__UpperCamelCase				)
  
  
  
  
  
  
  					def        __SCREAMING_SNAKE_CASE			(					self				):
  							return
  
  
  
  
  
  
style_context: 
  
  
  
  
  '''simple docstring'''
  
  
  
  
  
  
  
  import json
  from typing import List, Optional, Tuple
  
  from tokenizers import normalizers
  
  from ...tokenization_utils import AddedToken
  from ...tokenization_utils_fast import PreTrainedTokenizerFast
  from ...utils import logging
  from .tokenization_mpnet import MPNetTokenizer
  
  
  _lowerCamelCase							:		int										=						logging.get_logger(__name__)
  
  _lowerCamelCase							:		Any										=						{'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}
  
  _lowerCamelCase							:		Dict										=						{
      'vocab_file': {
          'microsoft/mpnet-base': 'https://huggingface.co/microsoft/mpnet-base/resolve/main/vocab.txt',
      },
      'tokenizer_file': {
          'microsoft/mpnet-base': 'https://huggingface.co/microsoft/mpnet-base/resolve/main/tokenizer.json',
      },
  }
  
  _lowerCamelCase							:		List[str]										=						{
      'microsoft/mpnet-base': 512,
  }
  
  _lowerCamelCase							:		Tuple										=						{
      'microsoft/mpnet-base': {'do_lower_case': True},
  }
  
  
  
  
  
  class   lowerCamelCase_							( UpperCAmelCase_							):
  
  
  
  
  					'''simple docstring'''
  
  
  
  
  
  
  					lowercase__					=				VOCAB_FILES_NAMES
  					lowercase__					=				PRETRAINED_VOCAB_FILES_MAP
  					lowercase__					=				PRETRAINED_INIT_CONFIGURATION
  					lowercase__					=				PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  					lowercase__					=				MPNetTokenizer
  					lowercase__					=				["""input_ids""", """attention_mask"""]
  
  
  
  
  
  
  					def __init__(					self,						__UpperCamelCase=None,						__UpperCamelCase=None,						__UpperCamelCase=True,						__UpperCamelCase="<s>",						__UpperCamelCase="</s>",						__UpperCamelCase="</s>",						__UpperCamelCase="<s>",						__UpperCamelCase="[UNK]",						__UpperCamelCase="<pad>",						__UpperCamelCase="<mask>",						__UpperCamelCase=True,						__UpperCamelCase=None,						**__UpperCamelCase,						):
  							super().__init__(
  							    __UpperCamelCase,						tokenizer_file=__UpperCamelCase,						do_lower_case=__UpperCamelCase,						bos_token=__UpperCamelCase,						eos_token=__UpperCamelCase,						sep_token=__UpperCamelCase,						cls_token=__UpperCamelCase,						unk_token=__UpperCamelCase,						pad_token=__UpperCamelCase,						mask_token=__UpperCamelCase,						tokenize_chinese_chars=__UpperCamelCase,						strip_accents=__UpperCamelCase,						**__UpperCamelCase,						)
  
  							_snake_case			 = json.loads(self.backend_tokenizer.normalizer.__getstate__()				)
  							if (
  							    pre_tok_state.get("lowercase",						__UpperCamelCase				) != do_lower_case
  							    or pre_tok_state.get("strip_accents",						__UpperCamelCase				) != strip_accents
  							):
  									_snake_case			 = getattr(__UpperCamelCase,						pre_tok_state.pop("type"				)				)
  									_snake_case			 = do_lower_case
  									_snake_case			 = strip_accents
  									_snake_case			 = pre_tok_class(**__UpperCamelCase				)
  
  							_snake_case			 = do_lower_case
  
  
  
  
  
  
  					@property
  					def        __SCREAMING_SNAKE_CASE			(					self				):
  							if self._mask_token is None:
  									if self.verbose:
  											logger.error("Using mask_token, but it is not set yet."				)
  									return None
  							return str(self._mask_token				)
  
  
  
  
  
  
  					@mask_token.setter
  					def        __SCREAMING_SNAKE_CASE			(					self,						__UpperCamelCase				):
  							_snake_case			 = AddedToken(__UpperCamelCase,						lstrip=__UpperCamelCase,						rstrip=__UpperCamelCase				) if isinstance(__UpperCamelCase,						__UpperCamelCase				) else value
  							_snake_case			 = value
  
  
  
  
  
  
  					def        __SCREAMING_SNAKE_CASE			(					self,						__UpperCamelCase,						__UpperCamelCase=None				):
  							_snake_case			 = [self.bos_token_id] + token_ids_a + [self.eos_token_id]
  							if token_ids_a is None:
  									return output
  
  							return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]
  
  
  
  
  
  
  					def        __SCREAMING_SNAKE_CASE			(					self,						__UpperCamelCase,						__UpperCamelCase = None				):
  							_snake_case			 = [self.sep_token_id]
  							_snake_case			 = [self.cls_token_id]
  
  							if token_ids_a is None:
  									return len(cls + token_ids_a + sep				) * [0]
  							return len(cls + token_ids_a + sep + sep + token_ids_a + sep				) * [0]
  
  
  
  
  
  
  					def        __SCREAMING_SNAKE_CASE			(					self,						__UpperCamelCase,						__UpperCamelCase = None				):
  							_snake_case			 = self._tokenizer.model.save(__UpperCamelCase,						name=__UpperCamelCase				)
  							return tuple(__UpperCamelCase				)
  
  
  
  
  
  