





import numpy as np
from cva import destroyAllWindows, imread, imshow, waitKey







class 	__lowerCAmelCase      :





   def __init__(			self       ,      snake_case       ,      snake_case       ,      snake_case   )					->	str:
      """simple docstring"""





      if dst_width < 0 or dst_height < 0:
         raise ValueError("Destination width/height should be > 0"   )

      a__						:    List[Any]   		=	img
      a__						:    Optional[int]   		=	img.shape[1]
      a__						:    Tuple   		=	img.shape[0]
      a__						:    Any   		=	dst_width
      a__						:    int   		=	dst_height

      a__						:    Tuple   		=	self.src_w / self.dst_w
      a__						:    Optional[int]   		=	self.src_h / self.dst_h

      a__						:    Optional[Any]   		=	(
          np.ones((self.dst_h, self.dst_w, 3)       ,      np.uinta   ) * 255
      )





   def 						_snake_case			(			self   )					->	Dict:
      """simple docstring"""





      for i in range(self.dst_h   ):
         for j in range(self.dst_w   ):
            a__						:    List[str]   		=	self.img[self.get_y(snake_case   )][self.get_x(snake_case   )]





   def 						_snake_case			(			self       ,      snake_case   )					->	int:
      """simple docstring"""





      return int(self.ratio_x * x   )





   def 						_snake_case			(			self       ,      snake_case   )					->	int:
      """simple docstring"""





      return int(self.ratio_y * y   )


if __name__ == "__main__":
  SCREAMING_SNAKE_CASE__   ,  SCREAMING_SNAKE_CASE__							:      Union[str, Any]         =    8_0_0, 6_0_0
  SCREAMING_SNAKE_CASE__							:      List[Any]         =    imread("""image_data/lena.jpg""", 1)
  SCREAMING_SNAKE_CASE__							:      Tuple         =    NearestNeighbour(im, dst_w, dst_h)
  n.process()

  imshow(
      f'Image resized from: {im.shape[1]}x{im.shape[0]} to {dst_w}x{dst_h}', n.output
  )
  waitKey(0)
  destroyAllWindows()








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       ,      snake_case   )					->	Dict:
      """simple docstring"""





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





   def 						_snake_case			(			self   )					->	List[str]:
      """simple docstring"""





      pass







def    _A	(   lowerCamelCase				,			lowerCamelCase				,			lowerCamelCase ):
   # load longformer model from model identifier
   a__						:    List[str]   		=	LongformerModel.from_pretrained(lowerCamelCase )
   a__						:    Dict   		=	LightningModel(lowerCamelCase )

   a__						:    str   		=	torch.load(lowerCamelCase				,			map_location=torch.device("cpu" ) )
   lightning_model.load_state_dict(ckpt["state_dict"] )

   # init longformer question answering model
   a__						:    Dict   		=	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__":
  SCREAMING_SNAKE_CASE__							:      Any         =    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."""
  )
  SCREAMING_SNAKE_CASE__							:      Optional[Any]         =    parser.parse_args()
  convert_longformer_qa_checkpoint_to_pytorch(
      args.longformer_model, args.longformer_question_answering_ckpt_path, args.pytorch_dump_folder_path
  )

