code: 
  
  
  
  import tempfile
  import unittest
  
  from diffusers import (
      DDIMScheduler,
      DDPMScheduler,
      DPMSolverMultistepScheduler,
      EulerAncestralDiscreteScheduler,
      EulerDiscreteScheduler,
      PNDMScheduler,
      logging,
  )
  from diffusers.configuration_utils import ConfigMixin, register_to_config
  from diffusers.utils.testing_utils import CaptureLogger
  
  
  
  
  
  class     __a						(					A__ ):
   _lowerCAmelCase : Optional[int] 				=				'''config.json'''
  
  
  
  
  
  
  
   @register_to_config
   def __init__(	self      :     Optional[int]							,     SCREAMING_SNAKE_CASE      :     str=2							,     SCREAMING_SNAKE_CASE      :     Any=5							,     SCREAMING_SNAKE_CASE      :     Any=(2, 5)							,     SCREAMING_SNAKE_CASE      :     int="for diffusion"							,     SCREAMING_SNAKE_CASE      :     str=[1, 3]							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        pass
  
  
  
  
  
  
  
  class     __a						(					A__ ):
   _lowerCAmelCase : List[Any] 				=				'''config.json'''
  
  
  
  
  
  
  
   @register_to_config
   def __init__(	self      :     str							,     SCREAMING_SNAKE_CASE      :     Optional[Any]=2							,     SCREAMING_SNAKE_CASE      :     Union[str, Any]=5							,     SCREAMING_SNAKE_CASE      :     Tuple=(2, 5)							,     SCREAMING_SNAKE_CASE      :     List[Any]="for diffusion"							,     SCREAMING_SNAKE_CASE      :     List[Any]=[1, 3]							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        pass
  
  
  
  
  
  
  
  class     __a						(					A__ ):
   _lowerCAmelCase : int 				=				'''config.json'''
  
  
  
  
  
  
  
   @register_to_config
   def __init__(	self      :     str							,     SCREAMING_SNAKE_CASE      :     Union[str, Any]=2							,     SCREAMING_SNAKE_CASE      :     Optional[Any]=5							,     SCREAMING_SNAKE_CASE      :     str=(2, 5)							,     SCREAMING_SNAKE_CASE      :     Dict="for diffusion"							,     SCREAMING_SNAKE_CASE      :     Tuple=[1, 3]							,     SCREAMING_SNAKE_CASE      :     Any=[1, 3]							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        pass
  
  
  
  
  
  
  
  class     __a						(					A__ ):
   _lowerCAmelCase : Optional[int] 				=				'''config.json'''
  
  
  
  
  
  
  
   @register_to_config
   def __init__(	self      :     List[Any]							,     SCREAMING_SNAKE_CASE      :     Any=2							,     SCREAMING_SNAKE_CASE      :     Optional[Any]=5							,     SCREAMING_SNAKE_CASE      :     str=(2, 5)							,     SCREAMING_SNAKE_CASE      :     Optional[int]="for diffusion"							,     SCREAMING_SNAKE_CASE      :     Any=[1, 5]							,     SCREAMING_SNAKE_CASE      :     Union[str, Any]=[5, 4]							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        pass
  
  
  
  
  
  
  
  class     __a						(					unittest.TestCase ):
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     str		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        with self.assertRaises(SCREAMING_SNAKE_CASE		):
             ConfigMixin.load_config("dummy_path"		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Tuple		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[Any]        =						SampleObject()
        UpperCamelCase__    :     Any        =						obj.config
        assert config["a"] == 2
        assert config["b"] == 5
        assert config["c"] == (2, 5)
        assert config["d"] == "for diffusion"
        assert config["e"] == [1, 3]
  
        # init ignore private arguments
        UpperCamelCase__    :     Any        =						SampleObject(_name_or_path="lalala"		)
        UpperCamelCase__    :     str        =						obj.config
        assert config["a"] == 2
        assert config["b"] == 5
        assert config["c"] == (2, 5)
        assert config["d"] == "for diffusion"
        assert config["e"] == [1, 3]
  
        # can override default
        UpperCamelCase__    :     Dict        =						SampleObject(c=6		)
        UpperCamelCase__    :     Dict        =						obj.config
        assert config["a"] == 2
        assert config["b"] == 5
        assert config["c"] == 6
        assert config["d"] == "for diffusion"
        assert config["e"] == [1, 3]
  
        # can use positional arguments.
        UpperCamelCase__    :     int        =						SampleObject(1							,     c=6		)
        UpperCamelCase__    :     Dict        =						obj.config
        assert config["a"] == 1
        assert config["b"] == 5
        assert config["c"] == 6
        assert config["d"] == "for diffusion"
        assert config["e"] == [1, 3]
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     int		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     int        =						SampleObject()
        UpperCamelCase__    :     Any        =						obj.config
  
        assert config["a"] == 2
        assert config["b"] == 5
        assert config["c"] == (2, 5)
        assert config["d"] == "for diffusion"
        assert config["e"] == [1, 3]
  
        with tempfile.TemporaryDirectory() as tmpdirname:
             obj.save_config(SCREAMING_SNAKE_CASE		)
             UpperCamelCase__    :     Union[str, Any]        =						SampleObject.from_config(SampleObject.load_config(SCREAMING_SNAKE_CASE		)		)
             UpperCamelCase__    :     Optional[int]        =						new_obj.config
  
        # unfreeze configs
        UpperCamelCase__    :     List[Any]        =						dict(SCREAMING_SNAKE_CASE		)
        UpperCamelCase__    :     Any        =						dict(SCREAMING_SNAKE_CASE		)
  
        assert config.pop("c"		) == (2, 5)  # instantiated as tuple
        assert new_config.pop("c"		) == [2, 5]  # saved & loaded as list because of json
        config.pop("_use_default_values"		)
        assert config == new_config
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Union[str, Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[Any]        =						logging.get_logger("diffusers.configuration_utils"		)
        # 30 for warning
        logger.setLevel(30		)
  
        with CaptureLogger(SCREAMING_SNAKE_CASE		) as cap_logger:
             UpperCamelCase__    :     Optional[int]        =						DDIMScheduler.from_pretrained(
                 "hf-internal-testing/tiny-stable-diffusion-torch"							,     subfolder="scheduler"		)
  
        assert ddim.__class__ == DDIMScheduler
        # no warning should be thrown
        assert cap_logger.out == ""
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Tuple		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[Any]        =						logging.get_logger("diffusers.configuration_utils"		)
        # 30 for warning
        logger.setLevel(30		)
  
        with CaptureLogger(SCREAMING_SNAKE_CASE		) as cap_logger:
             UpperCamelCase__    :     Tuple        =						EulerDiscreteScheduler.from_pretrained(
                 "hf-internal-testing/tiny-stable-diffusion-torch"							,     subfolder="scheduler"		)
  
        assert euler.__class__ == EulerDiscreteScheduler
        # no warning should be thrown
        assert cap_logger.out == ""
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Tuple		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[Any]        =						logging.get_logger("diffusers.configuration_utils"		)
        # 30 for warning
        logger.setLevel(30		)
  
        with CaptureLogger(SCREAMING_SNAKE_CASE		) as cap_logger:
             UpperCamelCase__    :     Any        =						EulerAncestralDiscreteScheduler.from_pretrained(
                 "hf-internal-testing/tiny-stable-diffusion-torch"							,     subfolder="scheduler"		)
  
        assert euler.__class__ == EulerAncestralDiscreteScheduler
        # no warning should be thrown
        assert cap_logger.out == ""
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Optional[Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Any        =						logging.get_logger("diffusers.configuration_utils"		)
        # 30 for warning
        logger.setLevel(30		)
  
        with CaptureLogger(SCREAMING_SNAKE_CASE		) as cap_logger:
             UpperCamelCase__    :     str        =						PNDMScheduler.from_pretrained(
                 "hf-internal-testing/tiny-stable-diffusion-torch"							,     subfolder="scheduler"		)
  
        assert pndm.__class__ == PNDMScheduler
        # no warning should be thrown
        assert cap_logger.out == ""
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     str		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Union[str, Any]        =						logging.get_logger("diffusers.configuration_utils"		)
        # 30 for warning
        logger.setLevel(30		)
  
        with CaptureLogger(SCREAMING_SNAKE_CASE		) as cap_logger:
             UpperCamelCase__    :     Dict        =						DDPMScheduler.from_pretrained(
                 "hf-internal-testing/tiny-stable-diffusion-torch"							,     subfolder="scheduler"							,     prediction_type="sample"							,     beta_end=8							,     )
  
        with CaptureLogger(SCREAMING_SNAKE_CASE		) as cap_logger_a:
             UpperCamelCase__    :     str        =						DDPMScheduler.from_pretrained("google/ddpm-celebahq-256"							,     beta_start=88		)
  
        assert ddpm.__class__ == DDPMScheduler
        assert ddpm.config.prediction_type == "sample"
        assert ddpm.config.beta_end == 8
        assert ddpm_a.config.beta_start == 88
  
        # no warning should be thrown
        assert cap_logger.out == ""
        assert cap_logger_a.out == ""
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Optional[Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[str]        =						logging.get_logger("diffusers.configuration_utils"		)
        # 30 for warning
        logger.setLevel(30		)
  
        with CaptureLogger(SCREAMING_SNAKE_CASE		) as cap_logger:
             UpperCamelCase__    :     int        =						DPMSolverMultistepScheduler.from_pretrained(
                 "hf-internal-testing/tiny-stable-diffusion-torch"							,     subfolder="scheduler"		)
  
        assert dpm.__class__ == DPMSolverMultistepScheduler
        # no warning should be thrown
        assert cap_logger.out == ""
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     List[str]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[str]        =						SampleObject()
  
        UpperCamelCase__    :     str        =						{k: v for k, v in config.config.items() if not k.startswith("_"		)}
  
        # make sure that default config has all keys in `_use_default_values`
        assert set(config_dict.keys()		) == set(config.config._use_default_values		)
  
        with tempfile.TemporaryDirectory() as tmpdirname:
             config.save_config(SCREAMING_SNAKE_CASE		)
  
             # now loading it with SampleObject2 should put f into `_use_default_values`
             UpperCamelCase__    :     Dict        =						SampleObjecta.from_config(SCREAMING_SNAKE_CASE		)
  
             assert "f" in config._use_default_values
             assert config.f == [1, 3]
  
        # now loading the config, should **NOT** use [1, 3] for `f`, but the default [1, 4] value
        # **BECAUSE** it is part of `config._use_default_values`
        UpperCamelCase__    :     Dict        =						SampleObjecta.from_config(config.config		)
        assert new_config.f == [5, 4]
  
        config.config._use_default_values.pop()
        UpperCamelCase__    :     Tuple        =						SampleObjecta.from_config(config.config		)
        assert new_config_a.f == [1, 3]
  
        # Nevertheless "e" should still be correctly loaded to [1, 3] from SampleObject2 instead of defaulting to [1, 5]
        assert new_config_a.e == [1, 3]
style_context: 
  
  
  
  
  
  
  import unittest
  
  from transformers import (
      MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
      TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
      PreTrainedTokenizer,
      is_vision_available,
  )
  from transformers.pipelines import ImageClassificationPipeline, pipeline
  from transformers.testing_utils import (
      is_pipeline_test,
      nested_simplify,
      require_tf,
      require_torch,
      require_torch_or_tf,
      require_vision,
      slow,
  )
  
  from .test_pipelines_common import ANY
  
  
  if is_vision_available():
   from PIL import Image
  else:
  
  
  
  
  
   class     __a						:
  
  
  
  
  
  
  
    @staticmethod
    def       __lowercase      (	*SCREAMING_SNAKE_CASE      :     Optional[Any]							,     **SCREAMING_SNAKE_CASE      :     Union[str, Any]		):
  
  
         '''simple docstring'''
  
  
  
  
  
  
         pass
  
  
  
  
  
  @is_pipeline_test
  @require_torch_or_tf
  @require_vision
  class     __a						(					unittest.TestCase ):
   _lowerCAmelCase : Tuple 				=				MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
   _lowerCAmelCase : str 				=				TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Union[str, Any]							,     SCREAMING_SNAKE_CASE      :     str							,     SCREAMING_SNAKE_CASE      :     Union[str, Any]							,     SCREAMING_SNAKE_CASE      :     Optional[Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Dict        =						ImageClassificationPipeline(model=SCREAMING_SNAKE_CASE							,     image_processor=SCREAMING_SNAKE_CASE							,     top_k=2		)
        UpperCamelCase__    :     Union[str, Any]        =						[
            Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"		),
            "http://images.cocodataset.org/val2017/000000039769.jpg",
        ]
        return image_classifier, examples
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Tuple							,     SCREAMING_SNAKE_CASE      :     Tuple							,     SCREAMING_SNAKE_CASE      :     Tuple		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[Any]        =						image_classifier("./tests/fixtures/tests_samples/COCO/000000039769.png"		)
  
        self.assertEqual(
            SCREAMING_SNAKE_CASE							,     [
                {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
            ]							,     )
  
        import datasets
  
        UpperCamelCase__    :     int        =						datasets.load_dataset("hf-internal-testing/fixtures_image_utils"							,     "image"							,     split="test"		)
  
        # Accepts URL + PIL.Image + lists
        UpperCamelCase__    :     Tuple        =						image_classifier(
            [
                Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"		),
                "http://images.cocodataset.org/val2017/000000039769.jpg",
                # RGBA
                dataset[0]["file"],
                # LA
                dataset[1]["file"],
                # L
                dataset[2]["file"],
            ]		)
        self.assertEqual(
            SCREAMING_SNAKE_CASE							,     [
                [
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                ],
                [
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                ],
                [
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                ],
                [
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                ],
                [
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                ],
            ]							,     )
  
  
  
  
  
  
  
   @require_torch
   def       __lowercase      (	self      :     List[str]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[Any]        =						"hf-internal-testing/tiny-random-vit"
        UpperCamelCase__    :     List[str]        =						pipeline("image-classification"							,     model=SCREAMING_SNAKE_CASE		)
  
        UpperCamelCase__    :     List[str]        =						image_classifier("http://images.cocodataset.org/val2017/000000039769.jpg"		)
        self.assertEqual(
            nested_simplify(SCREAMING_SNAKE_CASE							,     decimals=4		)							,     [{"label": "LABEL_1", "score": 0.5_7_4}, {"label": "LABEL_0", "score": 0.4_2_6}]							,     )
  
        UpperCamelCase__    :     Optional[Any]        =						image_classifier(
            [
                "http://images.cocodataset.org/val2017/000000039769.jpg",
                "http://images.cocodataset.org/val2017/000000039769.jpg",
            ]							,     top_k=2							,     )
        self.assertEqual(
            nested_simplify(SCREAMING_SNAKE_CASE							,     decimals=4		)							,     [
                [{"label": "LABEL_1", "score": 0.5_7_4}, {"label": "LABEL_0", "score": 0.4_2_6}],
                [{"label": "LABEL_1", "score": 0.5_7_4}, {"label": "LABEL_0", "score": 0.4_2_6}],
            ]							,     )
  
  
  
  
  
  
  
   @require_tf
   def       __lowercase      (	self      :     int		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     str        =						"hf-internal-testing/tiny-random-vit"
        UpperCamelCase__    :     int        =						pipeline("image-classification"							,     model=SCREAMING_SNAKE_CASE							,     framework="tf"		)
  
        UpperCamelCase__    :     List[Any]        =						image_classifier("http://images.cocodataset.org/val2017/000000039769.jpg"		)
        self.assertEqual(
            nested_simplify(SCREAMING_SNAKE_CASE							,     decimals=4		)							,     [{"label": "LABEL_1", "score": 0.5_7_4}, {"label": "LABEL_0", "score": 0.4_2_6}]							,     )
  
        UpperCamelCase__    :     int        =						image_classifier(
            [
                "http://images.cocodataset.org/val2017/000000039769.jpg",
                "http://images.cocodataset.org/val2017/000000039769.jpg",
            ]							,     top_k=2							,     )
        self.assertEqual(
            nested_simplify(SCREAMING_SNAKE_CASE							,     decimals=4		)							,     [
                [{"label": "LABEL_1", "score": 0.5_7_4}, {"label": "LABEL_0", "score": 0.4_2_6}],
                [{"label": "LABEL_1", "score": 0.5_7_4}, {"label": "LABEL_0", "score": 0.4_2_6}],
            ]							,     )
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Optional[int]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Any        =						PreTrainedTokenizer()
  
        # Assert that the pipeline can be initialized with a feature extractor that is not in any mapping
        UpperCamelCase__    :     str        =						pipeline(
            "image-classification"							,     model="hf-internal-testing/tiny-random-vit"							,     tokenizer=SCREAMING_SNAKE_CASE		)
  
        self.assertIs(image_classifier.tokenizer							,     SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   @slow
   @require_torch
   def       __lowercase      (	self      :     int		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[Any]        =						pipeline("image-classification"							,     model="deepmind/vision-perceiver-conv"		)
        UpperCamelCase__    :     Any        =						image_classifier("http://images.cocodataset.org/val2017/000000039769.jpg"		)
        self.assertEqual(
            nested_simplify(SCREAMING_SNAKE_CASE							,     decimals=4		)							,     [
                {"score": 0.4_3_8_5, "label": "tabby, tabby cat"},
                {"score": 0.3_2_1, "label": "tiger cat"},
                {"score": 0.0_5_0_2, "label": "Egyptian cat"},
                {"score": 0.0_1_3_7, "label": "crib, cot"},
                {"score": 0.0_0_7, "label": "radiator"},
            ]							,     )
  
        UpperCamelCase__    :     Optional[Any]        =						pipeline("image-classification"							,     model="deepmind/vision-perceiver-fourier"		)
        UpperCamelCase__    :     List[str]        =						image_classifier("http://images.cocodataset.org/val2017/000000039769.jpg"		)
        self.assertEqual(
            nested_simplify(SCREAMING_SNAKE_CASE							,     decimals=4		)							,     [
                {"score": 0.5_6_5_8, "label": "tabby, tabby cat"},
                {"score": 0.1_3_0_9, "label": "tiger cat"},
                {"score": 0.0_7_2_2, "label": "Egyptian cat"},
                {"score": 0.0_7_0_7, "label": "remote control, remote"},
                {"score": 0.0_0_8_2, "label": "computer keyboard, keypad"},
            ]							,     )
  
        UpperCamelCase__    :     List[str]        =						pipeline("image-classification"							,     model="deepmind/vision-perceiver-learned"		)
        UpperCamelCase__    :     Optional[int]        =						image_classifier("http://images.cocodataset.org/val2017/000000039769.jpg"		)
        self.assertEqual(
            nested_simplify(SCREAMING_SNAKE_CASE							,     decimals=4		)							,     [
                {"score": 0.3_0_2_2, "label": "tabby, tabby cat"},
                {"score": 0.2_3_6_2, "label": "Egyptian cat"},
                {"score": 0.1_8_5_6, "label": "tiger cat"},
                {"score": 0.0_3_2_4, "label": "remote control, remote"},
                {"score": 0.0_0_9_6, "label": "quilt, comforter, comfort, puff"},
            ]							,     )