



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 			_lowerCAmelCase   ( lowerCamelCase__			):






			"""simple docstring"""





			lowercase__      :  Optional[int]      =			42





class 			_lowerCAmelCase   ( lowerCamelCase__    ,					lowerCamelCase__			):






			"""simple docstring"""





			@register_to_config
			def __init__(				self	:       Optional[Any]			,     lowercase	:       List[Any] = 16			,     lowercase	:       Optional[Any] = 88			,     lowercase	:       Tuple = None			,     lowercase	:       List[Any] = None			,     lowercase	:       int = 1			,     lowercase	:       List[str] = 0.0			,     lowercase	:       Any = 32			,     lowercase	:       Optional[int] = None			,     lowercase	:       int = False			,     lowercase	:       Tuple = None			,     lowercase	:       Optional[Any] = "geglu"			,     lowercase	:       Union[str, Any] = True			,     lowercase	:       Tuple = True			,     )						->					Union[str, Any]:
									"""simple docstring"""







									super().__init__()
									__lowercase					=				num_attention_heads
									__lowercase					=				attention_head_dim
									__lowercase					=				num_attention_heads * attention_head_dim

									__lowercase					=				in_channels

									__lowercase					=				torch.nn.GroupNorm(num_groups=__lowerCamelCase			,     num_channels=__lowerCamelCase			,     eps=1E-6			,     affine=__lowerCamelCase   )
									__lowercase					=				nn.Linear(__lowerCamelCase			,     __lowerCamelCase   )

									# 3. Define transformers blocks
									__lowercase					=				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   )
									    ]   )

									__lowercase					=				nn.Linear(__lowerCamelCase			,     __lowerCamelCase   )







			def 		snake_case__			(				self	:       Any			,     lowercase	:       Union[str, Any]			,     lowercase	:       Union[str, Any]=None			,     lowercase	:       List[Any]=None			,     lowercase	:       List[str]=None			,     lowercase	:       List[Any]=1			,     lowercase	:       int=None			,     lowercase	:       str = True			,     )						->					Union[str, Any]:
									"""simple docstring"""







									__lowercase					=				hidden_states.shape
									__lowercase					=				batch_frames // num_frames

									__lowercase					=				hidden_states

									__lowercase					=				hidden_states[None, :].reshape(__lowerCamelCase			,     __lowerCamelCase			,     __lowerCamelCase			,     __lowerCamelCase			,     __lowerCamelCase   )
									__lowercase					=				hidden_states.permute(0			,     2			,     1			,     3			,     4   )

									__lowercase					=				self.norm(__lowerCamelCase   )
									__lowercase					=				hidden_states.permute(0			,     3			,     4			,     2			,     1   ).reshape(batch_size * height * width			,     __lowerCamelCase			,     __lowerCamelCase   )

									__lowercase					=				self.proj_in(__lowerCamelCase   )

									# 2. Blocks
									for block in self.transformer_blocks:
															__lowercase					=				block(
															    __lowerCamelCase			,     encoder_hidden_states=__lowerCamelCase			,     timestep=__lowerCamelCase			,     cross_attention_kwargs=__lowerCamelCase			,     class_labels=__lowerCamelCase			,     )

									# 3. Output
									__lowercase					=				self.proj_out(__lowerCamelCase   )
									__lowercase					=				(
									    hidden_states[None, None, :]
									    .reshape(__lowerCamelCase			,     __lowerCamelCase			,     __lowerCamelCase			,     __lowerCamelCase			,     __lowerCamelCase   )
									    .permute(0			,     3			,     4			,     1			,     2   )
									    .contiguous()
									)
									__lowercase					=				hidden_states.reshape(__lowerCamelCase			,     __lowerCamelCase			,     __lowerCamelCase			,     __lowerCamelCase   )

									__lowercase					=				hidden_states + residual

									if not return_dict:
															return (output,)

									return TransformerTemporalModelOutput(sample=__lowerCamelCase   )










def  UpperCAmelCase__    (    lowercase__						,       lowercase__   ) ->      bool:
						__lowercase					=				len(lowercase__   )
						__lowercase					=				[[False] * (required_sum + 1) for _ in range(arr_len + 1   )]

						# for each arr value, a sum of zero(0) can be formed by not taking any element
						# hence True/1
						for i in range(arr_len + 1   ):
												__lowercase					=				True

						# sum is not zero and set is empty then false
						for i in range(1						,       required_sum + 1   ):
												__lowercase					=				False

						for i in range(1						,       arr_len + 1   ):
												for j in range(1						,       required_sum + 1   ):
																		if arr[i - 1] > j:
																								__lowercase					=				subset[i - 1][j]
																		if arr[i - 1] <= j:
																								__lowercase					=				subset[i - 1][j] or subset[i - 1][j - arr[i - 1]]

						return subset[arr_len][required_sum]


if __name__ == "__main__":
			import doctest

			doctest.testmod()





