






"""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       __A		(   SCREAMING_SNAKE_CASE_			):
					UpperCAmelCase__								=				42



class       __A		(   SCREAMING_SNAKE_CASE_     ,SCREAMING_SNAKE_CASE_			):

					@register_to_config
					def __init__(			self  :      Union[str, Any]     ,		__snake_case  :      int = 1_6     ,		__snake_case  :      int = 8_8     ,		__snake_case  :      Optional[int] = None     ,		__snake_case  :      Optional[int] = None     ,		__snake_case  :      int = 1     ,		__snake_case  :      float = 0.0     ,		__snake_case  :      int = 3_2     ,		__snake_case  :      Optional[int] = None     ,		__snake_case  :      bool = False     ,		__snake_case  :      Optional[int] = None     ,		__snake_case  :      str = "geglu"     ,		__snake_case  :      bool = True     ,		__snake_case  :      bool = True     ,		)			->							Any:
											super().__init__()
											__magic_name__:	int							=       num_attention_heads
											__magic_name__:	Tuple							=       attention_head_dim
											__magic_name__:	str							=       num_attention_heads * attention_head_dim

											__magic_name__:	List[str]							=       in_channels

											__magic_name__:	List[str]							=       torch.nn.GroupNorm(num_groups=__snake_case     ,		num_channels=__snake_case     ,		eps=1E-6     ,		affine=__snake_case					)
											__magic_name__:	Union[str, Any]							=       nn.Linear(__snake_case     ,		__snake_case					)

											# 3. Define transformers blocks
											__magic_name__:	Union[str, Any]							=       nn.ModuleList(
											    [
											        BasicTransformerBlock(
											            __snake_case     ,		__snake_case     ,		__snake_case     ,		dropout=__snake_case     ,		cross_attention_dim=__snake_case     ,		activation_fn=__snake_case     ,		attention_bias=__snake_case     ,		double_self_attention=__snake_case     ,		norm_elementwise_affine=__snake_case     ,		)
											        for d in range(__snake_case					)
											    ]					)

											__magic_name__:	Optional[Any]							=       nn.Linear(__snake_case     ,		__snake_case					)






					def   lowerCamelCase__   (			self  :      List[Any]     ,		__snake_case  :      Optional[Any]     ,		__snake_case  :      Tuple=None     ,		__snake_case  :      Union[str, Any]=None     ,		__snake_case  :      int=None     ,		__snake_case  :      Optional[int]=1     ,		__snake_case  :      List[str]=None     ,		__snake_case  :      bool = True     ,		)			->							str:
											__magic_name__,			__magic_name__,			__magic_name__,			__magic_name__:	int							=       hidden_states.shape
											__magic_name__:	Optional[Any]							=       batch_frames // num_frames

											__magic_name__:	int							=       hidden_states

											__magic_name__:	str							=       hidden_states[None, :].reshape(__snake_case     ,		__snake_case     ,		__snake_case     ,		__snake_case     ,		__snake_case					)
											__magic_name__:	int							=       hidden_states.permute(0     ,		2     ,		1     ,		3     ,		4					)

											__magic_name__:	Union[str, Any]							=       self.norm(__snake_case					)
											__magic_name__:	Dict							=       hidden_states.permute(0     ,		3     ,		4     ,		2     ,		1					).reshape(batch_size * height * width     ,		__snake_case     ,		__snake_case					)

											__magic_name__:	Optional[Any]							=       self.proj_in(__snake_case					)

											# 2. Blocks
											for block in self.transformer_blocks:
																	__magic_name__:	Dict							=       block(
																	    __snake_case     ,		encoder_hidden_states=__snake_case     ,		timestep=__snake_case     ,		cross_attention_kwargs=__snake_case     ,		class_labels=__snake_case     ,		)

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

											__magic_name__:	List[str]							=       hidden_states + residual

											if not return_dict:
																	return (output,)

											return TransformerTemporalModelOutput(sample=__snake_case					)








'''simple docstring'''
def A__       (	UpperCAmelCase_    ,    UpperCAmelCase_				):
						return int((input_a, input_a).count(0				) != 0				)






def A__       (	):
						assert nand_gate(0    ,    0				) == 1
						assert nand_gate(0    ,    1				) == 1
						assert nand_gate(1    ,    0				) == 1
						assert nand_gate(1    ,    1				) == 0


if __name__ == "__main__":
					print(nand_gate(0, 0))
					print(nand_gate(0, 1))
					print(nand_gate(1, 0))
					print(nand_gate(1, 1))


