
"""simple docstring"""




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


lowerCAmelCase__							=				logging.get_logger(__name__)

lowerCAmelCase__							=				{
    'tiiuae/falcon-40b': 'https://huggingface.co/tiiuae/falcon-40b/resolve/main/config.json',
    'tiiuae/falcon-7b': 'https://huggingface.co/tiiuae/falcon-7b/resolve/main/config.json',
}





class  snake_case     (							__lowercase   ):
							UpperCAmelCase__						     =      '''falcon'''
							UpperCAmelCase__						     =      ['''past_key_values''']

							def __init__(self       ,       SCREAMING_SNAKE_CASE_=6_50_24       ,       SCREAMING_SNAKE_CASE_=45_44       ,       SCREAMING_SNAKE_CASE_=32       ,       SCREAMING_SNAKE_CASE_=71       ,       SCREAMING_SNAKE_CASE_=1e-5       ,       SCREAMING_SNAKE_CASE_=0.02       ,       SCREAMING_SNAKE_CASE_=True       ,       SCREAMING_SNAKE_CASE_=0.0       ,       SCREAMING_SNAKE_CASE_=0.0       ,       SCREAMING_SNAKE_CASE_=None       ,       SCREAMING_SNAKE_CASE_=False       ,       SCREAMING_SNAKE_CASE_=False       ,       SCREAMING_SNAKE_CASE_=True       ,       SCREAMING_SNAKE_CASE_=True       ,       SCREAMING_SNAKE_CASE_=False       ,       SCREAMING_SNAKE_CASE_=11       ,       SCREAMING_SNAKE_CASE_=11       ,       **SCREAMING_SNAKE_CASE_       ,       ):

									"""simple docstring"""







									SCREAMING_SNAKE_CASE_						 = vocab_size
									# Backward compatibility with n_embed kwarg
									SCREAMING_SNAKE_CASE_						 = kwargs.pop('''n_embed'''       ,       SCREAMING_SNAKE_CASE_    )
									SCREAMING_SNAKE_CASE_						 = hidden_size if n_embed is None else n_embed
									SCREAMING_SNAKE_CASE_						 = num_hidden_layers
									SCREAMING_SNAKE_CASE_						 = num_attention_heads
									SCREAMING_SNAKE_CASE_						 = layer_norm_epsilon
									SCREAMING_SNAKE_CASE_						 = initializer_range
									SCREAMING_SNAKE_CASE_						 = use_cache
									SCREAMING_SNAKE_CASE_						 = hidden_dropout
									SCREAMING_SNAKE_CASE_						 = attention_dropout

									SCREAMING_SNAKE_CASE_						 = bos_token_id
									SCREAMING_SNAKE_CASE_						 = eos_token_id
									SCREAMING_SNAKE_CASE_						 = num_attention_heads if num_kv_heads is None else num_kv_heads
									SCREAMING_SNAKE_CASE_						 = alibi
									SCREAMING_SNAKE_CASE_						 = new_decoder_architecture
									SCREAMING_SNAKE_CASE_						 = multi_query  # Ignored when new_decoder_architecture is True
									SCREAMING_SNAKE_CASE_						 = parallel_attn
									SCREAMING_SNAKE_CASE_						 = bias

									super().__init__(bos_token_id=SCREAMING_SNAKE_CASE_       ,       eos_token_id=SCREAMING_SNAKE_CASE_       ,       **SCREAMING_SNAKE_CASE_    )

							@property
							def _lowercase					(self    ):

									"""simple docstring"""







									return self.hidden_size // self.num_attention_heads







							@property
							def _lowercase					(self    ):

									"""simple docstring"""







									return not self.alibi

"""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,							__a,							__a,							__a    ):
		# Initialise PyTorch model
		SCREAMING_SNAKE_CASE_						 = BigBirdConfig.from_json_file(__a    )
		print(F'Building PyTorch model from configuration: {config}'    )

		if is_trivia_qa:
				SCREAMING_SNAKE_CASE_						 = BigBirdForQuestionAnswering(__a    )
		else:
				SCREAMING_SNAKE_CASE_						 = 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__":
						lowerCAmelCase__							=				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.'
						)
						lowerCAmelCase__							=				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
						)