




import inspect
import unittest

from transformers import RegNetConfig, is_flax_available
from transformers.testing_utils import require_flax, slow
from transformers.utils import cached_property, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor


if is_flax_available():
						import jax
						import jax.numpy as jnp

						from transformers.models.regnet.modeling_flax_regnet import FlaxRegNetForImageClassification, FlaxRegNetModel

if is_vision_available():
						from PIL import Image

						from transformers import AutoImageProcessor


class  A		(  unittest.TestCase     ):



		def __init__(     self,	UpperCamelCase__,	UpperCamelCase__=3,	UpperCamelCase__=32,	UpperCamelCase__=3,	UpperCamelCase__=10,	UpperCamelCase__=[10, 20, 30, 40],	UpperCamelCase__=[1, 1, 2, 1],	UpperCamelCase__=True,	UpperCamelCase__=True,	UpperCamelCase__="relu",	UpperCamelCase__=3,	UpperCamelCase__=None,	):







								"""simple docstring"""



								lowerCAmelCase_      			=  parent
								lowerCAmelCase_      			=  batch_size
								lowerCAmelCase_      			=  image_size
								lowerCAmelCase_      			=  num_channels
								lowerCAmelCase_      			=  embeddings_size
								lowerCAmelCase_      			=  hidden_sizes
								lowerCAmelCase_      			=  depths
								lowerCAmelCase_      			=  is_training
								lowerCAmelCase_      			=  use_labels
								lowerCAmelCase_      			=  hidden_act
								lowerCAmelCase_      			=  num_labels
								lowerCAmelCase_      			=  scope
								lowerCAmelCase_      			=  len(UpperCamelCase__   )



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]   )

								lowerCAmelCase_      			=  self.get_config()

								return config, pixel_values



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								return RegNetConfig(
								    num_channels=self.num_channels,	embeddings_size=self.embeddings_size,	hidden_sizes=self.hidden_sizes,	depths=self.depths,	hidden_act=self.hidden_act,	num_labels=self.num_labels,	image_size=self.image_size,	)



		def        SCREAMING_SNAKE_CASE__			(     self,	UpperCamelCase__,	UpperCamelCase__   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  FlaxRegNetModel(config=UpperCamelCase__   )
								lowerCAmelCase_      			=  model(UpperCamelCase__   )

								# Output shape (b, c, h, w)
								self.parent.assertEqual(
								    result.last_hidden_state.shape,	(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32),	)



		def        SCREAMING_SNAKE_CASE__			(     self,	UpperCamelCase__,	UpperCamelCase__   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  self.num_labels
								lowerCAmelCase_      			=  FlaxRegNetForImageClassification(config=UpperCamelCase__   )
								lowerCAmelCase_      			=  model(UpperCamelCase__   )
								self.parent.assertEqual(result.logits.shape,	(self.batch_size, self.num_labels)   )







		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  self.prepare_config_and_inputs()
								lowerCAmelCase_			,					lowerCAmelCase_      			=  config_and_inputs
								lowerCAmelCase_      			=  {'''pixel_values''': pixel_values}
								return config, inputs_dict







@require_flax
class  A		(  __UpperCAmelCase      ,				unittest.TestCase     ):
		__snake_case									=   (FlaxRegNetModel, FlaxRegNetForImageClassification) if is_flax_available() else ()

		__snake_case									=   False
		__snake_case									=   False
		__snake_case									=   False



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  FlaxRegNetModelTester(self   )
								lowerCAmelCase_      			=  ConfigTester(self,	config_class=UpperCamelCase__,	has_text_modality=UpperCamelCase__   )



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""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        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								return



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*UpperCamelCase__   )



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_image_classification(*UpperCamelCase__   )



		@unittest.skip(reason='''RegNet does not use inputs_embeds'''   )
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								pass



		@unittest.skip(reason='''RegNet does not support input and output embeddings'''   )
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								pass



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_			,					lowerCAmelCase_      			=  self.model_tester.prepare_config_and_inputs_for_common()

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

														lowerCAmelCase_      			=  ['''pixel_values''']
														self.assertListEqual(arg_names[:1],	UpperCamelCase__   )



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								def check_hidden_states_output(UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__   ):
														lowerCAmelCase_      			=  model_class(UpperCamelCase__   )

														lowerCAmelCase_      			=  model(**self._prepare_for_class(UpperCamelCase__,	UpperCamelCase__   )   )

														lowerCAmelCase_      			=  outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

														lowerCAmelCase_      			=  self.model_tester.num_stages
														self.assertEqual(len(UpperCamelCase__   ),	expected_num_stages + 1   )

								lowerCAmelCase_			,					lowerCAmelCase_      			=  self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
														lowerCAmelCase_      			=  True
														check_hidden_states_output(UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__   )

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

														check_hidden_states_output(UpperCamelCase__,	UpperCamelCase__,	UpperCamelCase__   )







		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_			,					lowerCAmelCase_      			=  self.model_tester.prepare_config_and_inputs_for_common()

								for model_class in self.all_model_classes:
														with self.subTest(model_class.__name__   ):
																				lowerCAmelCase_      			=  self._prepare_for_class(UpperCamelCase__,	UpperCamelCase__   )
																				lowerCAmelCase_      			=  model_class(UpperCamelCase__   )

																				@jax.jit
																				def model_jitted(UpperCamelCase__,	**UpperCamelCase__   ):
																										return model(pixel_values=UpperCamelCase__,	**UpperCamelCase__   )

																				with self.subTest('''JIT Enabled'''   ):
																										lowerCAmelCase_      			=  model_jitted(**UpperCamelCase__   ).to_tuple()

																				with self.subTest('''JIT Disabled'''   ):
																										with jax.disable_jit():
																																lowerCAmelCase_      			=  model_jitted(**UpperCamelCase__   ).to_tuple()

																				self.assertEqual(len(UpperCamelCase__   ),	len(UpperCamelCase__   )   )
																				for jitted_output, output in zip(UpperCamelCase__,	UpperCamelCase__   ):
																										self.assertEqual(jitted_output.shape,	output.shape   )







def __UpperCamelCase			(       ):
						lowerCAmelCase_      			=  Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''  )
						return image






@require_flax
class  A		(  unittest.TestCase     ):



		@cached_property
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								return AutoImageProcessor.from_pretrained('''facebook/regnet-y-040'''   ) if is_vision_available() else None







		@slow
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  FlaxRegNetForImageClassification.from_pretrained('''facebook/regnet-y-040'''   )

								lowerCAmelCase_      			=  self.default_image_processor
								lowerCAmelCase_      			=  prepare_img()
								lowerCAmelCase_      			=  image_processor(images=UpperCamelCase__,	return_tensors='''np'''   )

								lowerCAmelCase_      			=  model(**UpperCamelCase__   )

								# verify the logits
								lowerCAmelCase_      			=  (1, 1000)
								self.assertEqual(outputs.logits.shape,	UpperCamelCase__   )

								lowerCAmelCase_      			=  jnp.array([-0.4_180, -1.5_051, -3.4_836]   )

								self.assertTrue(jnp.allclose(outputs.logits[0, :3],	UpperCamelCase__,	atol=1E-4   )   )










import importlib
import os
from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, Optional, Union

import torch

from ..utils import BaseOutput


_A     =			'''scheduler_config.json'''


class  A		(  __UpperCAmelCase     ):
		__snake_case									=   1
		__snake_case									=   2
		__snake_case									=   3
		__snake_case									=   4
		__snake_case									=   5
		__snake_case									=   6
		__snake_case									=   7
		__snake_case									=   8
		__snake_case									=   9
		__snake_case									=   10
		__snake_case									=   11
		__snake_case									=   12
		__snake_case									=   13
		__snake_case									=   14







@dataclass
class  A		(  __UpperCAmelCase     ):
		__snake_case									=   42







class  A		:
		__snake_case									=   SCHEDULER_CONFIG_NAME
		__snake_case									=   []
		__snake_case									=   True



		@classmethod
		def        SCREAMING_SNAKE_CASE__			(     cls,	UpperCamelCase__ = None,	UpperCamelCase__ = None,	UpperCamelCase__=False,	**UpperCamelCase__,	):







								"""simple docstring"""



								lowerCAmelCase_			,					lowerCAmelCase_			,					lowerCAmelCase_      			=  cls.load_config(
								    pretrained_model_name_or_path=UpperCamelCase__,	subfolder=UpperCamelCase__,	return_unused_kwargs=UpperCamelCase__,	return_commit_hash=UpperCamelCase__,	**UpperCamelCase__,	)
								return cls.from_config(UpperCamelCase__,	return_unused_kwargs=UpperCamelCase__,	**UpperCamelCase__   )



		def        SCREAMING_SNAKE_CASE__			(     self,	UpperCamelCase__,	UpperCamelCase__ = False,	**UpperCamelCase__   ):







								"""simple docstring"""



								self.save_config(save_directory=UpperCamelCase__,	push_to_hub=UpperCamelCase__,	**UpperCamelCase__   )



		@property
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								return self._get_compatibles()







		@classmethod
		def        SCREAMING_SNAKE_CASE__			(     cls   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  list(set([cls.__name__] + cls._compatibles   )   )
								lowerCAmelCase_      			=  importlib.import_module(__name__.split('''.'''   )[0]   )
								lowerCAmelCase_      			=  [
								    getattr(UpperCamelCase__,	UpperCamelCase__   ) for c in compatible_classes_str if hasattr(UpperCamelCase__,	UpperCamelCase__   )
								]
								return compatible_classes




