



'''simple docstring'''
from dataclasses import dataclass
from typing import Optional

import torch
from torch import nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput
from .attention import BasicTransformerBlock
from .modeling_utils import ModelMixin






@dataclass
class 				lowercase__      (				lowercase  ):
	lowercase__    							=     42






class 				lowercase__      (				lowercase		,   lowercase  ):





	@register_to_config
	def __init__(					self   :							str					,lowerCamelCase__   :							int = 16					,lowerCamelCase__   :							int = 88					,lowerCamelCase__   :							Optional[int] = None					,lowerCamelCase__   :							Optional[int] = None					,lowerCamelCase__   :							int = 1					,lowerCamelCase__   :							float = 0.0					,lowerCamelCase__   :							int = 32					,lowerCamelCase__   :							Optional[int] = None					,lowerCamelCase__   :							bool = False					,lowerCamelCase__   :							Optional[int] = None					,lowerCamelCase__   :							str = "geglu"					,lowerCamelCase__   :							bool = True					,lowerCamelCase__   :							bool = True					,):







							'''simple docstring'''
							super().__init__()
							_UpperCamelCase   :						Any												=  num_attention_heads
							_UpperCamelCase   :						str												=  attention_head_dim
							_UpperCamelCase   :						List[Any]												=  num_attention_heads * attention_head_dim

							_UpperCamelCase   :						Dict												=  in_channels

							_UpperCamelCase   :						Tuple												=  torch.nn.GroupNorm(num_groups=lowerCamelCase__					,num_channels=lowerCamelCase__					,eps=1E-6					,affine=lowerCamelCase__					)
							_UpperCamelCase   :						List[Any]												=  nn.Linear(lowerCamelCase__					,lowerCamelCase__					)

							# 3. Define transformers blocks
							_UpperCamelCase   :						List[str]												=  nn.ModuleList(
							    [
							        BasicTransformerBlock(
							            lowerCamelCase__					,lowerCamelCase__					,lowerCamelCase__					,dropout=lowerCamelCase__					,cross_attention_dim=lowerCamelCase__					,activation_fn=lowerCamelCase__					,attention_bias=lowerCamelCase__					,double_self_attention=lowerCamelCase__					,norm_elementwise_affine=lowerCamelCase__					,)
							        for d in range(lowerCamelCase__					)
							    ]					)

							_UpperCamelCase   :						Optional[Any]												=  nn.Linear(lowerCamelCase__					,lowerCamelCase__					)





	def       UpperCamelCase_    (					self   :							Dict					,lowerCamelCase__   :							Optional[Any]					,lowerCamelCase__   :							Dict=None					,lowerCamelCase__   :							int=None					,lowerCamelCase__   :							Union[str, Any]=None					,lowerCamelCase__   :							Optional[Any]=1					,lowerCamelCase__   :							Tuple=None					,lowerCamelCase__   :							bool = True					,):







							'''simple docstring'''
							_UpperCamelCase							,     _UpperCamelCase							,     _UpperCamelCase							,     _UpperCamelCase   :						List[str]												=  hidden_states.shape
							_UpperCamelCase   :						Tuple												=  batch_frames // num_frames

							_UpperCamelCase   :						Dict												=  hidden_states

							_UpperCamelCase   :						Dict												=  hidden_states[None, :].reshape(lowerCamelCase__					,lowerCamelCase__					,lowerCamelCase__					,lowerCamelCase__					,lowerCamelCase__					)
							_UpperCamelCase   :						Optional[Any]												=  hidden_states.permute(0					,2					,1					,3					,4					)

							_UpperCamelCase   :						str												=  self.norm(lowerCamelCase__					)
							_UpperCamelCase   :						int												=  hidden_states.permute(0					,3					,4					,2					,1					).reshape(batch_size * height * width					,lowerCamelCase__					,lowerCamelCase__					)

							_UpperCamelCase   :						int												=  self.proj_in(lowerCamelCase__					)

							# 2. Blocks
							for block in self.transformer_blocks:
													_UpperCamelCase   :						List[str]												=  block(
													    lowerCamelCase__					,encoder_hidden_states=lowerCamelCase__					,timestep=lowerCamelCase__					,cross_attention_kwargs=lowerCamelCase__					,class_labels=lowerCamelCase__					,)

							# 3. Output
							_UpperCamelCase   :						List[Any]												=  self.proj_out(lowerCamelCase__					)
							_UpperCamelCase   :						int												=  (
							    hidden_states[None, None, :]
							    .reshape(lowerCamelCase__					,lowerCamelCase__					,lowerCamelCase__					,lowerCamelCase__					,lowerCamelCase__					)
							    .permute(0					,3					,4					,1					,2					)
							    .contiguous()
							)
							_UpperCamelCase   :						Any												=  hidden_states.reshape(lowerCamelCase__					,lowerCamelCase__					,lowerCamelCase__					,lowerCamelCase__					)

							_UpperCamelCase   :						Any												=  hidden_states + residual

							if not return_dict:
													return (output,)

							return TransformerTemporalModelOutput(sample=lowerCamelCase__					)







'''simple docstring'''
from math import ceil






def A__       (	UpperCAmelCase_ = 1_0_0_1				):
						_UpperCamelCase   :						int												=  1

						for i in range(1    ,    int(ceil(n / 2.0				)				)				):
												_UpperCamelCase   :						Dict												=  2 * i + 1
												_UpperCamelCase   :						Tuple												=  2 * i
												_UpperCamelCase   :						Any												=  total + 4 * odd**2 - 6 * even

						return total


if __name__ == "__main__":
					import sys

					if len(sys.argv) == 1:
										print(solution())
					else:
										try:
															snake_case_					:      Tuple    			=    int(sys.argv[1])
															print(solution(n))
										except ValueError:
															print('Invalid entry - please enter a number')


