



'''simple docstring'''
from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


_UpperCamelCase									=      logging.get_logger(__name__)

_UpperCamelCase									=      {
    '''google/bigbird-pegasus-large-arxiv''': (
        '''https://huggingface.co/google/bigbird-pegasus-large-arxiv/resolve/main/config.json'''
    ),
    '''google/bigbird-pegasus-large-pubmed''': (
        '''https://huggingface.co/google/bigbird-pegasus-large-pubmed/resolve/main/config.json'''
    ),
    '''google/bigbird-pegasus-large-bigpatent''': (
        '''https://huggingface.co/google/bigbird-pegasus-large-bigpatent/resolve/main/config.json'''
    ),
    # See all BigBirdPegasus models at https://huggingface.co/models?filter=bigbird_pegasus
}



class _A	(     __SCREAMING_SNAKE_CASE     ):
		_SCREAMING_SNAKE_CASE       :     str       =      "bigbird_pegasus"
		_SCREAMING_SNAKE_CASE       :     Optional[Any]       =      ["past_key_values"]
		_SCREAMING_SNAKE_CASE       :     Union[str, Any]       =      {
		    "num_attention_heads": "encoder_attention_heads",
		    "hidden_size": "d_model",
		    "attention_probs_dropout_prob": "attention_dropout",
		}





		def __init__(  self			,							__UpperCAmelCase=96_103			,							__UpperCAmelCase=4_096			,							__UpperCAmelCase=16			,							__UpperCAmelCase=4_096			,							__UpperCAmelCase=16			,							__UpperCAmelCase=16			,							__UpperCAmelCase=4_096			,							__UpperCAmelCase=16			,							__UpperCAmelCase=0.0			,							__UpperCAmelCase=0.0			,							__UpperCAmelCase=True			,							__UpperCAmelCase=True			,							__UpperCAmelCase="gelu_new"			,							__UpperCAmelCase=1_024			,							__UpperCAmelCase=0.1			,							__UpperCAmelCase=0.0			,							__UpperCAmelCase=0.0			,							__UpperCAmelCase=0.02			,							__UpperCAmelCase=2			,							__UpperCAmelCase=0.0			,							__UpperCAmelCase=True			,							__UpperCAmelCase=0			,							__UpperCAmelCase=2			,							__UpperCAmelCase=1			,							__UpperCAmelCase="block_sparse"			,							__UpperCAmelCase=64			,							__UpperCAmelCase=3			,							__UpperCAmelCase=False			,							**__UpperCAmelCase			,							)							->  Optional[Any]:

					'''simple docstring'''
					__UpperCAmelCase :   int    					=  vocab_size
					__UpperCAmelCase :   int    					=  max_position_embeddings
					__UpperCAmelCase :   Tuple    					=  d_model
					__UpperCAmelCase :   List[str]    					=  encoder_ffn_dim
					__UpperCAmelCase :   int    					=  encoder_layers
					__UpperCAmelCase :   List[str]    					=  encoder_attention_heads
					__UpperCAmelCase :   Any    					=  decoder_ffn_dim
					__UpperCAmelCase :   List[Any]    					=  decoder_layers
					__UpperCAmelCase :   Optional[Any]    					=  decoder_attention_heads
					__UpperCAmelCase :   Any    					=  dropout
					__UpperCAmelCase :   Optional[int]    					=  attention_dropout
					__UpperCAmelCase :   int    					=  activation_dropout
					__UpperCAmelCase :   int    					=  activation_function
					__UpperCAmelCase :   Any    					=  init_std
					__UpperCAmelCase :   Optional[int]    					=  encoder_layerdrop
					__UpperCAmelCase :   int    					=  decoder_layerdrop
					__UpperCAmelCase :   str    					=  classifier_dropout
					__UpperCAmelCase :   Tuple    					=  use_cache
					__UpperCAmelCase :   Optional[Any]    					=  encoder_layers
					__UpperCAmelCase :   str    					=  scale_embedding  # scale factor will be sqrt(d_model) if True

					# extra config
					__UpperCAmelCase :   Optional[int]    					=  attention_type
					__UpperCAmelCase :   List[Any]    					=  block_size
					__UpperCAmelCase :   List[str]    					=  num_random_blocks
					__UpperCAmelCase :   List[Any]    					=  use_bias

					super().__init__(
					    pad_token_id=__UpperCAmelCase			,							bos_token_id=__UpperCAmelCase			,							eos_token_id=__UpperCAmelCase			,							is_encoder_decoder=__UpperCAmelCase			,							decoder_start_token_id=__UpperCAmelCase			,							**__UpperCAmelCase			,							)



class _A	(     __SCREAMING_SNAKE_CASE     ):





		@property
		def 				__A							(  self					)							->  Mapping[str, Mapping[int, str]]:

					'''simple docstring'''
					if self.task in ["default", "seq2seq-lm"]:
								__UpperCAmelCase :   List[Any]    					=  OrderedDict(
								    [
								        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
								        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
								    ]					)

								if self.use_past:
											__UpperCAmelCase :   Dict    					=  {0: """batch"""}
											__UpperCAmelCase :   Optional[Any]    					=  {0: """batch""", 1: """past_decoder_sequence + sequence"""}
								else:
											__UpperCAmelCase :   List[Any]    					=  {0: """batch""", 1: """decoder_sequence"""}
											__UpperCAmelCase :   List[Any]    					=  {0: """batch""", 1: """decoder_sequence"""}

								if self.use_past:
											self.fill_with_past_key_values_(__UpperCAmelCase			,							direction="""inputs"""					)
					elif self.task == "causal-lm":
								# TODO: figure this case out.
								__UpperCAmelCase :   Tuple    					=  OrderedDict(
								    [
								        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
								        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
								    ]					)
								if self.use_past:
											__UpperCAmelCase					,	__UpperCAmelCase :   Dict    					=  self.num_layers
											for i in range(__UpperCAmelCase					):
														__UpperCAmelCase :   Optional[Any]    					=  {0: """batch""", 2: """past_sequence + sequence"""}
														__UpperCAmelCase :   List[str]    					=  {0: """batch""", 2: """past_sequence + sequence"""}
					else:
								__UpperCAmelCase :   int    					=  OrderedDict(
								    [
								        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
								        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
								        ("""decoder_input_ids""", {0: """batch""", 1: """decoder_sequence"""}),
								        ("""decoder_attention_mask""", {0: """batch""", 1: """decoder_sequence"""}),
								    ]					)

					return common_inputs





		@property
		def 				__A							(  self					)							->  Mapping[str, Mapping[int, str]]:

					'''simple docstring'''
					if self.task in ["default", "seq2seq-lm"]:
								__UpperCAmelCase :   Any    					=  super().outputs
					else:
								__UpperCAmelCase :   int    					=  super(__UpperCAmelCase			,							self					).outputs
								if self.use_past:
											__UpperCAmelCase					,	__UpperCAmelCase :   str    					=  self.num_layers
											for i in range(__UpperCAmelCase					):
														__UpperCAmelCase :   int    					=  {0: """batch""", 2: """past_sequence + sequence"""}
														__UpperCAmelCase :   List[Any]    					=  {0: """batch""", 2: """past_sequence + sequence"""}
					return common_outputs





		def 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase = -1			,							__UpperCAmelCase = -1			,							__UpperCAmelCase = False			,							__UpperCAmelCase = None			,							)							->  Mapping[str, Any]:

					'''simple docstring'''
					__UpperCAmelCase :   Dict    					=  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
					    __UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)

					# Generate decoder inputs
					__UpperCAmelCase :   Union[str, Any]    					=  seq_length if not self.use_past else 1
					__UpperCAmelCase :   Optional[Any]    					=  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
					    __UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)
					__UpperCAmelCase :   List[Any]    					=  {f'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
					__UpperCAmelCase :   Any    					=  dict(**__UpperCAmelCase			,							**__UpperCAmelCase					)

					if self.use_past:
								if not is_torch_available():
											raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""					)
								else:
											import torch
								__UpperCAmelCase					,	__UpperCAmelCase :   Optional[Any]    					=  common_inputs["""input_ids"""].shape
								__UpperCAmelCase :   Optional[Any]    					=  common_inputs["""decoder_input_ids"""].shape[1]
								__UpperCAmelCase					,	__UpperCAmelCase :   str    					=  self.num_attention_heads
								__UpperCAmelCase :   Optional[int]    					=  (
								    batch,
								    num_encoder_attention_heads,
								    encoder_seq_length,
								    self._config.hidden_size // num_encoder_attention_heads,
								)
								__UpperCAmelCase :   Tuple    					=  decoder_seq_length + 3
								__UpperCAmelCase :   List[Any]    					=  (
								    batch,
								    num_decoder_attention_heads,
								    decoder_past_length,
								    self._config.hidden_size // num_decoder_attention_heads,
								)

								__UpperCAmelCase :   Union[str, Any]    					=  torch.cat(
								    [common_inputs["""decoder_attention_mask"""], torch.ones(__UpperCAmelCase			,							__UpperCAmelCase					)]			,							dim=1					)

								__UpperCAmelCase :   List[Any]    					=  []
								# If the number of encoder and decoder layers are present in the model configuration, both are considered
								__UpperCAmelCase					,	__UpperCAmelCase :   Any    					=  self.num_layers
								__UpperCAmelCase :   Optional[int]    					=  min(__UpperCAmelCase			,							__UpperCAmelCase					)
								__UpperCAmelCase :   Optional[int]    					=  max(__UpperCAmelCase			,							__UpperCAmelCase					) - min_num_layers
								__UpperCAmelCase :   str    					=  """encoder""" if num_encoder_layers > num_decoder_layers else """decoder"""

								for _ in range(__UpperCAmelCase					):
											common_inputs["past_key_values"].append(
											    (
											        torch.zeros(__UpperCAmelCase					),
											        torch.zeros(__UpperCAmelCase					),
											        torch.zeros(__UpperCAmelCase					),
											        torch.zeros(__UpperCAmelCase					),
											    )					)
								# TODO: test this.
								__UpperCAmelCase :   List[Any]    					=  encoder_shape if remaining_side_name == """encoder""" else decoder_shape
								for _ in range(__UpperCAmelCase			,							__UpperCAmelCase					):
											common_inputs["past_key_values"].append((torch.zeros(__UpperCAmelCase					), torch.zeros(__UpperCAmelCase					))					)
					return common_inputs





		def 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase = -1			,							__UpperCAmelCase = -1			,							__UpperCAmelCase = False			,							__UpperCAmelCase = None			,							)							->  Mapping[str, Any]:

					'''simple docstring'''
					__UpperCAmelCase :   Tuple    					=  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
					    __UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)

					if self.use_past:
								if not is_torch_available():
											raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""					)
								else:
											import torch
								__UpperCAmelCase					,	__UpperCAmelCase :   str    					=  common_inputs["""input_ids"""].shape
								# Not using the same length for past_key_values
								__UpperCAmelCase :   Optional[int]    					=  seqlen + 2
								__UpperCAmelCase					,	__UpperCAmelCase :   str    					=  self.num_layers
								__UpperCAmelCase					,	__UpperCAmelCase :   Union[str, Any]    					=  self.num_attention_heads
								__UpperCAmelCase :   List[str]    					=  (
								    batch,
								    num_encoder_attention_heads,
								    past_key_values_length,
								    self._config.hidden_size // num_encoder_attention_heads,
								)

								__UpperCAmelCase :   Dict    					=  common_inputs["""attention_mask"""].dtype
								__UpperCAmelCase :   Tuple    					=  torch.cat(
								    [common_inputs["""attention_mask"""], torch.ones(__UpperCAmelCase			,							__UpperCAmelCase			,							dtype=__UpperCAmelCase					)]			,							dim=1					)
								__UpperCAmelCase :   int    					=  [
								    (torch.zeros(__UpperCAmelCase					), torch.zeros(__UpperCAmelCase					)) for _ in range(__UpperCAmelCase					)
								]
					return common_inputs





		def 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase = -1			,							__UpperCAmelCase = -1			,							__UpperCAmelCase = False			,							__UpperCAmelCase = None			,							)							->  Mapping[str, Any]:

					'''simple docstring'''
					# Copied from OnnxConfig.generate_dummy_inputs
					# Did not use super(OnnxConfigWithPast, self).generate_dummy_inputs for code clarity.
					# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
					__UpperCAmelCase :   List[str]    					=  compute_effective_axis_dimension(
					    __UpperCAmelCase			,							fixed_dimension=OnnxConfig.default_fixed_batch			,							num_token_to_add=0					)

					# If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
					__UpperCAmelCase :   Any    					=  tokenizer.num_special_tokens_to_add(__UpperCAmelCase					)
					__UpperCAmelCase :   str    					=  compute_effective_axis_dimension(
					    __UpperCAmelCase			,							fixed_dimension=OnnxConfig.default_fixed_sequence			,							num_token_to_add=__UpperCAmelCase					)

					# Generate dummy inputs according to compute batch and sequence
					__UpperCAmelCase :   Optional[Any]    					=  [""" """.join([tokenizer.unk_token]					) * seq_length] * batch_size
					__UpperCAmelCase :   Optional[Any]    					=  dict(tokenizer(__UpperCAmelCase			,							return_tensors=__UpperCAmelCase					)					)
					return common_inputs





		def 				__A							(  self			,							__UpperCAmelCase			,							__UpperCAmelCase = -1			,							__UpperCAmelCase = -1			,							__UpperCAmelCase = False			,							__UpperCAmelCase = None			,							)							->  Mapping[str, Any]:

					'''simple docstring'''
					if self.task in ["default", "seq2seq-lm"]:
								__UpperCAmelCase :   str    					=  self._generate_dummy_inputs_for_default_and_seqaseq_lm(
								    __UpperCAmelCase			,							batch_size=__UpperCAmelCase			,							seq_length=__UpperCAmelCase			,							is_pair=__UpperCAmelCase			,							framework=__UpperCAmelCase					)

					elif self.task == "causal-lm":
								__UpperCAmelCase :   List[str]    					=  self._generate_dummy_inputs_for_causal_lm(
								    __UpperCAmelCase			,							batch_size=__UpperCAmelCase			,							seq_length=__UpperCAmelCase			,							is_pair=__UpperCAmelCase			,							framework=__UpperCAmelCase					)
					else:
								__UpperCAmelCase :   Optional[int]    					=  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
								    __UpperCAmelCase			,							batch_size=__UpperCAmelCase			,							seq_length=__UpperCAmelCase			,							is_pair=__UpperCAmelCase			,							framework=__UpperCAmelCase					)

					return common_inputs





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

					'''simple docstring'''
					if self.task in ["default", "seq2seq-lm"]:
								__UpperCAmelCase :   Optional[Any]    					=  super()._flatten_past_key_values_(__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)
					else:
								__UpperCAmelCase :   Dict    					=  super(__UpperCAmelCase			,							self					)._flatten_past_key_values_(
								    __UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase			,							__UpperCAmelCase					)









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




