




import torch
from transformers import PreTrainedModel, XLMRobertaConfig, XLMRobertaModel







class 				lowerCAmelCase_       (					lowerCamelCase_							):
				__a     :       Union[str, Any]						=     "M-CLIP"






				def __init__(			self      ,snake_case__=1024      ,snake_case__=768      ,**snake_case__ ):
							SCREAMING_SNAKE_CASE_   : List[str]					  =      transformerDimSize
							SCREAMING_SNAKE_CASE_   : int					  =      imageDimSize
							super().__init__(**snake_case__ )







class 				lowerCAmelCase_       (					lowerCamelCase_							):
				__a     :       List[Any]						=     MCLIPConfig






				def __init__(			self      ,snake_case__      ,*snake_case__      ,**snake_case__ ):
							super().__init__(snake_case__      ,*snake_case__      ,**snake_case__ )
							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      XLMRobertaModel(snake_case__ )
							SCREAMING_SNAKE_CASE_   : Tuple					  =      torch.nn.Linear(
							    in_features=config.transformerDimensions      ,out_features=config.numDims )






				def 		snake_case	(			self      ,snake_case__      ,snake_case__ ):
							SCREAMING_SNAKE_CASE_   : int					  =      self.transformer(input_ids=snake_case__      ,attention_mask=snake_case__ )[0]
							SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      (embs * attention_mask.unsqueeze(2 )).sum(dim=1 ) / attention_mask.sum(dim=1 )[:, None]
							return self.LinearTransformation(snake_case__ ), embs









import argparse

import torch

from transformers import FunnelBaseModel, FunnelConfig, FunnelModel, load_tf_weights_in_funnel
from transformers.utils import logging


logging.set_verbosity_info()





def        __UpperCAmelCase						(							lowerCamelCase_ :     Dict  ,							lowerCamelCase_ :     Any  ,							lowerCamelCase_ :     int  ,							lowerCamelCase_ :     List[Any]  )       ->  int:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      FunnelConfig.from_json_file(lowerCamelCase_  )
			print(F'Building PyTorch model from configuration: {config}'  )
			SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      FunnelBaseModel(lowerCamelCase_  ) if base_model else FunnelModel(lowerCamelCase_  )

			# Load weights from tf checkpoint
			load_tf_weights_in_funnel(lowerCamelCase_  ,							lowerCamelCase_  ,							lowerCamelCase_  )

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


if __name__ == "__main__":
						UpperCamelCase__ :   Optional[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.'''
						)
						parser.add_argument(
						    '''--base_model''', action='''store_true''', help='''Whether you want just the base model (no decoder) or not.'''
						)
						UpperCamelCase__ :   Tuple						=							parser.parse_args()
						convert_tf_checkpoint_to_pytorch(
						    args.tf_checkpoint_path, args.config_file, args.pytorch_dump_path, args.base_model
						)



