code: 
  
  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 __UpperCamelCase    :
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					def __init__(							self							,			lowerCamelCase__							,			lowerCamelCase__=1_3							,			lowerCamelCase__=3_2							,			lowerCamelCase__=3							,			lowerCamelCase__=4							,			lowerCamelCase__=[1_0, 2_0, 3_0, 4_0]							,			lowerCamelCase__=[2, 2, 3, 2]							,			lowerCamelCase__=True							,			lowerCamelCase__=True							,			lowerCamelCase__=3_7							,			lowerCamelCase__="gelu"							,			lowerCamelCase__=1_0							,			lowerCamelCase__=0.02							,			lowerCamelCase__=3							,			lowerCamelCase__=None							,			):
  						UpperCAmelCase__:  Union[str, Any]		       =   parent
  						UpperCAmelCase__:  List[Any]		       =   batch_size
  						UpperCAmelCase__:  Optional[int]		       =   image_size
  						UpperCAmelCase__:  Optional[Any]		       =   num_channels
  						UpperCAmelCase__:  Tuple		       =   num_stages
  						UpperCAmelCase__:  List[str]		       =   hidden_sizes
  						UpperCAmelCase__:  int		       =   depths
  						UpperCAmelCase__:  Dict		       =   is_training
  						UpperCAmelCase__:  Union[str, Any]		       =   use_labels
  						UpperCAmelCase__:  int		       =   intermediate_size
  						UpperCAmelCase__:  int		       =   hidden_act
  						UpperCAmelCase__:  List[Any]		       =   type_sequence_label_size
  						UpperCAmelCase__:  Optional[Any]		       =   initializer_range
  						UpperCAmelCase__:  Dict		       =   scope
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Optional[int]		       =   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]	)
  
  						UpperCAmelCase__:  Optional[int]		       =   None
  						if self.use_labels:
  							UpperCAmelCase__:  Union[str, Any]		       =   ids_tensor([self.batch_size]							,			self.type_sequence_label_size	)
  
  						UpperCAmelCase__:  Dict		       =   self.get_config()
  
  						return config, pixel_values, labels
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						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       _UpperCAmelCase						(							self							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__	):
  						UpperCAmelCase__:  Union[str, Any]		       =   TFConvNextModel(config=lowerCamelCase__	)
  						UpperCAmelCase__:  Tuple		       =   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       _UpperCAmelCase						(							self							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__	):
  						UpperCAmelCase__:  str		       =   self.type_sequence_label_size
  						UpperCAmelCase__:  Any		       =   TFConvNextForImageClassification(lowerCamelCase__	)
  						UpperCAmelCase__:  str		       =   model(lowerCamelCase__							,			labels=lowerCamelCase__							,			training=lowerCamelCase__	)
  						self.parent.assertEqual(result.logits.shape							,			(self.batch_size, self.type_sequence_label_size)	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  int		       =   self.prepare_config_and_inputs()
  						UpperCAmelCase__       ,	UpperCAmelCase__       ,	UpperCAmelCase__:  List[str]		       =   config_and_inputs
  						UpperCAmelCase__:  Dict		       =   {"pixel_values": pixel_values}
  						return config, inputs_dict
  
  @require_tf
  class __UpperCamelCase    (							_a				,_a				,unittest.TestCase		):
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					__magic_name__     			=      (TFConvNextModel, TFConvNextForImageClassification) if is_tf_available() else ()
  					__magic_name__     			=      (
  					    {"feature-extraction": TFConvNextModel, "image-classification": TFConvNextForImageClassification}
  					    if is_tf_available()
  					    else {}
  					)
  
  					__magic_name__     			=      False
  					__magic_name__     			=      False
  					__magic_name__     			=      False
  					__magic_name__     			=      False
  					__magic_name__     			=      False
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  List[str]		       =   TFConvNextModelTester(self	)
  						UpperCAmelCase__:  Optional[Any]		       =   ConfigTester(
  						    self							,			config_class=lowerCamelCase__							,			has_text_modality=lowerCamelCase__							,			hidden_size=3_7							,			)
  
  
  
  
  
  					@unittest.skip(reason="ConvNext does not use inputs_embeds"	)
  					def       _UpperCAmelCase						(							self	):
  						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       _UpperCAmelCase						(							self	):
  						super().test_keras_fit()
  
  
  
  
  
  					@unittest.skip(reason="ConvNext does not support input and output embeddings"	)
  					def       _UpperCAmelCase						(							self	):
  						pass
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__       ,	UpperCAmelCase__:  List[Any]		       =   self.model_tester.prepare_config_and_inputs_for_common()
  
  						for model_class in self.all_model_classes:
  							UpperCAmelCase__:  List[Any]		       =   model_class(lowerCamelCase__	)
  							UpperCAmelCase__:  Tuple		       =   inspect.signature(model.call	)
  							# signature.parameters is an OrderedDict => so arg_names order is deterministic
  							UpperCAmelCase__:  List[Any]		       =   [*signature.parameters.keys()]
  
  							UpperCAmelCase__:  Optional[int]		       =   ["pixel_values"]
  							self.assertListEqual(arg_names[:1]							,			lowerCamelCase__	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  str		       =   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       _UpperCAmelCase						(							self	):
  						super().test_dataset_conversion()
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						def check_hidden_states_output(lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__	):
  							UpperCAmelCase__:  Any		       =   model_class(lowerCamelCase__	)
  
  							UpperCAmelCase__:  int		       =   model(**self._prepare_for_class(lowerCamelCase__							,			lowerCamelCase__	)	)
  							UpperCAmelCase__:  Optional[int]		       =   outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
  
  							UpperCAmelCase__:  Dict		       =   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]							,			)
  
  						UpperCAmelCase__       ,	UpperCAmelCase__:  Dict		       =   self.model_tester.prepare_config_and_inputs_for_common()
  
  						for model_class in self.all_model_classes:
  							UpperCAmelCase__:  str		       =   True
  							check_hidden_states_output(lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__	)
  
  							# check that output_hidden_states also work using config
  							del inputs_dict["output_hidden_states"]
  							UpperCAmelCase__:  Optional[int]		       =   True
  
  							check_hidden_states_output(lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__       ,	UpperCAmelCase__:  Any		       =   self.model_tester.prepare_config_and_inputs_for_common()
  
  						def check_equivalence(lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__={}	):
  							UpperCAmelCase__:  Optional[Any]		       =   model(lowerCamelCase__							,			return_dict=lowerCamelCase__							,			**lowerCamelCase__	)
  							UpperCAmelCase__:  Union[str, Any]		       =   model(lowerCamelCase__							,			return_dict=lowerCamelCase__							,			**lowerCamelCase__	).to_tuple()
  
  							def recursive_check(lowerCamelCase__							,			lowerCamelCase__	):
  								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:
  							UpperCAmelCase__:  Tuple		       =   model_class(lowerCamelCase__	)
  
  							UpperCAmelCase__:  Tuple		       =   self._prepare_for_class(lowerCamelCase__							,			lowerCamelCase__	)
  							UpperCAmelCase__:  int		       =   self._prepare_for_class(lowerCamelCase__							,			lowerCamelCase__	)
  							check_equivalence(lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__	)
  
  							UpperCAmelCase__:  Tuple		       =   self._prepare_for_class(lowerCamelCase__							,			lowerCamelCase__							,			return_labels=lowerCamelCase__	)
  							UpperCAmelCase__:  Any		       =   self._prepare_for_class(lowerCamelCase__							,			lowerCamelCase__							,			return_labels=lowerCamelCase__	)
  							check_equivalence(lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__	)
  
  							UpperCAmelCase__:  Any		       =   self._prepare_for_class(lowerCamelCase__							,			lowerCamelCase__	)
  							UpperCAmelCase__:  List[str]		       =   self._prepare_for_class(lowerCamelCase__							,			lowerCamelCase__	)
  							check_equivalence(lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			{"output_hidden_states": True}	)
  
  							UpperCAmelCase__:  Union[str, Any]		       =   self._prepare_for_class(lowerCamelCase__							,			lowerCamelCase__							,			return_labels=lowerCamelCase__	)
  							UpperCAmelCase__:  int		       =   self._prepare_for_class(lowerCamelCase__							,			lowerCamelCase__							,			return_labels=lowerCamelCase__	)
  							check_equivalence(lowerCamelCase__							,			lowerCamelCase__							,			lowerCamelCase__							,			{"output_hidden_states": True}	)
  
  
  
  
  
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Any		       =   self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_for_image_classification(*lowerCamelCase__	)
  
  
  
  
  
  					@slow
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Optional[Any]		       =   TFConvNextModel.from_pretrained("facebook/convnext-tiny-224"	)
  						self.assertIsNotNone(lowerCamelCase__	)
  
  
  
  def  _A  (			):
  	UpperCAmelCase__:  Optional[Any]		       =   Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"			)
  	return image
  
  @require_tf
  @require_vision
  class __UpperCamelCase    (							unittest.TestCase		):
  
  
  
  
  
  
  					'''simple docstring'''
  
  
  
  					@cached_property
  					def       _UpperCAmelCase						(							self	):
  						return ConvNextImageProcessor.from_pretrained("facebook/convnext-tiny-224"	) if is_vision_available() else None
  
  
  
  
  
  					@slow
  					def       _UpperCAmelCase						(							self	):
  						UpperCAmelCase__:  Tuple		       =   TFConvNextForImageClassification.from_pretrained("facebook/convnext-tiny-224"	)
  
  						UpperCAmelCase__:  List[str]		       =   self.default_image_processor
  						UpperCAmelCase__:  Union[str, Any]		       =   prepare_img()
  						UpperCAmelCase__:  Any		       =   image_processor(images=lowerCamelCase__							,			return_tensors="tf"	)
  
  						# forward pass
  						UpperCAmelCase__:  List[str]		       =   model(**lowerCamelCase__	)
  
  						# verify the logits
  						UpperCAmelCase__:  Tuple		       =   tf.TensorShape((1, 1_0_0_0)	)
  						self.assertEqual(outputs.logits.shape							,			lowerCamelCase__	)
  
  						UpperCAmelCase__:  List[Any]		       =   tf.constant([-0.0_260, -0.4_739, 0.1_911]	)
  
  						tf.debugging.assert_near(outputs.logits[0, :3]							,			lowerCamelCase__							,			atol=1e-4	)
style_context: 
  
  from __future__ import annotations
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	assert n > 1 and a > 0 and greatest_common_divisor(SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			) == 1
  	((UpperCAmelCase__)       ,	(UpperCAmelCase__)       ,	(UpperCAmelCase__)):  Optional[Any]		       =   extended_gcd(SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			)  # Implemented below
  	UpperCAmelCase__:  List[str]		       =   (b * s) % n
  	return x
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	((UpperCAmelCase__)       ,	(UpperCAmelCase__)):  int		       =   extended_euclid(SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			)  # Implemented below
  	if b < 0:
  		UpperCAmelCase__:  List[str]		       =   (b % n + n) % n
  	return b
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	UpperCAmelCase__:  Union[str, Any]		       =   invert_modulo(SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			)
  	UpperCAmelCase__:  Any		       =   (b * s) % n
  	return x
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	assert a >= 0 and b >= 0
  
  	if b == 0:
  		UpperCAmelCase__       ,	UpperCAmelCase__       ,	UpperCAmelCase__:  List[Any]		       =   a, 1, 0
  	else:
  		((UpperCAmelCase__)       ,	(UpperCAmelCase__)       ,	(UpperCAmelCase__)):  Tuple		       =   extended_gcd(SCREAMING_SNAKE_CASE  ,a % b			)
  		UpperCAmelCase__:  Union[str, Any]		       =   q
  		UpperCAmelCase__:  Union[str, Any]		       =   p - q * (a // b)
  
  	assert a % d == 0 and b % d == 0
  	assert d == a * x + b * y
  
  	return (d, x, y)
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	if b == 0:
  		return (1, 0)
  	((UpperCAmelCase__)       ,	(UpperCAmelCase__)):  List[str]		       =   extended_euclid(SCREAMING_SNAKE_CASE  ,a % b			)
  	UpperCAmelCase__:  Optional[Any]		       =   a // b
  	return (y, x - k * y)
  
  
  
  def  _A  (			SCREAMING_SNAKE_CASE  ,SCREAMING_SNAKE_CASE			):
  	if a < b:
  		UpperCAmelCase__       ,	UpperCAmelCase__:  str		       =   b, a
  
  	while a % b != 0:
  		UpperCAmelCase__       ,	UpperCAmelCase__:  Union[str, Any]		       =   b, a % b
  
  	return b
  
  
  if __name__ == "__main__":
  					from doctest import testmod
  
  					testmod(name="""modular_division""", verbose=True)
  					testmod(name="""modular_division2""", verbose=True)
  					testmod(name="""invert_modulo""", verbose=True)
  					testmod(name="""extended_gcd""", verbose=True)
  					testmod(name="""extended_euclid""", verbose=True)
  					testmod(name="""greatest_common_divisor""", verbose=True)