
"""simple docstring"""




import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


UpperCAmelCase__ :       List[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')
UpperCAmelCase__ :       Optional[Any]       				=					parser.parse_args()


UpperCAmelCase__ :       Optional[Any]       				=					'''cpu'''
UpperCAmelCase__ :       Union[str, Any]       				=					'''a lovely <dicoo> in red dress and hat, in the snowly and brightly night, with many brighly buildings'''

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

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

# optimize with ipex
UpperCAmelCase__ :       Tuple       				=					torch.randn(2, 4, 6_4, 6_4)
UpperCAmelCase__ :       Optional[Any]       				=					torch.rand(1) * 9_9_9
UpperCAmelCase__ :       Optional[int]       				=					torch.randn(2, 7_7, 7_6_8)
UpperCAmelCase__ :       int       				=					(sample, timestep, encoder_hidden_status)
try:
					UpperCAmelCase__ :       Optional[int]       				=					ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True, sample_input=input_example)
except Exception:
					UpperCAmelCase__ :       List[Any]       				=					ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True)
UpperCAmelCase__ :       List[Any]       				=					ipex.optimize(pipe.vae.eval(), dtype=torch.bfloataa, inplace=True)
UpperCAmelCase__ :       List[Any]       				=					ipex.optimize(pipe.text_encoder.eval(), dtype=torch.bfloataa, inplace=True)
if pipe.requires_safety_checker:
					UpperCAmelCase__ :       int       				=					ipex.optimize(pipe.safety_checker.eval(), dtype=torch.bfloataa, inplace=True)

# compute
UpperCAmelCase__ :       Tuple       				=					6_6_6
UpperCAmelCase__ :       Any       				=					torch.Generator(device).manual_seed(seed)
UpperCAmelCase__ :       List[str]       				=					{'''generator''': generator}
if args.steps is not None:
					UpperCAmelCase__ :       List[str]       				=					args.steps

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

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








def 							__lowerCamelCase		(					UpperCAmelCase_		:						int					,    UpperCAmelCase_		:						int		):




      """simple docstring"""





      while b:
            a				,							a		:int									=			b, a % b
      return a
def 							__lowerCamelCase		(					UpperCAmelCase_		:						int					,    UpperCAmelCase_		:						int		):




      """simple docstring"""





      return a if b == 0 else euclidean_gcd_recursive(UpperCAmelCase_					,    a % b		)
def 							__lowerCamelCase		(					):




      """simple docstring"""





      print(F'''euclidean_gcd(3, 5) = {euclidean_gcd(3					,    5		)}'''		)
      print(F'''euclidean_gcd(5, 3) = {euclidean_gcd(5					,    3		)}'''		)
      print(F'''euclidean_gcd(1, 3) = {euclidean_gcd(1					,    3		)}'''		)
      print(F'''euclidean_gcd(3, 6) = {euclidean_gcd(3					,    6		)}'''		)
      print(F'''euclidean_gcd(6, 3) = {euclidean_gcd(6					,    3		)}'''		)

      print(F'''euclidean_gcd_recursive(3, 5) = {euclidean_gcd_recursive(3					,    5		)}'''		)
      print(F'''euclidean_gcd_recursive(5, 3) = {euclidean_gcd_recursive(5					,    3		)}'''		)
      print(F'''euclidean_gcd_recursive(1, 3) = {euclidean_gcd_recursive(1					,    3		)}'''		)
      print(F'''euclidean_gcd_recursive(3, 6) = {euclidean_gcd_recursive(3					,    6		)}'''		)
      print(F'''euclidean_gcd_recursive(6, 3) = {euclidean_gcd_recursive(6					,    3		)}'''		)


if __name__ == "__main__":
     main()





