






# We ignore warnings about stepping the scheduler since we step it ourselves during gradient accumulation

import warnings

from .state import AcceleratorState, GradientState


warnings.filterwarnings("ignore", category=UserWarning, module="torch.optim.lr_scheduler")




class  UpperCamelCase_      :



	'''simple docstring'''




	def __init__(       self       ,			a       ,			a       ,			a = True       ,			a = False					)       ->    int:
								snake_case_				=							scheduler
								snake_case_				=							optimizers if isinstance(_snake_case       ,			(list, tuple)					) else [optimizers]
								snake_case_				=							split_batches
								snake_case_				=							step_with_optimizer
								snake_case_				=							GradientState()




	def 							_UpperCamelCase			(       self       ,			*a       ,			**a					)       ->    Tuple:
								if not self.step_with_optimizer:
															# No link between scheduler and optimizer -> just step
															self.scheduler.step(*_snake_case       ,			**_snake_case					)
															return

								# Otherwise, first make sure the optimizer was stepped.
								if not self.gradient_state.sync_gradients:
															if self.gradient_state.adjust_scheduler:
																						self.scheduler._step_count += 1
															return

								for opt in self.optimizers:
															if opt.step_was_skipped:
																						return
								if self.split_batches:
															# Split batches -> the training dataloader batch size is not changed so one step per training step
															self.scheduler.step(*_snake_case       ,			**_snake_case					)
								else:
															# Otherwise the training dataloader batch size was multiplied by `num_processes`, so we need to do
															# num_processes steps per training step
															snake_case_				=							AcceleratorState().num_processes
															for _ in range(_snake_case					):
																						# Special case when using OneCycle and `drop_last` was not used
																						if hasattr(self.scheduler       ,			'total_steps'					):
																													if self.scheduler._step_count <= self.scheduler.total_steps:
																																				self.scheduler.step(*_snake_case       ,			**_snake_case					)
																						else:
																													self.scheduler.step(*_snake_case       ,			**_snake_case					)




	def 							_UpperCamelCase			(       self					)       ->    List[str]:
								return self.scheduler.get_last_lr()




	def 							_UpperCamelCase			(       self					)       ->    int:
								return self.scheduler.state_dict()




	def 							_UpperCamelCase			(       self       ,			a					)       ->    Optional[int]:
								self.scheduler.load_state_dict(_snake_case					)




	def 							_UpperCamelCase			(       self					)       ->    Union[str, Any]:
								return self.scheduler.get_lr()






	def 							_UpperCamelCase			(       self       ,			*a       ,			**a					)       ->    Optional[Any]:
								return self.scheduler.print_lr(*_snake_case       ,			**_snake_case					)










import argparse

import torch

from transformers import LxmertConfig, LxmertForPreTraining, load_tf_weights_in_lxmert
from transformers.utils import logging


logging.set_verbosity_info()
def        lowercase_							(A : str		,					A : List[Any]		,					A : Any      ):
       # Initialise PyTorch model
       snake_case__							:	List[Any]   	=	LxmertConfig.from_json_file(A      )
       print(F'''Building PyTorch model from configuration: {config}'''      )
       snake_case__							:	List[str]   	=	LxmertForPreTraining(A      )

       # Load weights from tf checkpoint
       load_tf_weights_in_lxmert(A		,					A		,					A      )

       # Save pytorch-model
       print(F'''Save PyTorch model to {pytorch_dump_path}'''      )
       torch.save(model.state_dict()		,					A      )


if __name__ == "__main__":
 a_   :Union[str, 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(
     "--config_file",
     default=None,
     type=str,
     required=True,
     help="The config json file corresponding to the pre-trained model. \nThis specifies the model architecture.",
 )
 parser.add_argument(
     "--pytorch_dump_path", default=None, type=str, required=True, help="Path to the output PyTorch model."
 )
 a_   :Optional[int]        =      parser.parse_args()
 convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path)






