



'''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
a      						=					sys.version_info >= (3, 1_0)



def    __lowerCamelCase						(      _lowercase=None			,       _lowercase=None	)   ->    Dict:
							return field(default_factory=lambda: default			,       metadata=_lowercase	)

@dataclass
class     UpperCamelCase_				:
	lowercase    =				42
	lowercase    =				42
	lowercase    =				42
	lowercase    =				42




@dataclass
class     UpperCamelCase_				:
	lowercase    =				42
	lowercase    =				field(default='toto'   ,  metadata={'help': 'help message'}    )




@dataclass
class     UpperCamelCase_				:
	lowercase    =				False
	lowercase    =				True
	lowercase    =				None




class     UpperCamelCase_				(							__lowerCAmelCase    ):
	lowercase    =				"titi"
	lowercase    =				"toto"




class     UpperCamelCase_				(							__lowerCAmelCase    ):
	lowercase    =				"titi"
	lowercase    =				"toto"
	lowercase    =				42




@dataclass
class     UpperCamelCase_				:
	lowercase    =				"toto"





	def 				_lowercase(						self					)    ->    Any:
								UpperCAmelCase  :	List[Any]							  =	BasicEnum(self.foo					)




@dataclass
class     UpperCamelCase_				:
	lowercase    =				"toto"





	def 				_lowercase(						self					)    ->    Tuple:
								UpperCAmelCase  :	List[str]							  =	MixedTypeEnum(self.foo					)




@dataclass
class     UpperCamelCase_				:
	lowercase    =				None
	lowercase    =				field(default=__lowerCAmelCase   ,  metadata={'help': 'help message'}    )
	lowercase    =				None
	lowercase    =				list_field(default=[]    )
	lowercase    =				list_field(default=[]    )




@dataclass
class     UpperCamelCase_				:
	lowercase    =				list_field(default=[]    )
	lowercase    =				list_field(default=[1, 2, 3]    )
	lowercase    =				list_field(default=['Hallo', 'Bonjour', 'Hello']    )
	lowercase    =				list_field(default=[0.1, 0.2, 0.3]    )




@dataclass
class     UpperCamelCase_				:
	lowercase    =				field()
	lowercase    =				field()
	lowercase    =				field()





	def 				_lowercase(						self					)    ->    Optional[int]:
								UpperCAmelCase  :	Dict							  =	BasicEnum(self.required_enum					)




@dataclass
class     UpperCamelCase_				:
	lowercase    =				42
	lowercase    =				field()
	lowercase    =				None
	lowercase    =				field(default='toto'   ,  metadata={'help': 'help message'}    )
	lowercase    =				list_field(default=['Hallo', 'Bonjour', 'Hello']    )


if is_python_no_less_than_3_10:

							@dataclass
							class     UpperCamelCase_				:
								lowercase    =				False
								lowercase    =				True
								lowercase    =				None




							@dataclass
							class     UpperCamelCase_				:
								lowercase    =				None
								lowercase    =				field(default=__lowerCAmelCase   ,  metadata={'help': 'help message'}    )
								lowercase    =				None
								lowercase    =				list_field(default=[]    )
								lowercase    =				list_field(default=[]    )


class     UpperCamelCase_				(							unittest.TestCase    ):





	def 				_lowercase(						self	,	A	,	A					)    ->    Union[str, Any]:
								self.assertEqual(len(a._actions					)	,	len(b._actions					)					)
								for x, y in zip(a._actions	,	b._actions					):
															UpperCAmelCase  :	List[str]							  =	{k: v for k, v in vars(lowerCamelCase__					).items() if k != '''container'''}
															UpperCAmelCase  :	int							  =	{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 				_lowercase(						self					)    ->    Optional[int]:
								UpperCAmelCase  :	Dict							  =	HfArgumentParser(lowerCamelCase__					)

								UpperCAmelCase  :	Any							  =	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__					)

								UpperCAmelCase  :	List[Any]							  =	['''--foo''', '''1''', '''--baz''', '''quux''', '''--bar''', '''0.5''']
								(UpperCAmelCase				)  :	Tuple							  =	parser.parse_args_into_dataclasses(lowerCamelCase__	,	look_for_args_file=lowerCamelCase__					)
								self.assertFalse(example.flag					)





	def 				_lowercase(						self					)    ->    Any:
								UpperCAmelCase  :	Optional[Any]							  =	HfArgumentParser(lowerCamelCase__					)

								UpperCAmelCase  :	Optional[int]							  =	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 				_lowercase(						self					)    ->    Union[str, Any]:
								UpperCAmelCase  :	Union[str, Any]							  =	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__					)

								UpperCAmelCase  :	List[str]							  =	[WithDefaultBoolExample]
								if is_python_no_less_than_3_10:
															dataclass_types.append(lowerCamelCase__					)

								for dataclass_type in dataclass_types:
															UpperCAmelCase  :	List[str]							  =	HfArgumentParser(lowerCamelCase__					)
															self.argparsersEqual(lowerCamelCase__	,	lowerCamelCase__					)

															UpperCAmelCase  :	Tuple							  =	parser.parse_args([]					)
															self.assertEqual(lowerCamelCase__	,	Namespace(foo=lowerCamelCase__	,	baz=lowerCamelCase__	,	opt=lowerCamelCase__					)					)

															UpperCAmelCase  :	Any							  =	parser.parse_args(["""--foo""", """--no_baz"""]					)
															self.assertEqual(lowerCamelCase__	,	Namespace(foo=lowerCamelCase__	,	baz=lowerCamelCase__	,	opt=lowerCamelCase__					)					)

															UpperCAmelCase  :	Tuple							  =	parser.parse_args(["""--foo""", """--baz"""]					)
															self.assertEqual(lowerCamelCase__	,	Namespace(foo=lowerCamelCase__	,	baz=lowerCamelCase__	,	opt=lowerCamelCase__					)					)

															UpperCAmelCase  :	List[Any]							  =	parser.parse_args(["""--foo""", """True""", """--baz""", """True""", """--opt""", """True"""]					)
															self.assertEqual(lowerCamelCase__	,	Namespace(foo=lowerCamelCase__	,	baz=lowerCamelCase__	,	opt=lowerCamelCase__					)					)

															UpperCAmelCase  :	int							  =	parser.parse_args(["""--foo""", """False""", """--baz""", """False""", """--opt""", """False"""]					)
															self.assertEqual(lowerCamelCase__	,	Namespace(foo=lowerCamelCase__	,	baz=lowerCamelCase__	,	opt=lowerCamelCase__					)					)





	def 				_lowercase(						self					)    ->    Tuple:
								UpperCAmelCase  :	int							  =	HfArgumentParser(lowerCamelCase__					)

								UpperCAmelCase  :	Optional[int]							  =	argparse.ArgumentParser()
								expected.add_argument(
								    """--foo"""	,	default="""toto"""	,	choices=["""titi""", """toto""", 42]	,	type=make_choice_type_function(["""titi""", """toto""", 42]					)	,	)
								self.argparsersEqual(lowerCamelCase__	,	lowerCamelCase__					)

								UpperCAmelCase  :	Dict							  =	parser.parse_args([]					)
								self.assertEqual(args.foo	,	"""toto"""					)
								UpperCAmelCase  :	Optional[int]							  =	parser.parse_args_into_dataclasses([]					)[0]
								self.assertEqual(enum_ex.foo	,	MixedTypeEnum.toto					)

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

								UpperCAmelCase  :	int							  =	parser.parse_args(["""--foo""", """42"""]					)
								self.assertEqual(args.foo	,	42					)
								UpperCAmelCase  :	Union[str, Any]							  =	parser.parse_args_into_dataclasses(["""--foo""", """42"""]					)[0]
								self.assertEqual(enum_ex.foo	,	MixedTypeEnum.fourtytwo					)





	def 				_lowercase(						self					)    ->    Union[str, Any]:

								@dataclass
								class     UpperCamelCase_				:
									lowercase    =				"toto"




								UpperCAmelCase  :	str							  =	HfArgumentParser(lowerCamelCase__					)

								UpperCAmelCase  :	Tuple							  =	argparse.ArgumentParser()
								expected.add_argument(
								    """--foo"""	,	default="""toto"""	,	choices=("""titi""", """toto""", 42)	,	type=make_choice_type_function(["""titi""", """toto""", 42]					)	,	)
								self.argparsersEqual(lowerCamelCase__	,	lowerCamelCase__					)

								UpperCAmelCase  :	Union[str, Any]							  =	parser.parse_args([]					)
								self.assertEqual(args.foo	,	"""toto"""					)

								UpperCAmelCase  :	Optional[Any]							  =	parser.parse_args(["""--foo""", """titi"""]					)
								self.assertEqual(args.foo	,	"""titi"""					)

								UpperCAmelCase  :	List[Any]							  =	parser.parse_args(["""--foo""", """42"""]					)
								self.assertEqual(args.foo	,	42					)





	def 				_lowercase(						self					)    ->    Union[str, Any]:
								UpperCAmelCase  :	Tuple							  =	HfArgumentParser(lowerCamelCase__					)

								UpperCAmelCase  :	Any							  =	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__					)

								UpperCAmelCase  :	Optional[int]							  =	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]					)	,	)

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

								UpperCAmelCase  :	Any							  =	[OptionalExample]
								if is_python_no_less_than_3_10:
															dataclass_types.append(lowerCamelCase__					)

								for dataclass_type in dataclass_types:
															UpperCAmelCase  :	Tuple							  =	HfArgumentParser(lowerCamelCase__					)

															self.argparsersEqual(lowerCamelCase__	,	lowerCamelCase__					)

															UpperCAmelCase  :	Optional[Any]							  =	parser.parse_args([]					)
															self.assertEqual(lowerCamelCase__	,	Namespace(foo=lowerCamelCase__	,	bar=lowerCamelCase__	,	baz=lowerCamelCase__	,	ces=[]	,	des=[]					)					)

															UpperCAmelCase  :	List[str]							  =	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.1_4	,	baz="""42"""	,	ces=["""a""", """b""", """c"""]	,	des=[1, 2, 3]					)					)





	def 				_lowercase(						self					)    ->    Optional[int]:
								UpperCAmelCase  :	str							  =	HfArgumentParser(lowerCamelCase__					)

								UpperCAmelCase  :	int							  =	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 				_lowercase(						self					)    ->    Optional[int]:
								UpperCAmelCase  :	List[str]							  =	HfArgumentParser(lowerCamelCase__					)

								UpperCAmelCase  :	List[Any]							  =	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 				_lowercase(						self					)    ->    List[Any]:
								UpperCAmelCase  :	Any							  =	HfArgumentParser(lowerCamelCase__					)

								UpperCAmelCase  :	int							  =	{
								    '''foo''': 12,
								    '''bar''': 3.1_4,
								    '''baz''': '''42''',
								    '''flag''': True,
								}

								UpperCAmelCase  :	List[Any]							  =	parser.parse_dict(lowerCamelCase__					)[0]
								UpperCAmelCase  :	Union[str, Any]							  =	BasicExample(**lowerCamelCase__					)
								self.assertEqual(lowerCamelCase__	,	lowerCamelCase__					)





	def 				_lowercase(						self					)    ->    str:
								UpperCAmelCase  :	Dict							  =	HfArgumentParser(lowerCamelCase__					)

								UpperCAmelCase  :	Union[str, Any]							  =	{
								    '''foo''': 12,
								    '''bar''': 3.1_4,
								    '''baz''': '''42''',
								    '''flag''': True,
								    '''extra''': 42,
								}

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





	def 				_lowercase(						self					)    ->    Tuple:
								UpperCAmelCase  :	Optional[Any]							  =	HfArgumentParser(lowerCamelCase__					)

								UpperCAmelCase  :	Any							  =	{
								    '''foo''': 12,
								    '''bar''': 3.1_4,
								    '''baz''': '''42''',
								    '''flag''': True,
								}
								with tempfile.TemporaryDirectory() as tmp_dir:
															UpperCAmelCase  :	int							  =	os.path.join(lowerCamelCase__	,	"""temp_json"""					)
															os.mkdir(lowerCamelCase__					)
															with open(temp_local_path + """.json"""	,	"""w+"""					) as f:
																						json.dump(lowerCamelCase__	,	lowerCamelCase__					)
															UpperCAmelCase  :	Dict							  =	parser.parse_yaml_file(Path(temp_local_path + """.json"""					)					)[0]

								UpperCAmelCase  :	Optional[int]							  =	BasicExample(**lowerCamelCase__					)
								self.assertEqual(lowerCamelCase__	,	lowerCamelCase__					)





	def 				_lowercase(						self					)    ->    Any:
								UpperCAmelCase  :	Dict							  =	HfArgumentParser(lowerCamelCase__					)

								UpperCAmelCase  :	Optional[Any]							  =	{
								    '''foo''': 12,
								    '''bar''': 3.1_4,
								    '''baz''': '''42''',
								    '''flag''': True,
								}
								with tempfile.TemporaryDirectory() as tmp_dir:
															UpperCAmelCase  :	Optional[Any]							  =	os.path.join(lowerCamelCase__	,	"""temp_yaml"""					)
															os.mkdir(lowerCamelCase__					)
															with open(temp_local_path + """.yaml"""	,	"""w+"""					) as f:
																						yaml.dump(lowerCamelCase__	,	lowerCamelCase__					)
															UpperCAmelCase  :	Optional[Any]							  =	parser.parse_yaml_file(Path(temp_local_path + """.yaml"""					)					)[0]
								UpperCAmelCase  :	Union[str, Any]							  =	BasicExample(**lowerCamelCase__					)
								self.assertEqual(lowerCamelCase__	,	lowerCamelCase__					)






	def 				_lowercase(						self					)    ->    Any:
								UpperCAmelCase  :	Optional[Any]							  =	HfArgumentParser(lowerCamelCase__					)
								self.assertIsNotNone(lowerCamelCase__					)






'''simple docstring'''




import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionImageVariationPipeline
from diffusers.utils.testing_utils import load_image, require_torch_gpu, slow, torch_device


a     :    Tuple      						=					False

class     UpperCamelCase_				(							unittest.TestCase    ):
	pass




@slow
@require_torch_gpu
class     UpperCamelCase_				(							unittest.TestCase    ):





	def 				_lowercase(						self					)    ->    Optional[Any]:
								UpperCAmelCase  :	Any							  =	VersatileDiffusionImageVariationPipeline.from_pretrained("""shi-labs/versatile-diffusion"""					)
								pipe.to(A					)
								pipe.set_progress_bar_config(disable=A					)

								UpperCAmelCase  :	List[str]							  =	load_image(
								    """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"""					)
								UpperCAmelCase  :	List[Any]							  =	torch.manual_seed(0					)
								UpperCAmelCase  :	List[str]							  =	pipe(
								    image=A	,	generator=A	,	guidance_scale=7.5	,	num_inference_steps=50	,	output_type="""numpy"""	,	).images

								UpperCAmelCase  :	Tuple							  =	image[0, 253:256, 253:256, -1]

								assert image.shape == (1, 512, 512, 3)
								UpperCAmelCase  :	List[str]							  =	np.array([0.0_4_4_1, 0.0_4_6_9, 0.0_5_0_7, 0.0_5_7_5, 0.0_6_3_2, 0.0_6_5_0, 0.0_8_6_5, 0.0_9_0_9, 0.0_9_4_5]					)

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

