
import math




def 			_SCREAMING_SNAKE_CASE      (	)      ->					None:






							'''simple docstring'''





							__UpperCamelCase			:     Optional[Any]         =      input("Enter message: ")
							__UpperCamelCase			:     Dict         =      int(input(F'Enter key [2-{len(_lowerCamelCase) - 1}]: '))
							__UpperCamelCase			:     List[str]         =      input("Encryption/Decryption [e/d]: ")

							if mode.lower().startswith("e"):
														__UpperCamelCase			:     Optional[Any]         =      encrypt_message(_lowerCamelCase		,						_lowerCamelCase)
							elif mode.lower().startswith("d"):
														__UpperCamelCase			:     Optional[int]         =      decrypt_message(_lowerCamelCase		,						_lowerCamelCase)

							# Append pipe symbol (vertical bar) to identify spaces at the end.
							print(F'Output:\n{text + "|"}')




def 			_SCREAMING_SNAKE_CASE      (	_lowerCamelCase				:    int		,						_lowerCamelCase				:    str)      ->					str:






							'''simple docstring'''





							__UpperCamelCase			:     Dict         =      [""] * key
							for col in range(_lowerCamelCase):
														__UpperCamelCase			:     Union[str, Any]         =      col
														while pointer < len(_lowerCamelCase):
																					cipher_text[col] += message[pointer]
																					pointer += key
							return "".join(_lowerCamelCase)




def 			_SCREAMING_SNAKE_CASE      (	_lowerCamelCase				:    int		,						_lowerCamelCase				:    str)      ->					str:






							'''simple docstring'''





							__UpperCamelCase			:     List[Any]         =      math.ceil(len(_lowerCamelCase) / key)
							__UpperCamelCase			:     List[str]         =      key
							__UpperCamelCase			:     Dict         =      (num_cols * num_rows) - len(_lowerCamelCase)
							__UpperCamelCase			:     Any         =      [""] * num_cols
							__UpperCamelCase			:     Optional[int]         =      0
							__UpperCamelCase			:     Dict         =      0

							for symbol in message:
														plain_text[col] += symbol
														col += 1

														if (
														    (col == num_cols)
														    or (col == num_cols - 1)
														    and (row >= num_rows - num_shaded_boxes)
														):
																					__UpperCamelCase			:     Any         =      0
																					row += 1

							return "".join(_lowerCamelCase)


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		main()

import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


lowercase						:      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')
lowercase						:      Tuple									= parser.parse_args()


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

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

# to channels last
lowercase						:      int									= pipe.unet.to(memory_format=torch.channels_last)
lowercase						:      int									= pipe.vae.to(memory_format=torch.channels_last)
lowercase						:      Dict									= pipe.text_encoder.to(memory_format=torch.channels_last)
if pipe.requires_safety_checker:
		lowercase						:      List[str]									= pipe.safety_checker.to(memory_format=torch.channels_last)

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

# compute
lowercase						:      Any									= 666
lowercase						:      int									= torch.Generator(device).manual_seed(seed)
lowercase						:      List[str]									= {'generator': generator}
if args.steps is not None:
		lowercase						:      List[str]									= args.steps

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

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