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






       """simple docstring"""
       _snake_case     :					List[Any]						    =   4_2

class     __lowerCAmelCase					(   _lowerCAmelCase						,						_lowerCAmelCase			):






       """simple docstring"""





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

            '''simple docstring'''




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

            _UpperCamelCase       =	in_channels

            _UpperCamelCase       =	torch.nn.GroupNorm(num_groups=SCREAMING_SNAKE_CASE_	,			num_channels=SCREAMING_SNAKE_CASE_	,			eps=1e-6	,			affine=SCREAMING_SNAKE_CASE_					)
            _UpperCamelCase       =	nn.Linear(SCREAMING_SNAKE_CASE_	,			SCREAMING_SNAKE_CASE_					)

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

            _UpperCamelCase       =	nn.Linear(SCREAMING_SNAKE_CASE_	,			SCREAMING_SNAKE_CASE_					)







       def snake_case__						(							self       :		Union[str, Any]	,			lowerCAmelCase__       :		List[str]	,			lowerCAmelCase__       :		Any=None	,			lowerCAmelCase__       :		List[Any]=None	,			lowerCAmelCase__       :		Optional[Any]=None	,			lowerCAmelCase__       :		List[str]=1	,			lowerCAmelCase__       :		Optional[int]=None	,			lowerCAmelCase__       :		Tuple = True	,			)   ->					List[Any]:

            '''simple docstring'''




            _UpperCamelCase       =	hidden_states.shape
            _UpperCamelCase       =	batch_frames // num_frames

            _UpperCamelCase       =	hidden_states

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

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

            _UpperCamelCase       =	self.proj_in(SCREAMING_SNAKE_CASE_					)

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

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

            _UpperCamelCase       =	hidden_states + residual

            if not return_dict:
                 return (output,)

            return TransformerTemporalModelOutput(sample=SCREAMING_SNAKE_CASE_					)










'''simple docstring'''

import importlib.metadata
from typing import Union

from packaging.version import Version, parse

from .constants import STR_OPERATION_TO_FUNC


lowercase__						:      List[Any]	=    parse(importlib.metadata.version('torch'))







def  a__    (    lowercase :					Union[str, Version], lowercase :					str, lowercase :					str				)		->		List[str]:





     """simple docstring"""

     if operation not in STR_OPERATION_TO_FUNC.keys():
          raise ValueError(F"""`operation` must be one of {list(STR_OPERATION_TO_FUNC.keys()				)}, received {operation}"""				)
     _UpperCamelCase       =	STR_OPERATION_TO_FUNC[operation]
     if isinstance(lowercase, lowercase				):
          _UpperCamelCase       =	parse(importlib.metadata.version(lowercase				)				)
     return operation(lowercase, parse(lowercase				)				)







def  a__    (    lowercase :					str, lowercase :					str				)		->		List[Any]:





     """simple docstring"""

     return compare_versions(lowercase, lowercase, lowercase				)



