



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







						"""simple docstring"""







						_A		:				torch.FloatTensor







class  __lowercase  (       a__       ,     a__):







						"""simple docstring"""







						@register_to_config
						def __init__(self ,		lowercase__ = 16 ,		lowercase__ = 88 ,		lowercase__ = None ,		lowercase__ = None ,		lowercase__ = 1 ,		lowercase__ = 0.0 ,		lowercase__ = 32 ,		lowercase__ = None ,		lowercase__ = False ,		lowercase__ = None ,		lowercase__ = "geglu" ,		lowercase__ = True ,		lowercase__ = True ,		):
											super().__init__()
											snake_case_       :		List[Any]			       =       num_attention_heads
											snake_case_       :		Any			       =       attention_head_dim
											snake_case_       :		Dict			       =       num_attention_heads * attention_head_dim

											snake_case_       :		List[Any]			       =       in_channels

											snake_case_       :		int			       =       torch.nn.GroupNorm(num_groups=lowerCamelCase_ ,		num_channels=lowerCamelCase_ ,		eps=1e-6 ,		affine=lowerCamelCase_							)
											snake_case_       :		Tuple			       =       nn.Linear(lowerCamelCase_ ,		lowerCamelCase_							)

											# 3. Define transformers blocks
											snake_case_       :		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_							)
											    ]							)

											snake_case_       :		str			       =       nn.Linear(lowerCamelCase_ ,		lowerCamelCase_							)







						def     __UpperCamelCase				(self ,		lowercase__ ,		lowercase__=None ,		lowercase__=None ,		lowercase__=None ,		lowercase__=1 ,		lowercase__=None ,		lowercase__ = True ,		):
											snake_case_       ,      snake_case_       ,      snake_case_       ,      snake_case_       :		str			       =       hidden_states.shape
											snake_case_       :		Dict			       =       batch_frames // num_frames

											snake_case_       :		Tuple			       =       hidden_states

											snake_case_       :		Optional[int]			       =       hidden_states[None, :].reshape(lowerCamelCase_ ,		lowerCamelCase_ ,		lowerCamelCase_ ,		lowerCamelCase_ ,		lowerCamelCase_							)
											snake_case_       :		Any			       =       hidden_states.permute(0 ,		2 ,		1 ,		3 ,		4							)

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

											snake_case_       :		Optional[Any]			       =       self.proj_in(lowerCamelCase_							)

											# 2. Blocks
											for block in self.transformer_blocks:
																snake_case_       :		Union[str, Any]			       =       block(
																    lowerCamelCase_ ,		encoder_hidden_states=lowerCamelCase_ ,		timestep=lowerCamelCase_ ,		cross_attention_kwargs=lowerCamelCase_ ,		class_labels=lowerCamelCase_ ,		)

											# 3. Output
											snake_case_       :		str			       =       self.proj_out(lowerCamelCase_							)
											snake_case_       :		Optional[Any]			       =       (
											    hidden_states[None, None, :]
											    .reshape(lowerCamelCase_ ,		lowerCamelCase_ ,		lowerCamelCase_ ,		lowerCamelCase_ ,		lowerCamelCase_							)
											    .permute(0 ,		3 ,		4 ,		1 ,		2							)
											    .contiguous()
											)
											snake_case_       :		Tuple			       =       hidden_states.reshape(lowerCamelCase_ ,		lowerCamelCase_ ,		lowerCamelCase_ ,		lowerCamelCase_							)

											snake_case_       :		List[str]			       =       hidden_states + residual

											if not return_dict:
																return (output,)

											return TransformerTemporalModelOutput(sample=lowerCamelCase_							)








'''simple docstring'''






from __future__ import annotations


def    _snake_case  (	A			)		->       bool:
							lowerCAmelCase__			  =      str(A			)
							return len(A			) == 9 and set(A			) == set('''123456789'''			)


def    _snake_case  (	)		->       int | None:
							for base_num in range(9999					,       4999					,       -1			):
														lowerCAmelCase__			  =      100002 * base_num
														if is_9_pandigital(A			):
																					return candidate

							for base_num in range(333					,       99					,       -1			):
														lowerCAmelCase__			  =      1002003 * base_num
														if is_9_pandigital(A			):
																					return candidate

							return None


if __name__ == "__main__":
		print(f"""{solution() = }""")