import argparse

import pytorch_lightning as pl
import torch
from torch import nn

from transformers import LongformerForQuestionAnswering, LongformerModel
class     lowerCAmelCase_     (       pl.LightningModule ):







							def __init__(   self      :     List[str] ,			_A      :     str		):
												super().__init__()
												_UpperCamelCase			     =     model
												_UpperCamelCase			     =     2
												_UpperCamelCase			     =     nn.Linear(self.model.config.hidden_size ,			self.num_labels		)







							def  UpperCamelCase_						(   self      :     List[str]		):
												pass




def 					_snake_case	(  __snake_case  ,     __snake_case  ,     __snake_case						):
					# load longformer model from model identifier
					_UpperCamelCase			     =     LongformerModel.from_pretrained(__snake_case						)
					_UpperCamelCase			     =     LightningModel(__snake_case						)

					_UpperCamelCase			     =     torch.load(__snake_case  ,     map_location=torch.device('''cpu'''						)						)
					lightning_model.load_state_dict(ckpt['''state_dict''']						)

					# init longformer question answering model
					_UpperCamelCase			     =     LongformerForQuestionAnswering.from_pretrained(__snake_case						)

					# 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(__snake_case						)

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


if __name__ == "__main__":
					_lowerCAmelCase       =		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."
					)
					_lowerCAmelCase       =		parser.parse_args()
					convert_longformer_qa_checkpoint_to_pytorch(
					    args.longformer_model, args.longformer_question_answering_ckpt_path, args.pytorch_dump_folder_path
					)

from __future__ import annotations

_lowerCAmelCase       =		[True] * 1_000_001
_lowerCAmelCase       =		2
while i * i <= 1_000_000:
					if seive[i]:
										for j in range(i * i, 1_000_001, i):
															_lowerCAmelCase       =		False
					i += 1
def 					_snake_case	(  __snake_case						):
					return seive[n]
def 					_snake_case	(  __snake_case						):
					return any(digit in '''02468''' for digit in str(__snake_case						)						)
def 					_snake_case	(  __snake_case = 1000000						):
					_UpperCamelCase			     =     [2]  # result already includes the number 2.
					for num in range(3  ,     limit + 1  ,     2						):
										if is_prime(__snake_case						) and not contains_an_even_digit(__snake_case						):
															_UpperCamelCase			     =     str(__snake_case						)
															_UpperCamelCase			     =     [int(str_num[j:] + str_num[:j]						) for j in range(len(__snake_case						)						)]
															if all(is_prime(__snake_case						) for i in list_nums						):
																				result.append(__snake_case						)
					return result
def 					_snake_case	(  ):
					return len(find_circular_primes()						)


if __name__ == "__main__":
					print(f'{len(find_circular_primes()) = }')
