





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


a__: int							   =						logging.get_logger(__name__)

a__: int							   =						{
    'funnel-transformer/small': 'https://huggingface.co/funnel-transformer/small/resolve/main/config.json',
    'funnel-transformer/small-base': 'https://huggingface.co/funnel-transformer/small-base/resolve/main/config.json',
    'funnel-transformer/medium': 'https://huggingface.co/funnel-transformer/medium/resolve/main/config.json',
    'funnel-transformer/medium-base': 'https://huggingface.co/funnel-transformer/medium-base/resolve/main/config.json',
    'funnel-transformer/intermediate': (
        'https://huggingface.co/funnel-transformer/intermediate/resolve/main/config.json'
    ),
    'funnel-transformer/intermediate-base': (
        'https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/config.json'
    ),
    'funnel-transformer/large': 'https://huggingface.co/funnel-transformer/large/resolve/main/config.json',
    'funnel-transformer/large-base': 'https://huggingface.co/funnel-transformer/large-base/resolve/main/config.json',
    'funnel-transformer/xlarge': 'https://huggingface.co/funnel-transformer/xlarge/resolve/main/config.json',
    'funnel-transformer/xlarge-base': 'https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/config.json',
}




class        SCREAMING_SNAKE_CASE__					(		UpperCamelCase__ ):
 __SCREAMING_SNAKE_CASE							=      '''funnel'''
 __SCREAMING_SNAKE_CASE							=      {
     '''hidden_size''': '''d_model''',
     '''num_attention_heads''': '''n_head''',
 }



 def __init__(				self,__lowerCamelCase=3_0522,__lowerCamelCase=[4, 4, 4],__lowerCamelCase=None,__lowerCamelCase=2,__lowerCamelCase=768,__lowerCamelCase=12,__lowerCamelCase=64,__lowerCamelCase=3072,__lowerCamelCase="gelu_new",__lowerCamelCase=0.1,__lowerCamelCase=0.1,__lowerCamelCase=0.0,__lowerCamelCase=0.1,__lowerCamelCase=None,__lowerCamelCase=1E-9,__lowerCamelCase="mean",__lowerCamelCase="relative_shift",__lowerCamelCase=True,__lowerCamelCase=True,__lowerCamelCase=True,**__lowerCamelCase,):
        A__		   =		vocab_size
        A__		   =		block_sizes
        A__		   =		[1] * len(__lowerCamelCase					) if block_repeats is None else block_repeats
        assert len(__lowerCamelCase					) == len(
            self.block_repeats					), "`block_sizes` and `block_repeats` should have the same length."
        A__		   =		num_decoder_layers
        A__		   =		d_model
        A__		   =		n_head
        A__		   =		d_head
        A__		   =		d_inner
        A__		   =		hidden_act
        A__		   =		hidden_dropout
        A__		   =		attention_dropout
        A__		   =		activation_dropout
        A__		   =		initializer_range
        A__		   =		initializer_std
        A__		   =		layer_norm_eps
        assert pooling_type in [
            "mean",
            "max",
        ], f"Got {pooling_type} for `pooling_type` but only 'mean' and 'max' are supported."
        A__		   =		pooling_type
        assert attention_type in [
            "relative_shift",
            "factorized",
        ], f"Got {attention_type} for `attention_type` but only 'relative_shift' and 'factorized' are supported."
        A__		   =		attention_type
        A__		   =		separate_cls
        A__		   =		truncate_seq
        A__		   =		pool_q_only

        super().__init__(**__lowerCamelCase					)



 @property
 def 							UpperCamelCase     (				self					):
        return sum(self.block_sizes					)



 @num_hidden_layers.setter
 def 							UpperCamelCase     (				self,__lowerCamelCase					):
        raise NotImplementedError(
            '''This model does not support the setting of `num_hidden_layers`. Please set `block_sizes`.'''					)



 @property
 def 							UpperCamelCase     (				self					):
        return len(self.block_sizes					)




 @num_blocks.setter
 def 							UpperCamelCase     (				self,__lowerCamelCase					):
        raise NotImplementedError('''This model does not support the setting of `num_blocks`. Please set `block_sizes`.'''					)












import argparse

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


logging.set_verbosity_info()


def       UpperCamelCase__(			UpperCamelCase__     :			Any					,	UpperCamelCase__     :			Optional[Any]					,	UpperCamelCase__     :			Dict					,	UpperCamelCase__     :			int    )->Union[str, Any]:
       # Initialise PyTorch model
       A__		   =		BigBirdConfig.from_json_file(UpperCamelCase__    )
       print(f"Building PyTorch model from configuration: {config}"    )

       if is_trivia_qa:
              A__		   =		BigBirdForQuestionAnswering(UpperCamelCase__    )
       else:
              A__		   =		BigBirdForPreTraining(UpperCamelCase__    )

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

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


if __name__ == "__main__":
       a__: Optional[int]							   =						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.'
       )
       a__: Tuple							   =						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
       )





