


from dataclasses import dataclass
from typing import Optional, Tuple, Union

import torch
import torch.nn as nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput
from .embeddings import GaussianFourierProjection, TimestepEmbedding, Timesteps
from .modeling_utils import ModelMixin
from .unet_ad_blocks import get_down_block, get_mid_block, get_out_block, get_up_block




@dataclass
class 							lowerCamelCase   (  _UpperCamelCase ):
	_lowerCAmelCase     :		torch.FloatTensor






class 							lowerCamelCase   (  _UpperCamelCase							,						_UpperCamelCase ):


	@register_to_config
	def __init__(    self				,     lowercase__ = 6_5_5_3_6				,     lowercase__ = None				,     lowercase__ = 2				,     lowercase__ = 2				,     lowercase__ = 0				,     lowercase__ = "fourier"				,     lowercase__ = True				,     lowercase__ = False				,     lowercase__ = 0.0				,     lowercase__ = ("DownBlock1DNoSkip", "DownBlock1D", "AttnDownBlock1D")				,     lowercase__ = ("AttnUpBlock1D", "UpBlock1D", "UpBlock1DNoSkip")				,     lowercase__ = "UNetMidBlock1D"				,     lowercase__ = None				,     lowercase__ = (3_2, 3_2, 6_4)				,     lowercase__ = None				,     lowercase__ = 8				,     lowercase__ = 1				,     lowercase__ = False				,     ):
							super().__init__()
							__UpperCAmelCase			:							int	    =	sample_size

							# time
							if time_embedding_type == "fourier":
													__UpperCAmelCase			:							Optional[int]	    =	GaussianFourierProjection(
													    embedding_size=8				,     set_W_to_weight=lowercase__				,     log=lowercase__				,     flip_sin_to_cos=lowercase__)
													__UpperCAmelCase			:							str	    =	2 * block_out_channels[0]
							elif time_embedding_type == "positional":
													__UpperCAmelCase			:							Optional[Any]	    =	Timesteps(
													    block_out_channels[0]				,     flip_sin_to_cos=lowercase__				,     downscale_freq_shift=lowercase__)
													__UpperCAmelCase			:							List[Any]	    =	block_out_channels[0]

							if use_timestep_embedding:
													__UpperCAmelCase			:							List[Any]	    =	block_out_channels[0] * 4
													__UpperCAmelCase			:							List[str]	    =	TimestepEmbedding(
													    in_channels=lowercase__				,     time_embed_dim=lowercase__				,     act_fn=lowercase__				,     out_dim=block_out_channels[0]				,     )

							__UpperCAmelCase			:							Dict	    =	nn.ModuleList([])
							__UpperCAmelCase			:							List[str]	    =	None
							__UpperCAmelCase			:							Optional[int]	    =	nn.ModuleList([])
							__UpperCAmelCase			:							List[str]	    =	None

							# down
							__UpperCAmelCase			:							Union[str, Any]	    =	in_channels
							for i, down_block_type in enumerate(lowercase__):
													__UpperCAmelCase			:							List[Any]	    =	output_channel
													__UpperCAmelCase			:							Optional[int]	    =	block_out_channels[i]

													if i == 0:
																			input_channel += extra_in_channels

													__UpperCAmelCase			:							Optional[int]	    =	i == len(lowercase__) - 1

													__UpperCAmelCase			:							Optional[Any]	    =	get_down_block(
													    lowercase__				,     num_layers=lowercase__				,     in_channels=lowercase__				,     out_channels=lowercase__				,     temb_channels=block_out_channels[0]				,     add_downsample=not is_final_block or downsample_each_block				,     )
													self.down_blocks.append(lowercase__)

							# mid
							__UpperCAmelCase			:							Optional[Any]	    =	get_mid_block(
							    lowercase__				,     in_channels=block_out_channels[-1]				,     mid_channels=block_out_channels[-1]				,     out_channels=block_out_channels[-1]				,     embed_dim=block_out_channels[0]				,     num_layers=lowercase__				,     add_downsample=lowercase__				,     )

							# up
							__UpperCAmelCase			:							Optional[Any]	    =	list(reversed(lowercase__))
							__UpperCAmelCase			:							List[str]	    =	reversed_block_out_channels[0]
							if out_block_type is None:
													__UpperCAmelCase			:							Optional[int]	    =	out_channels
							else:
													__UpperCAmelCase			:							Optional[int]	    =	block_out_channels[0]

							for i, up_block_type in enumerate(lowercase__):
													__UpperCAmelCase			:							Tuple	    =	output_channel
													__UpperCAmelCase			:							Tuple	    =	(
													    reversed_block_out_channels[i + 1] if i < len(lowercase__) - 1 else final_upsample_channels
													)

													__UpperCAmelCase			:							Tuple	    =	i == len(lowercase__) - 1

													__UpperCAmelCase			:							Tuple	    =	get_up_block(
													    lowercase__				,     num_layers=lowercase__				,     in_channels=lowercase__				,     out_channels=lowercase__				,     temb_channels=block_out_channels[0]				,     add_upsample=not is_final_block				,     )
													self.up_blocks.append(lowercase__)
													__UpperCAmelCase			:							str	    =	output_channel

							# out
							__UpperCAmelCase			:							int	    =	norm_num_groups if norm_num_groups is not None else min(block_out_channels[0] // 4				,     3_2)
							__UpperCAmelCase			:							str	    =	get_out_block(
							    out_block_type=lowercase__				,     num_groups_out=lowercase__				,     embed_dim=block_out_channels[0]				,     out_channels=lowercase__				,     act_fn=lowercase__				,     fc_dim=block_out_channels[-1] // 4				,     )


	def  A(    self				,     lowercase__				,     lowercase__				,     lowercase__ = True				,     ):
							__UpperCAmelCase			:							List[Any]	    =	timestep
							if not torch.is_tensor(lowercase__):
													__UpperCAmelCase			:							Dict	    =	torch.tensor([timesteps]				,     dtype=torch.long				,     device=sample.device)
							elif torch.is_tensor(lowercase__) and len(timesteps.shape) == 0:
													__UpperCAmelCase			:							Union[str, Any]	    =	timesteps[None].to(sample.device)

							__UpperCAmelCase			:							Dict	    =	self.time_proj(lowercase__)
							if self.config.use_timestep_embedding:
													__UpperCAmelCase			:							Optional[int]	    =	self.time_mlp(lowercase__)
							else:
													__UpperCAmelCase			:							List[Any]	    =	timestep_embed[..., None]
													__UpperCAmelCase			:							Union[str, Any]	    =	timestep_embed.repeat([1, 1, sample.shape[2]]).to(sample.dtype)
													__UpperCAmelCase			:							Union[str, Any]	    =	timestep_embed.broadcast_to((sample.shape[:1] + timestep_embed.shape[1:]))

							# 2. down
							__UpperCAmelCase			:							Optional[int]	    =	()
							for downsample_block in self.down_blocks:
													__UpperCAmelCase    ,      __UpperCAmelCase			:							Optional[int]	    =	downsample_block(hidden_states=lowercase__				,     temb=lowercase__)
													down_block_res_samples += res_samples

							# 3. mid
							if self.mid_block:
													__UpperCAmelCase			:							Union[str, Any]	    =	self.mid_block(lowercase__				,     lowercase__)

							# 4. up
							for i, upsample_block in enumerate(self.up_blocks):
													__UpperCAmelCase			:							Tuple	    =	down_block_res_samples[-1:]
													__UpperCAmelCase			:							List[Any]	    =	down_block_res_samples[:-1]
													__UpperCAmelCase			:							Optional[Any]	    =	upsample_block(lowercase__				,     res_hidden_states_tuple=lowercase__				,     temb=lowercase__)

							# 5. post-process
							if self.out_block:
													__UpperCAmelCase			:							Optional[int]	    =	self.out_block(lowercase__				,     lowercase__)

							if not return_dict:
													return (sample,)

							return UNetaDOutput(sample=lowercase__)





def     __SCREAMING_SNAKE_CASE							(       )		->     Optional[int]:




						'''simple docstring'''







						__UpperCAmelCase			:							str	    =	[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

						__UpperCAmelCase			:							Union[str, Any]	    =	6
						__UpperCAmelCase			:							Optional[Any]	    =	1
						__UpperCAmelCase			:							Tuple	    =	1901

						__UpperCAmelCase			:							Any	    =	0

						while year < 2001:
												day += 7

												if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
																		if day > days_per_month[month - 1] and month != 2:
																								month += 1
																								__UpperCAmelCase			:							Optional[int]	    =	day - days_per_month[month - 2]
																		elif day > 29 and month == 2:
																								month += 1
																								__UpperCAmelCase			:							Optional[Any]	    =	day - 29
												else:
																		if day > days_per_month[month - 1]:
																								month += 1
																								__UpperCAmelCase			:							Optional[Any]	    =	day - days_per_month[month - 2]

												if month > 12:
																		year += 1
																		__UpperCAmelCase			:							int	    =	1

												if year < 2001 and day == 1:
																		sundays += 1
						return sundays


if __name__ == "__main__":
				print(solution())

