



"""simple docstring"""





from ...configuration_utils import PretrainedConfig
from ...utils import logging


__lowerCAmelCase       :					str      					=					logging.get_logger(__name__)

__lowerCAmelCase       :					Dict      					=					{
    '''caidas/swin2sr-classicalsr-x2-64''': (
        '''https://huggingface.co/caidas/swin2sr-classicalsr-x2-64/resolve/main/config.json'''
    ),
}



class    _lowerCAmelCase    (				_UpperCamelCase		):





		"""simple docstring"""






		_lowerCamelCase			  =       '''swin2sr'''

		_lowerCamelCase			  =       {
		    '''hidden_size''': '''embed_dim''',
		    '''num_attention_heads''': '''num_heads''',
		    '''num_hidden_layers''': '''num_layers''',
		}





		def __init__(					self							,    _lowercase=6_4							,    _lowercase=1							,    _lowercase=3							,    _lowercase=1_8_0							,    _lowercase=[6, 6, 6, 6, 6, 6]							,    _lowercase=[6, 6, 6, 6, 6, 6]							,    _lowercase=8							,    _lowercase=2.0							,    _lowercase=True							,    _lowercase=0.0							,    _lowercase=0.0							,    _lowercase=0.1							,    _lowercase="gelu"							,    _lowercase=False							,    _lowercase=0.02							,    _lowercase=1E-5							,    _lowercase=2							,    _lowercase=1.0							,    _lowercase="1conv"							,    _lowercase="pixelshuffle"							,    **_lowercase							,    ) ->						Optional[Any]:







								'''simple docstring'''

								super().__init__(**_UpperCAmelCase   )

								snake_case_   : List[Any]						=			image_size
								snake_case_   : int						=			patch_size
								snake_case_   : Optional[int]						=			num_channels
								snake_case_   : List[str]						=			embed_dim
								snake_case_   : List[str]						=			depths
								snake_case_   : Optional[int]						=			len(_UpperCAmelCase   )
								snake_case_   : Optional[Any]						=			num_heads
								snake_case_   : List[Any]						=			window_size
								snake_case_   : List[Any]						=			mlp_ratio
								snake_case_   : List[str]						=			qkv_bias
								snake_case_   : Dict						=			hidden_dropout_prob
								snake_case_   : Dict						=			attention_probs_dropout_prob
								snake_case_   : Optional[int]						=			drop_path_rate
								snake_case_   : str						=			hidden_act
								snake_case_   : Any						=			use_absolute_embeddings
								snake_case_   : Union[str, Any]						=			layer_norm_eps
								snake_case_   : Dict						=			initializer_range
								snake_case_   : Any						=			upscale
								snake_case_   : Union[str, Any]						=			img_range
								snake_case_   : int						=			resi_connection
								snake_case_   : Dict						=			upsampler






"""simple docstring"""





import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


__lowerCAmelCase       :					Optional[int]      					=					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       :					Optional[Any]      					=					parser.parse_args()


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

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

# to channels last
__lowerCAmelCase       :					Optional[Any]      					=					pipe.unet.to(memory_format=torch.channels_last)
__lowerCAmelCase       :					List[str]      					=					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       :					Dict      					=					pipe.safety_checker.to(memory_format=torch.channels_last)

# optimize with ipex
__lowerCAmelCase       :					Tuple      					=					torch.randn(2, 4, 64, 64)
__lowerCAmelCase       :					Any      					=					torch.rand(1) * 999
__lowerCAmelCase       :					List[str]      					=					torch.randn(2, 77, 768)
__lowerCAmelCase       :					Optional[int]      					=					(sample, timestep, encoder_hidden_status)
try:
					__lowerCAmelCase       :					List[Any]      					=					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       :					Any      					=					ipex.optimize(pipe.vae.eval(), dtype=torch.bfloataa, inplace=True)
__lowerCAmelCase       :					int      					=					ipex.optimize(pipe.text_encoder.eval(), dtype=torch.bfloataa, inplace=True)
if pipe.requires_safety_checker:
					__lowerCAmelCase       :					Union[str, Any]      					=					ipex.optimize(pipe.safety_checker.eval(), dtype=torch.bfloataa, inplace=True)

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

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

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

