code: from typing import List, Optional, Tuple, Union
  
  import torch
  
  from ...utils import randn_tensor
  from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput
  
  
  
  
  class      lowercase_						(						UpperCamelCase_		):
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  	def __init__(							self	,    __SCREAMING_SNAKE_CASE	,    __SCREAMING_SNAKE_CASE       )		->Optional[Any]:
  								super().__init__()
  								self.register_modules(unet=__SCREAMING_SNAKE_CASE	,    scheduler=__SCREAMING_SNAKE_CASE       )
  
  
  
  
  	@torch.no_grad()
  	def __call__(							self	,    __SCREAMING_SNAKE_CASE = 1	,    __SCREAMING_SNAKE_CASE = None	,    __SCREAMING_SNAKE_CASE = 1000	,    __SCREAMING_SNAKE_CASE = "pil"	,    __SCREAMING_SNAKE_CASE = True	,    )		->Union[ImagePipelineOutput, Tuple]:
  								# Sample gaussian noise to begin loop
  								if isinstance(self.unet.config.sample_size	,    __SCREAMING_SNAKE_CASE       ):
  															lowerCAmelCase				=	(
  															    batch_size,
  															    self.unet.config.in_channels,
  															    self.unet.config.sample_size,
  															    self.unet.config.sample_size,
  															)
  								else:
  															lowerCAmelCase				=	(batch_size, self.unet.config.in_channels, *self.unet.config.sample_size)
  
  								if self.device.type == "mps":
  															# randn does not work reproducibly on mps
  															lowerCAmelCase				=	randn_tensor(__SCREAMING_SNAKE_CASE	,    generator=__SCREAMING_SNAKE_CASE       )
  															lowerCAmelCase				=	image.to(self.device       )
  								else:
  															lowerCAmelCase				=	randn_tensor(__SCREAMING_SNAKE_CASE	,    generator=__SCREAMING_SNAKE_CASE	,    device=self.device       )
  
  								# set step values
  								self.scheduler.set_timesteps(__SCREAMING_SNAKE_CASE       )
  
  								for t in self.progress_bar(self.scheduler.timesteps       ):
  															# 1. predict noise model_output
  															lowerCAmelCase				=	self.unet(__SCREAMING_SNAKE_CASE	,    __SCREAMING_SNAKE_CASE       ).sample
  
  															# 2. compute previous image: x_t -> x_t-1
  															lowerCAmelCase				=	self.scheduler.step(__SCREAMING_SNAKE_CASE	,    __SCREAMING_SNAKE_CASE	,    __SCREAMING_SNAKE_CASE	,    generator=__SCREAMING_SNAKE_CASE       ).prev_sample
  
  								lowerCAmelCase				=	(image / 2 + 0.5).clamp(0	,    1       )
  								lowerCAmelCase				=	image.cpu().permute(0	,    2	,    3	,    1       ).numpy()
  								if output_type == "pil":
  															lowerCAmelCase				=	self.numpy_to_pil(__SCREAMING_SNAKE_CASE       )
  
  								if not return_dict:
  															return (image,)
  
  								return ImagePipelineOutput(images=__SCREAMING_SNAKE_CASE       )
  
  
  
  
style_context: from typing import Callable, Optional, Union
  
  from ...configuration_utils import PretrainedConfig
  from ...utils import logging
  
  
  lowercase__    :       Optional[Any]						=			logging.get_logger(__name__)
  
  lowercase__    :       Union[str, Any]						=			{
      '''microsoft/prophetnet-large-uncased''': (
          '''https://huggingface.co/microsoft/prophetnet-large-uncased/resolve/main/config.json'''
      ),
  }
  
  
  
  
  class      lowercase_						(						UpperCamelCase_		):
  
  
  
  	"""simple docstring"""
  
  
  
  
  
  	UpperCAmelCase_						:      Optional[int]     =       """prophetnet"""
  	UpperCAmelCase_						:      Optional[int]     =       ["""past_key_values"""]
  	UpperCAmelCase_						:      Any     =       {
  	    """num_attention_heads""": """num_encoder_attention_heads""",
  	}
  
  
  	def __init__(							self	,    __SCREAMING_SNAKE_CASE = 0.1	,    __SCREAMING_SNAKE_CASE = "gelu"	,    __SCREAMING_SNAKE_CASE = 30522	,    __SCREAMING_SNAKE_CASE = 1024	,    __SCREAMING_SNAKE_CASE = 4096	,    __SCREAMING_SNAKE_CASE = 12	,    __SCREAMING_SNAKE_CASE = 16	,    __SCREAMING_SNAKE_CASE = 4096	,    __SCREAMING_SNAKE_CASE = 12	,    __SCREAMING_SNAKE_CASE = 16	,    __SCREAMING_SNAKE_CASE = 0.1	,    __SCREAMING_SNAKE_CASE = 0.1	,    __SCREAMING_SNAKE_CASE = 512	,    __SCREAMING_SNAKE_CASE = 0.0_2	,    __SCREAMING_SNAKE_CASE = True	,    __SCREAMING_SNAKE_CASE = True	,    __SCREAMING_SNAKE_CASE = 0	,    __SCREAMING_SNAKE_CASE = 2	,    __SCREAMING_SNAKE_CASE = 32	,    __SCREAMING_SNAKE_CASE = 128	,    __SCREAMING_SNAKE_CASE = False	,    __SCREAMING_SNAKE_CASE = 0.0	,    __SCREAMING_SNAKE_CASE = True	,    __SCREAMING_SNAKE_CASE = 0	,    __SCREAMING_SNAKE_CASE = 1	,    __SCREAMING_SNAKE_CASE = 2	,    **__SCREAMING_SNAKE_CASE	,    )		->int:
  								lowerCAmelCase				=	vocab_size
  								lowerCAmelCase				=	hidden_size
  								lowerCAmelCase				=	encoder_ffn_dim
  								lowerCAmelCase				=	num_encoder_layers
  								lowerCAmelCase				=	num_encoder_attention_heads
  								lowerCAmelCase				=	decoder_ffn_dim
  								lowerCAmelCase				=	num_decoder_layers
  								lowerCAmelCase				=	num_decoder_attention_heads
  								lowerCAmelCase				=	max_position_embeddings
  								lowerCAmelCase				=	init_std  # Normal(0, this parameter)
  								lowerCAmelCase				=	activation_function
  
  								# parameters for prophetnet
  								lowerCAmelCase				=	ngram
  								lowerCAmelCase				=	num_buckets
  								lowerCAmelCase				=	relative_max_distance
  								lowerCAmelCase				=	disable_ngram_loss
  								lowerCAmelCase				=	eps
  
  								# 3 Types of Dropout
  								lowerCAmelCase				=	attention_dropout
  								lowerCAmelCase				=	activation_dropout
  								lowerCAmelCase				=	dropout
  
  								lowerCAmelCase				=	use_cache
  
  								super().__init__(
  								    pad_token_id=__SCREAMING_SNAKE_CASE	,    bos_token_id=__SCREAMING_SNAKE_CASE	,    eos_token_id=__SCREAMING_SNAKE_CASE	,    is_encoder_decoder=__SCREAMING_SNAKE_CASE	,    add_cross_attention=__SCREAMING_SNAKE_CASE	,    decoder_start_token_id=__SCREAMING_SNAKE_CASE	,    **__SCREAMING_SNAKE_CASE	,    )
  
  
  	@property
  	def     SCREAMING_SNAKE_CASE_       (							self       )		->int:
  								return self.num_encoder_layers + self.num_decoder_layers
  
  
  
  
  	@num_hidden_layers.setter
  	def     SCREAMING_SNAKE_CASE_       (							self	,    __SCREAMING_SNAKE_CASE       )		->Union[str, Any]:
  								raise NotImplementedError(
  								    '''This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and'''
  								    ''' `num_decoder_layers`.'''       )
  
  
  
  