




import argparse

import pytorch_lightning as pl
import torch
from torch import nn

from transformers import LongformerForQuestionAnswering, LongformerModel

class   __a(					pl.LightningModule       ):






    """simple docstring"""





    def __init__(				self       ,_SCREAMING_SNAKE_CASE  )			->		Optional[int]:
         super().__init__()
         UpperCAmelCase_      :							List[Any]       =      model
         UpperCAmelCase_      :							List[str]       =      2
         UpperCAmelCase_      :							int       =      nn.Linear(self.model.config.hidden_size       ,self.num_labels  )





    def 							a__				(				self  )			->		List[str]:
         pass







def lowerCamelCase__       (      _lowercase			,						_lowercase			,						_lowercase				):

     '''simple docstring'''


     UpperCAmelCase_      :							Optional[Any]       =      LongformerModel.from_pretrained(_lowercase				)
     UpperCAmelCase_      :							Optional[Any]       =      LightningModel(_lowercase				)

     UpperCAmelCase_      :							List[Any]       =      torch.load(_lowercase			,						map_location=torch.device('''cpu'''				)				)
     lightning_model.load_state_dict(ckpt['''state_dict''']				)

     # init longformer question answering model
     UpperCAmelCase_      :							Tuple       =      LongformerForQuestionAnswering.from_pretrained(_lowercase				)

     # transfer weights
     longformer_for_qa.longformer.load_state_dict(lightning_model.model.state_dict()				)
     longformer_for_qa.qa_outputs.load_state_dict(lightning_model.qa_outputs.state_dict()				)
     longformer_for_qa.eval()

     # save model
     longformer_for_qa.save_pretrained(_lowercase				)

     print(f'''Conversion successful. Model saved under {pytorch_dump_folder_path}'''				)


if __name__ == "__main__":
     __a          =			argparse.ArgumentParser()
     # Required parameters
     parser.add_argument(
         '--longformer_model',
         default=None,
         type=str,
         required=True,
         help='model identifier of longformer. Should be either `longformer-base-4096` or `longformer-large-4096`.',
     )
     parser.add_argument(
         '--longformer_question_answering_ckpt_path',
         default=None,
         type=str,
         required=True,
         help='Path the official PyTorch Lightning Checkpoint.',
     )
     parser.add_argument(
         '--pytorch_dump_folder_path', default=None, type=str, required=True, help='Path to the output PyTorch model.'
     )
     __a          =			parser.parse_args()
     convert_longformer_qa_checkpoint_to_pytorch(
         args.longformer_model, args.longformer_question_answering_ckpt_path, args.pytorch_dump_folder_path
     )





import argparse
import logging
import pickle
from collections import Counter


logging.basicConfig(
    format='%(asctime)s - %(levelname)s - %(name)s - %(message)s', datefmt='%m/%d/%Y %H:%M:%S', level=logging.INFO
)
__a          =			logging.getLogger(__name__)

if __name__ == "__main__":
     __a          =			argparse.ArgumentParser(
         description='Token Counts for smoothing the masking probabilities in MLM (cf XLM/word2vec)'
     )
     parser.add_argument(
         '--data_file', type=str, default='data/dump.bert-base-uncased.pickle', help='The binarized dataset.'
     )
     parser.add_argument(
         '--token_counts_dump', type=str, default='data/token_counts.bert-base-uncased.pickle', help='The dump file.'
     )
     parser.add_argument('--vocab_size', default=30_522, type=int)
     __a          =			parser.parse_args()

     logger.info(F"""Loading data from {args.data_file}""")
     with open(args.data_file, 'rb') as fp:
          __a          =			pickle.load(fp)

     logger.info('Counting occurrences for MLM.')
     __a          =			Counter()
     for tk_ids in data:
          counter.update(tk_ids)
     __a          =			[0] * args.vocab_size
     for k, v in counter.items():
          __a          =			v

     logger.info(F"""Dump to {args.token_counts_dump}""")
     with open(args.token_counts_dump, 'wb') as handle:
          pickle.dump(counts, handle, protocol=pickle.HIGHEST_PROTOCOL)