



"""simple docstring"""





from typing import List, Optional

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


__lowerCAmelCase       :					Optional[int]      					=					logging.get_logger(__name__)

__lowerCAmelCase       :					str      					=					{
    '''huggingface/autoformer-tourism-monthly''': '''https://huggingface.co/huggingface/autoformer-tourism-monthly/resolve/main/config.json''',
}



class    _lowerCAmelCase    (				SCREAMING_SNAKE_CASE__		):





		"""simple docstring"""






		_lowerCamelCase			  =       '''autoformer'''
		_lowerCamelCase			  =       {
		    '''hidden_size''': '''d_model''',
		    '''num_attention_heads''': '''encoder_attention_heads''',
		    '''num_hidden_layers''': '''encoder_layers''',
		}





		def __init__(					self							,    _lowercase = None							,    _lowercase = None							,    _lowercase = "student_t"							,    _lowercase = "nll"							,    _lowercase = 1							,    _lowercase = [1, 2, 3, 4, 5, 6, 7]							,    _lowercase = True							,    _lowercase = 0							,    _lowercase = 0							,    _lowercase = 0							,    _lowercase = 0							,    _lowercase = None							,    _lowercase = None							,    _lowercase = 6_4							,    _lowercase = 2							,    _lowercase = 2							,    _lowercase = 2							,    _lowercase = 2							,    _lowercase = 3_2							,    _lowercase = 3_2							,    _lowercase = "gelu"							,    _lowercase = 0.1							,    _lowercase = 0.1							,    _lowercase = 0.1							,    _lowercase = 0.1							,    _lowercase = 0.1							,    _lowercase = 1_0_0							,    _lowercase = 0.02							,    _lowercase = True							,    _lowercase=True							,    _lowercase = 1_0							,    _lowercase = 2_5							,    _lowercase = 3							,    **_lowercase							,    ) ->						Optional[Any]:







								'''simple docstring'''

								snake_case_   : Tuple						=			prediction_length
								snake_case_   : Tuple						=			context_length if context_length is not None else prediction_length
								snake_case_   : Optional[int]						=			distribution_output
								snake_case_   : List[str]						=			loss
								snake_case_   : Dict						=			input_size
								snake_case_   : str						=			num_time_features
								snake_case_   : Union[str, Any]						=			lags_sequence
								snake_case_   : Union[str, Any]						=			scaling
								snake_case_   : str						=			num_dynamic_real_features
								snake_case_   : List[Any]						=			num_static_real_features
								snake_case_   : str						=			num_static_categorical_features
								if cardinality is not None and num_static_categorical_features > 0:
														if len(_lowercase   ) != num_static_categorical_features:
																				raise ValueError(
																				    """The cardinality should be a list of the same length as `num_static_categorical_features`"""   )
														snake_case_   : Optional[Any]						=			cardinality
								else:
														snake_case_   : Tuple						=			[0]
								if embedding_dimension is not None and num_static_categorical_features > 0:
														if len(_lowercase   ) != num_static_categorical_features:
																				raise ValueError(
																				    """The embedding dimension should be a list of the same length as `num_static_categorical_features`"""   )
														snake_case_   : Optional[int]						=			embedding_dimension
								else:
														snake_case_   : str						=			[min(5_0							,    (cat + 1) // 2   ) for cat in self.cardinality]
								snake_case_   : str						=			num_parallel_samples

								# Transformer architecture configuration
								snake_case_   : List[str]						=			input_size * len(self.lags_sequence   ) + self._number_of_features
								snake_case_   : Any						=			d_model
								snake_case_   : Optional[Any]						=			encoder_attention_heads
								snake_case_   : Optional[int]						=			decoder_attention_heads
								snake_case_   : List[Any]						=			encoder_ffn_dim
								snake_case_   : Optional[int]						=			decoder_ffn_dim
								snake_case_   : Any						=			encoder_layers
								snake_case_   : Any						=			decoder_layers

								snake_case_   : Union[str, Any]						=			dropout
								snake_case_   : List[Any]						=			attention_dropout
								snake_case_   : Dict						=			activation_dropout
								snake_case_   : str						=			encoder_layerdrop
								snake_case_   : Any						=			decoder_layerdrop

								snake_case_   : Tuple						=			activation_function
								snake_case_   : Optional[Any]						=			init_std

								snake_case_   : Optional[int]						=			use_cache

								# Autoformer
								snake_case_   : List[Any]						=			label_length
								snake_case_   : Union[str, Any]						=			moving_average
								snake_case_   : Optional[Any]						=			autocorrelation_factor

								super().__init__(is_encoder_decoder=_lowercase							,    **_lowercase   )





		@property
		def    UpperCAmelCase__							(					self   ) ->						int:







								'''simple docstring'''

								return (
								    sum(self.embedding_dimension   )
								    + self.num_dynamic_real_features
								    + self.num_time_features
								    + self.num_static_real_features
								    + self.input_size * 2  # the log1p(abs(loc)) and log(scale) features
								)






"""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''')

