

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_				(	snake_case__      ):
     _lowercase    :  Any          =			'config.json'


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







class 							A_				(	snake_case__      ):
     _lowercase    :  Any          =			'config.json'


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







class 							A_				(	snake_case__      ):
     _lowercase    :  Union[str, Any]          =			'config.json'


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







class 							A_				(	snake_case__      ):
     _lowercase    :  Optional[int]          =			'config.json'


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







class 							A_				(	unittest.TestCase      ):


     def 						UpperCAmelCase						(							self    :	List[str]      )							->			Dict:
      with self.assertRaises(UpperCAmelCase      ):
       ConfigMixin.load_config('dummy_path'      )


     def 						UpperCAmelCase						(							self    :	Tuple      )							->			List[str]:
      __lowerCAmelCase:     int     			=   SampleObject()
      __lowerCAmelCase:     Optional[int]     			=   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:     Any     			=   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:     Dict     			=   SampleObject(c=6      )
      __lowerCAmelCase:     Optional[Any]     			=   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:     List[str]     			=   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 						UpperCAmelCase						(							self    :	Optional[int]      )							->			int:
      __lowerCAmelCase:     List[Any]     			=   SampleObject()
      __lowerCAmelCase:     Optional[int]     			=   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:     str     			=   SampleObject.from_config(SampleObject.load_config(UpperCAmelCase      )      )
       __lowerCAmelCase:     Union[str, Any]     			=   new_obj.config

      # unfreeze configs
      __lowerCAmelCase:     Dict     			=   dict(UpperCAmelCase      )
      __lowerCAmelCase:     Union[str, Any]     			=   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 						UpperCAmelCase						(							self    :	List[Any]      )							->			Dict:
      __lowerCAmelCase:     Union[str, Any]     			=   logging.get_logger('diffusers.configuration_utils'      )
      # 30 for warning
      logger.setLevel(3_0      )

      with CaptureLogger(UpperCAmelCase      ) as cap_logger:
       __lowerCAmelCase:     Optional[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 						UpperCAmelCase						(							self    :	Dict      )							->			List[Any]:
      __lowerCAmelCase:     Union[str, Any]     			=   logging.get_logger('diffusers.configuration_utils'      )
      # 30 for warning
      logger.setLevel(3_0      )

      with CaptureLogger(UpperCAmelCase      ) as cap_logger:
       __lowerCAmelCase:     List[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 						UpperCAmelCase						(							self    :	Optional[Any]      )							->			List[str]:
      __lowerCAmelCase:     Any     			=   logging.get_logger('diffusers.configuration_utils'      )
      # 30 for warning
      logger.setLevel(3_0      )

      with CaptureLogger(UpperCAmelCase      ) as cap_logger:
       __lowerCAmelCase:     List[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 						UpperCAmelCase						(							self    :	Optional[Any]      )							->			Any:
      __lowerCAmelCase:     List[Any]     			=   logging.get_logger('diffusers.configuration_utils'      )
      # 30 for warning
      logger.setLevel(3_0      )

      with CaptureLogger(UpperCAmelCase      ) as cap_logger:
       __lowerCAmelCase:     Dict     			=   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    :	List[Any]      )							->			Tuple:
      __lowerCAmelCase:     Optional[Any]     			=   logging.get_logger('diffusers.configuration_utils'      )
      # 30 for warning
      logger.setLevel(3_0      )

      with CaptureLogger(UpperCAmelCase      ) as cap_logger:
       __lowerCAmelCase:     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[Any]     			=   DDPMScheduler.from_pretrained('google/ddpm-celebahq-256'    ,						beta_start=8_8      )

      assert ddpm.__class__ == DDPMScheduler
      assert ddpm.config.prediction_type == "sample"
      assert ddpm.config.beta_end == 8
      assert ddpm_a.config.beta_start == 8_8

      # no warning should be thrown
      assert cap_logger.out == ""
      assert cap_logger_a.out == ""


     def 						UpperCAmelCase						(							self    :	Dict      )							->			List[str]:
      __lowerCAmelCase:     Dict     			=   logging.get_logger('diffusers.configuration_utils'      )
      # 30 for warning
      logger.setLevel(3_0      )

      with CaptureLogger(UpperCAmelCase      ) as cap_logger:
       __lowerCAmelCase:     List[str]     			=   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    :	int      )							->			Dict:
      # 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:     Union[str, Any]     			=   SampleObject()

      __lowerCAmelCase:     List[Any]     			=   {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:     List[Any]     			=   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:     List[Any]     			=   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 typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_keras_nlp_available,
    is_tensorflow_text_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_a	 =     {
    '''configuration_gpt2''': ['''GPT2_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''GPT2Config''', '''GPT2OnnxConfig'''],
    '''tokenization_gpt2''': ['''GPT2Tokenizer'''],
}

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  _a	 =     ['''GPT2TokenizerFast''']

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  _a	 =     [
      '''GPT2_PRETRAINED_MODEL_ARCHIVE_LIST''',
      '''GPT2DoubleHeadsModel''',
      '''GPT2ForQuestionAnswering''',
      '''GPT2ForSequenceClassification''',
      '''GPT2ForTokenClassification''',
      '''GPT2LMHeadModel''',
      '''GPT2Model''',
      '''GPT2PreTrainedModel''',
      '''load_tf_weights_in_gpt2''',
  ]

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  _a	 =     [
      '''TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST''',
      '''TFGPT2DoubleHeadsModel''',
      '''TFGPT2ForSequenceClassification''',
      '''TFGPT2LMHeadModel''',
      '''TFGPT2MainLayer''',
      '''TFGPT2Model''',
      '''TFGPT2PreTrainedModel''',
  ]

try:
  if not is_keras_nlp_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  _a	 =     ['''TFGPT2Tokenizer''']

try:
  if not is_flax_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  _a	 =     ['''FlaxGPT2LMHeadModel''', '''FlaxGPT2Model''', '''FlaxGPT2PreTrainedModel''']

if TYPE_CHECKING:
  from .configuration_gpta import GPT2_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTaConfig, GPTaOnnxConfig
  from .tokenization_gpta import GPTaTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_gpta_fast import GPTaTokenizerFast

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_gpta import (
        GPT2_PRETRAINED_MODEL_ARCHIVE_LIST,
        GPTaDoubleHeadsModel,
        GPTaForQuestionAnswering,
        GPTaForSequenceClassification,
        GPTaForTokenClassification,
        GPTaLMHeadModel,
        GPTaModel,
        GPTaPreTrainedModel,
        load_tf_weights_in_gpta,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_gpta import (
        TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFGPTaDoubleHeadsModel,
        TFGPTaForSequenceClassification,
        TFGPTaLMHeadModel,
        TFGPTaMainLayer,
        TFGPTaModel,
        TFGPTaPreTrainedModel,
    )

  try:
    if not is_keras_nlp_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_gpta_tf import TFGPTaTokenizer

  try:
    if not is_flax_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_flax_gpta import FlaxGPTaLMHeadModel, FlaxGPTaModel, FlaxGPTaPreTrainedModel

else:
  import sys

  _a	 =     _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





