





'''simple docstring'''




import unittest

from diffusers.models.unet_ad_blocks import *  # noqa F403
from diffusers.utils import torch_device

from .test_unet_blocks_common import UNetBlockTesterMixin







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : Tuple           =							DownBlockaD  # noqa F405
 _lowerCamelCase  : Optional[int]           =							"""down"""




 def      lowercase	(					self       :    List[Any]    ):
      _UpperCAmelCase     							=   [-0.0_2_3_2, -0.9_8_6_9, 0.8_0_5_4, -0.0_6_3_7, -0.1_6_8_8, -1.4_2_6_4, 0.4_4_7_0, -1.3_3_9_4, 0.0_9_0_4]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : Tuple           =							ResnetDownsampleBlockaD  # noqa F405
 _lowerCamelCase  : Tuple           =							"""down"""




 def      lowercase	(					self       :    Dict    ):
      _UpperCAmelCase     							=   [0.0_7_1_0, 0.2_4_1_0, -0.7_3_2_0, -1.0_7_5_7, -1.1_3_4_3, 0.3_5_4_0, -0.0_1_3_3, -0.2_5_7_6, 0.0_9_4_8]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : Optional[int]           =							AttnDownBlockaD  # noqa F405
 _lowerCamelCase  : Optional[int]           =							"""down"""




 def      lowercase	(					self       :    Dict    ):
      _UpperCAmelCase     							=   [0.0_6_3_6, 0.8_9_6_4, -0.6_2_3_4, -1.0_1_3_1, 0.0_8_4_4, 0.4_9_3_5, 0.3_4_3_7, 0.0_9_1_1, -0.2_9_5_7]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : Optional[Any]           =							CrossAttnDownBlockaD  # noqa F405
 _lowerCamelCase  : Dict           =							"""down"""




 def      lowercase	(					self       :    List[str]    ):
      _UpperCAmelCase							,  _UpperCAmelCase     							=   super().prepare_init_args_and_inputs_for_common()
      _UpperCAmelCase     							=   3_2
      return init_dict, inputs_dict




 def      lowercase	(					self       :    List[str]    ):
      _UpperCAmelCase     							=   [0.2_2_3_8, -0.7_3_9_6, -0.2_2_5_5, -0.3_8_2_9, 0.1_9_2_5, 1.1_6_6_5, 0.0_6_0_3, -0.7_2_9_5, 0.1_9_8_3]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : str           =							SimpleCrossAttnDownBlockaD  # noqa F405
 _lowerCamelCase  : List[Any]           =							"""down"""




 @property
 def      lowercase	(					self       :    Optional[Any]    ):
      return super().get_dummy_input(include_encoder_hidden_states=snake_case_    )




 def      lowercase	(					self       :    Optional[int]    ):
      _UpperCAmelCase							,  _UpperCAmelCase     							=   super().prepare_init_args_and_inputs_for_common()
      _UpperCAmelCase     							=   3_2
      return init_dict, inputs_dict




 @unittest.skipIf(torch_device == "mps"	,			"MPS result is not consistent"    )
 def      lowercase	(					self       :    Dict    ):
      _UpperCAmelCase     							=   [0.7_9_2_1, -0.0_9_9_2, -0.1_9_6_2, -0.7_6_9_5, -0.4_2_4_2, 0.7_8_0_4, 0.4_7_3_7, 0.2_7_6_5, 0.3_3_3_8]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : Union[str, Any]           =							SkipDownBlockaD  # noqa F405
 _lowerCamelCase  : Optional[int]           =							"""down"""




 @property
 def      lowercase	(					self       :    List[str]    ):
      return super().get_dummy_input(include_skip_sample=snake_case_    )




 def      lowercase	(					self       :    int    ):
      _UpperCAmelCase     							=   [-0.0_8_4_5, -0.2_0_8_7, -0.2_4_6_5, 0.0_9_7_1, 0.1_9_0_0, -0.0_4_8_4, 0.2_6_6_4, 0.4_1_7_9, 0.5_0_6_9]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : List[str]           =							AttnSkipDownBlockaD  # noqa F405
 _lowerCamelCase  : Optional[int]           =							"""down"""




 @property
 def      lowercase	(					self       :    Any    ):
      return super().get_dummy_input(include_skip_sample=snake_case_    )




 def      lowercase	(					self       :    Any    ):
      _UpperCAmelCase     							=   [0.5_5_3_9, 0.1_6_0_9, 0.4_9_2_4, 0.0_5_3_7, -0.1_9_9_5, 0.4_0_5_0, 0.0_9_7_9, -0.2_7_2_1, -0.0_6_4_2]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : str           =							DownEncoderBlockaD  # noqa F405
 _lowerCamelCase  : Any           =							"""down"""




 @property
 def      lowercase	(					self       :    Dict    ):
      return super().get_dummy_input(include_temb=snake_case_    )




 def      lowercase	(					self       :    List[str]    ):
      _UpperCAmelCase     							=   {
          "in_channels": 3_2,
          "out_channels": 3_2,
      }
      _UpperCAmelCase     							=   self.dummy_input
      return init_dict, inputs_dict




 def      lowercase	(					self       :    List[Any]    ):
      _UpperCAmelCase     							=   [1.1_1_0_2, 0.5_3_0_2, 0.4_8_7_2, -0.0_0_2_3, -0.8_0_4_2, 0.0_4_8_3, -0.3_4_8_9, -0.5_6_3_2, 0.7_6_2_6]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : Optional[Any]           =							AttnDownEncoderBlockaD  # noqa F405
 _lowerCamelCase  : str           =							"""down"""




 @property
 def      lowercase	(					self       :    str    ):
      return super().get_dummy_input(include_temb=snake_case_    )




 def      lowercase	(					self       :    int    ):
      _UpperCAmelCase     							=   {
          "in_channels": 3_2,
          "out_channels": 3_2,
      }
      _UpperCAmelCase     							=   self.dummy_input
      return init_dict, inputs_dict




 def      lowercase	(					self       :    Tuple    ):
      _UpperCAmelCase     							=   [0.8_9_6_6, -0.1_4_8_6, 0.8_5_6_8, 0.8_1_4_1, -0.9_0_4_6, -0.1_3_4_2, -0.0_9_7_2, -0.7_4_1_7, 0.1_5_3_8]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : List[Any]           =							UNetMidBlockaD  # noqa F405
 _lowerCamelCase  : Dict           =							"""mid"""




 def      lowercase	(					self       :    List[str]    ):
      _UpperCAmelCase     							=   {
          "in_channels": 3_2,
          "temb_channels": 1_2_8,
      }
      _UpperCAmelCase     							=   self.dummy_input
      return init_dict, inputs_dict




 def      lowercase	(					self       :    List[Any]    ):
      _UpperCAmelCase     							=   [-0.1_0_6_2, 1.7_2_4_8, 0.3_4_9_4, 1.4_5_6_9, -0.0_9_1_0, -1.2_4_2_1, -0.9_9_8_4, 0.6_7_3_6, 1.0_0_2_8]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : List[Any]           =							UNetMidBlockaDCrossAttn  # noqa F405
 _lowerCamelCase  : Any           =							"""mid"""




 def      lowercase	(					self       :    Dict    ):
      _UpperCAmelCase							,  _UpperCAmelCase     							=   super().prepare_init_args_and_inputs_for_common()
      _UpperCAmelCase     							=   3_2
      return init_dict, inputs_dict




 def      lowercase	(					self       :    str    ):
      _UpperCAmelCase     							=   [0.0_1_8_7, 2.4_2_2_0, 0.4_4_8_4, 1.1_2_0_3, -0.6_1_2_1, -1.5_1_2_2, -0.8_2_7_0, 0.7_8_5_1, 1.8_3_3_5]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : Dict           =							UNetMidBlockaDSimpleCrossAttn  # noqa F405
 _lowerCamelCase  : List[Any]           =							"""mid"""




 @property
 def      lowercase	(					self       :    Tuple    ):
      return super().get_dummy_input(include_encoder_hidden_states=snake_case_    )




 def      lowercase	(					self       :    Optional[int]    ):
      _UpperCAmelCase							,  _UpperCAmelCase     							=   super().prepare_init_args_and_inputs_for_common()
      _UpperCAmelCase     							=   3_2
      return init_dict, inputs_dict




 def      lowercase	(					self       :    Dict    ):
      _UpperCAmelCase     							=   [0.7_1_4_3, 1.9_9_7_4, 0.5_4_4_8, 1.3_9_7_7, 0.1_2_8_2, -1.1_2_3_7, -1.4_2_3_8, 0.5_5_3_0, 0.8_8_8_0]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : int           =							UpBlockaD  # noqa F405
 _lowerCamelCase  : Optional[int]           =							"""up"""




 @property
 def      lowercase	(					self       :    List[str]    ):
      return super().get_dummy_input(include_res_hidden_states_tuple=snake_case_    )




 def      lowercase	(					self       :    List[str]    ):
      _UpperCAmelCase     							=   [-0.2_0_4_1, -0.4_1_6_5, -0.3_0_2_2, 0.0_0_4_1, -0.6_6_2_8, -0.7_0_5_3, 0.1_9_2_8, -0.0_3_2_5, 0.0_5_2_3]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : Any           =							ResnetUpsampleBlockaD  # noqa F405
 _lowerCamelCase  : Union[str, Any]           =							"""up"""




 @property
 def      lowercase	(					self       :    List[str]    ):
      return super().get_dummy_input(include_res_hidden_states_tuple=snake_case_    )




 def      lowercase	(					self       :    List[Any]    ):
      _UpperCAmelCase     							=   [0.2_2_8_7, 0.3_5_4_9, -0.1_3_4_6, 0.4_7_9_7, -0.1_7_1_5, -0.9_6_4_9, 0.7_3_0_5, -0.5_8_6_4, -0.6_2_4_4]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : Any           =							CrossAttnUpBlockaD  # noqa F405
 _lowerCamelCase  : Any           =							"""up"""




 @property
 def      lowercase	(					self       :    List[str]    ):
      return super().get_dummy_input(include_res_hidden_states_tuple=snake_case_    )




 def      lowercase	(					self       :    List[Any]    ):
      _UpperCAmelCase							,  _UpperCAmelCase     							=   super().prepare_init_args_and_inputs_for_common()
      _UpperCAmelCase     							=   3_2
      return init_dict, inputs_dict




 def      lowercase	(					self       :    int    ):
      _UpperCAmelCase     							=   [-0.1_4_0_3, -0.3_5_1_5, -0.0_4_2_0, -0.1_4_2_5, 0.3_1_6_7, 0.5_0_9_4, -0.2_1_8_1, 0.5_9_3_1, 0.5_5_8_2]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : Tuple           =							SimpleCrossAttnUpBlockaD  # noqa F405
 _lowerCamelCase  : Tuple           =							"""up"""




 @property
 def      lowercase	(					self       :    Any    ):
      return super().get_dummy_input(include_res_hidden_states_tuple=snake_case_	,			include_encoder_hidden_states=snake_case_    )




 def      lowercase	(					self       :    int    ):
      _UpperCAmelCase							,  _UpperCAmelCase     							=   super().prepare_init_args_and_inputs_for_common()
      _UpperCAmelCase     							=   3_2
      return init_dict, inputs_dict




 def      lowercase	(					self       :    List[str]    ):
      _UpperCAmelCase     							=   [0.2_6_4_5, 0.1_4_8_0, 0.0_9_0_9, 0.8_0_4_4, -0.9_7_5_8, -0.9_0_8_3, 0.0_9_9_4, -1.1_4_5_3, -0.7_4_0_2]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : List[str]           =							AttnUpBlockaD  # noqa F405
 _lowerCamelCase  : str           =							"""up"""




 @property
 def      lowercase	(					self       :    Optional[int]    ):
      return super().get_dummy_input(include_res_hidden_states_tuple=snake_case_    )




 @unittest.skipIf(torch_device == "mps"	,			"MPS result is not consistent"    )
 def      lowercase	(					self       :    Optional[int]    ):
      _UpperCAmelCase     							=   [0.0_9_7_9, 0.1_3_2_6, 0.0_0_2_1, 0.0_6_5_9, 0.2_2_4_9, 0.0_0_5_9, 0.1_1_3_2, 0.5_9_5_2, 0.1_0_3_3]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : Dict           =							SkipUpBlockaD  # noqa F405
 _lowerCamelCase  : Union[str, Any]           =							"""up"""




 @property
 def      lowercase	(					self       :    Tuple    ):
      return super().get_dummy_input(include_res_hidden_states_tuple=snake_case_    )




 def      lowercase	(					self       :    str    ):
      _UpperCAmelCase     							=   [-0.0_8_9_3, -0.1_2_3_4, -0.1_5_0_6, -0.0_3_3_2, 0.0_1_2_3, -0.0_2_1_1, 0.0_5_6_6, 0.0_1_4_3, 0.0_3_6_2]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : Optional[Any]           =							AttnSkipUpBlockaD  # noqa F405
 _lowerCamelCase  : int           =							"""up"""




 @property
 def      lowercase	(					self       :    List[Any]    ):
      return super().get_dummy_input(include_res_hidden_states_tuple=snake_case_    )




 def      lowercase	(					self       :    Optional[Any]    ):
      _UpperCAmelCase     							=   [0.0_3_6_1, 0.0_6_1_7, 0.2_7_8_7, -0.0_3_5_0, 0.0_3_4_2, 0.3_4_2_1, -0.0_8_4_3, 0.0_9_1_3, 0.3_0_1_5]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : Dict           =							UpDecoderBlockaD  # noqa F405
 _lowerCamelCase  : Tuple           =							"""up"""




 @property
 def      lowercase	(					self       :    Optional[Any]    ):
      return super().get_dummy_input(include_temb=snake_case_    )




 def      lowercase	(					self       :    str    ):
      _UpperCAmelCase     							=   {"in_channels": 3_2, "out_channels": 3_2}

      _UpperCAmelCase     							=   self.dummy_input
      return init_dict, inputs_dict




 def      lowercase	(					self       :    Optional[int]    ):
      _UpperCAmelCase     							=   [0.4_4_0_4, 0.1_9_9_8, -0.9_8_8_6, -0.3_3_2_0, -0.3_1_2_8, -0.7_0_3_4, -0.6_9_5_5, -0.2_3_3_8, -0.3_1_3_7]
      super().test_output(snake_case_    )







class   A_	(  lowerCAmelCase_							,						unittest.TestCase			):
 _lowerCamelCase  : Union[str, Any]           =							AttnUpDecoderBlockaD  # noqa F405
 _lowerCamelCase  : int           =							"""up"""




 @property
 def      lowercase	(					self       :    Optional[int]    ):
      return super().get_dummy_input(include_temb=snake_case_    )




 def      lowercase	(					self       :    Optional[int]    ):
      _UpperCAmelCase     							=   {"in_channels": 3_2, "out_channels": 3_2}

      _UpperCAmelCase     							=   self.dummy_input
      return init_dict, inputs_dict




 def      lowercase	(					self       :    Optional[int]    ):
      _UpperCAmelCase     							=   [0.6_7_3_8, 0.4_4_9_1, 0.1_0_5_5, 1.0_7_1_0, 0.7_3_1_6, 0.3_3_3_9, 0.3_3_5_2, 0.1_0_2_3, 0.3_5_6_8]
      super().test_output(snake_case_    )











'''simple docstring'''




import os

import pytest
import yaml

from datasets.features.features import Features, Value
from datasets.info import DatasetInfo, DatasetInfosDict
@pytest.mark.parametrize(
    "files"			,     [
        ["full:README.md", "dataset_infos.json"],
        ["empty:README.md", "dataset_infos.json"],
        ["dataset_infos.json"],
        ["full:README.md"],
    ]			,     )
def 	UpperCAmelCase_							(					__lowercase							:      Any			,     __lowercase							:      int       )		->       int:


     '''simple docstring'''



     _UpperCAmelCase     							=   tmp_path_factory.mktemp("dset_infos_dir"       )
     if "full:README.md" in files:
          with open(dataset_infos_dir / "README.md"			,     "w"       ) as f:
               f.write("---\ndataset_info:\n  dataset_size: 42\n---"       )
     if "empty:README.md" in files:
          with open(dataset_infos_dir / "README.md"			,     "w"       ) as f:
               f.write(""       )
    # we want to support dataset_infos.json for backward compatibility
     if "dataset_infos.json" in files:
          with open(dataset_infos_dir / "dataset_infos.json"			,     "w"       ) as f:
               f.write("{\"default\": {\"dataset_size\": 42}}"       )
     _UpperCAmelCase     							=   DatasetInfosDict.from_directory(__lowercase       )
     assert dataset_infos
     assert dataset_infos["default"].dataset_size == 42
@pytest.mark.parametrize(
    "dataset_info"			,     [
        DatasetInfo(),
        DatasetInfo(
            description="foo"			,     features=Features({"a": Value("int32"       )}       )			,     builder_name="builder"			,     config_name="config"			,     version="1.0.0"			,     splits=[{"name": "train"}]			,     download_size=42			,     ),
    ]			,     )
def 	UpperCAmelCase_							(					__lowercase							:      Tuple			,     __lowercase							:      DatasetInfo       )		->       Any:


     '''simple docstring'''



     _UpperCAmelCase     							=   str(__lowercase       )
     dataset_info.write_to_directory(__lowercase       )
     _UpperCAmelCase     							=   DatasetInfo.from_directory(__lowercase       )
     assert dataset_info == reloaded
     assert os.path.exists(os.path.join(__lowercase			,     "dataset_info.json"       )       )
def 	UpperCAmelCase_							(					)		->       Optional[Any]:


     '''simple docstring'''



     _UpperCAmelCase     							=   DatasetInfo(
         description="foo"			,     citation="bar"			,     homepage="https://foo.bar"			,     license="CC0"			,     features=Features({"a": Value("int32"       )}       )			,     post_processed={}			,     supervised_keys=()			,     task_templates=[]			,     builder_name="builder"			,     config_name="config"			,     version="1.0.0"			,     splits=[{"name": "train", "num_examples": 42}]			,     download_checksums={}			,     download_size=1337			,     post_processing_size=442			,     dataset_size=1234			,     size_in_bytes=1337 + 442 + 1234			,     )
     _UpperCAmelCase     							=   dataset_info._to_yaml_dict()
     assert sorted(__lowercase       ) == sorted(DatasetInfo._INCLUDED_INFO_IN_YAML       )
     for key in DatasetInfo._INCLUDED_INFO_IN_YAML:
          assert key in dataset_info_yaml_dict
          assert isinstance(dataset_info_yaml_dict[key]			,     (list, dict, int, str)       )
     _UpperCAmelCase     							=   yaml.safe_dump(__lowercase       )
     _UpperCAmelCase     							=   yaml.safe_load(__lowercase       )
     assert dataset_info_yaml_dict == reloaded
def 	UpperCAmelCase_							(					)		->       Optional[int]:


     '''simple docstring'''



     _UpperCAmelCase     							=   DatasetInfo()
     _UpperCAmelCase     							=   dataset_info._to_yaml_dict()
     assert dataset_info_yaml_dict == {}






@pytest.mark.parametrize(
    "dataset_infos_dict"			,     [
        DatasetInfosDict(),
        DatasetInfosDict({"default": DatasetInfo()}       ),
        DatasetInfosDict({"my_config_name": DatasetInfo()}       ),
        DatasetInfosDict(
            {
                "default": DatasetInfo(
                    description="foo"			,     features=Features({"a": Value("int32"       )}       )			,     builder_name="builder"			,     config_name="config"			,     version="1.0.0"			,     splits=[{"name": "train"}]			,     download_size=42			,     )
            }       ),
        DatasetInfosDict(
            {
                "v1": DatasetInfo(dataset_size=42       ),
                "v2": DatasetInfo(dataset_size=1337       ),
            }       ),
    ]			,     )
def 	UpperCAmelCase_							(					__lowercase							:      int			,     __lowercase							:      DatasetInfosDict       )		->       Dict:


     '''simple docstring'''



     _UpperCAmelCase     							=   str(__lowercase       )
     dataset_infos_dict.write_to_directory(__lowercase       )
     _UpperCAmelCase     							=   DatasetInfosDict.from_directory(__lowercase       )

     # the config_name of the dataset_infos_dict take over the attribute
     for config_name, dataset_info in dataset_infos_dict.items():
          _UpperCAmelCase     							=   config_name
          # the yaml representation doesn't include fields like description or citation
          # so we just test that we can recover what we can from the yaml
          _UpperCAmelCase     							=   DatasetInfo._from_yaml_dict(dataset_info._to_yaml_dict()       )
     assert dataset_infos_dict == reloaded

     if dataset_infos_dict:
          assert os.path.exists(os.path.join(__lowercase			,     "README.md"       )       )




