
'''simple docstring'''




from typing import List, Optional, Union

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


lowercase			:				Tuple    		=			logging.get_logger(__name__)

lowercase			:				Union[str, Any]    		=			{
    'huggingface/informer-tourism-monthly': (
        'https://huggingface.co/huggingface/informer-tourism-monthly/resolve/main/config.json'
    ),
    # See all Informer models at https://huggingface.co/models?filter=informer
}





class  A				(							__snake_case						):
     __magic_name__						=		'''informer'''
     __magic_name__						=		{
         '''hidden_size''': '''d_model''',
         '''num_attention_heads''': '''encoder_attention_heads''',
         '''num_hidden_layers''': '''encoder_layers''',
     }





     def __init__(							self						,			SCREAMING_SNAKE_CASE = None						,			SCREAMING_SNAKE_CASE = None						,			SCREAMING_SNAKE_CASE = "student_t"						,			SCREAMING_SNAKE_CASE = "nll"						,			SCREAMING_SNAKE_CASE = 1						,			SCREAMING_SNAKE_CASE = None						,			SCREAMING_SNAKE_CASE = "mean"						,			SCREAMING_SNAKE_CASE = 0						,			SCREAMING_SNAKE_CASE = 0						,			SCREAMING_SNAKE_CASE = 0						,			SCREAMING_SNAKE_CASE = 0						,			SCREAMING_SNAKE_CASE = None						,			SCREAMING_SNAKE_CASE = None						,			SCREAMING_SNAKE_CASE = 64						,			SCREAMING_SNAKE_CASE = 32						,			SCREAMING_SNAKE_CASE = 32						,			SCREAMING_SNAKE_CASE = 2						,			SCREAMING_SNAKE_CASE = 2						,			SCREAMING_SNAKE_CASE = 2						,			SCREAMING_SNAKE_CASE = 2						,			SCREAMING_SNAKE_CASE = True						,			SCREAMING_SNAKE_CASE = "gelu"						,			SCREAMING_SNAKE_CASE = 0.05						,			SCREAMING_SNAKE_CASE = 0.1						,			SCREAMING_SNAKE_CASE = 0.1						,			SCREAMING_SNAKE_CASE = 0.1						,			SCREAMING_SNAKE_CASE = 0.1						,			SCREAMING_SNAKE_CASE = 100						,			SCREAMING_SNAKE_CASE = 0.02						,			SCREAMING_SNAKE_CASE=True						,			SCREAMING_SNAKE_CASE = "prob"						,			SCREAMING_SNAKE_CASE = 5						,			SCREAMING_SNAKE_CASE = True						,			**SCREAMING_SNAKE_CASE						,			) ->				Any:






         """simple docstring"""






         A       :   Any					=						prediction_length
         A       :   Dict					=						context_length or prediction_length
         A       :   List[Any]					=						distribution_output
         A       :   List[str]					=						loss
         A       :   int					=						input_size
         A       :   List[Any]					=						num_time_features
         A       :   str					=						lags_sequence if lags_sequence is not None else [1, 2, 3, 4, 5, 6, 7]
         A       :   List[str]					=						scaling
         A       :   Any					=						num_dynamic_real_features
         A       :   str					=						num_static_real_features
         A       :   Optional[int]					=						num_static_categorical_features

         # set cardinality
         if cardinality and num_static_categorical_features > 0:
             if len(SCREAMING_SNAKE_CASE	) != num_static_categorical_features:
                 raise ValueError(
                     '''The cardinality should be a list of the same length as `num_static_categorical_features`'''	)
             A       :   str					=						cardinality
         else:
             A       :   List[Any]					=						[0]

         # set embedding_dimension
         if embedding_dimension and num_static_categorical_features > 0:
             if len(SCREAMING_SNAKE_CASE	) != num_static_categorical_features:
                 raise ValueError(
                     '''The embedding dimension should be a list of the same length as `num_static_categorical_features`'''	)
             A       :   int					=						embedding_dimension
         else:
             A       :   List[str]					=						[min(50						,			(cat + 1) // 2	) for cat in self.cardinality]

         A       :   int					=						num_parallel_samples

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

         A       :   Optional[int]					=						dropout
         A       :   List[Any]					=						attention_dropout
         A       :   List[Any]					=						activation_dropout
         A       :   int					=						encoder_layerdrop
         A       :   str					=						decoder_layerdrop

         A       :   Optional[Any]					=						activation_function
         A       :   List[str]					=						init_std

         A       :   List[str]					=						use_cache

         # Informer
         A       :   List[Any]					=						attention_type
         A       :   Tuple					=						sampling_factor
         A       :   Dict					=						distil

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





     @property
     def 				__lowerCAmelCase							(							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
         )










import unittest

import numpy as np
import torch

from diffusers import KarrasVePipeline, KarrasVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()


class  A		(  unittest.TestCase     ):



		@property
		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								torch.manual_seed(0   )
								lowerCAmelCase_      			=  UNetaDModel(
								    block_out_channels=(32, 64),	layers_per_block=2,	sample_size=32,	in_channels=3,	out_channels=3,	down_block_types=('''DownBlock2D''', '''AttnDownBlock2D'''),	up_block_types=('''AttnUpBlock2D''', '''UpBlock2D'''),	)
								return model







		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  self.dummy_uncond_unet
								lowerCAmelCase_      			=  KarrasVeScheduler()

								lowerCAmelCase_      			=  KarrasVePipeline(unet=UpperCamelCase__,	scheduler=UpperCamelCase__   )
								pipe.to(UpperCamelCase__   )
								pipe.set_progress_bar_config(disable=UpperCamelCase__   )

								lowerCAmelCase_      			=  torch.manual_seed(0   )
								lowerCAmelCase_      			=  pipe(num_inference_steps=2,	generator=UpperCamelCase__,	output_type='''numpy'''   ).images

								lowerCAmelCase_      			=  torch.manual_seed(0   )
								lowerCAmelCase_      			=  pipe(num_inference_steps=2,	generator=UpperCamelCase__,	output_type='''numpy''',	return_dict=UpperCamelCase__   )[0]

								lowerCAmelCase_      			=  image[0, -3:, -3:, -1]
								lowerCAmelCase_      			=  image_from_tuple[0, -3:, -3:, -1]

								assert image.shape == (1, 32, 32, 3)
								lowerCAmelCase_      			=  np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]   )

								assert np.abs(image_slice.flatten() - expected_slice   ).max() < 1E-2
								assert np.abs(image_from_tuple_slice.flatten() - expected_slice   ).max() < 1E-2







@slow
@require_torch
class  A		(  unittest.TestCase     ):



		def        SCREAMING_SNAKE_CASE__			(     self   ):







								"""simple docstring"""



								lowerCAmelCase_      			=  '''google/ncsnpp-celebahq-256'''
								lowerCAmelCase_      			=  UNetaDModel.from_pretrained(UpperCamelCase__   )
								lowerCAmelCase_      			=  KarrasVeScheduler()

								lowerCAmelCase_      			=  KarrasVePipeline(unet=UpperCamelCase__,	scheduler=UpperCamelCase__   )
								pipe.to(UpperCamelCase__   )
								pipe.set_progress_bar_config(disable=UpperCamelCase__   )

								lowerCAmelCase_      			=  torch.manual_seed(0   )
								lowerCAmelCase_      			=  pipe(num_inference_steps=20,	generator=UpperCamelCase__,	output_type='''numpy'''   ).images

								lowerCAmelCase_      			=  image[0, -3:, -3:, -1]
								assert image.shape == (1, 256, 256, 3)
								lowerCAmelCase_      			=  np.array([0.578, 0.5_811, 0.5_924, 0.5_809, 0.587, 0.5_886, 0.5_861, 0.5_802, 0.586]   )

								assert np.abs(image_slice.flatten() - expected_slice   ).max() < 1E-2




