



import argparse
from argparse import Namespace

import torch
from torch import nn

from transformers import XGLMConfig, XGLMForCausalLM

def   _lowerCAmelCase   (						A__	):
      lowercase__     =  [
          'decoder.version',
          'decoder.output_projection.weight',
          '_float_tensor',
          'decoder.embed_positions._float_tensor',
      ]
      for k in ignore_keys:
            state_dict.pop(A__						,  A__	)

def   _lowerCAmelCase   (						A__	):
      lowercase__,	lowercase__     =  emb.weight.shape
      lowercase__     =  nn.Linear(A__						,  A__						,  bias=A__	)
      lowercase__     =  emb.weight.data
      return lin_layer

def   _lowerCAmelCase   (						A__	):
      lowercase__     =  torch.load(A__						,  map_location='cpu'	)
      lowercase__     =  Namespace(**checkpoint['cfg']['model']	)
      lowercase__     =  checkpoint['model']
      remove_ignore_keys_(A__	)
      lowercase__     =  state_dict['decoder.embed_tokens.weight'].shape[0]

      lowercase__     =  {key.replace('decoder'						,  'model'	): val for key, val in state_dict.items()}

      lowercase__     =  XGLMConfig(
          vocab_size=A__						,  max_position_embeddings=args.max_target_positions						,  num_layers=args.decoder_layers						,  attention_heads=args.decoder_attention_heads						,  ffn_dim=args.decoder_ffn_embed_dim						,  d_model=args.decoder_embed_dim						,  layerdrop=args.decoder_layerdrop						,  dropout=args.dropout						,  attention_dropout=args.attention_dropout						,  activation_dropout=args.activation_dropout						,  activation_function='gelu'						,  scale_embedding=not args.no_scale_embedding						,  tie_word_embeddings=args.share_decoder_input_output_embed						,  )

      lowercase__     =  XGLMForCausalLM(A__	)
      lowercase__     =  model.load_state_dict(A__						,  strict=A__	)
      print(A__	)
      lowercase__     =  make_linear_from_emb(model.model.embed_tokens	)

      return model


if __name__ == "__main__":
       a__      :				int   	=			argparse.ArgumentParser()
       # Required parameters
       parser.add_argument("fairseq_path", type=str, help="path to a model.pt on local filesystem.")
       parser.add_argument("pytorch_dump_folder_path", default=None, type=str, help="Path to the output PyTorch model.")
       a__      :				Union[str, Any]   	=			parser.parse_args()
       a__      :				Union[str, Any]   	=			convert_fairseq_xglm_checkpoint_from_disk(args.fairseq_path)
       model.save_pretrained(args.pytorch_dump_folder_path)





def   _lowerCAmelCase   (						A__						,  A__						,  A__	):
      if principal <= 0:
            raise Exception('Principal borrowed must be > 0'	)
      if rate_per_annum < 0:
            raise Exception('Rate of interest must be >= 0'	)
      if years_to_repay <= 0 or not isinstance(A__						,  A__	):
            raise Exception('Years to repay must be an integer > 0'	)

      # Yearly rate is divided by 12 to get monthly rate
      lowercase__     =  rate_per_annum / 12

      # Years to repay is multiplied by 12 to get number of payments as payment is monthly
      lowercase__     =  years_to_repay * 12

      return (
          principal
          * rate_per_month
          * (1 + rate_per_month) ** number_of_payments
          / ((1 + rate_per_month) ** number_of_payments - 1)
      )


if __name__ == "__main__":
       import doctest

       doctest.testmod()
