
"""simple docstring"""




import logging
import os

from .state import PartialState


class       __magic_name__							(							logging.LoggerAdapter			):
       @staticmethod
       def 				lowercase_				(  A_							)  ->						int:





         """simple docstring"""




         _lowercase:      Any   			=  PartialState()
         return not main_process_only or (main_process_only and state.is_main_process)



       def 				lowercase_				(  self			,					A_			,					A_			,					*A_			,					**A_							)  ->						Union[str, Any]:





         """simple docstring"""




         if PartialState._shared_state == {}:
           raise RuntimeError(
               '''You must initialize the accelerate state by calling either `PartialState()` or `Accelerator()` before using the logging utility.'''							)
         _lowercase:      Optional[int]   			=  kwargs.pop('''main_process_only'''			,					A_							)
         _lowercase:      Dict   			=  kwargs.pop('''in_order'''			,					A_							)

         if self.isEnabledFor(A_							):
           if self._should_log(A_							):
             _lowercase			,					_lowercase:      int   			=  self.process(A_			,					A_							)
             self.logger.log(A_			,					A_			,					*A_			,					**A_							)

           elif in_order:
             _lowercase:      Dict   			=  PartialState()
             for i in range(state.num_processes							):
               if i == state.process_index:
                 _lowercase			,					_lowercase:      List[str]   			=  self.process(A_			,					A_							)
                 self.logger.log(A_			,					A_			,					*A_			,					**A_							)
               state.wait_for_everyone()




def 			_lowerCAmelCase		(		_UpperCamelCase			,					_UpperCamelCase = None    ):






  """simple docstring"""



  if log_level is None:
    _lowercase:      Dict   			=  os.environ.get('''ACCELERATE_LOG_LEVEL'''			,					_UpperCamelCase    )
  _lowercase:      Any   			=  logging.getLogger(_UpperCamelCase    )
  if log_level is not None:
    logger.setLevel(log_level.upper()    )
    logger.root.setLevel(log_level.upper()    )
  return MultiProcessAdapter(_UpperCamelCase			,					{}    )


"""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		(		_UpperCamelCase			,					_UpperCamelCase			,					_UpperCamelCase			,					_UpperCamelCase    ):






  """simple docstring"""



  _lowercase:      int   			=  BigBirdConfig.from_json_file(_UpperCamelCase    )
  print(f'''Building PyTorch model from configuration: {config}'''    )

  if is_trivia_qa:
    _lowercase:      Union[str, Any]   			=  BigBirdForQuestionAnswering(_UpperCamelCase    )
  else:
    _lowercase:      Dict   			=  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__ :       List[Any]				= 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__ :       Optional[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
  )
