



from ..utils import DummyObject, requires_backends



class        lowerCAmelCase__					(  metaclass=_lowerCamelCase       ):
				A_   :     Optional[Any]								=     ['flax']


				def __init__(							self      :  Tuple						, *__UpperCamelCase      :  Union[str, Any]						, **__UpperCamelCase      :  str       )		->     Dict:
											requires_backends(self						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  List[str]						, *__UpperCamelCase      :  Union[str, Any]						, **__UpperCamelCase      :  List[str]       )		->     List[str]:
											requires_backends(cls						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Optional[Any]						, *__UpperCamelCase      :  List[str]						, **__UpperCamelCase      :  Optional[Any]       )		->     Any:
											requires_backends(cls						, ['flax']       )





class        lowerCAmelCase__					(  metaclass=_lowerCamelCase       ):
				A_   :     int								=     ['flax']


				def __init__(							self      :  List[Any]						, *__UpperCamelCase      :  str						, **__UpperCamelCase      :  List[str]       )		->     int:
											requires_backends(self						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  List[Any]						, *__UpperCamelCase      :  Dict						, **__UpperCamelCase      :  List[str]       )		->     str:
											requires_backends(cls						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  int						, *__UpperCamelCase      :  Optional[int]						, **__UpperCamelCase      :  Optional[Any]       )		->     List[Any]:
											requires_backends(cls						, ['flax']       )





class        lowerCAmelCase__					(  metaclass=_lowerCamelCase       ):
				A_   :     Tuple								=     ['flax']


				def __init__(							self      :  str						, *__UpperCamelCase      :  Union[str, Any]						, **__UpperCamelCase      :  Union[str, Any]       )		->     Tuple:
											requires_backends(self						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  List[str]						, *__UpperCamelCase      :  Tuple						, **__UpperCamelCase      :  Optional[Any]       )		->     Tuple:
											requires_backends(cls						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  str						, *__UpperCamelCase      :  Any						, **__UpperCamelCase      :  str       )		->     Union[str, Any]:
											requires_backends(cls						, ['flax']       )





class        lowerCAmelCase__					(  metaclass=_lowerCamelCase       ):
				A_   :     Union[str, Any]								=     ['flax']


				def __init__(							self      :  Optional[int]						, *__UpperCamelCase      :  Any						, **__UpperCamelCase      :  Optional[Any]       )		->     Optional[int]:
											requires_backends(self						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Tuple						, *__UpperCamelCase      :  Union[str, Any]						, **__UpperCamelCase      :  Union[str, Any]       )		->     List[str]:
											requires_backends(cls						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Any						, *__UpperCamelCase      :  List[Any]						, **__UpperCamelCase      :  Dict       )		->     Union[str, Any]:
											requires_backends(cls						, ['flax']       )





class        lowerCAmelCase__					(  metaclass=_lowerCamelCase       ):
				A_   :     Optional[int]								=     ['flax']


				def __init__(							self      :  Any						, *__UpperCamelCase      :  Any						, **__UpperCamelCase      :  Optional[int]       )		->     Union[str, Any]:
											requires_backends(self						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Tuple						, *__UpperCamelCase      :  int						, **__UpperCamelCase      :  Tuple       )		->     Tuple:
											requires_backends(cls						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Optional[int]						, *__UpperCamelCase      :  str						, **__UpperCamelCase      :  Union[str, Any]       )		->     Tuple:
											requires_backends(cls						, ['flax']       )





class        lowerCAmelCase__					(  metaclass=_lowerCamelCase       ):
				A_   :     List[Any]								=     ['flax']


				def __init__(							self      :  Tuple						, *__UpperCamelCase      :  Any						, **__UpperCamelCase      :  str       )		->     Union[str, Any]:
											requires_backends(self						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Optional[int]						, *__UpperCamelCase      :  List[str]						, **__UpperCamelCase      :  Tuple       )		->     Optional[int]:
											requires_backends(cls						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Union[str, Any]						, *__UpperCamelCase      :  List[Any]						, **__UpperCamelCase      :  List[Any]       )		->     Union[str, Any]:
											requires_backends(cls						, ['flax']       )





class        lowerCAmelCase__					(  metaclass=_lowerCamelCase       ):
				A_   :     Optional[Any]								=     ['flax']


				def __init__(							self      :  str						, *__UpperCamelCase      :  Optional[Any]						, **__UpperCamelCase      :  Optional[int]       )		->     int:
											requires_backends(self						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  List[str]						, *__UpperCamelCase      :  List[str]						, **__UpperCamelCase      :  Any       )		->     str:
											requires_backends(cls						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Optional[int]						, *__UpperCamelCase      :  List[str]						, **__UpperCamelCase      :  str       )		->     Optional[Any]:
											requires_backends(cls						, ['flax']       )





class        lowerCAmelCase__					(  metaclass=_lowerCamelCase       ):
				A_   :     int								=     ['flax']


				def __init__(							self      :  Any						, *__UpperCamelCase      :  List[Any]						, **__UpperCamelCase      :  List[Any]       )		->     Dict:
											requires_backends(self						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  str						, *__UpperCamelCase      :  str						, **__UpperCamelCase      :  str       )		->     Union[str, Any]:
											requires_backends(cls						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Optional[Any]						, *__UpperCamelCase      :  Any						, **__UpperCamelCase      :  Tuple       )		->     Union[str, Any]:
											requires_backends(cls						, ['flax']       )





class        lowerCAmelCase__					(  metaclass=_lowerCamelCase       ):
				A_   :     int								=     ['flax']


				def __init__(							self      :  Dict						, *__UpperCamelCase      :  Any						, **__UpperCamelCase      :  Any       )		->     List[Any]:
											requires_backends(self						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  int						, *__UpperCamelCase      :  Tuple						, **__UpperCamelCase      :  Dict       )		->     List[str]:
											requires_backends(cls						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  List[str]						, *__UpperCamelCase      :  int						, **__UpperCamelCase      :  Union[str, Any]       )		->     Dict:
											requires_backends(cls						, ['flax']       )





class        lowerCAmelCase__					(  metaclass=_lowerCamelCase       ):
				A_   :     str								=     ['flax']


				def __init__(							self      :  Dict						, *__UpperCamelCase      :  Union[str, Any]						, **__UpperCamelCase      :  Any       )		->     Dict:
											requires_backends(self						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Dict						, *__UpperCamelCase      :  Any						, **__UpperCamelCase      :  Union[str, Any]       )		->     List[str]:
											requires_backends(cls						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Optional[Any]						, *__UpperCamelCase      :  str						, **__UpperCamelCase      :  List[str]       )		->     Optional[int]:
											requires_backends(cls						, ['flax']       )





class        lowerCAmelCase__					(  metaclass=_lowerCamelCase       ):
				A_   :     int								=     ['flax']


				def __init__(							self      :  Tuple						, *__UpperCamelCase      :  Optional[int]						, **__UpperCamelCase      :  Any       )		->     List[str]:
											requires_backends(self						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Tuple						, *__UpperCamelCase      :  str						, **__UpperCamelCase      :  List[str]       )		->     Union[str, Any]:
											requires_backends(cls						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Union[str, Any]						, *__UpperCamelCase      :  int						, **__UpperCamelCase      :  List[Any]       )		->     Optional[Any]:
											requires_backends(cls						, ['flax']       )





class        lowerCAmelCase__					(  metaclass=_lowerCamelCase       ):
				A_   :     int								=     ['flax']


				def __init__(							self      :  Tuple						, *__UpperCamelCase      :  Optional[Any]						, **__UpperCamelCase      :  Dict       )		->     Dict:
											requires_backends(self						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Union[str, Any]						, *__UpperCamelCase      :  List[str]						, **__UpperCamelCase      :  Any       )		->     Any:
											requires_backends(cls						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Optional[int]						, *__UpperCamelCase      :  Union[str, Any]						, **__UpperCamelCase      :  Union[str, Any]       )		->     List[str]:
											requires_backends(cls						, ['flax']       )





class        lowerCAmelCase__					(  metaclass=_lowerCamelCase       ):
				A_   :     List[Any]								=     ['flax']


				def __init__(							self      :  int						, *__UpperCamelCase      :  Dict						, **__UpperCamelCase      :  Dict       )		->     Union[str, Any]:
											requires_backends(self						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Tuple						, *__UpperCamelCase      :  Any						, **__UpperCamelCase      :  List[Any]       )		->     str:
											requires_backends(cls						, ['flax']       )


				@classmethod
				def __UpperCamelCase						(							cls      :  Optional[int]						, *__UpperCamelCase      :  Dict						, **__UpperCamelCase      :  int       )		->     Any:
											requires_backends(cls						, ['flax']       )






import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


_lowerCAmelCase				:   Any						       =						argparse.ArgumentParser('''Stable Diffusion script with intel optimization''', add_help=False)
parser.add_argument('''--dpm''', action='''store_true''', help='''Enable DPMSolver or not''')
parser.add_argument('''--steps''', default=None, type=int, help='''Num inference steps''')
_lowerCAmelCase				:   Tuple						       =						parser.parse_args()


_lowerCAmelCase				:   Any						       =						'''cpu'''
_lowerCAmelCase				:   Dict						       =						'''a lovely <dicoo> in red dress and hat, in the snowly and brightly night, with many brighly buildings'''

_lowerCAmelCase				:   Union[str, Any]						       =						'''path-to-your-trained-model'''
_lowerCAmelCase				:   Tuple						       =						StableDiffusionPipeline.from_pretrained(model_id)
if args.dpm:
 _lowerCAmelCase				:   List[str]						       =						DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
_lowerCAmelCase				:   List[Any]						       =						pipe.to(device)

# to channels last
_lowerCAmelCase				:   Any						       =						pipe.unet.to(memory_format=torch.channels_last)
_lowerCAmelCase				:   int						       =						pipe.vae.to(memory_format=torch.channels_last)
_lowerCAmelCase				:   Optional[Any]						       =						pipe.text_encoder.to(memory_format=torch.channels_last)
if pipe.requires_safety_checker:
 _lowerCAmelCase				:   Optional[int]						       =						pipe.safety_checker.to(memory_format=torch.channels_last)

# optimize with ipex
_lowerCAmelCase				:   Tuple						       =						torch.randn(2, 4, 64, 64)
_lowerCAmelCase				:   List[str]						       =						torch.rand(1) * 999
_lowerCAmelCase				:   List[Any]						       =						torch.randn(2, 77, 768)
_lowerCAmelCase				:   int						       =						(sample, timestep, encoder_hidden_status)
try:
 _lowerCAmelCase				:   Tuple						       =						ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True, sample_input=input_example)
except Exception:
 _lowerCAmelCase				:   Optional[Any]						       =						ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True)
_lowerCAmelCase				:   Dict						       =						ipex.optimize(pipe.vae.eval(), dtype=torch.bfloataa, inplace=True)
_lowerCAmelCase				:   Dict						       =						ipex.optimize(pipe.text_encoder.eval(), dtype=torch.bfloataa, inplace=True)
if pipe.requires_safety_checker:
 _lowerCAmelCase				:   Tuple						       =						ipex.optimize(pipe.safety_checker.eval(), dtype=torch.bfloataa, inplace=True)

# compute
_lowerCAmelCase				:   Dict						       =						666
_lowerCAmelCase				:   Tuple						       =						torch.Generator(device).manual_seed(seed)
_lowerCAmelCase				:   Tuple						       =						{'''generator''': generator}
if args.steps is not None:
 _lowerCAmelCase				:   Tuple						       =						args.steps

with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloataa):
 _lowerCAmelCase				:   int						       =						pipe(prompt, **generate_kwargs).images[0]

# save image
image.save('''generated.png''')
