


"""simple docstring"""






import collections
import inspect
import unittest

from transformers import DonutSwinConfig
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import is_torch_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch
					from torch import nn

					from transformers import DonutSwinModel
					from transformers.models.donut.modeling_donut_swin import DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST


class 			SCREAMING_SNAKE_CASE_  :




							'''simple docstring'''





							def __init__(						self	,					lowerCamelCase__	,					lowerCamelCase__=13	,					lowerCamelCase__=32	,					lowerCamelCase__=2	,					lowerCamelCase__=3	,					lowerCamelCase__=16	,					lowerCamelCase__=[1, 2, 1]	,					lowerCamelCase__=[2, 2, 4]	,					lowerCamelCase__=2	,					lowerCamelCase__=2.0	,					lowerCamelCase__=True	,					lowerCamelCase__=0.0	,					lowerCamelCase__=0.0	,					lowerCamelCase__=0.1	,					lowerCamelCase__="gelu"	,					lowerCamelCase__=False	,					lowerCamelCase__=True	,					lowerCamelCase__=0.02	,					lowerCamelCase__=1E-5	,					lowerCamelCase__=True	,					lowerCamelCase__=None	,					lowerCamelCase__=True	,					lowerCamelCase__=10	,					lowerCamelCase__=8	,					)   ->	Union[str, Any]:







								'''simple docstring'''




								snake_case__  :						Any		=      parent
								snake_case__  :						Union[str, Any]		=      batch_size
								snake_case__  :						Union[str, Any]		=      image_size
								snake_case__  :						List[Any]		=      patch_size
								snake_case__  :						int		=      num_channels
								snake_case__  :						int		=      embed_dim
								snake_case__  :						Union[str, Any]		=      depths
								snake_case__  :						int		=      num_heads
								snake_case__  :						Dict		=      window_size
								snake_case__  :						Optional[Any]		=      mlp_ratio
								snake_case__  :						Optional[Any]		=      qkv_bias
								snake_case__  :						str		=      hidden_dropout_prob
								snake_case__  :						int		=      attention_probs_dropout_prob
								snake_case__  :						Dict		=      drop_path_rate
								snake_case__  :						int		=      hidden_act
								snake_case__  :						str		=      use_absolute_embeddings
								snake_case__  :						Any		=      patch_norm
								snake_case__  :						Tuple		=      layer_norm_eps
								snake_case__  :						Union[str, Any]		=      initializer_range
								snake_case__  :						Dict		=      is_training
								snake_case__  :						int		=      scope
								snake_case__  :						Dict		=      use_labels
								snake_case__  :						Optional[Any]		=      type_sequence_label_size
								snake_case__  :						Any		=      encoder_stride




							def        UpperCAmelCase (						self)   ->	List[Any]:







								'''simple docstring'''




								snake_case__  :						Union[str, Any]		=      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

								snake_case__  :						str		=      None
								if self.use_labels:
									snake_case__  :						Optional[int]		=      ids_tensor([self.batch_size]	,					self.type_sequence_label_size)

								snake_case__  :						Any		=      self.get_config()

								return config, pixel_values, labels




							def        UpperCAmelCase (						self)   ->	str:







								'''simple docstring'''




								return DonutSwinConfig(
								    image_size=self.image_size	,					patch_size=self.patch_size	,					num_channels=self.num_channels	,					embed_dim=self.embed_dim	,					depths=self.depths	,					num_heads=self.num_heads	,					window_size=self.window_size	,					mlp_ratio=self.mlp_ratio	,					qkv_bias=self.qkv_bias	,					hidden_dropout_prob=self.hidden_dropout_prob	,					attention_probs_dropout_prob=self.attention_probs_dropout_prob	,					drop_path_rate=self.drop_path_rate	,					hidden_act=self.hidden_act	,					use_absolute_embeddings=self.use_absolute_embeddings	,					path_norm=self.patch_norm	,					layer_norm_eps=self.layer_norm_eps	,					initializer_range=self.initializer_range	,					encoder_stride=self.encoder_stride	,					)




							def        UpperCAmelCase (						self	,					lowerCamelCase__	,					lowerCamelCase__	,					lowerCamelCase__)   ->	str:







								'''simple docstring'''




								snake_case__  :						Union[str, Any]		=      DonutSwinModel(config=__lowerCamelCase)
								model.to(__lowerCamelCase)
								model.eval()
								snake_case__  :						Optional[int]		=      model(__lowerCamelCase)

								snake_case__  :						Union[str, Any]		=      ((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths) - 1))
								snake_case__  :						Any		=      int(config.embed_dim * 2 ** (len(config.depths) - 1))

								self.parent.assertEqual(result.last_hidden_state.shape	,					(self.batch_size, expected_seq_len, expected_dim))







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







								'''simple docstring'''




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


@require_torch
class 			SCREAMING_SNAKE_CASE_  (   snake_case_	,      snake_case_	,      unittest.TestCase):




							'''simple docstring'''





							__magic_name__					:     str				  =  (DonutSwinModel,) if is_torch_available() else ()
							__magic_name__					:     int				  =  {'''feature-extraction''': DonutSwinModel} if is_torch_available() else {}
							__magic_name__					:     Any				  =  True

							__magic_name__					:     Dict				  =  False
							__magic_name__					:     List[Any]				  =  False
							__magic_name__					:     Any				  =  False




							def        UpperCAmelCase (						self)   ->	Any:







								'''simple docstring'''




								snake_case__  :						Optional[Any]		=      DonutSwinModelTester(self)
								snake_case__  :						List[str]		=      ConfigTester(self	,					config_class=__lowerCamelCase	,					embed_dim=37)




							def        UpperCAmelCase (						self)   ->	int:







								'''simple docstring'''




								self.create_and_test_config_common_properties()
								self.config_tester.create_and_test_config_to_json_string()
								self.config_tester.create_and_test_config_to_json_file()
								self.config_tester.create_and_test_config_from_and_save_pretrained()
								self.config_tester.create_and_test_config_with_num_labels()
								self.config_tester.check_config_can_be_init_without_params()
								self.config_tester.check_config_arguments_init()




							def        UpperCAmelCase (						self)   ->	int:







								'''simple docstring'''




								return




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







								'''simple docstring'''




								snake_case__  :						Optional[int]		=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*__lowerCamelCase)




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







								'''simple docstring'''




								pass




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







								'''simple docstring'''




								snake_case__,					snake_case__  :						Dict		=      self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
									snake_case__  :						Optional[int]		=      model_class(__lowerCamelCase)
									self.assertIsInstance(model.get_input_embeddings()	,					(nn.Module))
									snake_case__  :						Optional[Any]		=      model.get_output_embeddings()
									self.assertTrue(x is None or isinstance(__lowerCamelCase	,					nn.Linear))




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







								'''simple docstring'''




								snake_case__,					snake_case__  :						List[Any]		=      self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
									snake_case__  :						List[str]		=      model_class(__lowerCamelCase)
									snake_case__  :						Tuple		=      inspect.signature(model.forward)
									# signature.parameters is an OrderedDict => so arg_names order is deterministic
									snake_case__  :						Dict		=      [*signature.parameters.keys()]

									snake_case__  :						str		=      ["pixel_values"]
									self.assertListEqual(arg_names[:1]	,					__lowerCamelCase)




							def        UpperCAmelCase (						self)   ->	Tuple:







								'''simple docstring'''




								snake_case__,					snake_case__  :						Tuple		=      self.model_tester.prepare_config_and_inputs_for_common()
								snake_case__  :						str		=      True

								for model_class in self.all_model_classes:
									snake_case__  :						Optional[int]		=      True
									snake_case__  :						Dict		=      False
									snake_case__  :						int		=      True
									snake_case__  :						Union[str, Any]		=      model_class(__lowerCamelCase)
									model.to(__lowerCamelCase)
									model.eval()
									with torch.no_grad():
										snake_case__  :						Any		=      model(**self._prepare_for_class(__lowerCamelCase	,					__lowerCamelCase))
									snake_case__  :						int		=      outputs.attentions
									snake_case__  :						str		=      len(self.model_tester.depths)
									self.assertEqual(len(__lowerCamelCase)	,					__lowerCamelCase)

									# check that output_attentions also work using config
									del inputs_dict["output_attentions"]
									snake_case__  :						List[Any]		=      True
									snake_case__  :						Any		=      config.window_size**2
									snake_case__  :						Any		=      model_class(__lowerCamelCase)
									model.to(__lowerCamelCase)
									model.eval()
									with torch.no_grad():
										snake_case__  :						Dict		=      model(**self._prepare_for_class(__lowerCamelCase	,					__lowerCamelCase))
									snake_case__  :						Any		=      outputs.attentions
									self.assertEqual(len(__lowerCamelCase)	,					__lowerCamelCase)

									self.assertListEqual(
									    list(attentions[0].shape[-3:])	,					[self.model_tester.num_heads[0], window_size_squared, window_size_squared]	,					)
									snake_case__  :						int		=      len(__lowerCamelCase)

									# Check attention is always last and order is fine
									snake_case__  :						str		=      True
									snake_case__  :						Tuple		=      True
									snake_case__  :						Tuple		=      model_class(__lowerCamelCase)
									model.to(__lowerCamelCase)
									model.eval()
									with torch.no_grad():
										snake_case__  :						List[str]		=      model(**self._prepare_for_class(__lowerCamelCase	,					__lowerCamelCase))

									if hasattr(self.model_tester	,					"num_hidden_states_types"):
										snake_case__  :						Optional[Any]		=      self.model_tester.num_hidden_states_types
									else:
										# also another +1 for reshaped_hidden_states
										snake_case__  :						Optional[int]		=      2
									self.assertEqual(out_len + added_hidden_states	,					len(__lowerCamelCase))

									snake_case__  :						Dict		=      outputs.attentions

									self.assertEqual(len(__lowerCamelCase)	,					__lowerCamelCase)

									self.assertListEqual(
									    list(self_attentions[0].shape[-3:])	,					[self.model_tester.num_heads[0], window_size_squared, window_size_squared]	,					)




							def        UpperCAmelCase (						self	,					lowerCamelCase__	,					lowerCamelCase__	,					lowerCamelCase__	,					lowerCamelCase__)   ->	Any:







								'''simple docstring'''




								snake_case__  :						Any		=      model_class(__lowerCamelCase)
								model.to(__lowerCamelCase)
								model.eval()

								with torch.no_grad():
									snake_case__  :						Dict		=      model(**self._prepare_for_class(__lowerCamelCase	,					__lowerCamelCase))

								snake_case__  :						Optional[int]		=      outputs.hidden_states

								snake_case__  :						Tuple		=      getattr(
								    self.model_tester	,					"expected_num_hidden_layers"	,					len(self.model_tester.depths) + 1)
								self.assertEqual(len(__lowerCamelCase)	,					__lowerCamelCase)

								# DonutSwin has a different seq_length
								snake_case__  :						Tuple		=      (
								    config.patch_size
								    if isinstance(config.patch_size	,					collections.abc.Iterable)
								    else (config.patch_size, config.patch_size)
								)

								snake_case__  :						List[str]		=      (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

								self.assertListEqual(
								    list(hidden_states[0].shape[-2:])	,					[num_patches, self.model_tester.embed_dim]	,					)

								snake_case__  :						int		=      outputs.reshaped_hidden_states
								self.assertEqual(len(__lowerCamelCase)	,					__lowerCamelCase)

								snake_case__,					snake_case__,					snake_case__,					snake_case__  :						Any		=      reshaped_hidden_states[0].shape
								snake_case__  :						Tuple		=      (
								    reshaped_hidden_states[0].view(__lowerCamelCase	,					__lowerCamelCase	,					height * width).permute(0	,					2	,					1)
								)
								self.assertListEqual(
								    list(reshaped_hidden_states.shape[-2:])	,					[num_patches, self.model_tester.embed_dim]	,					)




							def        UpperCAmelCase (						self)   ->	List[Any]:







								'''simple docstring'''




								snake_case__,					snake_case__  :						List[Any]		=      self.model_tester.prepare_config_and_inputs_for_common()

								snake_case__  :						Optional[int]		=      (
								    self.model_tester.image_size
								    if isinstance(self.model_tester.image_size	,					collections.abc.Iterable)
								    else (self.model_tester.image_size, self.model_tester.image_size)
								)

								for model_class in self.all_model_classes:
									snake_case__  :						int		=      True
									self.check_hidden_states_output(__lowerCamelCase	,					__lowerCamelCase	,					__lowerCamelCase	,					__lowerCamelCase)

									# check that output_hidden_states also work using config
									del inputs_dict["output_hidden_states"]
									snake_case__  :						Optional[int]		=      True

									self.check_hidden_states_output(__lowerCamelCase	,					__lowerCamelCase	,					__lowerCamelCase	,					__lowerCamelCase)




							def        UpperCAmelCase (						self)   ->	Tuple:







								'''simple docstring'''




								snake_case__,					snake_case__  :						int		=      self.model_tester.prepare_config_and_inputs_for_common()
								snake_case__  :						Dict		=      3

								snake_case__  :						Optional[Any]		=      (
								    self.model_tester.image_size
								    if isinstance(self.model_tester.image_size	,					collections.abc.Iterable)
								    else (self.model_tester.image_size, self.model_tester.image_size)
								)
								snake_case__  :						Optional[Any]		=      (
								    config.patch_size
								    if isinstance(config.patch_size	,					collections.abc.Iterable)
								    else (config.patch_size, config.patch_size)
								)

								snake_case__  :						List[str]		=      image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
								snake_case__  :						Dict		=      image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

								for model_class in self.all_model_classes:
									snake_case__  :						Optional[Any]		=      True
									self.check_hidden_states_output(__lowerCamelCase	,					__lowerCamelCase	,					__lowerCamelCase	,					(padded_height, padded_width))

									# check that output_hidden_states also work using config
									del inputs_dict["output_hidden_states"]
									snake_case__  :						Optional[int]		=      True
									self.check_hidden_states_output(__lowerCamelCase	,					__lowerCamelCase	,					__lowerCamelCase	,					(padded_height, padded_width))




							@slow
							def        UpperCAmelCase (						self)   ->	Any:







								'''simple docstring'''




								for model_name in DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									snake_case__  :						Optional[Any]		=      DonutSwinModel.from_pretrained(__lowerCamelCase)
									self.assertIsNotNone(__lowerCamelCase)







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







								'''simple docstring'''




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

								snake_case__  :						Optional[int]		=      _config_zero_init(__lowerCamelCase)
								for model_class in self.all_model_classes:
									snake_case__  :						Optional[Any]		=      model_class(config=__lowerCamelCase)
									for name, param in model.named_parameters():
										if "embeddings" not in name and param.requires_grad:
											self.assertIn(
											    ((param.data.mean() * 1E9).round() / 1E9).item()	,					[0.0, 1.0]	,					msg=f"""Parameter {name} of model {model_class} seems not properly initialized"""	,					)













"""simple docstring"""

from __future__ import annotations

import inspect
import unittest
from typing import List, Tuple

from transformers import ConvNextConfig
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 TFConvNextForImageClassification, TFConvNextModel


if is_vision_available():
			from PIL import Image

			from transformers import ConvNextImageProcessor

class     A_				:







				def __init__(				self				:    Optional[int]    ,     __lowerCamelCase				:    Tuple    ,     __lowerCamelCase				:    int=1_3    ,     __lowerCamelCase				:    Any=3_2    ,     __lowerCamelCase				:    Dict=3    ,     __lowerCamelCase				:    List[Any]=4    ,     __lowerCamelCase				:    Union[str, Any]=[1_0, 2_0, 3_0, 4_0]    ,     __lowerCamelCase				:    int=[2, 2, 3, 2]    ,     __lowerCamelCase				:    str=True    ,     __lowerCamelCase				:    List[str]=True    ,     __lowerCamelCase				:    List[Any]=3_7    ,     __lowerCamelCase				:    Optional[Any]="gelu"    ,     __lowerCamelCase				:    str=1_0    ,     __lowerCamelCase				:    int=0.02    ,     __lowerCamelCase				:    Optional[int]=3    ,     __lowerCamelCase				:    Any=None    ,     )					->       List[Any]:
										__magic_name__      =  parent
										__magic_name__      =  batch_size
										__magic_name__      =  image_size
										__magic_name__      =  num_channels
										__magic_name__      =  num_stages
										__magic_name__      =  hidden_sizes
										__magic_name__      =  depths
										__magic_name__      =  is_training
										__magic_name__      =  use_labels
										__magic_name__      =  intermediate_size
										__magic_name__      =  hidden_act
										__magic_name__      =  type_sequence_label_size
										__magic_name__      =  initializer_range
										__magic_name__      =  scope







				def      _snake_case       (				self				:    Optional[Any]						)					->       int:
										__magic_name__      =  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

										__magic_name__      =  None
										if self.use_labels:
																__magic_name__      =  ids_tensor([self.batch_size]    ,     self.type_sequence_label_size						)

										__magic_name__      =  self.get_config()

										return config, pixel_values, labels







				def      _snake_case       (				self				:    Optional[int]						)					->       Union[str, Any]:
										return ConvNextConfig(
										    num_channels=self.num_channels    ,     hidden_sizes=self.hidden_sizes    ,     depths=self.depths    ,     num_stages=self.num_stages    ,     hidden_act=self.hidden_act    ,     is_decoder=__lowerCamelCase    ,     initializer_range=self.initializer_range    ,     )







				def      _snake_case       (				self				:    List[Any]    ,     __lowerCamelCase				:    List[str]    ,     __lowerCamelCase				:    Union[str, Any]    ,     __lowerCamelCase				:    Optional[Any]						)					->       List[str]:
										__magic_name__      =  TFConvNextModel(config=__lowerCamelCase						)
										__magic_name__      =  model(__lowerCamelCase    ,     training=__lowerCamelCase						)
										# expected last hidden states: B, C, H // 32, W // 32
										self.parent.assertEqual(
										    result.last_hidden_state.shape    ,     (self.batch_size, self.hidden_sizes[-1], self.image_size // 3_2, self.image_size // 3_2)    ,     )







				def      _snake_case       (				self				:    List[Any]    ,     __lowerCamelCase				:    Union[str, Any]    ,     __lowerCamelCase				:    Tuple    ,     __lowerCamelCase				:    List[str]						)					->       int:
										__magic_name__      =  self.type_sequence_label_size
										__magic_name__      =  TFConvNextForImageClassification(__lowerCamelCase						)
										__magic_name__      =  model(__lowerCamelCase    ,     labels=__lowerCamelCase    ,     training=__lowerCamelCase						)
										self.parent.assertEqual(result.logits.shape    ,     (self.batch_size, self.type_sequence_label_size)						)







				def      _snake_case       (				self				:    List[str]						)					->       str:
										__magic_name__      =  self.prepare_config_and_inputs()
										__magic_name__   ,     __magic_name__   ,     __magic_name__      =  config_and_inputs
										__magic_name__      =  {"pixel_values": pixel_values}
										return config, inputs_dict





@require_tf
class     A_				(   snake_case_       ,				snake_case_       ,				unittest.TestCase	):
				UpperCAmelCase__										=					(TFConvNextModel, TFConvNextForImageClassification) if is_tf_available() else ()
				UpperCAmelCase__										=					(
				    {'''feature-extraction''': TFConvNextModel, '''image-classification''': TFConvNextForImageClassification}
				    if is_tf_available()
				    else {}
				)

				UpperCAmelCase__										=					False
				UpperCAmelCase__										=					False
				UpperCAmelCase__										=					False
				UpperCAmelCase__										=					False
				UpperCAmelCase__										=					False







				def      _snake_case       (				self				:    str						)					->       str:
										__magic_name__      =  TFConvNextModelTester(self						)
										__magic_name__      =  ConfigTester(
										    self    ,     config_class=__lowerCamelCase    ,     has_text_modality=__lowerCamelCase    ,     hidden_size=3_7    ,     )







				@unittest.skip(reason="ConvNext does not use inputs_embeds"						)
				def      _snake_case       (				self				:    Dict						)					->       Dict:
										pass







				@unittest.skipIf(
				    not is_tf_available() or len(tf.config.list_physical_devices("GPU"						)						) == 0    ,     reason="TF does not support backprop for grouped convolutions on CPU."    ,     )
				@slow
				def      _snake_case       (				self				:    List[str]						)					->       Tuple:
										super().test_keras_fit()







				@unittest.skip(reason="ConvNext does not support input and output embeddings"						)
				def      _snake_case       (				self				:    str						)					->       Tuple:
										pass







				def      _snake_case       (				self				:    Union[str, Any]						)					->       Optional[int]:
										__magic_name__   ,     __magic_name__      =  self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
																__magic_name__      =  model_class(__lowerCamelCase						)
																__magic_name__      =  inspect.signature(model.call						)
																# signature.parameters is an OrderedDict => so arg_names order is deterministic
																__magic_name__      =  [*signature.parameters.keys()]

																__magic_name__      =  ["pixel_values"]
																self.assertListEqual(arg_names[:1]    ,     __lowerCamelCase						)







				def      _snake_case       (				self				:    Dict						)					->       Optional[int]:
										__magic_name__      =  self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*__lowerCamelCase						)







				@unittest.skipIf(
				    not is_tf_available() or len(tf.config.list_physical_devices("GPU"						)						) == 0    ,     reason="TF does not support backprop for grouped convolutions on CPU."    ,     )
				def      _snake_case       (				self				:    Optional[int]						)					->       Tuple:
										super().test_dataset_conversion()







				def      _snake_case       (				self				:    int						)					->       List[str]:
										def check_hidden_states_output(__lowerCamelCase				:    Union[str, Any]    ,     __lowerCamelCase				:    Dict    ,     __lowerCamelCase				:    List[str]						):
																__magic_name__      =  model_class(__lowerCamelCase						)

																__magic_name__      =  model(**self._prepare_for_class(__lowerCamelCase    ,     __lowerCamelCase						)						)
																__magic_name__      =  outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

																__magic_name__      =  self.model_tester.num_stages
																self.assertEqual(len(__lowerCamelCase						)    ,     expected_num_stages + 1						)

																# ConvNext's feature maps are of shape (batch_size, num_channels, height, width)
																self.assertListEqual(
																    list(hidden_states[0].shape[-2:]						)    ,     [self.model_tester.image_size // 4, self.model_tester.image_size // 4]    ,     )

										__magic_name__   ,     __magic_name__      =  self.model_tester.prepare_config_and_inputs_for_common()

										for model_class in self.all_model_classes:
																__magic_name__      =  True
																check_hidden_states_output(__lowerCamelCase    ,     __lowerCamelCase    ,     __lowerCamelCase						)

																# check that output_hidden_states also work using config
																del inputs_dict["output_hidden_states"]
																__magic_name__      =  True

																check_hidden_states_output(__lowerCamelCase    ,     __lowerCamelCase    ,     __lowerCamelCase						)







				def      _snake_case       (				self				:    List[str]						)					->       Dict:
										__magic_name__   ,     __magic_name__      =  self.model_tester.prepare_config_and_inputs_for_common()

										def check_equivalence(__lowerCamelCase				:    Dict    ,     __lowerCamelCase				:    Any    ,     __lowerCamelCase				:    Union[str, Any]    ,     __lowerCamelCase				:    Any={}						):
																__magic_name__      =  model(__lowerCamelCase    ,     return_dict=__lowerCamelCase    ,     **__lowerCamelCase						)
																__magic_name__      =  model(__lowerCamelCase    ,     return_dict=__lowerCamelCase    ,     **__lowerCamelCase						).to_tuple()

																def recursive_check(__lowerCamelCase				:    Union[str, Any]    ,     __lowerCamelCase				:    Union[str, Any]						):
																						if isinstance(__lowerCamelCase    ,     (List, Tuple)						):
																												for tuple_iterable_value, dict_iterable_value in zip(__lowerCamelCase    ,     __lowerCamelCase						):
																																		recursive_check(__lowerCamelCase    ,     __lowerCamelCase						)
																						elif tuple_object is None:
																												return
																						else:
																												self.assertTrue(
																												    all(tf.equal(__lowerCamelCase    ,     __lowerCamelCase						)						)    ,     msg=(
																												        "Tuple and dict output are not equal. Difference:"
																												        f''' {tf.math.reduce_max(tf.abs(tuple_object - dict_object						)						)}'''
																												    )    ,     )

																						recursive_check(__lowerCamelCase    ,     __lowerCamelCase						)

										for model_class in self.all_model_classes:
																__magic_name__      =  model_class(__lowerCamelCase						)

																__magic_name__      =  self._prepare_for_class(__lowerCamelCase    ,     __lowerCamelCase						)
																__magic_name__      =  self._prepare_for_class(__lowerCamelCase    ,     __lowerCamelCase						)
																check_equivalence(__lowerCamelCase    ,     __lowerCamelCase    ,     __lowerCamelCase						)

																__magic_name__      =  self._prepare_for_class(__lowerCamelCase    ,     __lowerCamelCase    ,     return_labels=__lowerCamelCase						)
																__magic_name__      =  self._prepare_for_class(__lowerCamelCase    ,     __lowerCamelCase    ,     return_labels=__lowerCamelCase						)
																check_equivalence(__lowerCamelCase    ,     __lowerCamelCase    ,     __lowerCamelCase						)

																__magic_name__      =  self._prepare_for_class(__lowerCamelCase    ,     __lowerCamelCase						)
																__magic_name__      =  self._prepare_for_class(__lowerCamelCase    ,     __lowerCamelCase						)
																check_equivalence(__lowerCamelCase    ,     __lowerCamelCase    ,     __lowerCamelCase    ,     {"output_hidden_states": True}						)

																__magic_name__      =  self._prepare_for_class(__lowerCamelCase    ,     __lowerCamelCase    ,     return_labels=__lowerCamelCase						)
																__magic_name__      =  self._prepare_for_class(__lowerCamelCase    ,     __lowerCamelCase    ,     return_labels=__lowerCamelCase						)
																check_equivalence(__lowerCamelCase    ,     __lowerCamelCase    ,     __lowerCamelCase    ,     {"output_hidden_states": True}						)







				def      _snake_case       (				self				:    Union[str, Any]						)					->       Dict:
										__magic_name__      =  self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_for_image_classification(*__lowerCamelCase						)







				@slow
				def      _snake_case       (				self				:    List[str]						)					->       Tuple:
										__magic_name__      =  TFConvNextModel.from_pretrained("facebook/convnext-tiny-224"						)
										self.assertIsNotNone(__lowerCamelCase						)






def _lowerCAmelCase						(	):

						'''simple docstring'''






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


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







				@cached_property
				def      _snake_case       (				self				:    Tuple						)					->       Any:
										return ConvNextImageProcessor.from_pretrained("facebook/convnext-tiny-224"						) if is_vision_available() else None







				@slow
				def      _snake_case       (				self				:    Any						)					->       str:
										__magic_name__      =  TFConvNextForImageClassification.from_pretrained("facebook/convnext-tiny-224"						)

										__magic_name__      =  self.default_image_processor
										__magic_name__      =  prepare_img()
										__magic_name__      =  image_processor(images=__lowerCamelCase    ,     return_tensors="tf"						)

										# forward pass
										__magic_name__      =  model(**__lowerCamelCase						)

										# verify the logits
										__magic_name__      =  tf.TensorShape((1, 1_0_0_0)						)
										self.assertEqual(outputs.logits.shape    ,     __lowerCamelCase						)

										__magic_name__      =  tf.constant([-0.0260, -0.4739, 0.1911]						)

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



