



'''simple docstring'''
import tempfile
import unittest

from transformers import DPRConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import DPRContextEncoder, DPRQuestionEncoder, DPRReader, DPRReaderTokenizer
					from transformers.models.dpr.modeling_dpr import (
					    DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
					    DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
					    DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
					)



class _A	:





		def __init__(  self			,							__UpperCAmelCase			,							__UpperCAmelCase=13			,							__UpperCAmelCase=7			,							__UpperCAmelCase=False			,							__UpperCAmelCase=True			,							__UpperCAmelCase=True			,							__UpperCAmelCase=True			,							__UpperCAmelCase=99			,							__UpperCAmelCase=32			,							__UpperCAmelCase=5			,							__UpperCAmelCase=4			,							__UpperCAmelCase=37			,							__UpperCAmelCase="gelu"			,							__UpperCAmelCase=0.1			,							__UpperCAmelCase=0.1			,							__UpperCAmelCase=512			,							__UpperCAmelCase=16			,							__UpperCAmelCase=2			,							__UpperCAmelCase=0.02			,							__UpperCAmelCase=3			,							__UpperCAmelCase=4			,							__UpperCAmelCase=None			,							__UpperCAmelCase=0			,							)							->  str:

					'''simple docstring'''
					__UpperCAmelCase :   int    					=  parent
					__UpperCAmelCase :   Optional[int]    					=  batch_size
					__UpperCAmelCase :   Dict    					=  seq_length
					__UpperCAmelCase :   Optional[Any]    					=  is_training
					__UpperCAmelCase :   List[str]    					=  use_input_mask
					__UpperCAmelCase :   Optional[Any]    					=  use_token_type_ids
					__UpperCAmelCase :   Optional[Any]    					=  use_labels
					__UpperCAmelCase :   List[str]    					=  vocab_size
					__UpperCAmelCase :   Optional[Any]    					=  hidden_size
					__UpperCAmelCase :   Dict    					=  num_hidden_layers
					__UpperCAmelCase :   List[Any]    					=  num_attention_heads
					__UpperCAmelCase :   List[Any]    					=  intermediate_size
					__UpperCAmelCase :   Optional[int]    					=  hidden_act
					__UpperCAmelCase :   Dict    					=  hidden_dropout_prob
					__UpperCAmelCase :   Optional[int]    					=  attention_probs_dropout_prob
					__UpperCAmelCase :   Optional[Any]    					=  max_position_embeddings
					__UpperCAmelCase :   Tuple    					=  type_vocab_size
					__UpperCAmelCase :   Optional[int]    					=  type_sequence_label_size
					__UpperCAmelCase :   Optional[int]    					=  initializer_range
					__UpperCAmelCase :   Tuple    					=  num_labels
					__UpperCAmelCase :   Any    					=  num_choices
					__UpperCAmelCase :   List[Any]    					=  scope
					__UpperCAmelCase :   Any    					=  projection_dim





		def 				__A							(  self					)							->  str:

					'''simple docstring'''
					__UpperCAmelCase :   List[Any]    					=  ids_tensor([self.batch_size, self.seq_length]			,							self.vocab_size					)

					__UpperCAmelCase :   int    					=  None
					if self.use_input_mask:
								__UpperCAmelCase :   Any    					=  random_attention_mask([self.batch_size, self.seq_length]					)

					__UpperCAmelCase :   Tuple    					=  None
					if self.use_token_type_ids:
								__UpperCAmelCase :   Tuple    					=  ids_tensor([self.batch_size, self.seq_length]			,							self.type_vocab_size					)

					__UpperCAmelCase :   Dict    					=  None
					__UpperCAmelCase :   str    					=  None
					__UpperCAmelCase :   str    					=  None
					if self.use_labels:
								__UpperCAmelCase :   List[Any]    					=  ids_tensor([self.batch_size]			,							self.type_sequence_label_size					)
								__UpperCAmelCase :   Optional[Any]    					=  ids_tensor([self.batch_size, self.seq_length]			,							self.num_labels					)
								__UpperCAmelCase :   Optional[int]    					=  ids_tensor([self.batch_size]			,							self.num_choices					)

					__UpperCAmelCase :   str    					=  self.get_config()

					return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels





		def 				__A							(  self					)							->  Dict:

					'''simple docstring'''
					return DPRConfig(
					    projection_dim=self.projection_dim			,							vocab_size=self.vocab_size			,							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			,							max_position_embeddings=self.max_position_embeddings			,							type_vocab_size=self.type_vocab_size			,							initializer_range=self.initializer_range			,							)





		def 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)							->  List[str]:

					'''simple docstring'''
					__UpperCAmelCase :   Tuple    					=  DPRContextEncoder(config=__UpperCAmelCase					)
					model.to(__UpperCAmelCase					)
					model.eval()
					__UpperCAmelCase :   Optional[Any]    					=  model(__UpperCAmelCase			,							attention_mask=__UpperCAmelCase			,							token_type_ids=__UpperCAmelCase					)
					__UpperCAmelCase :   Optional[int]    					=  model(__UpperCAmelCase			,							token_type_ids=__UpperCAmelCase					)
					__UpperCAmelCase :   List[str]    					=  model(__UpperCAmelCase					)
					self.parent.assertEqual(result.pooler_output.shape			,							(self.batch_size, self.projection_dim or self.hidden_size)					)





		def 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)							->  Optional[int]:

					'''simple docstring'''
					__UpperCAmelCase :   int    					=  DPRQuestionEncoder(config=__UpperCAmelCase					)
					model.to(__UpperCAmelCase					)
					model.eval()
					__UpperCAmelCase :   Any    					=  model(__UpperCAmelCase			,							attention_mask=__UpperCAmelCase			,							token_type_ids=__UpperCAmelCase					)
					__UpperCAmelCase :   List[str]    					=  model(__UpperCAmelCase			,							token_type_ids=__UpperCAmelCase					)
					__UpperCAmelCase :   Any    					=  model(__UpperCAmelCase					)
					self.parent.assertEqual(result.pooler_output.shape			,							(self.batch_size, self.projection_dim or self.hidden_size)					)





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

					'''simple docstring'''
					__UpperCAmelCase :   Optional[int]    					=  DPRReader(config=__UpperCAmelCase					)
					model.to(__UpperCAmelCase					)
					model.eval()
					__UpperCAmelCase :   List[str]    					=  model(
					    __UpperCAmelCase			,							attention_mask=__UpperCAmelCase			,							)

					self.parent.assertEqual(result.start_logits.shape			,							(self.batch_size, self.seq_length)					)
					self.parent.assertEqual(result.end_logits.shape			,							(self.batch_size, self.seq_length)					)
					self.parent.assertEqual(result.relevance_logits.shape			,							(self.batch_size,)					)





		def 				__A							(  self					)							->  Tuple:

					'''simple docstring'''
					__UpperCAmelCase :   List[Any]    					=  self.prepare_config_and_inputs()
					(
					    (
					    __UpperCAmelCase
					)					,	(
					    __UpperCAmelCase
					)					,	(
					    __UpperCAmelCase
					)					,	(
					    __UpperCAmelCase
					)					,	(
					    __UpperCAmelCase
					)					,	(
					    __UpperCAmelCase
					)					,	(
					    __UpperCAmelCase
					)					,	
					) :   int    					=  config_and_inputs
					__UpperCAmelCase :   Optional[int]    					=  {"""input_ids""": input_ids}
					return config, inputs_dict



@require_torch
class _A	(     __SCREAMING_SNAKE_CASE						,					__SCREAMING_SNAKE_CASE						,					unittest.TestCase     ):
		_SCREAMING_SNAKE_CASE       :     Optional[int]       =      (
		    (
		        DPRContextEncoder,
		        DPRQuestionEncoder,
		        DPRReader,
		    )
		    if is_torch_available()
		    else ()
		)
		_SCREAMING_SNAKE_CASE       :     Optional[int]       =      {"feature-extraction": DPRQuestionEncoder} if is_torch_available() else {}

		_SCREAMING_SNAKE_CASE       :     Optional[Any]       =      False
		_SCREAMING_SNAKE_CASE       :     List[str]       =      False  # why?
		_SCREAMING_SNAKE_CASE       :     Dict       =      False
		_SCREAMING_SNAKE_CASE       :     str       =      False





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

					'''simple docstring'''
					__UpperCAmelCase :   int    					=  DPRModelTester(self					)
					__UpperCAmelCase :   Dict    					=  ConfigTester(self			,							config_class=__UpperCAmelCase			,							hidden_size=37					)





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

					'''simple docstring'''
					self.config_tester.run_common_tests()





		def 				__A							(  self					)							->  int:

					'''simple docstring'''
					__UpperCAmelCase :   List[Any]    					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_context_encoder(*__UpperCAmelCase					)





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

					'''simple docstring'''
					__UpperCAmelCase :   str    					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_question_encoder(*__UpperCAmelCase					)





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

					'''simple docstring'''
					__UpperCAmelCase :   Dict    					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_reader(*__UpperCAmelCase					)





		def 				__A							(  self					)							->  Any:

					'''simple docstring'''
					__UpperCAmelCase :   Any    					=  self.model_tester.prepare_config_and_inputs()[0]

					__UpperCAmelCase :   Any    					=  DPRQuestionEncoder(config=__UpperCAmelCase					)
					model.to(__UpperCAmelCase					)
					model.eval()

					with tempfile.TemporaryDirectory() as tmp_dirname:
								model.save_pretrained(__UpperCAmelCase					)
								__UpperCAmelCase :   List[Any]    					=  DPRQuestionEncoder.from_pretrained(__UpperCAmelCase			,							projection_dim=512					)

					self.assertIsNotNone(__UpperCAmelCase					)





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

					'''simple docstring'''
					for model_name in DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								__UpperCAmelCase :   str    					=  DPRContextEncoder.from_pretrained(__UpperCAmelCase					)
								self.assertIsNotNone(__UpperCAmelCase					)

					for model_name in DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								__UpperCAmelCase :   Tuple    					=  DPRContextEncoder.from_pretrained(__UpperCAmelCase					)
								self.assertIsNotNone(__UpperCAmelCase					)

					for model_name in DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								__UpperCAmelCase :   Any    					=  DPRQuestionEncoder.from_pretrained(__UpperCAmelCase					)
								self.assertIsNotNone(__UpperCAmelCase					)

					for model_name in DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								__UpperCAmelCase :   Optional[int]    					=  DPRReader.from_pretrained(__UpperCAmelCase					)
								self.assertIsNotNone(__UpperCAmelCase					)



@require_torch
class _A	(     unittest.TestCase     ):





		@slow
		def 				__A							(  self					)							->  Optional[Any]:

					'''simple docstring'''
					__UpperCAmelCase :   Optional[Any]    					=  DPRQuestionEncoder.from_pretrained("""facebook/dpr-question_encoder-single-nq-base"""			,							return_dict=__UpperCAmelCase					)
					model.to(__UpperCAmelCase					)

					__UpperCAmelCase :   List[Any]    					=  torch.tensor(
					    [[101, 7_592, 1_010, 2_003, 2_026, 3_899, 10_140, 1_029, 102]]			,							dtype=torch.long			,							device=__UpperCAmelCase					)  # [CLS] hello, is my dog cute? [SEP]
					__UpperCAmelCase :   Dict    					=  model(__UpperCAmelCase					)[0]  # embedding shape = (1, 768)
					# compare the actual values for a slice.
					__UpperCAmelCase :   List[Any]    					=  torch.tensor(
					    [
					        [
					            0.0323_6253,
					            0.1275_3335,
					            0.1681_8509,
					            0.0027_9786,
					            0.389_6933,
					            0.2426_4945,
					            0.217_8971,
					            -0.0233_5227,
					            -0.0848_1959,
					            -0.1432_4117,
					        ]
					    ]			,							dtype=torch.float			,							device=__UpperCAmelCase			,							)
					self.assertTrue(torch.allclose(output[:, :10]			,							__UpperCAmelCase			,							atol=1E-4					)					)





		@slow
		def 				__A							(  self					)							->  Tuple:

					'''simple docstring'''
					__UpperCAmelCase :   List[Any]    					=  DPRReaderTokenizer.from_pretrained("""facebook/dpr-reader-single-nq-base"""					)
					__UpperCAmelCase :   Tuple    					=  DPRReader.from_pretrained("""facebook/dpr-reader-single-nq-base"""					)
					model.to(__UpperCAmelCase					)

					__UpperCAmelCase :   Dict    					=  tokenizer(
					    questions="""What is love ?"""			,							titles="""Haddaway"""			,							texts="""What Is Love is a song recorded by the artist Haddaway"""			,							padding=__UpperCAmelCase			,							return_tensors="""pt"""			,							)
					encoded_inputs.to(__UpperCAmelCase					)

					__UpperCAmelCase :   str    					=  model(**__UpperCAmelCase					)

					# compare the actual values for a slice.
					__UpperCAmelCase :   Union[str, Any]    					=  torch.tensor(
					    [[-10.3005, -10.7765, -11.4872, -11.6841, -11.9312, -10.3002, -9.8544, -11.7378, -12.0821, -10.2975]]			,							dtype=torch.float			,							device=__UpperCAmelCase			,							)

					__UpperCAmelCase :   Union[str, Any]    					=  torch.tensor(
					    [[-11.0684, -11.7041, -11.5397, -10.3465, -10.8791, -6.8443, -11.9959, -11.0364, -10.0096, -6.8405]]			,							dtype=torch.float			,							device=__UpperCAmelCase			,							)
					self.assertTrue(torch.allclose(outputs.start_logits[:, :10]			,							__UpperCAmelCase			,							atol=1E-4					)					)
					self.assertTrue(torch.allclose(outputs.end_logits[:, :10]			,							__UpperCAmelCase			,							atol=1E-4					)					)









'''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			,							__UpperCAmelCase			,							__UpperCAmelCase=13			,							__UpperCAmelCase=32			,							__UpperCAmelCase=3			,							__UpperCAmelCase=4			,							__UpperCAmelCase=[10, 20, 30, 40]			,							__UpperCAmelCase=[2, 2, 3, 2]			,							__UpperCAmelCase=True			,							__UpperCAmelCase=True			,							__UpperCAmelCase=37			,							__UpperCAmelCase="gelu"			,							__UpperCAmelCase=10			,							__UpperCAmelCase=0.02			,							__UpperCAmelCase=3			,							__UpperCAmelCase=None			,							)							->  Any:

					'''simple docstring'''
					__UpperCAmelCase :   Optional[int]    					=  parent
					__UpperCAmelCase :   Optional[Any]    					=  batch_size
					__UpperCAmelCase :   List[str]    					=  image_size
					__UpperCAmelCase :   Optional[Any]    					=  num_channels
					__UpperCAmelCase :   int    					=  num_stages
					__UpperCAmelCase :   List[Any]    					=  hidden_sizes
					__UpperCAmelCase :   Optional[Any]    					=  depths
					__UpperCAmelCase :   List[str]    					=  is_training
					__UpperCAmelCase :   Tuple    					=  use_labels
					__UpperCAmelCase :   Optional[Any]    					=  intermediate_size
					__UpperCAmelCase :   Dict    					=  hidden_act
					__UpperCAmelCase :   List[str]    					=  type_sequence_label_size
					__UpperCAmelCase :   Union[str, Any]    					=  initializer_range
					__UpperCAmelCase :   Optional[Any]    					=  scope





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

					'''simple docstring'''
					__UpperCAmelCase :   List[Any]    					=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

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

					__UpperCAmelCase :   Optional[int]    					=  self.get_config()

					return config, pixel_values, labels





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

					'''simple docstring'''
					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=__UpperCAmelCase			,							initializer_range=self.initializer_range			,							)





		def 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)							->  List[Any]:

					'''simple docstring'''
					__UpperCAmelCase :   List[Any]    					=  TFConvNextModel(config=__UpperCAmelCase					)
					__UpperCAmelCase :   List[Any]    					=  model(__UpperCAmelCase			,							training=__UpperCAmelCase					)
					# 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 // 32, self.image_size // 32)			,							)





		def 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)							->  Optional[int]:

					'''simple docstring'''
					__UpperCAmelCase :   Optional[int]    					=  self.type_sequence_label_size
					__UpperCAmelCase :   List[Any]    					=  TFConvNextForImageClassification(__UpperCAmelCase					)
					__UpperCAmelCase :   List[str]    					=  model(__UpperCAmelCase			,							labels=__UpperCAmelCase			,							training=__UpperCAmelCase					)
					self.parent.assertEqual(result.logits.shape			,							(self.batch_size, self.type_sequence_label_size)					)





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

					'''simple docstring'''
					__UpperCAmelCase :   List[str]    					=  self.prepare_config_and_inputs()
					__UpperCAmelCase					,	__UpperCAmelCase					,	__UpperCAmelCase :   Optional[int]    					=  config_and_inputs
					__UpperCAmelCase :   Union[str, Any]    					=  {"""pixel_values""": pixel_values}
					return config, inputs_dict



@require_tf
class _A	(     __SCREAMING_SNAKE_CASE						,					__SCREAMING_SNAKE_CASE						,					unittest.TestCase     ):
		_SCREAMING_SNAKE_CASE       :     Dict       =      (TFConvNextModel, TFConvNextForImageClassification) if is_tf_available() else ()
		_SCREAMING_SNAKE_CASE       :     Optional[Any]       =      (
		    {"feature-extraction": TFConvNextModel, "image-classification": TFConvNextForImageClassification}
		    if is_tf_available()
		    else {}
		)

		_SCREAMING_SNAKE_CASE       :     Tuple       =      False
		_SCREAMING_SNAKE_CASE       :     Tuple       =      False
		_SCREAMING_SNAKE_CASE       :     Union[str, Any]       =      False
		_SCREAMING_SNAKE_CASE       :     Optional[Any]       =      False
		_SCREAMING_SNAKE_CASE       :     str       =      False





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

					'''simple docstring'''
					__UpperCAmelCase :   Dict    					=  TFConvNextModelTester(self					)
					__UpperCAmelCase :   Optional[int]    					=  ConfigTester(
					    self			,							config_class=__UpperCAmelCase			,							has_text_modality=__UpperCAmelCase			,							hidden_size=37			,							)





		@unittest.skip(reason="""ConvNext does not use inputs_embeds"""					)
		def 				__A							(  self					)							->  str:

					'''simple docstring'''
					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 				__A							(  self					)							->  Optional[int]:

					'''simple docstring'''
					super().test_keras_fit()





		@unittest.skip(reason="""ConvNext does not support input and output embeddings"""					)
		def 				__A							(  self					)							->  Dict:

					'''simple docstring'''
					pass





		def 				__A							(  self					)							->  str:

					'''simple docstring'''
					__UpperCAmelCase					,	__UpperCAmelCase :   List[str]    					=  self.model_tester.prepare_config_and_inputs_for_common()

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

								__UpperCAmelCase :   Tuple    					=  ["""pixel_values"""]
								self.assertListEqual(arg_names[:1]			,							__UpperCAmelCase					)





		def 				__A							(  self					)							->  Dict:

					'''simple docstring'''
					__UpperCAmelCase :   Dict    					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*__UpperCAmelCase					)





		@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 				__A							(  self					)							->  Union[str, Any]:

					'''simple docstring'''
					super().test_dataset_conversion()





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

					'''simple docstring'''
					def check_hidden_states_output(__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					):
								__UpperCAmelCase :   Optional[int]    					=  model_class(__UpperCAmelCase					)

								__UpperCAmelCase :   str    					=  model(**self._prepare_for_class(__UpperCAmelCase			,							__UpperCAmelCase					)					)
								__UpperCAmelCase :   List[str]    					=  outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

								__UpperCAmelCase :   Optional[int]    					=  self.model_tester.num_stages
								self.assertEqual(len(__UpperCAmelCase					)			,							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]			,							)

					__UpperCAmelCase					,	__UpperCAmelCase :   Union[str, Any]    					=  self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
								__UpperCAmelCase :   List[str]    					=  True
								check_hidden_states_output(__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)

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

								check_hidden_states_output(__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)





		def 				__A							(  self					)							->  Tuple:

					'''simple docstring'''
					__UpperCAmelCase					,	__UpperCAmelCase :   Any    					=  self.model_tester.prepare_config_and_inputs_for_common()

					def check_equivalence(__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase={}					):
								__UpperCAmelCase :   Optional[Any]    					=  model(__UpperCAmelCase			,							return_dict=__UpperCAmelCase			,							**__UpperCAmelCase					)
								__UpperCAmelCase :   Optional[int]    					=  model(__UpperCAmelCase			,							return_dict=__UpperCAmelCase			,							**__UpperCAmelCase					).to_tuple()

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

											recursive_check(__UpperCAmelCase			,							__UpperCAmelCase					)

					for model_class in self.all_model_classes:
								__UpperCAmelCase :   Dict    					=  model_class(__UpperCAmelCase					)

								__UpperCAmelCase :   Optional[int]    					=  self._prepare_for_class(__UpperCAmelCase			,							__UpperCAmelCase					)
								__UpperCAmelCase :   Tuple    					=  self._prepare_for_class(__UpperCAmelCase			,							__UpperCAmelCase					)
								check_equivalence(__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)

								__UpperCAmelCase :   Union[str, Any]    					=  self._prepare_for_class(__UpperCAmelCase			,							__UpperCAmelCase			,							return_labels=__UpperCAmelCase					)
								__UpperCAmelCase :   Union[str, Any]    					=  self._prepare_for_class(__UpperCAmelCase			,							__UpperCAmelCase			,							return_labels=__UpperCAmelCase					)
								check_equivalence(__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)

								__UpperCAmelCase :   Optional[Any]    					=  self._prepare_for_class(__UpperCAmelCase			,							__UpperCAmelCase					)
								__UpperCAmelCase :   List[str]    					=  self._prepare_for_class(__UpperCAmelCase			,							__UpperCAmelCase					)
								check_equivalence(__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							{"""output_hidden_states""": True}					)

								__UpperCAmelCase :   List[Any]    					=  self._prepare_for_class(__UpperCAmelCase			,							__UpperCAmelCase			,							return_labels=__UpperCAmelCase					)
								__UpperCAmelCase :   Dict    					=  self._prepare_for_class(__UpperCAmelCase			,							__UpperCAmelCase			,							return_labels=__UpperCAmelCase					)
								check_equivalence(__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							{"""output_hidden_states""": True}					)





		def 				__A							(  self					)							->  Tuple:

					'''simple docstring'''
					__UpperCAmelCase :   int    					=  self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_image_classification(*__UpperCAmelCase					)





		@slow
		def 				__A							(  self					)							->  Tuple:

					'''simple docstring'''
					__UpperCAmelCase :   Union[str, Any]    					=  TFConvNextModel.from_pretrained("""facebook/convnext-tiny-224"""					)
					self.assertIsNotNone(__UpperCAmelCase					)


def 	lowercase_						( ):

			"""simple docstring"""





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






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





		@cached_property
		def 				__A							(  self					)							->  Any:

					'''simple docstring'''
					return ConvNextImageProcessor.from_pretrained("""facebook/convnext-tiny-224"""					) if is_vision_available() else None





		@slow
		def 				__A							(  self					)							->  int:

					'''simple docstring'''
					__UpperCAmelCase :   Tuple    					=  TFConvNextForImageClassification.from_pretrained("""facebook/convnext-tiny-224"""					)

					__UpperCAmelCase :   List[Any]    					=  self.default_image_processor
					__UpperCAmelCase :   int    					=  prepare_img()
					__UpperCAmelCase :   Optional[Any]    					=  image_processor(images=__UpperCAmelCase			,							return_tensors="""tf"""					)

					# forward pass
					__UpperCAmelCase :   List[Any]    					=  model(**__UpperCAmelCase					)

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

					__UpperCAmelCase :   str    					=  tf.constant([-0.0260, -0.4739, 0.1911]					)

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




