
'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_keras_nlp_available,
    is_tensorflow_text_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


a__		:   List[Any]            =       {
    "configuration_gpt2": ["GPT2_PRETRAINED_CONFIG_ARCHIVE_MAP", "GPT2Config", "GPT2OnnxConfig"],
    "tokenization_gpt2": ["GPT2Tokenizer"],
}

try:
 if not is_tokenizers_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a__		:   int            =       ["GPT2TokenizerFast"]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a__		:   Optional[int]            =       [
     "GPT2_PRETRAINED_MODEL_ARCHIVE_LIST",
     "GPT2DoubleHeadsModel",
     "GPT2ForQuestionAnswering",
     "GPT2ForSequenceClassification",
     "GPT2ForTokenClassification",
     "GPT2LMHeadModel",
     "GPT2Model",
     "GPT2PreTrainedModel",
     "load_tf_weights_in_gpt2",
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a__		:   int            =       [
     "TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST",
     "TFGPT2DoubleHeadsModel",
     "TFGPT2ForSequenceClassification",
     "TFGPT2LMHeadModel",
     "TFGPT2MainLayer",
     "TFGPT2Model",
     "TFGPT2PreTrainedModel",
 ]

try:
 if not is_keras_nlp_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a__		:   Dict            =       ["TFGPT2Tokenizer"]

try:
 if not is_flax_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a__		:   Dict            =       ["FlaxGPT2LMHeadModel", "FlaxGPT2Model", "FlaxGPT2PreTrainedModel"]

if TYPE_CHECKING:
 from .configuration_gpta import GPT2_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTaConfig, GPTaOnnxConfig
 from .tokenization_gpta import GPTaTokenizer

 try:
  if not is_tokenizers_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_gpta_fast import GPTaTokenizerFast

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_gpta import (
      GPT2_PRETRAINED_MODEL_ARCHIVE_LIST,
      GPTaDoubleHeadsModel,
      GPTaForQuestionAnswering,
      GPTaForSequenceClassification,
      GPTaForTokenClassification,
      GPTaLMHeadModel,
      GPTaModel,
      GPTaPreTrainedModel,
      load_tf_weights_in_gpta,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_gpta import (
      TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFGPTaDoubleHeadsModel,
      TFGPTaForSequenceClassification,
      TFGPTaLMHeadModel,
      TFGPTaMainLayer,
      TFGPTaModel,
      TFGPTaPreTrainedModel,
  )

 try:
  if not is_keras_nlp_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_gpta_tf import TFGPTaTokenizer

 try:
  if not is_flax_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_flax_gpta import FlaxGPTaLMHeadModel, FlaxGPTaModel, FlaxGPTaPreTrainedModel

else:
 import sys

 a__		:   Tuple            =       _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)








'''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 DeiTImageProcessor


class  UpperCamelCase__  (    unittest.TestCase):






 def __init__(			self  :int	,				_A  :List[str]	,				_A  :Tuple=7	,				_A  :Dict=3	,				_A  :Any=18	,				_A  :List[Any]=30	,				_A  :Dict=400	,				_A  :Dict=True	,				_A  :Any=None	,				_A  :str=True	,				_A  :Union[str, Any]=None	,				_A  :Tuple=True	,				_A  :Any=[0.5, 0.5, 0.5]	,				_A  :List[str]=[0.5, 0.5, 0.5]	,				)				->			List[str]:







       '''simple docstring'''



       __A       	=			size if size is not None else {'height': 20, 'width': 20}
       __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 	lowercase_						(			self  :Dict			)				->			List[str]:







       '''simple docstring'''



       return {
           "do_resize": self.do_resize,
           "size": self.size,
           "do_center_crop": self.do_center_crop,
           "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  UpperCamelCase__  (    SCREAMING_SNAKE_CASE      ,     unittest.TestCase):
 UpperCAmelCase__    :    int										=					DeiTImageProcessor if is_vision_available() else None
 UpperCAmelCase__    :    Dict										=					True






 def 	lowercase_						(			self  :Dict			)				->			str:







       '''simple docstring'''



       __A       	=			DeiTImageProcessingTester(self			)






 @property
 def 	lowercase_						(			self  :Optional[Any]			)				->			Optional[Any]:







       '''simple docstring'''



       return self.image_processor_tester.prepare_image_processor_dict()






 def 	lowercase_						(			self  :Tuple			)				->			Tuple:







       '''simple docstring'''



       __A       	=			self.image_processing_class(**self.image_processor_dict			)
       self.assertTrue(hasattr(_A	,				'do_resize'			)			)
       self.assertTrue(hasattr(_A	,				'size'			)			)
       self.assertTrue(hasattr(_A	,				'do_center_crop'			)			)
       self.assertTrue(hasattr(_A	,				'center_crop'			)			)
       self.assertTrue(hasattr(_A	,				'do_normalize'			)			)
       self.assertTrue(hasattr(_A	,				'image_mean'			)			)
       self.assertTrue(hasattr(_A	,				'image_std'			)			)






 def 	lowercase_						(			self  :int			)				->			Optional[int]:







       '''simple docstring'''



       __A       	=			self.image_processing_class.from_dict(self.image_processor_dict			)
       self.assertEqual(image_processor.size	,				{'height': 20, 'width': 20}			)
       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	,				{'height': 42, 'width': 42}			)
       self.assertEqual(image_processor.crop_size	,				{'height': 84, 'width': 84}			)






 def 	lowercase_						(			self  :str			)				->			Any:







       '''simple docstring'''



       pass






 def 	lowercase_						(			self  :List[Any]			)				->			Optional[Any]:







       '''simple docstring'''



       __A       	=			self.image_processing_class(**self.image_processor_dict			)
       # create random PIL images
       __A       	=			prepare_image_inputs(self.image_processor_tester	,				equal_resolution=_A			)
       for image in image_inputs:
             self.assertIsInstance(_A	,				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(_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 	lowercase_						(			self  :Optional[Any]			)				->			Dict:







       '''simple docstring'''



       __A       	=			self.image_processing_class(**self.image_processor_dict			)
       # create random numpy tensors
       __A       	=			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
       __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(_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 	lowercase_						(			self  :List[Any]			)				->			Dict:







       '''simple docstring'''



       __A       	=			self.image_processing_class(**self.image_processor_dict			)
       # create random PyTorch tensors
       __A       	=			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
       __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(_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'],
           )	,				)






