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   lowerCAmelCase__ :
  
  
  
  
       '''simple docstring'''
  
  
       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				,		)    ->       Union[str, Any]:
              _A   : Optional[Any]       					=				parent
              _A   : Optional[Any]       					=				batch_size
              _A   : Tuple       					=				decoder_seq_length
              # For common tests
              _A   : int       					=				self.decoder_seq_length
              _A   : Union[str, Any]       					=				is_training
              _A   : List[str]       					=				use_attention_mask
              _A   : List[Any]       					=				use_labels
  
              _A   : Tuple       					=				vocab_size
              _A   : int       					=				d_model
              _A   : Optional[Any]       					=				d_model
              _A   : Any       					=				decoder_layers
              _A   : Dict       					=				decoder_layers
              _A   : List[Any]       					=				decoder_ffn_dim
              _A   : List[Any]       					=				decoder_attention_heads
              _A   : Union[str, Any]       					=				decoder_attention_heads
              _A   : Any       					=				eos_token_id
              _A   : List[str]       					=				bos_token_id
              _A   : str       					=				pad_token_id
              _A   : List[str]       					=				decoder_start_token_id
              _A   : List[Any]       					=				use_cache
              _A   : Dict       					=				max_position_embeddings
  
              _A   : Optional[Any]       					=				None
              _A   : Tuple       					=				decoder_seq_length
              _A   : Optional[int]       					=				2
              _A   : Tuple       					=				1
  
  
       def 				_lowerCamelCase				(		self)    ->       List[str]:
              _A   : Any       					=				ids_tensor([self.batch_size, self.decoder_seq_length]				,		self.vocab_size)
  
              _A   : List[Any]       					=				None
              if self.use_attention_mask:
                     _A   : List[Any]       					=				ids_tensor([self.batch_size, self.decoder_seq_length]				,		vocab_size=2)
  
              _A   : int       					=				None
              if self.use_labels:
                     _A   : int       					=				ids_tensor([self.batch_size, self.decoder_seq_length]				,		self.vocab_size)
  
              _A   : str       					=				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				,		__lowerCamelCase				,		__lowerCamelCase				,		__lowerCamelCase				,		__lowerCamelCase				,		)    ->       Optional[Any]:
              _A   : Union[str, Any]       					=				True
              _A   : Any       					=				SpeechaTextaDecoder(config=__lowerCamelCase).to(__lowerCamelCase).eval()
              _A   : Dict       					=				input_ids[:2]
  
              input_ids[input_ids == 0] += 1
              # first forward pass
              _A   : List[str]       					=				model(__lowerCamelCase				,		use_cache=__lowerCamelCase)
              _A   : Dict       					=				model(__lowerCamelCase)
              _A   : Union[str, Any]       					=				model(__lowerCamelCase				,		use_cache=__lowerCamelCase)
  
              self.parent.assertTrue(len(__lowerCamelCase) == len(__lowerCamelCase))
              self.parent.assertTrue(len(__lowerCamelCase) == len(__lowerCamelCase) + 1)
  
              _A   : Dict       					=				outputs["past_key_values"]
  
              # create hypothetical next token and extent to next_input_ids
              _A   : Union[str, Any]       					=				ids_tensor((2, 1)				,		config.vocab_size - 1) + 1
  
              # append to next input_ids and
              _A   : List[str]       					=				torch.cat([input_ids, next_tokens]				,		dim=-1)
  
              print(__lowerCamelCase)
  
              _A   : Tuple       					=				model(__lowerCamelCase)["last_hidden_state"]
              _A   : Tuple       					=				model(__lowerCamelCase				,		past_key_values=__lowerCamelCase)["last_hidden_state"]
  
              # select random slice
              _A   : Optional[Any]       					=				ids_tensor((1,)				,		output_from_past.shape[-1]).item()
              _A   : int       					=				output_from_no_past[:, next_input_ids.shape[-1] - 1, random_slice_idx].detach()
              _A   : Optional[Any]       					=				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)    ->       List[Any]:
              _A   : Tuple       					=				self.prepare_config_and_inputs()
              (
                  (
                  _A
              )					,    (
                  _A
              )					,    (
                  _A
              )					,    (
                  _A
              )					,    
              )   : Dict       					=				config_and_inputs
  
              _A   : Dict       					=				{
                  "input_ids": input_ids,
                  "attention_mask": attention_mask,
              }
              return config, inputs_dict
  
  
  
  
  
  
  
  @require_torch
  class   lowerCAmelCase__ (       a  ,					a  ,					a  ,					unittest.TestCase):
  
  
  
  
       '''simple docstring'''
       __SCREAMING_SNAKE_CASE						    =				(SpeechaTextaDecoder, SpeechaTextaForCausalLM) if is_torch_available() else ()
       __SCREAMING_SNAKE_CASE						    =				(SpeechaTextaForCausalLM,) if is_torch_available() else ()
       __SCREAMING_SNAKE_CASE						    =				{"text-generation": SpeechaTextaForCausalLM} if is_torch_available() else {}
       __SCREAMING_SNAKE_CASE						    =				True
       __SCREAMING_SNAKE_CASE						    =				False
  
  
       def 				_lowerCamelCase				(		self				,		)    ->       List[str]:
              _A   : List[Any]       					=				SpeechaTextaStandaloneDecoderModelTester(self				,		is_training=__lowerCamelCase)
              _A   : Union[str, Any]       					=				ConfigTester(self				,		config_class=__lowerCamelCase)
  
  
       def 				_lowerCamelCase				(		self)    ->       Optional[int]:
              pass
  
  
       def 				_lowerCamelCase				(		self)    ->       Optional[Any]:
              pass
  
  
       def 				_lowerCamelCase				(		self)    ->       Tuple:
              pass
  
  
       def 				_lowerCamelCase				(		self)    ->       List[Any]:
              self.config_tester.run_common_tests()
  
  
       def 				_lowerCamelCase				(		self)    ->       str:
              _A   : Optional[Any]       					=				self.model_tester.prepare_config_and_inputs()
              self.model_tester.create_and_check_decoder_model_past(*__lowerCamelCase)
  
  
       def 				_lowerCamelCase				(		self)    ->       str:
              return
  
style_context: 
  
  
  import argparse
  import pathlib
  
  import fairseq
  import torch
  from fairseq.models.roberta import RobertaModel as FairseqRobertaModel
  from fairseq.modules import TransformerSentenceEncoderLayer
  from packaging import version
  
  from transformers import RobertaConfig, RobertaForMaskedLM, RobertaForSequenceClassification
  from transformers.models.bert.modeling_bert import (
      BertIntermediate,
      BertLayer,
      BertOutput,
      BertSelfAttention,
      BertSelfOutput,
  )
  from transformers.utils import logging
  
  
  if version.parse(fairseq.__version__) < version.parse('0.9.0'):
      raise Exception('requires fairseq >= 0.9.0')
  
  
  logging.set_verbosity_info()
  lowerCAmelCase__   	=				logging.get_logger(__name__)
  
  lowerCAmelCase__   	=				'Hello world! cécé herlolip'
  def 							_UpperCAmelCase       (UpperCamelCase__  :						str       ,							UpperCamelCase__  :						str       ,							UpperCamelCase__  :						bool		):
         _A   : Union[str, Any]       					=				FairseqRobertaModel.from_pretrained(UpperCamelCase__		)
         roberta.eval()  # disable dropout
         _A   : Dict       					=				roberta.model.encoder.sentence_encoder
         _A   : int       					=				RobertaConfig(
             vocab_size=roberta_sent_encoder.embed_tokens.num_embeddings       ,							hidden_size=roberta.args.encoder_embed_dim       ,							num_hidden_layers=roberta.args.encoder_layers       ,							num_attention_heads=roberta.args.encoder_attention_heads       ,							intermediate_size=roberta.args.encoder_ffn_embed_dim       ,							max_position_embeddings=514       ,							type_vocab_size=1       ,							layer_norm_eps=1E-5       ,							)
         if classification_head:
                _A   : List[Any]       					=				roberta.model.classification_heads["mnli"].out_proj.weight.shape[0]
         print("Our BERT config:"       ,							UpperCamelCase__		)
  
         _A   : Dict       					=				RobertaForSequenceClassification(UpperCamelCase__		) if classification_head else RobertaForMaskedLM(UpperCamelCase__		)
         model.eval()
  
         # Now let's copy all the weights.
         # Embeddings
         _A   : Optional[int]       					=				roberta_sent_encoder.embed_tokens.weight
         _A   : List[str]       					=				roberta_sent_encoder.embed_positions.weight
         _A   : Optional[int]       					=				torch.zeros_like(
             model.roberta.embeddings.token_type_embeddings.weight		)  # just zero them out b/c RoBERTa doesn't use them.
         _A   : List[Any]       					=				roberta_sent_encoder.emb_layer_norm.weight
         _A   : Tuple       					=				roberta_sent_encoder.emb_layer_norm.bias
  
         for i in range(config.num_hidden_layers		):
                # Encoder: start of layer
                _A   : BertLayer       					=				model.roberta.encoder.layer[i]
                _A   : TransformerSentenceEncoderLayer       					=				roberta_sent_encoder.layers[i]
  
                # self attention
                _A   : BertSelfAttention       					=				layer.attention.self
                assert (
                    roberta_layer.self_attn.k_proj.weight.data.shape
                    == roberta_layer.self_attn.q_proj.weight.data.shape
                    == roberta_layer.self_attn.v_proj.weight.data.shape
                    == torch.Size((config.hidden_size, config.hidden_size)		)
                )
  
                _A   : List[str]       					=				roberta_layer.self_attn.q_proj.weight
                _A   : Optional[Any]       					=				roberta_layer.self_attn.q_proj.bias
                _A   : Union[str, Any]       					=				roberta_layer.self_attn.k_proj.weight
                _A   : Tuple       					=				roberta_layer.self_attn.k_proj.bias
                _A   : List[str]       					=				roberta_layer.self_attn.v_proj.weight
                _A   : Optional[Any]       					=				roberta_layer.self_attn.v_proj.bias
  
                # self-attention output
                _A   : BertSelfOutput       					=				layer.attention.output
                assert self_output.dense.weight.shape == roberta_layer.self_attn.out_proj.weight.shape
                _A   : Tuple       					=				roberta_layer.self_attn.out_proj.weight
                _A   : List[str]       					=				roberta_layer.self_attn.out_proj.bias
                _A   : Dict       					=				roberta_layer.self_attn_layer_norm.weight
                _A   : Optional[int]       					=				roberta_layer.self_attn_layer_norm.bias
  
                # intermediate
                _A   : BertIntermediate       					=				layer.intermediate
                assert intermediate.dense.weight.shape == roberta_layer.fca.weight.shape
                _A   : Tuple       					=				roberta_layer.fca.weight
                _A   : List[str]       					=				roberta_layer.fca.bias
  
                # output
                _A   : BertOutput       					=				layer.output
                assert bert_output.dense.weight.shape == roberta_layer.fca.weight.shape
                _A   : int       					=				roberta_layer.fca.weight
                _A   : List[str]       					=				roberta_layer.fca.bias
                _A   : List[str]       					=				roberta_layer.final_layer_norm.weight
                _A   : Any       					=				roberta_layer.final_layer_norm.bias
                # end of layer
  
         if classification_head:
                _A   : int       					=				roberta.model.classification_heads["mnli"].dense.weight
                _A   : List[Any]       					=				roberta.model.classification_heads["mnli"].dense.bias
                _A   : Optional[Any]       					=				roberta.model.classification_heads["mnli"].out_proj.weight
                _A   : Optional[int]       					=				roberta.model.classification_heads["mnli"].out_proj.bias
         else:
                # LM Head
                _A   : Any       					=				roberta.model.encoder.lm_head.dense.weight
                _A   : Dict       					=				roberta.model.encoder.lm_head.dense.bias
                _A   : List[str]       					=				roberta.model.encoder.lm_head.layer_norm.weight
                _A   : List[str]       					=				roberta.model.encoder.lm_head.layer_norm.bias
                _A   : List[Any]       					=				roberta.model.encoder.lm_head.weight
                _A   : Optional[Any]       					=				roberta.model.encoder.lm_head.bias
  
         # Let's check that we get the same results.
         _A   : torch.Tensor       					=				roberta.encode(UpperCamelCase__		).unsqueeze(0		)  # batch of size 1
  
         _A   : int       					=				model(UpperCamelCase__		)[0]
         if classification_head:
                _A   : str       					=				roberta.model.classification_heads["mnli"](roberta.extract_features(UpperCamelCase__		)		)
         else:
                _A   : int       					=				roberta.model(UpperCamelCase__		)[0]
         print(our_output.shape       ,							their_output.shape		)
         _A   : List[Any]       					=				torch.max(torch.abs(our_output - their_output		)		).item()
         print(f"max_absolute_diff = {max_absolute_diff}"		)  # ~ 1e-7
         _A   : List[Any]       					=				torch.allclose(UpperCamelCase__       ,							UpperCamelCase__       ,							atol=1E-3		)
         print("Do both models output the same tensors?"       ,							"🔥" if success else "💩"		)
         if not success:
                raise Exception("Something went wRoNg"		)
  
         pathlib.Path(UpperCamelCase__		).mkdir(parents=UpperCamelCase__       ,							exist_ok=UpperCamelCase__		)
         print(f"Saving model to {pytorch_dump_folder_path}"		)
         model.save_pretrained(UpperCamelCase__		)
  
  
  if __name__ == "__main__":
      lowerCAmelCase__   	=				argparse.ArgumentParser()
      # Required parameters
      parser.add_argument(
          '--roberta_checkpoint_path', default=None, type=str, required=True, help='Path the official PyTorch dump.'
      )
      parser.add_argument(
          '--pytorch_dump_folder_path', default=None, type=str, required=True, help='Path to the output PyTorch model.'
      )
      parser.add_argument(
          '--classification_head', action='store_true', help='Whether to convert a final classification head.'
      )
      lowerCAmelCase__   	=				parser.parse_args()
      convert_roberta_checkpoint_to_pytorch(
          args.roberta_checkpoint_path, args.pytorch_dump_folder_path, args.classification_head
      )
  