



'''simple docstring'''

import argparse

import pytorch_lightning as pl
import torch
from torch import nn

from transformers import LongformerForQuestionAnswering, LongformerModel

class      __magic_name__						(   pl.LightningModule       ):







							def __init__(							self :	List[str]     ,_UpperCAmelCase :	Any		):
									super().__init__()
									_a					:				str				=							model
									_a					:				int				=							2
									_a					:				Tuple				=							nn.Linear(self.model.config.hidden_size     ,self.num_labels		)







							def 							__lowercase      (							self :	Optional[Any]		):
									pass



def 					__lowerCamelCase					(				lowerCAmelCase_						,      lowerCAmelCase_						,      lowerCAmelCase_  )      ->				Union[str, Any]:
		# load longformer model from model identifier
		_a					:				Optional[int]				=							LongformerModel.from_pretrained(lowerCAmelCase_  )
		_a					:				str				=							LightningModel(lowerCAmelCase_  )

		_a					:				Optional[int]				=							torch.load(lowerCAmelCase_						,      map_location=torch.device('cpu'  )  )
		lightning_model.load_state_dict(ckpt['state_dict']  )

		# init longformer question answering model
		_a					:				Optional[Any]				=							LongformerForQuestionAnswering.from_pretrained(lowerCAmelCase_  )

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

		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
							)









'''simple docstring'''

from __future__ import annotations

import os
from typing import Any

import requests

__lowerCAmelCase						      =       '''https://api.github.com'''

# https://docs.github.com/en/free-pro-team@latest/rest/reference/users#get-the-authenticated-user
__lowerCAmelCase						      =       BASE_URL + '''/user'''

# https://github.com/settings/tokens
__lowerCAmelCase						      =       os.environ.get('''USER_TOKEN''', '''''')



def 					__lowerCamelCase					(				lowerCAmelCase_  )      ->				dict[Any, Any]:
		_a					:				Union[str, Any]				=							{
		    'Authorization': f"""token {auth_token}""",
		    'Accept': 'application/vnd.github.v3+json',
		}
		return requests.get(lowerCAmelCase_						,      headers=lowerCAmelCase_  ).json()


if __name__ == "__main__":  # pragma: no cover
							if USER_TOKEN:
														for key, value in fetch_github_info(USER_TOKEN).items():
																					print(f"""{key}: {value}""")
							else:
														raise ValueError('''\'USER_TOKEN\' field cannot be empty.''')




