






import argparse

import pytorch_lightning as pl
import torch
from torch import nn

from transformers import LongformerForQuestionAnswering, LongformerModel




class 							_lowerCAmelCase(			pl.LightningModule   ):





       """simple docstring"""







       def __init__(   self    ,     _lowerCamelCase				):
         super().__init__()
         UpperCamelCase_:   Optional[Any]        =							model
         UpperCamelCase_:   Any        =							2
         UpperCamelCase_:   Tuple        =							nn.Linear(self.model.config.hidden_size    ,     self.num_labels				)





       def      _a       (   self				):
         pass







def     snake_case   (UpperCAmelCase__      ,       UpperCAmelCase__      ,       UpperCAmelCase__    )			->							Tuple:
  # load longformer model from model identifier
  UpperCamelCase_:   List[str]        =							LongformerModel.from_pretrained(UpperCAmelCase__    )
  UpperCamelCase_:   Dict        =							LightningModel(UpperCAmelCase__    )

  UpperCamelCase_:   int        =							torch.load(UpperCAmelCase__      ,       map_location=torch.device('cpu'    )    )
  lightning_model.load_state_dict(ckpt['state_dict']    )

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

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

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


if __name__ == "__main__":
   A_						:						int						      =					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_						:						Dict						      =					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

from typing import Any







def       a_				(	UpperCamelCase_ ):
							create_state_space_tree(UpperCamelCase_						,  []						,  0 )







def       a_				(	UpperCamelCase_						,  UpperCamelCase_						,  UpperCamelCase_ ):

							if index == len(UpperCamelCase_ ):
														print(UpperCamelCase_ )
														return

							create_state_space_tree(UpperCamelCase_						,  UpperCamelCase_						,  index + 1 )
							current_subsequence.append(sequence[index] )
							create_state_space_tree(UpperCamelCase_						,  UpperCamelCase_						,  index + 1 )
							current_subsequence.pop()


if __name__ == "__main__":
							__SCREAMING_SNAKE_CASE					:				list[Any]									=		[3, 1, 2, 4]
							generate_all_subsequences(seq)

							seq.clear()
							seq.extend(['''A''', '''B''', '''C'''])
							generate_all_subsequences(seq)





