

import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


a		=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""")
a		=parser.parse_args()


a		="""cpu"""
a		="""a lovely <dicoo> in red dress and hat, in the snowly and brightly night, with many brighly buildings"""

a		="""path-to-your-trained-model"""
a		=StableDiffusionPipeline.from_pretrained(model_id)
if args.dpm:
					a		=DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
a		=pipe.to(device)

# to channels last
a		=pipe.unet.to(memory_format=torch.channels_last)
a		=pipe.vae.to(memory_format=torch.channels_last)
a		=pipe.text_encoder.to(memory_format=torch.channels_last)
if pipe.requires_safety_checker:
					a		=pipe.safety_checker.to(memory_format=torch.channels_last)

# optimize with ipex
a		=torch.randn(2, 4, 64, 64)
a		=torch.rand(1) * 999
a		=torch.randn(2, 77, 768)
a		=(sample, timestep, encoder_hidden_status)
try:
					a		=ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True, sample_input=input_example)
except Exception:
					a		=ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True)
a		=ipex.optimize(pipe.vae.eval(), dtype=torch.bfloataa, inplace=True)
a		=ipex.optimize(pipe.text_encoder.eval(), dtype=torch.bfloataa, inplace=True)
if pipe.requires_safety_checker:
					a		=ipex.optimize(pipe.safety_checker.eval(), dtype=torch.bfloataa, inplace=True)

# compute
a		=666
a		=torch.Generator(device).manual_seed(seed)
a		={"""generator""": generator}
if args.steps is not None:
					a		=args.steps

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

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







import os
import random
import sys

from . import cryptomath_module as cryptomath
from . import rabin_miller

a		=3






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__      )  ->					int:
	print('Generating primitive root of p'      )
	while True:
		__lowerCamelCase    :    Tuple 	=			random.randrange(3     ,			lowerCamelCase__      )
		if pow(lowerCamelCase__     ,			2     ,			lowerCamelCase__      ) == 1:
			continue
		if pow(lowerCamelCase__     ,			lowerCamelCase__     ,			lowerCamelCase__      ) == 1:
			continue
		return g






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__      )  ->					tuple[tuple[int, int, int, int], tuple[int, int]]:
	print('Generating prime p...'      )
	__lowerCamelCase    :    List[str] 	=			rabin_miller.generate_large_prime(lowerCamelCase__      )  # select large prime number.
	__lowerCamelCase    :    Dict 	=			primitive_root(lowerCamelCase__      )  # one primitive root on modulo p.
	__lowerCamelCase    :    Optional[int] 	=			random.randrange(3     ,			lowerCamelCase__      )  # private_key -> have to be greater than 2 for safety.
	__lowerCamelCase    :    List[Any] 	=			cryptomath.find_mod_inverse(pow(lowerCamelCase__     ,			lowerCamelCase__     ,			lowerCamelCase__      )     ,			lowerCamelCase__      )

	__lowerCamelCase    :    int 	=			(key_size, e_a, e_a, p)
	__lowerCamelCase    :    str 	=			(key_size, d)

	return public_key, private_key






def        SCREAMING_SNAKE_CASE__	(  lowerCamelCase__     ,			lowerCamelCase__      )  ->					None:
	if os.path.exists(F"{name}_pubkey.txt"      ) or os.path.exists(F"{name}_privkey.txt"      ):
		print('\nWARNING:'      )
		print(
		    F"\"{name}_pubkey.txt\" or \"{name}_privkey.txt\" already exists. \n"
		    'Use a different name or delete these files and re-run this program.'      )
		sys.exit()

	__lowerCamelCase	,			__lowerCamelCase    :    List[Any] 	=			generate_key(lowerCamelCase__      )
	print(F"\nWriting public key to file {name}_pubkey.txt..."      )
	with open(F"{name}_pubkey.txt"     ,			'w'      ) as fo:
		fo.write(F"{public_key[0]},{public_key[1]},{public_key[2]},{public_key[3]}"      )

	print(F"Writing private key to file {name}_privkey.txt..."      )
	with open(F"{name}_privkey.txt"     ,			'w'      ) as fo:
		fo.write(F"{private_key[0]},{private_key[1]}"      )






def        SCREAMING_SNAKE_CASE__	(  )  ->					None:
	print('Making key files...'      )
	make_key_files('elgamal'     ,			2_0_4_8      )
	print('Key files generation successful'      )


if __name__ == "__main__":
					main()




