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'''




 __A           = '''config.json'''







 @register_to_config
 def __init__(						self							:					Any				,      lowercase_							:					Tuple=2				,      lowercase_							:					Any=5				,      lowercase_							:					int=(2, 5)				,      lowercase_							:					List[str]="for diffusion"				,      lowercase_							:					Optional[Any]=[1, 3]				,      )		->     int:


   """simple docstring"""







   pass




class  _UpperCAmelCase       (			lowerCAmelCase   ):



 '''simple docstring'''




 __A           = '''config.json'''







 @register_to_config
 def __init__(						self							:					str				,      lowercase_							:					str=2				,      lowercase_							:					int=5				,      lowercase_							:					str=(2, 5)				,      lowercase_							:					Any="for diffusion"				,      lowercase_							:					Tuple=[1, 3]				,      )		->     Optional[int]:


   """simple docstring"""







   pass




class  _UpperCAmelCase       (			lowerCAmelCase   ):



 '''simple docstring'''




 __A           = '''config.json'''







 @register_to_config
 def __init__(						self							:					Optional[int]				,      lowercase_							:					str=2				,      lowercase_							:					str=5				,      lowercase_							:					Union[str, Any]=(2, 5)				,      lowercase_							:					Tuple="for diffusion"				,      lowercase_							:					List[str]=[1, 3]				,      lowercase_							:					Tuple=[1, 3]				,      )		->     Tuple:


   """simple docstring"""







   pass




class  _UpperCAmelCase       (			lowerCAmelCase   ):



 '''simple docstring'''




 __A           = '''config.json'''







 @register_to_config
 def __init__(						self							:					Any				,      lowercase_							:					Optional[Any]=2				,      lowercase_							:					List[Any]=5				,      lowercase_							:					List[Any]=(2, 5)				,      lowercase_							:					List[Any]="for diffusion"				,      lowercase_							:					List[str]=[1, 5]				,      lowercase_							:					Union[str, Any]=[5, 4]				,      )		->     Tuple:


   """simple docstring"""







   pass




class  _UpperCAmelCase       (			unittest.TestCase   ):



 '''simple docstring'''




 def 						__UpperCAmelCase							(						self							:					Tuple)		->     List[str]:


   """simple docstring"""







   with self.assertRaises(lowercase_):
     ConfigMixin.load_config("dummy_path")







 def 						__UpperCAmelCase							(						self							:					Dict)		->     int:


   """simple docstring"""







   _UpperCamelCase				=  SampleObject()
   _UpperCamelCase				=  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				=  SampleObject(_name_or_path="lalala")
   _UpperCamelCase				=  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				=  SampleObject(c=6)
   _UpperCamelCase				=  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				=  SampleObject(1				,      c=6)
   _UpperCamelCase				=  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 						__UpperCAmelCase							(						self							:					int)		->     Optional[int]:


   """simple docstring"""







   _UpperCamelCase				=  SampleObject()
   _UpperCamelCase				=  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(lowercase_)
     _UpperCamelCase				=  SampleObject.from_config(SampleObject.load_config(lowercase_))
     _UpperCamelCase				=  new_obj.config

   # unfreeze configs
   _UpperCamelCase				=  dict(lowercase_)
   _UpperCamelCase				=  dict(lowercase_)

   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 						__UpperCAmelCase							(						self							:					List[Any])		->     List[str]:


   """simple docstring"""







   _UpperCamelCase				=  logging.get_logger("diffusers.configuration_utils")
   # 30 for warning
   logger.setLevel(30)

   with CaptureLogger(lowercase_) as cap_logger:
     _UpperCamelCase				=  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 						__UpperCAmelCase							(						self							:					Optional[Any])		->     Any:


   """simple docstring"""







   _UpperCamelCase				=  logging.get_logger("diffusers.configuration_utils")
   # 30 for warning
   logger.setLevel(30)

   with CaptureLogger(lowercase_) as cap_logger:
     _UpperCamelCase				=  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 						__UpperCAmelCase							(						self							:					List[Any])		->     str:


   """simple docstring"""







   _UpperCamelCase				=  logging.get_logger("diffusers.configuration_utils")
   # 30 for warning
   logger.setLevel(30)

   with CaptureLogger(lowercase_) as cap_logger:
     _UpperCamelCase				=  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 						__UpperCAmelCase							(						self							:					Dict)		->     Dict:


   """simple docstring"""







   _UpperCamelCase				=  logging.get_logger("diffusers.configuration_utils")
   # 30 for warning
   logger.setLevel(30)

   with CaptureLogger(lowercase_) as cap_logger:
     _UpperCamelCase				=  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 						__UpperCAmelCase							(						self							:					Optional[int])		->     Optional[Any]:


   """simple docstring"""







   _UpperCamelCase				=  logging.get_logger("diffusers.configuration_utils")
   # 30 for warning
   logger.setLevel(30)

   with CaptureLogger(lowercase_) as cap_logger:
     _UpperCamelCase				=  DDPMScheduler.from_pretrained(
         "hf-internal-testing/tiny-stable-diffusion-torch"				,      subfolder="scheduler"				,      prediction_type="sample"				,      beta_end=8				,      )

   with CaptureLogger(lowercase_) as cap_logger_a:
     _UpperCamelCase				=  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 						__UpperCAmelCase							(						self							:					Optional[Any])		->     Optional[int]:


   """simple docstring"""







   _UpperCamelCase				=  logging.get_logger("diffusers.configuration_utils")
   # 30 for warning
   logger.setLevel(30)

   with CaptureLogger(lowercase_) as cap_logger:
     _UpperCamelCase				=  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 						__UpperCAmelCase							(						self							:					Tuple)		->     int:


   """simple docstring"""







   _UpperCamelCase				=  SampleObject()

   _UpperCamelCase				=  {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(lowercase_)

     # now loading it with SampleObject2 should put f into `_use_default_values`
     _UpperCamelCase				=  SampleObjecta.from_config(lowercase_)

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

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





from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCamelCase__   = logging.get_logger(__name__)

lowerCamelCase__   = {
    '''nghuyong/ernie-1.0-base-zh''': '''https://huggingface.co/nghuyong/ernie-1.0-base-zh/resolve/main/config.json''',
    '''nghuyong/ernie-2.0-base-en''': '''https://huggingface.co/nghuyong/ernie-2.0-base-en/resolve/main/config.json''',
    '''nghuyong/ernie-2.0-large-en''': '''https://huggingface.co/nghuyong/ernie-2.0-large-en/resolve/main/config.json''',
    '''nghuyong/ernie-3.0-base-zh''': '''https://huggingface.co/nghuyong/ernie-3.0-base-zh/resolve/main/config.json''',
    '''nghuyong/ernie-3.0-medium-zh''': '''https://huggingface.co/nghuyong/ernie-3.0-medium-zh/resolve/main/config.json''',
    '''nghuyong/ernie-3.0-mini-zh''': '''https://huggingface.co/nghuyong/ernie-3.0-mini-zh/resolve/main/config.json''',
    '''nghuyong/ernie-3.0-micro-zh''': '''https://huggingface.co/nghuyong/ernie-3.0-micro-zh/resolve/main/config.json''',
    '''nghuyong/ernie-3.0-nano-zh''': '''https://huggingface.co/nghuyong/ernie-3.0-nano-zh/resolve/main/config.json''',
    '''nghuyong/ernie-gram-zh''': '''https://huggingface.co/nghuyong/ernie-gram-zh/resolve/main/config.json''',
    '''nghuyong/ernie-health-zh''': '''https://huggingface.co/nghuyong/ernie-health-zh/resolve/main/config.json''',
}




class  _UpperCAmelCase       (			lowerCAmelCase   ):



 '''simple docstring'''




 __A           = '''ernie'''







 def __init__(						self							:					Dict				,      lowercase_							:					List[Any]=30522				,      lowercase_							:					Optional[int]=768				,      lowercase_							:					Tuple=12				,      lowercase_							:					Optional[int]=12				,      lowercase_							:					Any=3072				,      lowercase_							:					int="gelu"				,      lowercase_							:					List[Any]=0.1				,      lowercase_							:					Any=0.1				,      lowercase_							:					str=512				,      lowercase_							:					Any=2				,      lowercase_							:					Any=3				,      lowercase_							:					List[Any]=False				,      lowercase_							:					List[Any]=0.02				,      lowercase_							:					str=1e-1_2				,      lowercase_							:					int=0				,      lowercase_							:					str="absolute"				,      lowercase_							:					Dict=True				,      lowercase_							:					List[str]=None				,      **lowercase_							:					Dict				,      )		->     Union[str, Any]:


   """simple docstring"""







   super().__init__(pad_token_id=lowercase_				,      **lowercase_)

   _UpperCamelCase				=  vocab_size
   _UpperCamelCase				=  hidden_size
   _UpperCamelCase				=  num_hidden_layers
   _UpperCamelCase				=  num_attention_heads
   _UpperCamelCase				=  hidden_act
   _UpperCamelCase				=  intermediate_size
   _UpperCamelCase				=  hidden_dropout_prob
   _UpperCamelCase				=  attention_probs_dropout_prob
   _UpperCamelCase				=  max_position_embeddings
   _UpperCamelCase				=  type_vocab_size
   _UpperCamelCase				=  task_type_vocab_size
   _UpperCamelCase				=  use_task_id
   _UpperCamelCase				=  initializer_range
   _UpperCamelCase				=  layer_norm_eps
   _UpperCamelCase				=  position_embedding_type
   _UpperCamelCase				=  use_cache
   _UpperCamelCase				=  classifier_dropout




class  _UpperCAmelCase       (			lowerCAmelCase   ):



 '''simple docstring'''




 @property
 def 						__UpperCAmelCase							(						self							:					Optional[int])		->     Mapping[str, Mapping[int, str]]:


   """simple docstring"""







   if self.task == "multiple-choice":
     _UpperCamelCase				=  {0: "batch", 1: "choice", 2: "sequence"}
   else:
     _UpperCamelCase				=  {0: "batch", 1: "sequence"}
   return OrderedDict(
       [
           ("input_ids", dynamic_axis),
           ("attention_mask", dynamic_axis),
           ("token_type_ids", dynamic_axis),
           ("task_type_ids", dynamic_axis),
       ])




