





import tempfile

import torch

from diffusers import (
    DEISMultistepScheduler,
    DPMSolverMultistepScheduler,
    DPMSolverSinglestepScheduler,
    UniPCMultistepScheduler,
)

from .test_schedulers import SchedulerCommonTest



class        _SCREAMING_SNAKE_CASE						(     __SCREAMING_SNAKE_CASE   ):







 '''simple docstring'''
 lowercase_		=      (DEISMultistepScheduler,)
 lowercase_		=      (("num_inference_steps", 25),)

 def 							SCREAMING_SNAKE_CASE_ (self    :       str	,			**UpperCAmelCase_    :       Union[str, Any])	->Dict:



   '''simple docstring'''



   lowerCamelCase__:				Any        ={
       "num_train_timesteps": 1_000,
       "beta_start": 0.0001,
       "beta_end": 0.02,
       "beta_schedule": "linear",
       "solver_order": 2,
   }

   config.update(**UpperCAmelCase_)
   return config

 def 							SCREAMING_SNAKE_CASE_ (self    :       int	,			UpperCAmelCase_    :       Any=0	,			**UpperCAmelCase_    :       List[str])	->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__:				Dict        =dict(self.forward_default_kwargs)
   lowerCamelCase__:				Dict        =kwargs.pop("num_inference_steps"	,			UpperCAmelCase_)
   lowerCamelCase__:				Optional[Any]        =self.dummy_sample
   lowerCamelCase__:				Any        =0.1 * sample
   lowerCamelCase__:				Optional[Any]        =[residual + 0.2, residual + 0.15, residual + 0.10]

   for scheduler_class in self.scheduler_classes:
     lowerCamelCase__:				Dict        =self.get_scheduler_config(**UpperCAmelCase_)
     lowerCamelCase__:				int        =scheduler_class(**UpperCAmelCase_)
     scheduler.set_timesteps(UpperCAmelCase_)
     # copy over dummy past residuals
     lowerCamelCase__:				Dict        =dummy_past_residuals[: scheduler.config.solver_order]

     with tempfile.TemporaryDirectory() as tmpdirname:
       scheduler.save_config(UpperCAmelCase_)
       lowerCamelCase__:				str        =scheduler_class.from_pretrained(UpperCAmelCase_)
       new_scheduler.set_timesteps(UpperCAmelCase_)
       # copy over dummy past residuals
       lowerCamelCase__:				int        =dummy_past_residuals[: new_scheduler.config.solver_order]

     lowerCamelCase__  , lowerCamelCase__:				List[str]        =sample, sample
     for t in range(UpperCAmelCase_	,			time_step + scheduler.config.solver_order + 1):
       lowerCamelCase__:				int        =scheduler.step(UpperCAmelCase_	,			UpperCAmelCase_	,			UpperCAmelCase_	,			**UpperCAmelCase_).prev_sample
       lowerCamelCase__:				Union[str, Any]        =new_scheduler.step(UpperCAmelCase_	,			UpperCAmelCase_	,			UpperCAmelCase_	,			**UpperCAmelCase_).prev_sample

       assert torch.sum(torch.abs(output - new_output)) < 1E-5, "Scheduler outputs are not identical"

 def 							SCREAMING_SNAKE_CASE_ (self    :       Dict)	->List[Any]:



   '''simple docstring'''



   pass

 def 							SCREAMING_SNAKE_CASE_ (self    :       Dict	,			UpperCAmelCase_    :       List[str]=0	,			**UpperCAmelCase_    :       Optional[int])	->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__:				Any        =dict(self.forward_default_kwargs)
   lowerCamelCase__:				Dict        =kwargs.pop("num_inference_steps"	,			UpperCAmelCase_)
   lowerCamelCase__:				Optional[int]        =self.dummy_sample
   lowerCamelCase__:				List[Any]        =0.1 * sample
   lowerCamelCase__:				str        =[residual + 0.2, residual + 0.15, residual + 0.10]

   for scheduler_class in self.scheduler_classes:
     lowerCamelCase__:				Dict        =self.get_scheduler_config()
     lowerCamelCase__:				str        =scheduler_class(**UpperCAmelCase_)
     scheduler.set_timesteps(UpperCAmelCase_)

     # copy over dummy past residuals (must be after setting timesteps)
     lowerCamelCase__:				Tuple        =dummy_past_residuals[: scheduler.config.solver_order]

     with tempfile.TemporaryDirectory() as tmpdirname:
       scheduler.save_config(UpperCAmelCase_)
       lowerCamelCase__:				List[Any]        =scheduler_class.from_pretrained(UpperCAmelCase_)
       # copy over dummy past residuals
       new_scheduler.set_timesteps(UpperCAmelCase_)

       # copy over dummy past residual (must be after setting timesteps)
       lowerCamelCase__:				Dict        =dummy_past_residuals[: new_scheduler.config.solver_order]

     lowerCamelCase__:				List[Any]        =scheduler.step(UpperCAmelCase_	,			UpperCAmelCase_	,			UpperCAmelCase_	,			**UpperCAmelCase_).prev_sample
     lowerCamelCase__:				int        =new_scheduler.step(UpperCAmelCase_	,			UpperCAmelCase_	,			UpperCAmelCase_	,			**UpperCAmelCase_).prev_sample

     assert torch.sum(torch.abs(output - new_output)) < 1E-5, "Scheduler outputs are not identical"

 def 							SCREAMING_SNAKE_CASE_ (self    :       List[str]	,			UpperCAmelCase_    :       Tuple=None	,			**UpperCAmelCase_    :       Optional[Any])	->Union[str, Any]:



   '''simple docstring'''



   if scheduler is None:
     lowerCamelCase__:				List[str]        =self.scheduler_classes[0]
     lowerCamelCase__:				List[Any]        =self.get_scheduler_config(**UpperCAmelCase_)
     lowerCamelCase__:				Optional[int]        =scheduler_class(**UpperCAmelCase_)

   lowerCamelCase__:				Optional[Any]        =self.scheduler_classes[0]
   lowerCamelCase__:				List[str]        =self.get_scheduler_config(**UpperCAmelCase_)
   lowerCamelCase__:				List[str]        =scheduler_class(**UpperCAmelCase_)

   lowerCamelCase__:				Optional[int]        =10
   lowerCamelCase__:				Union[str, Any]        =self.dummy_model()
   lowerCamelCase__:				Tuple        =self.dummy_sample_deter
   scheduler.set_timesteps(UpperCAmelCase_)

   for i, t in enumerate(scheduler.timesteps):
     lowerCamelCase__:				Any        =model(UpperCAmelCase_	,			UpperCAmelCase_)
     lowerCamelCase__:				str        =scheduler.step(UpperCAmelCase_	,			UpperCAmelCase_	,			UpperCAmelCase_).prev_sample

   return sample

 def 							SCREAMING_SNAKE_CASE_ (self    :       Dict)	->List[Any]:



   '''simple docstring'''



   lowerCamelCase__:				Union[str, Any]        =dict(self.forward_default_kwargs)

   lowerCamelCase__:				Tuple        =kwargs.pop("num_inference_steps"	,			UpperCAmelCase_)

   for scheduler_class in self.scheduler_classes:
     lowerCamelCase__:				List[Any]        =self.get_scheduler_config()
     lowerCamelCase__:				Dict        =scheduler_class(**UpperCAmelCase_)

     lowerCamelCase__:				Tuple        =self.dummy_sample
     lowerCamelCase__:				Optional[Any]        =0.1 * sample

     if num_inference_steps is not None and hasattr(UpperCAmelCase_	,			"set_timesteps"):
       scheduler.set_timesteps(UpperCAmelCase_)
     elif num_inference_steps is not None and not hasattr(UpperCAmelCase_	,			"set_timesteps"):
       lowerCamelCase__:				List[Any]        =num_inference_steps

     # copy over dummy past residuals (must be done after set_timesteps)
     lowerCamelCase__:				List[Any]        =[residual + 0.2, residual + 0.15, residual + 0.10]
     lowerCamelCase__:				List[str]        =dummy_past_residuals[: scheduler.config.solver_order]

     lowerCamelCase__:				Tuple        =scheduler.timesteps[5]
     lowerCamelCase__:				Tuple        =scheduler.timesteps[6]

     lowerCamelCase__:				Tuple        =scheduler.step(UpperCAmelCase_	,			UpperCAmelCase_	,			UpperCAmelCase_	,			**UpperCAmelCase_).prev_sample
     lowerCamelCase__:				List[str]        =scheduler.step(UpperCAmelCase_	,			UpperCAmelCase_	,			UpperCAmelCase_	,			**UpperCAmelCase_).prev_sample

     self.assertEqual(output_a.shape	,			sample.shape)
     self.assertEqual(output_a.shape	,			output_a.shape)

 def 							SCREAMING_SNAKE_CASE_ (self    :       str)	->Any:



   '''simple docstring'''



   lowerCamelCase__:				Any        =DEISMultistepScheduler(**self.get_scheduler_config())
   lowerCamelCase__:				int        =self.full_loop(scheduler=UpperCAmelCase_)
   lowerCamelCase__:				Optional[Any]        =torch.mean(torch.abs(UpperCAmelCase_))

   assert abs(result_mean.item() - 0.2_3916) < 1E-3

   lowerCamelCase__:				int        =DPMSolverSinglestepScheduler.from_config(scheduler.config)
   lowerCamelCase__:				Dict        =DPMSolverMultistepScheduler.from_config(scheduler.config)
   lowerCamelCase__:				Any        =UniPCMultistepScheduler.from_config(scheduler.config)
   lowerCamelCase__:				str        =DEISMultistepScheduler.from_config(scheduler.config)

   lowerCamelCase__:				Tuple        =self.full_loop(scheduler=UpperCAmelCase_)
   lowerCamelCase__:				Dict        =torch.mean(torch.abs(UpperCAmelCase_))

   assert abs(result_mean.item() - 0.2_3916) < 1E-3

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



   '''simple docstring'''



   for timesteps in [25, 50, 100, 999, 1_000]:
     self.check_over_configs(num_train_timesteps=UpperCAmelCase_)

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



   '''simple docstring'''



   self.check_over_configs(thresholding=UpperCAmelCase_)
   for order in [1, 2, 3]:
     for solver_type in ["logrho"]:
       for threshold in [0.5, 1.0, 2.0]:
         for prediction_type in ["epsilon", "sample"]:
           self.check_over_configs(
               thresholding=UpperCAmelCase_	,			prediction_type=UpperCAmelCase_	,			sample_max_value=UpperCAmelCase_	,			algorithm_type="deis"	,			solver_order=UpperCAmelCase_	,			solver_type=UpperCAmelCase_	,			)

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



   '''simple docstring'''



   for prediction_type in ["epsilon", "v_prediction"]:
     self.check_over_configs(prediction_type=UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_ (self    :       Union[str, Any])	->List[Any]:



   '''simple docstring'''



   for algorithm_type in ["deis"]:
     for solver_type in ["logrho"]:
       for order in [1, 2, 3]:
         for prediction_type in ["epsilon", "sample"]:
           self.check_over_configs(
               solver_order=UpperCAmelCase_	,			solver_type=UpperCAmelCase_	,			prediction_type=UpperCAmelCase_	,			algorithm_type=UpperCAmelCase_	,			)
           lowerCamelCase__:				Any        =self.full_loop(
               solver_order=UpperCAmelCase_	,			solver_type=UpperCAmelCase_	,			prediction_type=UpperCAmelCase_	,			algorithm_type=UpperCAmelCase_	,			)
           assert not torch.isnan(UpperCAmelCase_).any(), "Samples have nan numbers"

 def 							SCREAMING_SNAKE_CASE_ (self    :       str)	->List[str]:



   '''simple docstring'''



   self.check_over_configs(lower_order_final=UpperCAmelCase_)
   self.check_over_configs(lower_order_final=UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_ (self    :       Optional[int])	->Tuple:



   '''simple docstring'''



   for num_inference_steps in [1, 2, 3, 5, 10, 50, 100, 999, 1_000]:
     self.check_over_forward(num_inference_steps=UpperCAmelCase_	,			time_step=0)

 def 							SCREAMING_SNAKE_CASE_ (self    :       Dict)	->Optional[Any]:



   '''simple docstring'''



   lowerCamelCase__:				Any        =self.full_loop()
   lowerCamelCase__:				Optional[Any]        =torch.mean(torch.abs(UpperCAmelCase_))

   assert abs(result_mean.item() - 0.2_3916) < 1E-3

 def 							SCREAMING_SNAKE_CASE_ (self    :       int)	->Dict:



   '''simple docstring'''



   lowerCamelCase__:				int        =self.full_loop(prediction_type="v_prediction")
   lowerCamelCase__:				Tuple        =torch.mean(torch.abs(UpperCAmelCase_))

   assert abs(result_mean.item() - 0.091) < 1E-3







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



   '''simple docstring'''



   lowerCamelCase__:				Dict        =self.scheduler_classes[0]
   lowerCamelCase__:				Union[str, Any]        =self.get_scheduler_config(thresholding=UpperCAmelCase_	,			dynamic_thresholding_ratio=0)
   lowerCamelCase__:				str        =scheduler_class(**UpperCAmelCase_)

   lowerCamelCase__:				Dict        =10
   lowerCamelCase__:				Union[str, Any]        =self.dummy_model()
   lowerCamelCase__:				int        =self.dummy_sample_deter.half()
   scheduler.set_timesteps(UpperCAmelCase_)

   for i, t in enumerate(scheduler.timesteps):
     lowerCamelCase__:				Optional[Any]        =model(UpperCAmelCase_	,			UpperCAmelCase_)
     lowerCamelCase__:				str        =scheduler.step(UpperCAmelCase_	,			UpperCAmelCase_	,			UpperCAmelCase_).prev_sample

   assert sample.dtype == torch.floataa








from __future__ import annotations

import inspect
import unittest

from transformers import ViTConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
     import tensorflow as tf

     from transformers import TFViTForImageClassification, TFViTModel


if is_vision_available():
     from PIL import Image

     from transformers import ViTImageProcessor



class        _SCREAMING_SNAKE_CASE						:







 '''simple docstring'''

 def __init__(self    :       Optional[Any]	,			UpperCAmelCase_    :       Optional[int]	,			UpperCAmelCase_    :       List[Any]=13	,			UpperCAmelCase_    :       Dict=30	,			UpperCAmelCase_    :       str=2	,			UpperCAmelCase_    :       Union[str, Any]=3	,			UpperCAmelCase_    :       Union[str, Any]=True	,			UpperCAmelCase_    :       List[str]=True	,			UpperCAmelCase_    :       Dict=32	,			UpperCAmelCase_    :       List[Any]=2	,			UpperCAmelCase_    :       List[str]=4	,			UpperCAmelCase_    :       List[str]=37	,			UpperCAmelCase_    :       List[str]="gelu"	,			UpperCAmelCase_    :       List[Any]=0.1	,			UpperCAmelCase_    :       Optional[Any]=0.1	,			UpperCAmelCase_    :       str=10	,			UpperCAmelCase_    :       str=0.02	,			UpperCAmelCase_    :       Optional[int]=3	,			UpperCAmelCase_    :       Dict=None	,			)	->Union[str, Any]:



   '''simple docstring'''



   lowerCamelCase__:				int        =parent
   lowerCamelCase__:				Any        =batch_size
   lowerCamelCase__:				List[str]        =image_size
   lowerCamelCase__:				Tuple        =patch_size
   lowerCamelCase__:				Tuple        =num_channels
   lowerCamelCase__:				Tuple        =is_training
   lowerCamelCase__:				Optional[int]        =use_labels
   lowerCamelCase__:				Dict        =hidden_size
   lowerCamelCase__:				Dict        =num_hidden_layers
   lowerCamelCase__:				Optional[Any]        =num_attention_heads
   lowerCamelCase__:				Union[str, Any]        =intermediate_size
   lowerCamelCase__:				List[str]        =hidden_act
   lowerCamelCase__:				Optional[Any]        =hidden_dropout_prob
   lowerCamelCase__:				str        =attention_probs_dropout_prob
   lowerCamelCase__:				str        =type_sequence_label_size
   lowerCamelCase__:				Optional[Any]        =initializer_range
   lowerCamelCase__:				Optional[int]        =scope

   # in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
   lowerCamelCase__:				List[str]        =(image_size // patch_size) ** 2
   lowerCamelCase__:				Optional[Any]        =num_patches + 1

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



   '''simple docstring'''



   lowerCamelCase__:				Tuple        =floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

   lowerCamelCase__:				List[str]        =None
   if self.use_labels:
     lowerCamelCase__:				Any        =ids_tensor([self.batch_size]	,			self.type_sequence_label_size)

   lowerCamelCase__:				List[str]        =self.get_config()

   return config, pixel_values, labels

 def 							SCREAMING_SNAKE_CASE_ (self    :       Optional[int])	->List[str]:



   '''simple docstring'''



   return ViTConfig(
       image_size=self.image_size	,			patch_size=self.patch_size	,			num_channels=self.num_channels	,			hidden_size=self.hidden_size	,			num_hidden_layers=self.num_hidden_layers	,			num_attention_heads=self.num_attention_heads	,			intermediate_size=self.intermediate_size	,			hidden_act=self.hidden_act	,			hidden_dropout_prob=self.hidden_dropout_prob	,			attention_probs_dropout_prob=self.attention_probs_dropout_prob	,			is_decoder=UpperCAmelCase_	,			initializer_range=self.initializer_range	,			)

 def 							SCREAMING_SNAKE_CASE_ (self    :       int	,			UpperCAmelCase_    :       int	,			UpperCAmelCase_    :       Optional[Any]	,			UpperCAmelCase_    :       Tuple)	->Tuple:



   '''simple docstring'''



   lowerCamelCase__:				List[str]        =TFViTModel(config=UpperCAmelCase_)
   lowerCamelCase__:				Tuple        =model(UpperCAmelCase_	,			training=UpperCAmelCase_)
   self.parent.assertEqual(result.last_hidden_state.shape	,			(self.batch_size, self.seq_length, self.hidden_size))

   # Test with an image with different size than the one specified in config.
   lowerCamelCase__:				Dict        =self.image_size // 2
   lowerCamelCase__:				List[str]        =pixel_values[:, :, :image_size, :image_size]
   lowerCamelCase__:				List[str]        =model(UpperCAmelCase_	,			interpolate_pos_encoding=UpperCAmelCase_	,			training=UpperCAmelCase_)
   lowerCamelCase__:				List[str]        =(image_size // self.patch_size) ** 2 + 1
   self.parent.assertEqual(result.last_hidden_state.shape	,			(self.batch_size, seq_length, self.hidden_size))

 def 							SCREAMING_SNAKE_CASE_ (self    :       Optional[Any]	,			UpperCAmelCase_    :       Tuple	,			UpperCAmelCase_    :       int	,			UpperCAmelCase_    :       Any)	->str:



   '''simple docstring'''



   lowerCamelCase__:				Any        =self.type_sequence_label_size
   lowerCamelCase__:				str        =TFViTForImageClassification(UpperCAmelCase_)
   lowerCamelCase__:				List[str]        =model(UpperCAmelCase_	,			labels=UpperCAmelCase_	,			training=UpperCAmelCase_)
   self.parent.assertEqual(result.logits.shape	,			(self.batch_size, self.type_sequence_label_size))

   # Test with an image with different size than the one specified in config.
   lowerCamelCase__:				Union[str, Any]        =self.image_size // 2
   lowerCamelCase__:				Dict        =pixel_values[:, :, :image_size, :image_size]
   lowerCamelCase__:				Tuple        =model(UpperCAmelCase_	,			interpolate_pos_encoding=UpperCAmelCase_	,			training=UpperCAmelCase_)
   self.parent.assertEqual(result.logits.shape	,			(self.batch_size, self.type_sequence_label_size))

   # test greyscale images
   lowerCamelCase__:				int        =1
   lowerCamelCase__:				List[str]        =TFViTForImageClassification(UpperCAmelCase_)
   lowerCamelCase__:				List[str]        =floats_tensor([self.batch_size, 1, self.image_size, self.image_size])
   lowerCamelCase__:				Any        =model(UpperCAmelCase_)
   self.parent.assertEqual(result.logits.shape	,			(self.batch_size, self.type_sequence_label_size))







 def 							SCREAMING_SNAKE_CASE_ (self    :       str)	->Union[str, Any]:



   '''simple docstring'''



   lowerCamelCase__:				Optional[Any]        =self.prepare_config_and_inputs()
   lowerCamelCase__  , lowerCamelCase__  , lowerCamelCase__:				Union[str, Any]        =config_and_inputs
   lowerCamelCase__:				Optional[Any]        ={"pixel_values": pixel_values}
   return config, inputs_dict



@require_tf
class        _SCREAMING_SNAKE_CASE						(     __SCREAMING_SNAKE_CASE   ,							__SCREAMING_SNAKE_CASE   ,							unittest.TestCase   ):







 '''simple docstring'''
 lowercase_		=      (TFViTModel, TFViTForImageClassification) if is_tf_available() else ()
 lowercase_		=      (
     {"feature-extraction": TFViTModel, "image-classification": TFViTForImageClassification}
     if is_tf_available()
     else {}
 )

 lowercase_		=      False
 lowercase_		=      False
 lowercase_		=      False

 def 							SCREAMING_SNAKE_CASE_ (self    :       List[str])	->Dict:



   '''simple docstring'''



   lowerCamelCase__:				int        =TFViTModelTester(self)
   lowerCamelCase__:				List[str]        =ConfigTester(self	,			config_class=UpperCAmelCase_	,			has_text_modality=UpperCAmelCase_	,			hidden_size=37)

 def 							SCREAMING_SNAKE_CASE_ (self    :       str)	->Tuple:



   '''simple docstring'''



   self.config_tester.run_common_tests()

 @unittest.skip(reason="ViT does not use inputs_embeds")
 def 							SCREAMING_SNAKE_CASE_ (self    :       List[str])	->Any:



   '''simple docstring'''



   pass

 @unittest.skip(reason="ViT does not use inputs_embeds")
 def 							SCREAMING_SNAKE_CASE_ (self    :       int)	->str:



   '''simple docstring'''



   pass

 def 							SCREAMING_SNAKE_CASE_ (self    :       Tuple)	->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__  , lowerCamelCase__:				int        =self.model_tester.prepare_config_and_inputs_for_common()

   for model_class in self.all_model_classes:
     lowerCamelCase__:				int        =model_class(UpperCAmelCase_)
     self.assertIsInstance(model.get_input_embeddings()	,			(tf.keras.layers.Layer))
     lowerCamelCase__:				Tuple        =model.get_output_embeddings()
     self.assertTrue(x is None or isinstance(UpperCAmelCase_	,			tf.keras.layers.Layer))

 def 							SCREAMING_SNAKE_CASE_ (self    :       Union[str, Any])	->Dict:



   '''simple docstring'''



   lowerCamelCase__  , lowerCamelCase__:				Optional[Any]        =self.model_tester.prepare_config_and_inputs_for_common()

   for model_class in self.all_model_classes:
     lowerCamelCase__:				List[Any]        =model_class(UpperCAmelCase_)
     lowerCamelCase__:				Tuple        =inspect.signature(model.call)
     # signature.parameters is an OrderedDict => so arg_names order is deterministic
     lowerCamelCase__:				str        =[*signature.parameters.keys()]

     lowerCamelCase__:				str        =["pixel_values"]
     self.assertListEqual(arg_names[:1]	,			UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_ (self    :       int)	->Union[str, Any]:



   '''simple docstring'''



   lowerCamelCase__:				Optional[int]        =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_model(*UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_ (self    :       Optional[Any])	->Any:



   '''simple docstring'''



   lowerCamelCase__:				List[str]        =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_image_classification(*UpperCAmelCase_)







 @slow
 def 							SCREAMING_SNAKE_CASE_ (self    :       Dict)	->List[Any]:



   '''simple docstring'''



   lowerCamelCase__:				Any        =TFViTModel.from_pretrained("google/vit-base-patch16-224")
   self.assertIsNotNone(UpperCAmelCase_)





def 					lowerCAmelCase_			(	)					->		Tuple:







  """simple docstring"""





  lowerCamelCase__:				Any        =Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"		)
  return image






@require_tf
@require_vision
class        _SCREAMING_SNAKE_CASE						(     unittest.TestCase   ):







 '''simple docstring'''

 @cached_property
 def 							SCREAMING_SNAKE_CASE_ (self    :       str)	->List[Any]:



   '''simple docstring'''



   return ViTImageProcessor.from_pretrained("google/vit-base-patch16-224") if is_vision_available() else None







 @slow
 def 							SCREAMING_SNAKE_CASE_ (self    :       Optional[int])	->Tuple:



   '''simple docstring'''



   lowerCamelCase__:				List[str]        =TFViTForImageClassification.from_pretrained("google/vit-base-patch16-224")

   lowerCamelCase__:				List[str]        =self.default_image_processor
   lowerCamelCase__:				Union[str, Any]        =prepare_img()
   lowerCamelCase__:				List[Any]        =image_processor(images=UpperCAmelCase_	,			return_tensors="tf")

   # forward pass
   lowerCamelCase__:				Dict        =model(**UpperCAmelCase_)

   # verify the logits
   lowerCamelCase__:				List[Any]        =tf.TensorShape((1, 1_000))
   self.assertEqual(outputs.logits.shape	,			UpperCAmelCase_)

   lowerCamelCase__:				List[Any]        =tf.constant([-0.2744, 0.8215, -0.0836])

   tf.debugging.assert_near(outputs.logits[0, :3]	,			UpperCAmelCase_	,			atol=1E-4)

