'''simple docstring'''




import argparse
import json
import os
import sys
import tempfile
import unittest
from argparse import Namespace
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional

import yaml

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import make_choice_type_function, string_to_bool


# Since Python 3.10, we can use the builtin `|` operator for Union types
# See PEP 604: https://peps.python.org/pep-0604
__lowercase          =  sys.version_info >= (3, 1_0)






def 				snake_case__							(			_A:					Any=None      ,   _A:					Optional[int]=None )    ->	int:

		'''simple docstring'''


		return field(default_factory=lambda: default      ,   metadata=_A )






@dataclass
class 				a__:


			'''simple docstring'''






			UpperCAmelCase_			:     int
			UpperCAmelCase_			:     float
			UpperCAmelCase_			:     str
			UpperCAmelCase_			:     bool







@dataclass
class 				a__:


			'''simple docstring'''






			UpperCAmelCase_			:     int      =       4_2
			UpperCAmelCase_			:     str      =       field(default='''toto''' ,						metadata={'''help''': '''help message'''}	)







@dataclass
class 				a__:


			'''simple docstring'''






			UpperCAmelCase_			:     bool      =       False
			UpperCAmelCase_			:     bool      =       True
			UpperCAmelCase_			:     Optional[bool]      =       None







class 				a__(					lowerCAmelCase__	):


			'''simple docstring'''






			UpperCAmelCase_			:     str      =       '''titi'''
			UpperCAmelCase_			:     Union[str, Any]      =       '''toto'''







class 				a__(					lowerCAmelCase__	):


			'''simple docstring'''






			UpperCAmelCase_			:     Optional[int]      =       '''titi'''
			UpperCAmelCase_			:     List[str]      =       '''toto'''
			UpperCAmelCase_			:     Dict      =       4_2







@dataclass
class 				a__:


			'''simple docstring'''






			UpperCAmelCase_			:     BasicEnum      =       "toto"



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  BasicEnum(self.foo)







@dataclass
class 				a__:


			'''simple docstring'''






			UpperCAmelCase_			:     MixedTypeEnum      =       "toto"



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  MixedTypeEnum(self.foo)







@dataclass
class 				a__:


			'''simple docstring'''






			UpperCAmelCase_			:     Optional[int]      =       None
			UpperCAmelCase_			:     Optional[float]      =       field(default=lowerCAmelCase__ ,						metadata={'''help''': '''help message'''}	)
			UpperCAmelCase_			:     Optional[str]      =       None
			UpperCAmelCase_			:     Optional[List[str]]      =       list_field(default=[]	)
			UpperCAmelCase_			:     Optional[List[int]]      =       list_field(default=[]	)







@dataclass
class 				a__:


			'''simple docstring'''






			UpperCAmelCase_			:     List[int]      =       list_field(default=[]	)
			UpperCAmelCase_			:     List[int]      =       list_field(default=[1, 2, 3]	)
			UpperCAmelCase_			:     List[str]      =       list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']	)
			UpperCAmelCase_			:     List[float]      =       list_field(default=[0.1, 0.2, 0.3]	)







@dataclass
class 				a__:


			'''simple docstring'''






			UpperCAmelCase_			:     List[int]      =       field()
			UpperCAmelCase_			:     str      =       field()
			UpperCAmelCase_			:     BasicEnum      =       field()



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  BasicEnum(self.required_enum)







@dataclass
class 				a__:


			'''simple docstring'''






			UpperCAmelCase_			:     int
			UpperCAmelCase_			:     "BasicEnum"      =       field()
			UpperCAmelCase_			:     "Optional[bool]"      =       None
			UpperCAmelCase_			:     "str"      =       field(default='''toto''' ,						metadata={'''help''': '''help message'''}	)
			UpperCAmelCase_			:     "List[str]"      =       list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']	)


if is_python_no_less_than_3_10:






						@dataclass
						class 				a__:


									'''simple docstring'''






									UpperCAmelCase_			:     bool      =       False
									UpperCAmelCase_			:     bool      =       True
									UpperCAmelCase_			:     bool | None      =       None







						@dataclass
						class 				a__:


									'''simple docstring'''






									UpperCAmelCase_			:     int | None      =       None
									UpperCAmelCase_			:     float | None      =       field(default=lowerCAmelCase__ ,						metadata={'''help''': '''help message'''}	)
									UpperCAmelCase_			:     str | None      =       None
									UpperCAmelCase_			:     list[str] | None      =       list_field(default=[]	)
									UpperCAmelCase_			:     list[int] | None      =       list_field(default=[]	)






class 				a__(					unittest.TestCase	):


			'''simple docstring'''






			def 							a_       (   self       ,    __lowerCAmelCase       ,    __lowerCAmelCase):




					"""simple docstring"""


					self.assertEqual(len(a._actions)       ,    len(b._actions))
					for x, y in zip(a._actions       ,    b._actions):
							lowerCAmelCase   					=  {k: v for k, v in vars(__lowerCAmelCase).items() if k != """container"""}
							lowerCAmelCase   					=  {k: v for k, v in vars(__lowerCAmelCase).items() if k != """container"""}

							# Choices with mixed type have custom function as "type"
							# So we need to compare results directly for equality
							if xx.get("""choices"""       ,    __lowerCAmelCase) and yy.get("""choices"""       ,    __lowerCAmelCase):
									for expected_choice in yy["choices"] + xx["choices"]:
											self.assertEqual(xx["""type"""](__lowerCAmelCase)       ,    yy["""type"""](__lowerCAmelCase))
									del xx["type"], yy["type"]

							self.assertEqual(__lowerCAmelCase       ,    __lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  HfArgumentParser(__lowerCAmelCase)

					lowerCAmelCase   					=  argparse.ArgumentParser()
					expected.add_argument("""--foo"""       ,    type=__lowerCAmelCase       ,    required=__lowerCAmelCase)
					expected.add_argument("""--bar"""       ,    type=__lowerCAmelCase       ,    required=__lowerCAmelCase)
					expected.add_argument("""--baz"""       ,    type=__lowerCAmelCase       ,    required=__lowerCAmelCase)
					expected.add_argument("""--flag"""       ,    type=__lowerCAmelCase       ,    default=__lowerCAmelCase       ,    const=__lowerCAmelCase       ,    nargs="""?""")
					self.argparsersEqual(__lowerCAmelCase       ,    __lowerCAmelCase)

					lowerCAmelCase   					=  ["""--foo""", """1""", """--baz""", """quux""", """--bar""", """0.5"""]
					((lowerCAmelCase)					,     )   					=  parser.parse_args_into_dataclasses(__lowerCAmelCase       ,    look_for_args_file=__lowerCAmelCase)
					self.assertFalse(example.flag)



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  HfArgumentParser(__lowerCAmelCase)

					lowerCAmelCase   					=  argparse.ArgumentParser()
					expected.add_argument("""--foo"""       ,    default=42       ,    type=__lowerCAmelCase)
					expected.add_argument("""--baz"""       ,    default="""toto"""       ,    type=__lowerCAmelCase       ,    help="""help message""")
					self.argparsersEqual(__lowerCAmelCase       ,    __lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  argparse.ArgumentParser()
					expected.add_argument("""--foo"""       ,    type=__lowerCAmelCase       ,    default=__lowerCAmelCase       ,    const=__lowerCAmelCase       ,    nargs="""?""")
					expected.add_argument("""--baz"""       ,    type=__lowerCAmelCase       ,    default=__lowerCAmelCase       ,    const=__lowerCAmelCase       ,    nargs="""?""")
					# A boolean no_* argument always has to come after its "default: True" regular counter-part
					# and its default must be set to False
					expected.add_argument("""--no_baz"""       ,    action="""store_false"""       ,    default=__lowerCAmelCase       ,    dest="""baz""")
					expected.add_argument("""--opt"""       ,    type=__lowerCAmelCase       ,    default=__lowerCAmelCase)

					lowerCAmelCase   					=  [WithDefaultBoolExample]
					if is_python_no_less_than_3_10:
							dataclass_types.append(__lowerCAmelCase)

					for dataclass_type in dataclass_types:
							lowerCAmelCase   					=  HfArgumentParser(__lowerCAmelCase)
							self.argparsersEqual(__lowerCAmelCase       ,    __lowerCAmelCase)

							lowerCAmelCase   					=  parser.parse_args([])
							self.assertEqual(__lowerCAmelCase       ,    Namespace(foo=__lowerCAmelCase       ,    baz=__lowerCAmelCase       ,    opt=__lowerCAmelCase))

							lowerCAmelCase   					=  parser.parse_args(["""--foo""", """--no_baz"""])
							self.assertEqual(__lowerCAmelCase       ,    Namespace(foo=__lowerCAmelCase       ,    baz=__lowerCAmelCase       ,    opt=__lowerCAmelCase))

							lowerCAmelCase   					=  parser.parse_args(["""--foo""", """--baz"""])
							self.assertEqual(__lowerCAmelCase       ,    Namespace(foo=__lowerCAmelCase       ,    baz=__lowerCAmelCase       ,    opt=__lowerCAmelCase))

							lowerCAmelCase   					=  parser.parse_args(["""--foo""", """True""", """--baz""", """True""", """--opt""", """True"""])
							self.assertEqual(__lowerCAmelCase       ,    Namespace(foo=__lowerCAmelCase       ,    baz=__lowerCAmelCase       ,    opt=__lowerCAmelCase))

							lowerCAmelCase   					=  parser.parse_args(["""--foo""", """False""", """--baz""", """False""", """--opt""", """False"""])
							self.assertEqual(__lowerCAmelCase       ,    Namespace(foo=__lowerCAmelCase       ,    baz=__lowerCAmelCase       ,    opt=__lowerCAmelCase))



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  HfArgumentParser(__lowerCAmelCase)

					lowerCAmelCase   					=  argparse.ArgumentParser()
					expected.add_argument(
					    """--foo"""       ,    default="""toto"""       ,    choices=["""titi""", """toto""", 42]       ,    type=make_choice_type_function(["""titi""", """toto""", 42])       ,    )
					self.argparsersEqual(__lowerCAmelCase       ,    __lowerCAmelCase)

					lowerCAmelCase   					=  parser.parse_args([])
					self.assertEqual(args.foo       ,    """toto""")
					lowerCAmelCase   					=  parser.parse_args_into_dataclasses([])[0]
					self.assertEqual(enum_ex.foo       ,    MixedTypeEnum.toto)

					lowerCAmelCase   					=  parser.parse_args(["""--foo""", """titi"""])
					self.assertEqual(args.foo       ,    """titi""")
					lowerCAmelCase   					=  parser.parse_args_into_dataclasses(["""--foo""", """titi"""])[0]
					self.assertEqual(enum_ex.foo       ,    MixedTypeEnum.titi)

					lowerCAmelCase   					=  parser.parse_args(["""--foo""", """42"""])
					self.assertEqual(args.foo       ,    42)
					lowerCAmelCase   					=  parser.parse_args_into_dataclasses(["""--foo""", """42"""])[0]
					self.assertEqual(enum_ex.foo       ,    MixedTypeEnum.fourtytwo)



			def 							a_       (   self):




					"""simple docstring"""


					@dataclass
					class 				a__:


								'''simple docstring'''






								UpperCAmelCase_			:     Literal["titi", "toto", 4_2]      =       "toto"







					lowerCAmelCase   					=  HfArgumentParser(__lowerCAmelCase)

					lowerCAmelCase   					=  argparse.ArgumentParser()
					expected.add_argument(
					    """--foo"""       ,    default="""toto"""       ,    choices=("""titi""", """toto""", 42)       ,    type=make_choice_type_function(["""titi""", """toto""", 42])       ,    )
					self.argparsersEqual(__lowerCAmelCase       ,    __lowerCAmelCase)

					lowerCAmelCase   					=  parser.parse_args([])
					self.assertEqual(args.foo       ,    """toto""")

					lowerCAmelCase   					=  parser.parse_args(["""--foo""", """titi"""])
					self.assertEqual(args.foo       ,    """titi""")

					lowerCAmelCase   					=  parser.parse_args(["""--foo""", """42"""])
					self.assertEqual(args.foo       ,    42)



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  HfArgumentParser(__lowerCAmelCase)

					lowerCAmelCase   					=  argparse.ArgumentParser()
					expected.add_argument("""--foo_int"""       ,    nargs="""+"""       ,    default=[]       ,    type=__lowerCAmelCase)
					expected.add_argument("""--bar_int"""       ,    nargs="""+"""       ,    default=[1, 2, 3]       ,    type=__lowerCAmelCase)
					expected.add_argument("""--foo_str"""       ,    nargs="""+"""       ,    default=["""Hallo""", """Bonjour""", """Hello"""]       ,    type=__lowerCAmelCase)
					expected.add_argument("""--foo_float"""       ,    nargs="""+"""       ,    default=[0.1, 0.2, 0.3]       ,    type=__lowerCAmelCase)

					self.argparsersEqual(__lowerCAmelCase       ,    __lowerCAmelCase)

					lowerCAmelCase   					=  parser.parse_args([])
					self.assertEqual(
					    __lowerCAmelCase       ,    Namespace(foo_int=[]       ,    bar_int=[1, 2, 3]       ,    foo_str=["""Hallo""", """Bonjour""", """Hello"""]       ,    foo_float=[0.1, 0.2, 0.3])       ,    )

					lowerCAmelCase   					=  parser.parse_args("""--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7""".split())
					self.assertEqual(__lowerCAmelCase       ,    Namespace(foo_int=[1]       ,    bar_int=[2, 3]       ,    foo_str=["""a""", """b""", """c"""]       ,    foo_float=[0.1, 0.7]))



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  argparse.ArgumentParser()
					expected.add_argument("""--foo"""       ,    default=__lowerCAmelCase       ,    type=__lowerCAmelCase)
					expected.add_argument("""--bar"""       ,    default=__lowerCAmelCase       ,    type=__lowerCAmelCase       ,    help="""help message""")
					expected.add_argument("""--baz"""       ,    default=__lowerCAmelCase       ,    type=__lowerCAmelCase)
					expected.add_argument("""--ces"""       ,    nargs="""+"""       ,    default=[]       ,    type=__lowerCAmelCase)
					expected.add_argument("""--des"""       ,    nargs="""+"""       ,    default=[]       ,    type=__lowerCAmelCase)

					lowerCAmelCase   					=  [OptionalExample]
					if is_python_no_less_than_3_10:
							dataclass_types.append(__lowerCAmelCase)

					for dataclass_type in dataclass_types:
							lowerCAmelCase   					=  HfArgumentParser(__lowerCAmelCase)

							self.argparsersEqual(__lowerCAmelCase       ,    __lowerCAmelCase)

							lowerCAmelCase   					=  parser.parse_args([])
							self.assertEqual(__lowerCAmelCase       ,    Namespace(foo=__lowerCAmelCase       ,    bar=__lowerCAmelCase       ,    baz=__lowerCAmelCase       ,    ces=[]       ,    des=[]))

							lowerCAmelCase   					=  parser.parse_args("""--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3""".split())
							self.assertEqual(__lowerCAmelCase       ,    Namespace(foo=12       ,    bar=3.14       ,    baz="""42"""       ,    ces=["""a""", """b""", """c"""]       ,    des=[1, 2, 3]))



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  HfArgumentParser(__lowerCAmelCase)

					lowerCAmelCase   					=  argparse.ArgumentParser()
					expected.add_argument("""--required_list"""       ,    nargs="""+"""       ,    type=__lowerCAmelCase       ,    required=__lowerCAmelCase)
					expected.add_argument("""--required_str"""       ,    type=__lowerCAmelCase       ,    required=__lowerCAmelCase)
					expected.add_argument(
					    """--required_enum"""       ,    type=make_choice_type_function(["""titi""", """toto"""])       ,    choices=["""titi""", """toto"""]       ,    required=__lowerCAmelCase       ,    )
					self.argparsersEqual(__lowerCAmelCase       ,    __lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  HfArgumentParser(__lowerCAmelCase)

					lowerCAmelCase   					=  argparse.ArgumentParser()
					expected.add_argument("""--foo"""       ,    type=__lowerCAmelCase       ,    required=__lowerCAmelCase)
					expected.add_argument(
					    """--required_enum"""       ,    type=make_choice_type_function(["""titi""", """toto"""])       ,    choices=["""titi""", """toto"""]       ,    required=__lowerCAmelCase       ,    )
					expected.add_argument("""--opt"""       ,    type=__lowerCAmelCase       ,    default=__lowerCAmelCase)
					expected.add_argument("""--baz"""       ,    default="""toto"""       ,    type=__lowerCAmelCase       ,    help="""help message""")
					expected.add_argument("""--foo_str"""       ,    nargs="""+"""       ,    default=["""Hallo""", """Bonjour""", """Hello"""]       ,    type=__lowerCAmelCase)
					self.argparsersEqual(__lowerCAmelCase       ,    __lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  HfArgumentParser(__lowerCAmelCase)

					lowerCAmelCase   					=  {
					    """foo""": 12,
					    """bar""": 3.14,
					    """baz""": """42""",
					    """flag""": True,
					}

					lowerCAmelCase   					=  parser.parse_dict(__lowerCAmelCase)[0]
					lowerCAmelCase   					=  BasicExample(**__lowerCAmelCase)
					self.assertEqual(__lowerCAmelCase       ,    __lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  HfArgumentParser(__lowerCAmelCase)

					lowerCAmelCase   					=  {
					    """foo""": 12,
					    """bar""": 3.14,
					    """baz""": """42""",
					    """flag""": True,
					    """extra""": 42,
					}

					self.assertRaises(__lowerCAmelCase       ,    parser.parse_dict       ,    __lowerCAmelCase       ,    allow_extra_keys=__lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  HfArgumentParser(__lowerCAmelCase)

					lowerCAmelCase   					=  {
					    """foo""": 12,
					    """bar""": 3.14,
					    """baz""": """42""",
					    """flag""": True,
					}
					with tempfile.TemporaryDirectory() as tmp_dir:
							lowerCAmelCase   					=  os.path.join(__lowerCAmelCase       ,    """temp_json""")
							os.mkdir(__lowerCAmelCase)
							with open(temp_local_path + """.json"""       ,    """w+""") as f:
									json.dump(__lowerCAmelCase       ,    __lowerCAmelCase)
							lowerCAmelCase   					=  parser.parse_yaml_file(Path(temp_local_path + """.json"""))[0]

					lowerCAmelCase   					=  BasicExample(**__lowerCAmelCase)
					self.assertEqual(__lowerCAmelCase       ,    __lowerCAmelCase)



			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  HfArgumentParser(__lowerCAmelCase)

					lowerCAmelCase   					=  {
					    """foo""": 12,
					    """bar""": 3.14,
					    """baz""": """42""",
					    """flag""": True,
					}
					with tempfile.TemporaryDirectory() as tmp_dir:
							lowerCAmelCase   					=  os.path.join(__lowerCAmelCase       ,    """temp_yaml""")
							os.mkdir(__lowerCAmelCase)
							with open(temp_local_path + """.yaml"""       ,    """w+""") as f:
									yaml.dump(__lowerCAmelCase       ,    __lowerCAmelCase)
							lowerCAmelCase   					=  parser.parse_yaml_file(Path(temp_local_path + """.yaml"""))[0]
					lowerCAmelCase   					=  BasicExample(**__lowerCAmelCase)
					self.assertEqual(__lowerCAmelCase       ,    __lowerCAmelCase)







			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  HfArgumentParser(__lowerCAmelCase)
					self.assertIsNotNone(__lowerCAmelCase)





'''simple docstring'''




import unittest

import numpy as np
import torch

from diffusers import PNDMPipeline, PNDMScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()






class 				a__(					unittest.TestCase	):


			'''simple docstring'''






			@property
			def 							a_       (   self):




					"""simple docstring"""


					torch.manual_seed(0)
					lowerCAmelCase   					=  UNetaDModel(
					    block_out_channels=(32, 64)       ,    layers_per_block=2       ,    sample_size=32       ,    in_channels=3       ,    out_channels=3       ,    down_block_types=("""DownBlock2D""", """AttnDownBlock2D""")       ,    up_block_types=("""AttnUpBlock2D""", """UpBlock2D""")       ,    )
					return model







			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  self.dummy_uncond_unet
					lowerCAmelCase   					=  PNDMScheduler()

					lowerCAmelCase   					=  PNDMPipeline(unet=__lowerCAmelCase       ,    scheduler=__lowerCAmelCase)
					pndm.to(__lowerCAmelCase)
					pndm.set_progress_bar_config(disable=__lowerCAmelCase)

					lowerCAmelCase   					=  torch.manual_seed(0)
					lowerCAmelCase   					=  pndm(generator=__lowerCAmelCase       ,    num_inference_steps=20       ,    output_type="""numpy""").images

					lowerCAmelCase   					=  torch.manual_seed(0)
					lowerCAmelCase   					=  pndm(generator=__lowerCAmelCase       ,    num_inference_steps=20       ,    output_type="""numpy"""       ,    return_dict=__lowerCAmelCase)[0]

					lowerCAmelCase   					=  image[0, -3:, -3:, -1]
					lowerCAmelCase   					=  image_from_tuple[0, -3:, -3:, -1]

					assert image.shape == (1, 32, 32, 3)
					lowerCAmelCase   					=  np.array([1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0])

					assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-2
					assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1E-2







@slow
@require_torch
class 				a__(					unittest.TestCase	):


			'''simple docstring'''






			def 							a_       (   self):




					"""simple docstring"""


					lowerCAmelCase   					=  """google/ddpm-cifar10-32"""

					lowerCAmelCase   					=  UNetaDModel.from_pretrained(__lowerCAmelCase)
					lowerCAmelCase   					=  PNDMScheduler()

					lowerCAmelCase   					=  PNDMPipeline(unet=__lowerCAmelCase       ,    scheduler=__lowerCAmelCase)
					pndm.to(__lowerCAmelCase)
					pndm.set_progress_bar_config(disable=__lowerCAmelCase)
					lowerCAmelCase   					=  torch.manual_seed(0)
					lowerCAmelCase   					=  pndm(generator=__lowerCAmelCase       ,    output_type="""numpy""").images

					lowerCAmelCase   					=  image[0, -3:, -3:, -1]

					assert image.shape == (1, 32, 32, 3)
					lowerCAmelCase   					=  np.array([0.1564, 0.14645, 0.1406, 0.14715, 0.12425, 0.14045, 0.13115, 0.12175, 0.125])

					assert np.abs(image_slice.flatten() - expected_slice).max() < 1E-2




