



'''simple docstring'''





import inspect
import unittest

from transformers import ResNetConfig, 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.resnet.modeling_flax_resnet import FlaxResNetForImageClassification, FlaxResNetModel

if is_vision_available():
   from PIL import Image

   from transformers import AutoImageProcessor






class  lowerCamelCase_   (    unittest.TestCase					):
  """simple docstring"""




  def __init__(			self				:     str      ,     _a				:     List[str]      ,     _a				:     Union[str, Any]=3      ,     _a				:     Optional[int]=32      ,     _a				:     Optional[int]=3      ,     _a				:     List[Any]=10      ,     _a				:     Optional[Any]=[10, 20, 30, 40]      ,     _a				:     Optional[Any]=[1, 1, 2, 1]      ,     _a				:     Optional[Any]=True      ,     _a				:     List[str]=True      ,     _a				:     Dict="relu"      ,     _a				:     Optional[Any]=3      ,     _a				:     str=None      ,     ) -> Union[str, Any]:
    __lowerCamelCase	:	str   	=			parent
    __lowerCamelCase	:	Tuple   	=			batch_size
    __lowerCamelCase	:	str   	=			image_size
    __lowerCamelCase	:	Union[str, Any]   	=			num_channels
    __lowerCamelCase	:	str   	=			embeddings_size
    __lowerCamelCase	:	Optional[int]   	=			hidden_sizes
    __lowerCamelCase	:	Any   	=			depths
    __lowerCamelCase	:	Tuple   	=			is_training
    __lowerCamelCase	:	List[Any]   	=			use_labels
    __lowerCamelCase	:	Optional[int]   	=			hidden_act
    __lowerCamelCase	:	int   	=			num_labels
    __lowerCamelCase	:	List[Any]   	=			scope
    __lowerCamelCase	:	Union[str, Any]   	=			len(_a       )




  def 						_lowercase					(			self				:     Tuple       ) -> str:
    __lowerCamelCase	:	List[str]   	=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]       )

    __lowerCamelCase	:	Union[str, Any]   	=			self.get_config()

    return config, pixel_values




  def 						_lowercase					(			self				:     Union[str, Any]       ) -> Union[str, Any]:
    return ResNetConfig(
        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 						_lowercase					(			self				:     Any      ,     _a				:     str      ,     _a				:     Any       ) -> List[str]:
    __lowerCamelCase	:	List[str]   	=			FlaxResNetModel(config=_a       )
    __lowerCamelCase	:	Union[str, Any]   	=			model(_a       )

    # 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 						_lowercase					(			self				:     List[str]      ,     _a				:     List[str]      ,     _a				:     Optional[Any]       ) -> Dict:
    __lowerCamelCase	:	List[Any]   	=			self.num_labels
    __lowerCamelCase	:	List[Any]   	=			FlaxResNetForImageClassification(config=_a       )
    __lowerCamelCase	:	Optional[int]   	=			model(_a       )
    self.parent.assertEqual(result.logits.shape      ,     (self.batch_size, self.num_labels)       )




  def 						_lowercase					(			self				:     Dict       ) -> List[Any]:
    __lowerCamelCase	:	Optional[Any]   	=			self.prepare_config_and_inputs()
    __lowerCamelCase	,__lowerCamelCase	:	Tuple   	=			config_and_inputs
    __lowerCamelCase	:	int   	=			{'pixel_values': pixel_values}
    return config, inputs_dict






@require_flax
class  lowerCamelCase_   (    SCREAMING_SNAKE_CASE_       ,       unittest.TestCase					):
  """simple docstring"""




  a_							 =(FlaxResNetModel, FlaxResNetForImageClassification) if is_flax_available() else ()

  a_							 =False
  a_							 =False
  a_							 =False




  def 						_lowercase					(			self				:     Any       ) -> None:
    __lowerCamelCase	:	Any   	=			FlaxResNetModelTester(self       )
    __lowerCamelCase	:	Union[str, Any]   	=			ConfigTester(self      ,     config_class=_a      ,     has_text_modality=_a       )




  def 						_lowercase					(			self				:     List[str]       ) -> Dict:
    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 						_lowercase					(			self				:     Any       ) -> Optional[Any]:
    return




  def 						_lowercase					(			self				:     Dict       ) -> Tuple:
    __lowerCamelCase	:	List[Any]   	=			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*_a       )




  def 						_lowercase					(			self				:     Optional[int]       ) -> Any:
    __lowerCamelCase	:	Dict   	=			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_image_classification(*_a       )




  @unittest.skip(reason='ResNet does not use inputs_embeds'       )
  def 						_lowercase					(			self				:     str       ) -> List[Any]:
    pass




  @unittest.skip(reason='ResNet does not support input and output embeddings'       )
  def 						_lowercase					(			self				:     str       ) -> str:
    pass




  def 						_lowercase					(			self				:     Optional[Any]       ) -> str:
    __lowerCamelCase	,__lowerCamelCase	:	Any   	=			self.model_tester.prepare_config_and_inputs_for_common()

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

      __lowerCamelCase	:	List[Any]   	=			['pixel_values']
      self.assertListEqual(arg_names[:1]      ,     _a       )




  def 						_lowercase					(			self				:     Optional[Any]       ) -> Optional[Any]:
    def check_hidden_states_output(_a				:     int      ,     _a				:     List[str]      ,     _a				:     str       ):
      __lowerCamelCase	:	Dict   	=			model_class(_a       )

      __lowerCamelCase	:	Union[str, Any]   	=			model(**self._prepare_for_class(_a      ,     _a       )       )

      __lowerCamelCase	:	List[Any]   	=			outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

      __lowerCamelCase	:	Any   	=			self.model_tester.num_stages
      self.assertEqual(len(_a       )      ,     expected_num_stages + 1       )




  @unittest.skip(reason='ResNet does not use feedforward chunking'       )
  def 						_lowercase					(			self				:     Any       ) -> Any:
    pass




  def 						_lowercase					(			self				:     Optional[Any]       ) -> Tuple:
    __lowerCamelCase	,__lowerCamelCase	:	Union[str, Any]   	=			self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
      with self.subTest(model_class.__name__       ):
        __lowerCamelCase	:	List[Any]   	=			self._prepare_for_class(_a      ,     _a       )
        __lowerCamelCase	:	List[Any]   	=			model_class(_a       )

        @jax.jit
        def model_jitted(_a				:     str      ,     **_a				:     Union[str, Any]       ):
          return model(pixel_values=_a      ,     **_a       )

        with self.subTest('JIT Enabled'       ):
          __lowerCamelCase	:	Optional[Any]   	=			model_jitted(**_a       ).to_tuple()

        with self.subTest('JIT Disabled'       ):
          with jax.disable_jit():
            __lowerCamelCase	:	Optional[Any]   	=			model_jitted(**_a       ).to_tuple()

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




def 	a_					(							)				->				Tuple:
  __lowerCamelCase	:	Dict   	=			Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'	)
  return image






@require_flax
class  lowerCamelCase_   (    unittest.TestCase					):
  """simple docstring"""




  @cached_property
  def 						_lowercase					(			self				:     Tuple       ) -> Tuple:
    return AutoImageProcessor.from_pretrained('microsoft/resnet-50'       ) if is_vision_available() else None




  @slow
  def 						_lowercase					(			self				:     Any       ) -> Any:
    __lowerCamelCase	:	str   	=			FlaxResNetForImageClassification.from_pretrained('microsoft/resnet-50'       )

    __lowerCamelCase	:	str   	=			self.default_image_processor
    __lowerCamelCase	:	Union[str, Any]   	=			prepare_img()
    __lowerCamelCase	:	Optional[int]   	=			image_processor(images=_a      ,     return_tensors='np'       )

    __lowerCamelCase	:	str   	=			model(**_a       )

    # verify the logits
    __lowerCamelCase	:	Dict   	=			(1, 1000)
    self.assertEqual(outputs.logits.shape      ,     _a       )

    __lowerCamelCase	:	Optional[Any]   	=			jnp.array([-11.1069, -9.7877, -8.3777]       )

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











'''simple docstring'''





import unittest

from diffusers import __version__
from diffusers.utils import deprecate






class  lowerCamelCase_   (    unittest.TestCase					):
  """simple docstring"""




  a_							 =""".""".join([str(int(__version__.split("""."""					)[0]					) + 1					)] + __version__.split("""."""					)[1:]					)
  a_							 ="""0.0.1"""




  def 						_lowercase					(			self				:     Optional[Any]       ) -> int:
    __lowerCamelCase	:	Any   	=			{'deprecated_arg': 4}

    with self.assertWarns(_a       ) as warning:
      __lowerCamelCase	:	Optional[int]   	=			deprecate('deprecated_arg'      ,     self.higher_version      ,     'message'      ,     take_from=_a       )

    assert output == 4
    assert (
        str(warning.warning       )
        == f'The `deprecated_arg` argument is deprecated and will be removed in version {self.higher_version}.'
        " message"
    )




  def 						_lowercase					(			self				:     Union[str, Any]       ) -> Optional[int]:
    __lowerCamelCase	:	int   	=			{'deprecated_arg': 4}

    with self.assertWarns(_a       ) as warning:
      __lowerCamelCase	:	Optional[Any]   	=			deprecate(('deprecated_arg', self.higher_version, 'message')      ,     take_from=_a       )

    assert output == 4
    assert (
        str(warning.warning       )
        == f'The `deprecated_arg` argument is deprecated and will be removed in version {self.higher_version}.'
        " message"
    )




  def 						_lowercase					(			self				:     int       ) -> Optional[Any]:
    __lowerCamelCase	:	Optional[int]   	=			{'deprecated_arg_1': 4, 'deprecated_arg_2': 8}
    with self.assertWarns(_a       ) as warning:
      __lowerCamelCase	,__lowerCamelCase	:	Any   	=			deprecate(
          ('deprecated_arg_1', self.higher_version, 'Hey')      ,     ('deprecated_arg_2', self.higher_version, 'Hey')      ,     take_from=_a      ,     )
    assert output_a == 4
    assert output_a == 8
    assert (
        str(warning.warnings[0].message       )
        == "The `deprecated_arg_1` argument is deprecated and will be removed in version"
        f' {self.higher_version}. Hey'
    )
    assert (
        str(warning.warnings[1].message       )
        == "The `deprecated_arg_2` argument is deprecated and will be removed in version"
        f' {self.higher_version}. Hey'
    )




  def 						_lowercase					(			self				:     str       ) -> Optional[Any]:
    __lowerCamelCase	:	Optional[int]   	=			{'deprecated_arg': 4}

    with self.assertRaises(_a       ) as error:
      deprecate(('wrong_arg', self.higher_version, 'message')      ,     take_from=_a       )

    assert "test_deprecate_function_incorrect_arg in" in str(error.exception       )
    assert "line" in str(error.exception       )
    assert "got an unexpected keyword argument `deprecated_arg`" in str(error.exception       )




  def 						_lowercase					(			self				:     Optional[Any]       ) -> Union[str, Any]:
    with self.assertWarns(_a       ) as warning:
      deprecate(('deprecated_arg', self.higher_version, 'message')       )

    assert (
        str(warning.warning       )
        == f'`deprecated_arg` is deprecated and will be removed in version {self.higher_version}. message'
    )




  def 						_lowercase					(			self				:     Optional[Any]       ) -> Union[str, Any]:
    with self.assertWarns(_a       ) as warning:
      deprecate(
          ('deprecated_arg_1', self.higher_version, 'Hey')      ,     ('deprecated_arg_2', self.higher_version, 'Hey')      ,     )
    assert (
        str(warning.warnings[0].message       )
        == f'`deprecated_arg_1` is deprecated and will be removed in version {self.higher_version}. Hey'
    )
    assert (
        str(warning.warnings[1].message       )
        == f'`deprecated_arg_2` is deprecated and will be removed in version {self.higher_version}. Hey'
    )




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






    class  lowerCamelCase_   :
      """simple docstring"""




      a_							 =5

    with self.assertWarns(_a       ) as warning:
      __lowerCamelCase	:	int   	=			deprecate(('arg', self.higher_version, 'message')      ,     take_from=Args()       )

    assert arg == 5
    assert (
        str(warning.warning       )
        == f'The `arg` attribute is deprecated and will be removed in version {self.higher_version}. message'
    )




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






    class  lowerCamelCase_   :
      """simple docstring"""




      a_							 =5
      a_							 =7

    with self.assertWarns(_a       ) as warning:
      __lowerCamelCase	,__lowerCamelCase	:	List[str]   	=			deprecate(
          ('arg', self.higher_version, 'message')      ,     ('foo', self.higher_version, 'message')      ,     ('does not exist', self.higher_version, 'message')      ,     take_from=Args()      ,     )

    assert arg_a == 5
    assert arg_a == 7
    assert (
        str(warning.warning       )
        == f'The `arg` attribute is deprecated and will be removed in version {self.higher_version}. message'
    )
    assert (
        str(warning.warnings[0].message       )
        == f'The `arg` attribute is deprecated and will be removed in version {self.higher_version}. message'
    )
    assert (
        str(warning.warnings[1].message       )
        == f'The `foo` attribute is deprecated and will be removed in version {self.higher_version}. message'
    )




  def 						_lowercase					(			self				:     Union[str, Any]       ) -> List[str]:
    __lowerCamelCase	:	Union[str, Any]   	=			{'deprecated_arg': 4}

    with self.assertRaises(_a       ) as error:
      deprecate(('wrong_arg', self.lower_version, 'message')      ,     take_from=_a       )

    assert (
        str(error.exception       )
        == "The deprecation tuple ('wrong_arg', '0.0.1', 'message') should be removed since diffusers' version"
        f' {__version__} is >= {self.lower_version}'
    )




  def 						_lowercase					(			self				:     Optional[int]       ) -> str:
    with self.assertWarns(_a       ) as warning:
      deprecate(('deprecated_arg', self.higher_version, 'This message is better!!!')      ,     standard_warn=_a       )

    assert str(warning.warning       ) == "This message is better!!!"




  def 						_lowercase					(			self				:     List[Any]       ) -> Union[str, Any]:
    with self.assertWarns(_a       ) as warning:
      deprecate(('deprecated_arg', self.higher_version, 'This message is better!!!')      ,     standard_warn=_a       )
    assert str(warning.warning       ) == "This message is better!!!"
    assert "diffusers/tests/others/test_utils.py" in warning.filename






