


import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
      import torch

if is_vision_available():
      from PIL import Image

      from transformers import PoolFormerImageProcessor





class   SCREAMING_SNAKE_CASE_			(unittest.TestCase						):




       '''simple docstring'''



       def __init__(						self				:				List[str]		,				__a				:				int		,				__a				:				Optional[int]=7		,				__a				:				Union[str, Any]=3		,				__a				:				int=30		,				__a				:				Tuple=400		,				__a				:				Dict=True		,				__a				:				Tuple=None		,				__a				:				List[str]=0.9		,				__a				:				Optional[Any]=None		,				__a				:				int=True		,				__a				:				Any=[0.5, 0.5, 0.5]		,				__a				:				Tuple=[0.5, 0.5, 0.5]		,				)					->str:
          lowerCamelCase_						:   List[Any]		= size if size is not None else {"""shortest_edge""": 30}
          lowerCamelCase_						:   Tuple		= crop_size if crop_size is not None else {"""height""": 30, """width""": 30}
          lowerCamelCase_						:   List[Any]		= parent
          lowerCamelCase_						:   Optional[int]		= batch_size
          lowerCamelCase_						:   List[Any]		= num_channels
          lowerCamelCase_						:   Dict		= min_resolution
          lowerCamelCase_						:   List[str]		= max_resolution
          lowerCamelCase_						:   List[str]		= do_resize_and_center_crop
          lowerCamelCase_						:   List[Any]		= size
          lowerCamelCase_						:   int		= crop_pct
          lowerCamelCase_						:   Dict		= crop_size
          lowerCamelCase_						:   List[str]		= do_normalize
          lowerCamelCase_						:   Optional[int]		= image_mean
          lowerCamelCase_						:   int		= image_std




       def 				_lowerCAmelCase							(						self				:				Any							)					->Optional[int]:
          return {
              "size": self.size,
              "do_resize_and_center_crop": self.do_resize_and_center_crop,
              "crop_pct": self.crop_pct,
              "crop_size": self.crop_size,
              "do_normalize": self.do_normalize,
              "image_mean": self.image_mean,
              "image_std": self.image_std,
          }







@require_torch
@require_vision
class   SCREAMING_SNAKE_CASE_			(a__						,       unittest.TestCase						):




       '''simple docstring'''



       _a   							=							PoolFormerImageProcessor if is_vision_available() else None



       def 				_lowerCAmelCase							(						self				:				Dict							)					->int:
          lowerCamelCase_						:   str		= PoolFormerImageProcessingTester(self							)



       @property
       def 				_lowerCAmelCase							(						self				:				str							)					->Tuple:
          return self.image_processor_tester.prepare_image_processor_dict()



       def 				_lowerCAmelCase							(						self				:				Tuple							)					->Union[str, Any]:
          lowerCamelCase_						:   str		= self.image_processing_class(**self.image_processor_dict							)
          self.assertTrue(hasattr(__a		,				"""do_resize_and_center_crop"""							)							)
          self.assertTrue(hasattr(__a		,				"""size"""							)							)
          self.assertTrue(hasattr(__a		,				"""crop_pct"""							)							)
          self.assertTrue(hasattr(__a		,				"""do_normalize"""							)							)
          self.assertTrue(hasattr(__a		,				"""image_mean"""							)							)
          self.assertTrue(hasattr(__a		,				"""image_std"""							)							)



       def 				_lowerCAmelCase							(						self				:				Union[str, Any]							)					->List[str]:
          lowerCamelCase_						:   Any		= self.image_processing_class.from_dict(self.image_processor_dict							)
          self.assertEqual(image_processor.size		,				{"""shortest_edge""": 30}							)
          self.assertEqual(image_processor.crop_size		,				{"""height""": 30, """width""": 30}							)

          lowerCamelCase_						:   List[str]		= self.image_processing_class.from_dict(self.image_processor_dict		,				size=42		,				crop_size=84							)
          self.assertEqual(image_processor.size		,				{"""shortest_edge""": 42}							)
          self.assertEqual(image_processor.crop_size		,				{"""height""": 84, """width""": 84}							)



       def 				_lowerCAmelCase							(						self				:				int							)					->Optional[Any]:
          pass



       def 				_lowerCAmelCase							(						self				:				Optional[Any]							)					->int:
          # Initialize image_processing
          lowerCamelCase_						:   Any		= self.image_processing_class(**self.image_processor_dict							)
          # create random PIL images
          lowerCamelCase_						:   Optional[Any]		= prepare_image_inputs(self.image_processor_tester		,				equal_resolution=__a							)
          for image in image_inputs:
             self.assertIsInstance(__a		,				Image.Image							)

          # Test not batched input
          lowerCamelCase_						:   Union[str, Any]		= image_processing(image_inputs[0]		,				return_tensors="""pt"""							).pixel_values

          self.assertEqual(
              encoded_images.shape		,				(
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["""height"""],
                  self.image_processor_tester.crop_size["""width"""],
              )		,				)

          # Test batched
          lowerCamelCase_						:   str		= image_processing(__a		,				return_tensors="""pt"""							).pixel_values
          self.assertEqual(
              encoded_images.shape		,				(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["""height"""],
                  self.image_processor_tester.crop_size["""width"""],
              )		,				)



       def 				_lowerCAmelCase							(						self				:				List[Any]							)					->List[str]:
          # Initialize image_processing
          lowerCamelCase_						:   Optional[int]		= self.image_processing_class(**self.image_processor_dict							)
          # create random numpy tensors
          lowerCamelCase_						:   Tuple		= prepare_image_inputs(self.image_processor_tester		,				equal_resolution=__a		,				numpify=__a							)
          for image in image_inputs:
             self.assertIsInstance(__a		,				np.ndarray							)

          # Test not batched input
          lowerCamelCase_						:   List[Any]		= image_processing(image_inputs[0]		,				return_tensors="""pt"""							).pixel_values
          self.assertEqual(
              encoded_images.shape		,				(
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["""height"""],
                  self.image_processor_tester.crop_size["""width"""],
              )		,				)

          # Test batched
          lowerCamelCase_						:   Dict		= image_processing(__a		,				return_tensors="""pt"""							).pixel_values
          self.assertEqual(
              encoded_images.shape		,				(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["""height"""],
                  self.image_processor_tester.crop_size["""width"""],
              )		,				)




       def 				_lowerCAmelCase							(						self				:				str							)					->str:
          # Initialize image_processing
          lowerCamelCase_						:   Tuple		= self.image_processing_class(**self.image_processor_dict							)
          # create random PyTorch tensors
          lowerCamelCase_						:   List[str]		= prepare_image_inputs(self.image_processor_tester		,				equal_resolution=__a		,				torchify=__a							)
          for image in image_inputs:
             self.assertIsInstance(__a		,				torch.Tensor							)

          # Test not batched input
          lowerCamelCase_						:   Tuple		= image_processing(image_inputs[0]		,				return_tensors="""pt"""							).pixel_values
          self.assertEqual(
              encoded_images.shape		,				(
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["""height"""],
                  self.image_processor_tester.crop_size["""width"""],
              )		,				)

          # Test batched
          lowerCamelCase_						:   Tuple		= image_processing(__a		,				return_tensors="""pt"""							).pixel_values
          self.assertEqual(
              encoded_images.shape		,				(
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.crop_size["""height"""],
                  self.image_processor_tester.crop_size["""width"""],
              )		,				)









from ...configuration_utils import PretrainedConfig
from ...utils import logging


snake_case__				:	List[Any]					       =					logging.get_logger(__name__)

snake_case__				:	str					       =					{
    'facebook/dpr-ctx_encoder-single-nq-base': (
        'https://huggingface.co/facebook/dpr-ctx_encoder-single-nq-base/resolve/main/config.json'
    ),
    'facebook/dpr-question_encoder-single-nq-base': (
        'https://huggingface.co/facebook/dpr-question_encoder-single-nq-base/resolve/main/config.json'
    ),
    'facebook/dpr-reader-single-nq-base': (
        'https://huggingface.co/facebook/dpr-reader-single-nq-base/resolve/main/config.json'
    ),
    'facebook/dpr-ctx_encoder-multiset-base': (
        'https://huggingface.co/facebook/dpr-ctx_encoder-multiset-base/resolve/main/config.json'
    ),
    'facebook/dpr-question_encoder-multiset-base': (
        'https://huggingface.co/facebook/dpr-question_encoder-multiset-base/resolve/main/config.json'
    ),
    'facebook/dpr-reader-multiset-base': (
        'https://huggingface.co/facebook/dpr-reader-multiset-base/resolve/main/config.json'
    ),
}





class   SCREAMING_SNAKE_CASE_			(a__						):




       '''simple docstring'''



       _a   							=							"dpr"



       def __init__(						self				:				Union[str, Any]		,				__a				:				Optional[Any]=30_522		,				__a				:				List[Any]=768		,				__a				:				List[Any]=12		,				__a				:				Dict=12		,				__a				:				Union[str, Any]=3_072		,				__a				:				Any="gelu"		,				__a				:				Any=0.1		,				__a				:				Any=0.1		,				__a				:				Tuple=512		,				__a				:				int=2		,				__a				:				Optional[Any]=0.02		,				__a				:				List[Any]=1e-12		,				__a				:				int=0		,				__a				:				int="absolute"		,				__a				:				int = 0		,				**__a				:				Optional[int]		,				)					->Tuple:
          super().__init__(pad_token_id=__a		,				**__a							)

          lowerCamelCase_						:   str		= vocab_size
          lowerCamelCase_						:   List[Any]		= hidden_size
          lowerCamelCase_						:   Optional[int]		= num_hidden_layers
          lowerCamelCase_						:   Optional[Any]		= num_attention_heads
          lowerCamelCase_						:   List[Any]		= hidden_act
          lowerCamelCase_						:   Optional[Any]		= intermediate_size
          lowerCamelCase_						:   List[Any]		= hidden_dropout_prob
          lowerCamelCase_						:   Any		= attention_probs_dropout_prob
          lowerCamelCase_						:   Any		= max_position_embeddings
          lowerCamelCase_						:   Tuple		= type_vocab_size
          lowerCamelCase_						:   Dict		= initializer_range
          lowerCamelCase_						:   List[Any]		= layer_norm_eps
          lowerCamelCase_						:   List[str]		= projection_dim
          lowerCamelCase_						:   Optional[int]		= position_embedding_type





