


"""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 			UpperCamelCase_     (			UpperCamelCase):

	"""simple docstring"""





	snake_case__    :  str    =      42




class 			UpperCamelCase_     (			UpperCamelCase      ,  UpperCamelCase):

	"""simple docstring"""





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

						__SCREAMING_SNAKE_CASE						       =    in_channels

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

						# 3. Define transformers blocks
						__SCREAMING_SNAKE_CASE						       =    nn.ModuleList(
						    [
						        BasicTransformerBlock(
						            __a      ,      __a      ,      __a      ,      dropout=__a      ,      cross_attention_dim=__a      ,      activation_fn=__a      ,      attention_bias=__a      ,      double_self_attention=__a      ,      norm_elementwise_affine=__a      ,      )
						        for d in range(__a       )
						    ]       )

						__SCREAMING_SNAKE_CASE						       =    nn.Linear(__a      ,      __a       )




	def   UpperCAmelCase_				(			self      :    Any      ,      UpperCAmelCase__      :    Union[str, Any]      ,      UpperCAmelCase__      :    Union[str, Any]=None      ,      UpperCAmelCase__      :    Dict=None      ,      UpperCAmelCase__      :    List[Any]=None      ,      UpperCAmelCase__      :    str=1      ,      UpperCAmelCase__      :    Optional[Any]=None      ,      UpperCAmelCase__      :    Tuple = True      ,      )	->     Dict:
						__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    hidden_states.shape
						__SCREAMING_SNAKE_CASE						       =    batch_frames // num_frames

						__SCREAMING_SNAKE_CASE						       =    hidden_states

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

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

						__SCREAMING_SNAKE_CASE						       =    self.proj_in(__a       )

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

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

						__SCREAMING_SNAKE_CASE						       =    hidden_states + residual

						if not return_dict:
											return (output,)

						return TransformerTemporalModelOutput(sample=__a       )




"""simple docstring"""







a__    :							Optional[Any]            =					'''ABCDEFGHIJKLMNOPQRSTUVWXYZ'''




def        UpperCAmelCase__	():




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    input("Enter message: "       )
					__SCREAMING_SNAKE_CASE						       =    input("Enter key [alphanumeric]: "       )
					__SCREAMING_SNAKE_CASE						       =    input("Encrypt/Decrypt [e/d]: "       )

					if mode.lower().startswith("e"       ):
										__SCREAMING_SNAKE_CASE						       =    "encrypt"
										__SCREAMING_SNAKE_CASE						       =    encrypt_message(lowerCAmelCase_  ,						lowerCAmelCase_       )
					elif mode.lower().startswith("d"       ):
										__SCREAMING_SNAKE_CASE						       =    "decrypt"
										__SCREAMING_SNAKE_CASE						       =    decrypt_message(lowerCAmelCase_  ,						lowerCAmelCase_       )

					print(f"""\n{mode.title()}ed message:"""       )
					print(lowerCAmelCase_       )




def        UpperCAmelCase__	(lowerCAmelCase_  ,						lowerCAmelCase_       ):




					'''simple docstring'''


					return translate_message(lowerCAmelCase_  ,						lowerCAmelCase_  ,						"encrypt"       )




def        UpperCAmelCase__	(lowerCAmelCase_  ,						lowerCAmelCase_       ):




					'''simple docstring'''


					return translate_message(lowerCAmelCase_  ,						lowerCAmelCase_  ,						"decrypt"       )




def        UpperCAmelCase__	(lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    []
					__SCREAMING_SNAKE_CASE						       =    0
					__SCREAMING_SNAKE_CASE						       =    key.upper()

					for symbol in message:
										__SCREAMING_SNAKE_CASE						       =    LETTERS.find(symbol.upper()       )
										if num != -1:
															if mode == "encrypt":
																				num += LETTERS.find(key[key_index]       )
															elif mode == "decrypt":
																				num -= LETTERS.find(key[key_index]       )

															num %= len(lowerCAmelCase_       )

															if symbol.isupper():
																				translated.append(LETTERS[num]       )
															elif symbol.islower():
																				translated.append(LETTERS[num].lower()       )

															key_index += 1
															if key_index == len(lowerCAmelCase_       ):
																				__SCREAMING_SNAKE_CASE						       =    0
										else:
															translated.append(lowerCAmelCase_       )
					return "".join(lowerCAmelCase_       )


if __name__ == "__main__":
		main()
