




'''simple docstring'''


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 LevitImageProcessor





class    __lowercase						(  unittest.TestCase ):







   def __init__(	self      ,							UpperCamelCase      ,							UpperCamelCase=7      ,							UpperCamelCase=3      ,							UpperCamelCase=18      ,							UpperCamelCase=30      ,							UpperCamelCase=400      ,							UpperCamelCase=True      ,							UpperCamelCase=None      ,							UpperCamelCase=True      ,							UpperCamelCase=None      ,							UpperCamelCase=True      ,							UpperCamelCase=[0.5, 0.5, 0.5]      ,							UpperCamelCase=[0.5, 0.5, 0.5]      ,							)				->    Optional[Any]:
     __a			=					size if size is not None else {'shortest_edge': 18}
     __a			=					crop_size if crop_size is not None else {'height': 18, 'width': 18}
     __a			=					parent
     __a			=					batch_size
     __a			=					num_channels
     __a			=					image_size
     __a			=					min_resolution
     __a			=					max_resolution
     __a			=					do_resize
     __a			=					size
     __a			=					do_center_crop
     __a			=					crop_size
     __a			=					do_normalize
     __a			=					image_mean
     __a			=					image_std







   def 		UpperCamelCase__			(	self      )				->    Union[str, Any]:
     return {
         "image_mean": self.image_mean,
         "image_std": self.image_std,
         "do_normalize": self.do_normalize,
         "do_resize": self.do_resize,
         "do_center_crop": self.do_center_crop,
         "size": self.size,
         "crop_size": self.crop_size,
     }





@require_torch
@require_vision
class    __lowercase						(  __magic_name__       ,							unittest.TestCase ):
   _a							=      LevitImageProcessor if is_vision_available() else None







   def 		UpperCamelCase__			(	self      )				->    Union[str, Any]:
     __a			=					LevitImageProcessingTester(self      )







   @property
   def 		UpperCamelCase__			(	self      )				->    List[str]:
     return self.image_processor_tester.prepare_image_processor_dict()







   def 		UpperCamelCase__			(	self      )				->    str:
     __a			=					self.image_processing_class(**self.image_processor_dict      )
     self.assertTrue(hasattr(UpperCamelCase      ,							'image_mean'      )      )
     self.assertTrue(hasattr(UpperCamelCase      ,							'image_std'      )      )
     self.assertTrue(hasattr(UpperCamelCase      ,							'do_normalize'      )      )
     self.assertTrue(hasattr(UpperCamelCase      ,							'do_resize'      )      )
     self.assertTrue(hasattr(UpperCamelCase      ,							'do_center_crop'      )      )
     self.assertTrue(hasattr(UpperCamelCase      ,							'size'      )      )







   def 		UpperCamelCase__			(	self      )				->    Dict:
     __a			=					self.image_processing_class.from_dict(self.image_processor_dict      )
     self.assertEqual(image_processor.size      ,							{'shortest_edge': 18}      )
     self.assertEqual(image_processor.crop_size      ,							{'height': 18, 'width': 18}      )

     __a			=					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 		UpperCamelCase__			(	self      )				->    Dict:
     pass







   def 		UpperCamelCase__			(	self      )				->    Any:
     # Initialize image_processing
     __a			=					self.image_processing_class(**self.image_processor_dict      )
     # create random PIL images
     __a			=					prepare_image_inputs(self.image_processor_tester      ,							equal_resolution=UpperCamelCase      )
     for image in image_inputs:
       self.assertIsInstance(UpperCamelCase      ,							Image.Image      )

     # Test not batched input
     __a			=					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
     __a			=					image_processing(UpperCamelCase      ,							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 		UpperCamelCase__			(	self      )				->    Dict:
     # Initialize image_processing
     __a			=					self.image_processing_class(**self.image_processor_dict      )
     # create random numpy tensors
     __a			=					prepare_image_inputs(self.image_processor_tester      ,							equal_resolution=UpperCamelCase      ,							numpify=UpperCamelCase      )
     for image in image_inputs:
       self.assertIsInstance(UpperCamelCase      ,							np.ndarray      )

     # Test not batched input
     __a			=					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
     __a			=					image_processing(UpperCamelCase      ,							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 		UpperCamelCase__			(	self      )				->    str:
     # Initialize image_processing
     __a			=					self.image_processing_class(**self.image_processor_dict      )
     # create random PyTorch tensors
     __a			=					prepare_image_inputs(self.image_processor_tester      ,							equal_resolution=UpperCamelCase      ,							torchify=UpperCamelCase      )
     for image in image_inputs:
       self.assertIsInstance(UpperCamelCase      ,							torch.Tensor      )

     # Test not batched input
     __a			=					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
     __a			=					image_processing(UpperCamelCase      ,							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'],
         )      ,							)









'''simple docstring'''


from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


UpperCAmelCase_ 		=      logging.get_logger(__name__)

UpperCAmelCase_ 		=      {
    "distilbert-base-uncased": "https://huggingface.co/distilbert-base-uncased/resolve/main/config.json",
    "distilbert-base-uncased-distilled-squad": (
        "https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/config.json"
    ),
    "distilbert-base-cased": "https://huggingface.co/distilbert-base-cased/resolve/main/config.json",
    "distilbert-base-cased-distilled-squad": (
        "https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/config.json"
    ),
    "distilbert-base-german-cased": "https://huggingface.co/distilbert-base-german-cased/resolve/main/config.json",
    "distilbert-base-multilingual-cased": (
        "https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/config.json"
    ),
    "distilbert-base-uncased-finetuned-sst-2-english": (
        "https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english/resolve/main/config.json"
    ),
}





class    __lowercase						(  __magic_name__ ):
   _a							=      """distilbert"""
   _a							=      {
       """hidden_size""": """dim""",
       """num_attention_heads""": """n_heads""",
       """num_hidden_layers""": """n_layers""",
   }







   def __init__(	self      ,							UpperCamelCase=3_0522      ,							UpperCamelCase=512      ,							UpperCamelCase=False      ,							UpperCamelCase=6      ,							UpperCamelCase=12      ,							UpperCamelCase=768      ,							UpperCamelCase=4 * 768      ,							UpperCamelCase=0.1      ,							UpperCamelCase=0.1      ,							UpperCamelCase="gelu"      ,							UpperCamelCase=0.02      ,							UpperCamelCase=0.1      ,							UpperCamelCase=0.2      ,							UpperCamelCase=0      ,							**UpperCamelCase      ,							)				->    int:
     __a			=					vocab_size
     __a			=					max_position_embeddings
     __a			=					sinusoidal_pos_embds
     __a			=					n_layers
     __a			=					n_heads
     __a			=					dim
     __a			=					hidden_dim
     __a			=					dropout
     __a			=					attention_dropout
     __a			=					activation
     __a			=					initializer_range
     __a			=					qa_dropout
     __a			=					seq_classif_dropout
     super().__init__(**UpperCamelCase      ,							pad_token_id=UpperCamelCase      )





class    __lowercase						(  __magic_name__ ):







   @property
   def 		UpperCamelCase__			(	self      )				->    Mapping[str, Mapping[int, str]]:
     if self.task == "multiple-choice":
       __a			=					{0: 'batch', 1: 'choice', 2: 'sequence'}
     else:
       __a			=					{0: 'batch', 1: 'sequence'}
     return OrderedDict(
         [
             ('input_ids', dynamic_axis),
             ('attention_mask', dynamic_axis),
         ]      )



