code: 
  
  
  
  
  import argparse
  import collections
  from pathlib import Path
  
  import torch
  from torch.serialization import default_restore_location
  
  from transformers import BertConfig, DPRConfig, DPRContextEncoder, DPRQuestionEncoder, DPRReader
  
  
  SCREAMING_SNAKE_CASE__    :    List[str]								=					collections.namedtuple(
      "CheckpointState", ["model_dict", "optimizer_dict", "scheduler_dict", "offset", "epoch", "encoder_params"]
  )
  
  def lowercase						(     SCREAMING_SNAKE_CASE   ) ->       CheckpointState:
  
  
     '''simple docstring'''
  
  
  
  
  
  
  
     print(F'Reading saved model from {model_file}'   )
     SCREAMING_SNAKE_CASE_			=	torch.load(SCREAMING_SNAKE_CASE					,						map_location=lambda SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE   : default_restore_location(SCREAMING_SNAKE_CASE					,						'cpu'   )   )
     return CheckpointState(**SCREAMING_SNAKE_CASE   )
  
  
  
  class 			a_					:
  
  
  
  
  
   def __init__(       self			,    SCREAMING_SNAKE_CASE			)     ->				Optional[int]:
  
  
  
  
      """simple docstring"""
  
  
  
      SCREAMING_SNAKE_CASE_			=	src_file
  
  
  
  
  
   def 	A_(       self			)     ->				List[Any]:
  
  
  
  
      """simple docstring"""
  
  
  
      raise NotImplementedError
  
  
  
  
  
   @staticmethod
   def 	A_(       SCREAMING_SNAKE_CASE			,    *SCREAMING_SNAKE_CASE			,    **SCREAMING_SNAKE_CASE			)     ->				Optional[int]:
  
  
  
  
      """simple docstring"""
  
  
  
      if comp_type.startswith('c'			):
         return DPRContextEncoderState(*SCREAMING_SNAKE_CASE			,    **SCREAMING_SNAKE_CASE			)
      if comp_type.startswith('q'			):
         return DPRQuestionEncoderState(*SCREAMING_SNAKE_CASE			,    **SCREAMING_SNAKE_CASE			)
      if comp_type.startswith('r'			):
         return DPRReaderState(*SCREAMING_SNAKE_CASE			,    **SCREAMING_SNAKE_CASE			)
      else:
         raise ValueError('Component type must be either \'ctx_encoder\', \'question_encoder\' or \'reader\'.'			)
  
  
  
  
  class 			a_					(    lowercase_    ):
  
  
  
  
  
   def 	A_(       self			)     ->				Tuple:
  
  
  
  
      """simple docstring"""
  
  
  
      SCREAMING_SNAKE_CASE_			=	DPRContextEncoder(DPRConfig(**BertConfig.get_config_dict('bert-base-uncased'			)[0]			)			)
      print(f'Loading DPR biencoder from {self.src_file}'			)
      SCREAMING_SNAKE_CASE_			=	load_states_from_checkpoint(self.src_file			)
      SCREAMING_SNAKE_CASE_	,		SCREAMING_SNAKE_CASE_			=	model.ctx_encoder, 'ctx_model.'
      # Fix changes from https://github.com/huggingface/transformers/commit/614fef1691edb806de976756d4948ecbcd0c0ca3
      SCREAMING_SNAKE_CASE_			=	{'bert_model.embeddings.position_ids': model.ctx_encoder.bert_model.embeddings.position_ids}
      for key, value in saved_state.model_dict.items():
         if key.startswith(SCREAMING_SNAKE_CASE			):
            SCREAMING_SNAKE_CASE_			=	key[len(SCREAMING_SNAKE_CASE			) :]
            if not key.startswith('encode_proj.'			):
               SCREAMING_SNAKE_CASE_			=	'bert_model.' + key
            SCREAMING_SNAKE_CASE_			=	value
      encoder.load_state_dict(SCREAMING_SNAKE_CASE			)
      return model
  
  
  
  
  class 			a_					(    lowercase_    ):
  
  
  
  
  
   def 	A_(       self			)     ->				Union[str, Any]:
  
  
  
  
      """simple docstring"""
  
  
  
      SCREAMING_SNAKE_CASE_			=	DPRQuestionEncoder(DPRConfig(**BertConfig.get_config_dict('bert-base-uncased'			)[0]			)			)
      print(f'Loading DPR biencoder from {self.src_file}'			)
      SCREAMING_SNAKE_CASE_			=	load_states_from_checkpoint(self.src_file			)
      SCREAMING_SNAKE_CASE_	,		SCREAMING_SNAKE_CASE_			=	model.question_encoder, 'question_model.'
      # Fix changes from https://github.com/huggingface/transformers/commit/614fef1691edb806de976756d4948ecbcd0c0ca3
      SCREAMING_SNAKE_CASE_			=	{'bert_model.embeddings.position_ids': model.question_encoder.bert_model.embeddings.position_ids}
      for key, value in saved_state.model_dict.items():
         if key.startswith(SCREAMING_SNAKE_CASE			):
            SCREAMING_SNAKE_CASE_			=	key[len(SCREAMING_SNAKE_CASE			) :]
            if not key.startswith('encode_proj.'			):
               SCREAMING_SNAKE_CASE_			=	'bert_model.' + key
            SCREAMING_SNAKE_CASE_			=	value
      encoder.load_state_dict(SCREAMING_SNAKE_CASE			)
      return model
  
  
  
  
  class 			a_					(    lowercase_    ):
  
  
  
  
  
   def 	A_(       self			)     ->				List[str]:
  
  
  
  
      """simple docstring"""
  
  
  
      SCREAMING_SNAKE_CASE_			=	DPRReader(DPRConfig(**BertConfig.get_config_dict('bert-base-uncased'			)[0]			)			)
      print(f'Loading DPR reader from {self.src_file}'			)
      SCREAMING_SNAKE_CASE_			=	load_states_from_checkpoint(self.src_file			)
      # Fix changes from https://github.com/huggingface/transformers/commit/614fef1691edb806de976756d4948ecbcd0c0ca3
      SCREAMING_SNAKE_CASE_			=	{
          'encoder.bert_model.embeddings.position_ids': model.span_predictor.encoder.bert_model.embeddings.position_ids
      }
      for key, value in saved_state.model_dict.items():
         if key.startswith('encoder.'			) and not key.startswith('encoder.encode_proj'			):
            SCREAMING_SNAKE_CASE_			=	'encoder.bert_model.' + key[len('encoder.'			) :]
         SCREAMING_SNAKE_CASE_			=	value
      model.span_predictor.load_state_dict(SCREAMING_SNAKE_CASE			)
      return model
  
  
  
  
  def lowercase						(     SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE   ) ->       Optional[Any]:
  
  
     '''simple docstring'''
  
  
  
  
  
  
  
     SCREAMING_SNAKE_CASE_			=	Path(SCREAMING_SNAKE_CASE   )
     dest_dir.mkdir(exist_ok=SCREAMING_SNAKE_CASE   )
  
     SCREAMING_SNAKE_CASE_			=	DPRState.from_type(SCREAMING_SNAKE_CASE					,						src_file=SCREAMING_SNAKE_CASE   )
     SCREAMING_SNAKE_CASE_			=	dpr_state.load_dpr_model()
     model.save_pretrained(SCREAMING_SNAKE_CASE   )
     model.from_pretrained(SCREAMING_SNAKE_CASE   )  # sanity check
  
  
  if __name__ == "__main__":
      SCREAMING_SNAKE_CASE__    :    List[Any]								=					argparse.ArgumentParser()
      # Required parameters
      parser.add_argument(
          "--type", type=str, help="Type of the component to convert: \'ctx_encoder\', \'question_encoder\' or \'reader\'."
      )
      parser.add_argument(
          "--src",
          type=str,
          help=(
              "Path to the dpr checkpoint file. They can be downloaded from the official DPR repo"
              " https://github.com/facebookresearch/DPR. Note that in the official repo, both encoders are stored in the"
              " \'retriever\' checkpoints."
          ),
      )
      parser.add_argument("--dest", type=str, default=None, help="Path to the output PyTorch model directory.")
      SCREAMING_SNAKE_CASE__    :    Optional[int]								=					parser.parse_args()
  
      SCREAMING_SNAKE_CASE__    :    List[str]								=					Path(args.src)
      SCREAMING_SNAKE_CASE__    :    List[Any]								=					f"""converted-{src_file.name}""" if args.dest is None else args.dest
      SCREAMING_SNAKE_CASE__    :    Optional[int]								=					Path(dest_dir)
      assert src_file.exists()
      assert (
          args.type is not None
      ), "Please specify the component type of the DPR model to convert: 'ctx_encoder', 'question_encoder' or 'reader'."
      convert(args.type, src_file, dest_dir)
  
style_context: 
  
  
  
  
  from __future__ import annotations
  
  def lowercase						(     SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE   ) ->       None:
  
  
  			'''simple docstring'''
  
  
  
  
  
  
  
  			SCREAMING_SNAKE_CASE_	,		SCREAMING_SNAKE_CASE_			=	m - 1, 0
  			while i >= 0 and j < n:
  						if key == mat[i][j]:
  									print(F'Key {key} found at row- {i + 1} column- {j + 1}'   )
  									return
  						if key < mat[i][j]:
  									i -= 1
  						else:
  									j += 1
  			print(F'Key {key} not found'   )
  
  def lowercase						(     ) ->       None:
  
  
  			'''simple docstring'''
  
  
  
  
  
  
  
  			SCREAMING_SNAKE_CASE_			=	[[2, 5, 7], [4, 8, 13], [9, 11, 15], [12, 17, 20]]
  			SCREAMING_SNAKE_CASE_			=	int(input('Enter the element to be searched:'   )   )
  			print(SCREAMING_SNAKE_CASE   )
  			search_in_a_sorted_matrix(SCREAMING_SNAKE_CASE					,						len(SCREAMING_SNAKE_CASE   )					,						len(mat[0]   )					,						SCREAMING_SNAKE_CASE   )
  
  
  if __name__ == "__main__":
  				import doctest
  
  				doctest.testmod()
  				main()
  