


'''simple docstring'''



from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowercase    :    Union[str, Any]			     =  logging.get_logger(__name__)

_lowercase    :    Tuple			     =  {
    """facebook/s2t-small-librispeech-asr""": (
        """https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/config.json"""
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech_to_text
}






class  UpperCamelCase__(     lowerCAmelCase ):
				__magic_name__       :   List[Any]							= "speech_to_text"
				__magic_name__       :   int							= ["past_key_values"]
				__magic_name__       :   Optional[int]							= {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}




				def __init__(	self    :				int   ,					lowerCAmelCase    :				int=10000   ,					lowerCAmelCase    :				List[str]=12   ,					lowerCAmelCase    :				Optional[int]=2048   ,					lowerCAmelCase    :				List[Any]=4   ,					lowerCAmelCase    :				Optional[Any]=6   ,					lowerCAmelCase    :				List[str]=2048   ,					lowerCAmelCase    :				str=4   ,					lowerCAmelCase    :				Dict=0.0   ,					lowerCAmelCase    :				List[Any]=0.0   ,					lowerCAmelCase    :				Optional[int]=True   ,					lowerCAmelCase    :				str=True   ,					lowerCAmelCase    :				Optional[Any]="relu"   ,					lowerCAmelCase    :				Optional[Any]=256   ,					lowerCAmelCase    :				Union[str, Any]=0.1   ,					lowerCAmelCase    :				str=0.0   ,					lowerCAmelCase    :				Dict=0.0   ,					lowerCAmelCase    :				Tuple=0.02   ,					lowerCAmelCase    :				Dict=2   ,					lowerCAmelCase    :				int=True   ,					lowerCAmelCase    :				Optional[Any]=1   ,					lowerCAmelCase    :				int=0   ,					lowerCAmelCase    :				Dict=2   ,					lowerCAmelCase    :				Dict=6000   ,					lowerCAmelCase    :				Optional[int]=1024   ,					lowerCAmelCase    :				Any=2   ,					lowerCAmelCase    :				int=(5, 5)   ,					lowerCAmelCase    :				Dict=1024   ,					lowerCAmelCase    :				List[str]=80   ,					lowerCAmelCase    :				List[str]=1   ,					**lowerCAmelCase    :				Any   ,					)->  List[Any]:

										"""simple docstring"""




										UpperCAmelCase         =			vocab_size
										UpperCAmelCase         =			d_model
										UpperCAmelCase         =			encoder_ffn_dim
										UpperCAmelCase         =			encoder_layers
										UpperCAmelCase         =			encoder_attention_heads
										UpperCAmelCase         =			decoder_ffn_dim
										UpperCAmelCase         =			decoder_layers
										UpperCAmelCase         =			decoder_attention_heads
										UpperCAmelCase         =			dropout
										UpperCAmelCase         =			attention_dropout
										UpperCAmelCase         =			activation_dropout
										UpperCAmelCase         =			activation_function
										UpperCAmelCase         =			init_std
										UpperCAmelCase         =			encoder_layerdrop
										UpperCAmelCase         =			decoder_layerdrop
										UpperCAmelCase         =			use_cache
										UpperCAmelCase         =			encoder_layers
										UpperCAmelCase         =			scale_embedding  # scale factor will be sqrt(d_model) if True
										UpperCAmelCase         =			max_source_positions
										UpperCAmelCase         =			max_target_positions
										UpperCAmelCase         =			num_conv_layers
										UpperCAmelCase         =			list(lowerCAmelCase   )
										UpperCAmelCase         =			conv_channels
										UpperCAmelCase         =			input_feat_per_channel
										UpperCAmelCase         =			input_channels

										if len(self.conv_kernel_sizes   ) != self.num_conv_layers:
																raise ValueError(
																    '''Configuration for convolutional module is incorrect. '''
																    '''It is required that `len(config.conv_kernel_sizes)` == `config.num_conv_layers` '''
																    F"""but is `len(config.conv_kernel_sizes) = {len(self.conv_kernel_sizes   )}`, """
																    F"""`config.num_conv_layers = {self.num_conv_layers}`."""   )

										super().__init__(
										    pad_token_id=lowerCAmelCase   ,					bos_token_id=lowerCAmelCase   ,					eos_token_id=lowerCAmelCase   ,					is_encoder_decoder=lowerCAmelCase   ,					decoder_start_token_id=lowerCAmelCase   ,					**lowerCAmelCase   ,					)









'''simple docstring'''



import argparse

from transformers import BigBirdConfig, BigBirdForPreTraining, BigBirdForQuestionAnswering, load_tf_weights_in_big_bird
from transformers.utils import logging


logging.set_verbosity_info()


def    lowerCamelCase__   ( A     :    List[Any]   ,     A     :    int   ,     A     :    List[str]   ,     A     :    Optional[int]  ):




						'''simple docstring'''






						UpperCAmelCase         =			BigBirdConfig.from_json_file(A  )
						print(f"""Building PyTorch model from configuration: {config}"""  )

						if is_trivia_qa:
												UpperCAmelCase         =			BigBirdForQuestionAnswering(A  )
						else:
												UpperCAmelCase         =			BigBirdForPreTraining(A  )

						# Load weights from tf checkpoint
						load_tf_weights_in_big_bird(A   ,     A   ,     is_trivia_qa=A  )

						# Save pytorch-model
						print(f"""Save PyTorch model to {pytorch_dump_path}"""  )
						model.save_pretrained(A  )


if __name__ == "__main__":
	_lowercase    :    List[str]			     =  argparse.ArgumentParser()
	# Required parameters
	parser.add_argument(
	    """--tf_checkpoint_path""", default=None, type=str, required=True, help="""Path to the TensorFlow checkpoint path."""
	)
	parser.add_argument(
	    """--big_bird_config_file""",
	    default=None,
	    type=str,
	    required=True,
	    help=(
	        """The config json file corresponding to the pre-trained BERT model. \n"""
	        """This specifies the model architecture."""
	    ),
	)
	parser.add_argument(
	    """--pytorch_dump_path""", default=None, type=str, required=True, help="""Path to the output PyTorch model."""
	)
	parser.add_argument(
	    """--is_trivia_qa""", action="""store_true""", help="""Whether to convert a model with a trivia_qa head."""
	)
	_lowercase    :    Any			     =  parser.parse_args()
	convert_tf_checkpoint_to_pytorch(
	    args.tf_checkpoint_path, args.big_bird_config_file, args.pytorch_dump_path, args.is_trivia_qa
	)





