




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 		UpperCamelCase__     (lowerCAmelCase__					):

    '''simple docstring'''



    lowerCamelCase_				:     Union[str, Any]     					=				"""config.json"""







    @register_to_config
    def __init__(   self					,  UpperCamelCase__=2					,  UpperCamelCase__=5					,  UpperCamelCase__=(2, 5)					,  UpperCamelCase__="for diffusion"					,  UpperCamelCase__=[1, 3]					,  )					->				Dict:
           pass




class 		UpperCamelCase__     (lowerCAmelCase__					):

    '''simple docstring'''



    lowerCamelCase_				:     int     					=				"""config.json"""







    @register_to_config
    def __init__(   self					,  UpperCamelCase__=2					,  UpperCamelCase__=5					,  UpperCamelCase__=(2, 5)					,  UpperCamelCase__="for diffusion"					,  UpperCamelCase__=[1, 3]					,  )					->				Dict:
           pass




class 		UpperCamelCase__     (lowerCAmelCase__					):

    '''simple docstring'''



    lowerCamelCase_				:     Any     					=				"""config.json"""







    @register_to_config
    def __init__(   self					,  UpperCamelCase__=2					,  UpperCamelCase__=5					,  UpperCamelCase__=(2, 5)					,  UpperCamelCase__="for diffusion"					,  UpperCamelCase__=[1, 3]					,  UpperCamelCase__=[1, 3]					,  )					->				str:
           pass




class 		UpperCamelCase__     (lowerCAmelCase__					):

    '''simple docstring'''



    lowerCamelCase_				:     int     					=				"""config.json"""







    @register_to_config
    def __init__(   self					,  UpperCamelCase__=2					,  UpperCamelCase__=5					,  UpperCamelCase__=(2, 5)					,  UpperCamelCase__="for diffusion"					,  UpperCamelCase__=[1, 5]					,  UpperCamelCase__=[5, 4]					,  )					->				int:
           pass




class 		UpperCamelCase__     (unittest.TestCase					):

    '''simple docstring'''



    def    _lowercase					(   self					)					->				List[Any]:
           with self.assertRaises(UpperCamelCase__					):
                  ConfigMixin.load_config("dummy_path"					)







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

           # init ignore private arguments
           lowerCamelCase       :				Optional[int]      			= SampleObject(_name_or_path="lalala"					)
           lowerCamelCase       :				Dict      			= 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
           lowerCamelCase       :				Tuple      			= SampleObject(c=6					)
           lowerCamelCase       :				Tuple      			= 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.
           lowerCamelCase       :				Optional[Any]      			= SampleObject(1					,  c=6					)
           lowerCamelCase       :				Union[str, Any]      			= 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					)					->				str:
           lowerCamelCase       :				Dict      			= SampleObject()
           lowerCamelCase       :				Optional[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(UpperCamelCase__					)
                  lowerCamelCase       :				Tuple      			= SampleObject.from_config(SampleObject.load_config(UpperCamelCase__					)					)
                  lowerCamelCase       :				str      			= new_obj.config

           # unfreeze configs
           lowerCamelCase       :				Optional[int]      			= dict(UpperCamelCase__					)
           lowerCamelCase       :				int      			= dict(UpperCamelCase__					)

           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					)					->				Any:
           lowerCamelCase       :				int      			= logging.get_logger("diffusers.configuration_utils"					)
           # 30 for warning
           logger.setLevel(30					)

           with CaptureLogger(UpperCamelCase__					) as cap_logger:
                  lowerCamelCase       :				List[Any]      			= 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					)					->				str:
           lowerCamelCase       :				Optional[Any]      			= logging.get_logger("diffusers.configuration_utils"					)
           # 30 for warning
           logger.setLevel(30					)

           with CaptureLogger(UpperCamelCase__					) as cap_logger:
                  lowerCamelCase       :				Union[str, Any]      			= 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					)					->				Optional[int]:
           lowerCamelCase       :				Tuple      			= logging.get_logger("diffusers.configuration_utils"					)
           # 30 for warning
           logger.setLevel(30					)

           with CaptureLogger(UpperCamelCase__					) as cap_logger:
                  lowerCamelCase       :				str      			= 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					)					->				Any:
           lowerCamelCase       :				Optional[Any]      			= logging.get_logger("diffusers.configuration_utils"					)
           # 30 for warning
           logger.setLevel(30					)

           with CaptureLogger(UpperCamelCase__					) as cap_logger:
                  lowerCamelCase       :				Optional[int]      			= 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					)					->				Any:
           lowerCamelCase       :				str      			= logging.get_logger("diffusers.configuration_utils"					)
           # 30 for warning
           logger.setLevel(30					)

           with CaptureLogger(UpperCamelCase__					) as cap_logger:
                  lowerCamelCase       :				Optional[int]      			= DDPMScheduler.from_pretrained(
                      "hf-internal-testing/tiny-stable-diffusion-torch"					,  subfolder="scheduler"					,  prediction_type="sample"					,  beta_end=8					,  )

           with CaptureLogger(UpperCamelCase__					) as cap_logger_a:
                  lowerCamelCase       :				List[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					)					->				str:
           lowerCamelCase       :				Optional[Any]      			= logging.get_logger("diffusers.configuration_utils"					)
           # 30 for warning
           logger.setLevel(30					)

           with CaptureLogger(UpperCamelCase__					) as cap_logger:
                  lowerCamelCase       :				Optional[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					)					->				str:
           # let's first save a config that should be in the form
           #    a=2,
           #    b=5,
           #    c=(2, 5),
           #    d="for diffusion",
           #    e=[1, 3],

           lowerCamelCase       :				Tuple      			= SampleObject()

           lowerCamelCase       :				Dict      			= {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(UpperCamelCase__					)

                  # now loading it with SampleObject2 should put f into `_use_default_values`
                  lowerCamelCase       :				Dict      			= SampleObjecta.from_config(UpperCamelCase__					)

                  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`
           lowerCamelCase       :				Dict      			= SampleObjecta.from_config(config.config					)
           assert new_config.f == [5, 4]

           config.config._use_default_values.pop()
           lowerCamelCase       :				Dict      			= 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]












import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig


SCREAMING_SNAKE_CASE__	:				int  =       logging.get_logger(__name__)




class 		UpperCamelCase__     (lowerCAmelCase__					):

    '''simple docstring'''



    lowerCamelCase_				:     str     					=				"""speech-encoder-decoder"""
    lowerCamelCase_				:     List[str]     					=				True







    def __init__(   self					,  **UpperCamelCase__					)					->				Dict:
           super().__init__(**UpperCamelCase__					)
           if "encoder" not in kwargs or "decoder" not in kwargs:
                  raise ValueError(
                      F'''A configuraton of type {self.model_type} cannot be instantiated because not both `encoder` and'''
                      F''' `decoder` sub-configurations are passed, but only {kwargs}'''					)

           lowerCamelCase       :				Dict      			= kwargs.pop("encoder"					)
           lowerCamelCase       :				Tuple      			= encoder_config.pop("model_type"					)
           lowerCamelCase       :				int      			= kwargs.pop("decoder"					)
           lowerCamelCase       :				List[Any]      			= decoder_config.pop("model_type"					)

           lowerCamelCase       :				str      			= AutoConfig.for_model(UpperCamelCase__					,  **UpperCamelCase__					)
           lowerCamelCase       :				str      			= AutoConfig.for_model(UpperCamelCase__					,  **UpperCamelCase__					)
           lowerCamelCase       :				Tuple      			= True







    @classmethod
    def    _lowercase					(   cls					,  UpperCamelCase__					,  UpperCamelCase__					,  **UpperCamelCase__					)					->				PretrainedConfig:
           logger.info("Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config"					)
           lowerCamelCase       :				Dict      			= True
           lowerCamelCase       :				Union[str, Any]      			= True

           return cls(encoder=encoder_config.to_dict()					,  decoder=decoder_config.to_dict()					,  **UpperCamelCase__					)







    def    _lowercase					(   self					)					->				Tuple:
           lowerCamelCase       :				Tuple      			= copy.deepcopy(self.__dict__					)
           lowerCamelCase       :				Optional[int]      			= self.encoder.to_dict()
           lowerCamelCase       :				List[str]      			= self.decoder.to_dict()
           lowerCamelCase       :				Dict      			= self.__class__.model_type
           return output






