




"""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    (					a_						):
   _lowerCamelCase    :torch.FloatTensor






class _lowerCamelCase    (					a_       ,	a_						):






   @register_to_config
   def __init__(		self       :		str   ,     UpperCamelCase       :		int = 16   ,     UpperCamelCase       :		int = 88   ,     UpperCamelCase       :		Optional[int] = None   ,     UpperCamelCase       :		Optional[int] = None   ,     UpperCamelCase       :		int = 1   ,     UpperCamelCase       :		float = 0.0   ,     UpperCamelCase       :		int = 32   ,     UpperCamelCase       :		Optional[int] = None   ,     UpperCamelCase       :		bool = False   ,     UpperCamelCase       :		Optional[int] = None   ,     UpperCamelCase       :		str = "geglu"   ,     UpperCamelCase       :		bool = True   ,     UpperCamelCase       :		bool = True   ,     )			->						int:

         """simple docstring"""
         super().__init__()
         lowerCAmelCase__      :			Optional[Any]   =	num_attention_heads
         lowerCAmelCase__      :			List[str]   =	attention_head_dim
         lowerCAmelCase__      :			Any   =	num_attention_heads * attention_head_dim

         lowerCAmelCase__      :			str   =	in_channels

         lowerCAmelCase__      :			Optional[Any]   =	torch.nn.GroupNorm(num_groups=UpperCamelCase   ,     num_channels=UpperCamelCase   ,     eps=1E-6   ,     affine=UpperCamelCase   )
         lowerCAmelCase__      :			Union[str, Any]   =	nn.Linear(UpperCamelCase   ,     UpperCamelCase   )

         # 3. Define transformers blocks
         lowerCAmelCase__      :			Optional[int]   =	nn.ModuleList(
             [
                 BasicTransformerBlock(
                     UpperCamelCase   ,     UpperCamelCase   ,     UpperCamelCase   ,     dropout=UpperCamelCase   ,     cross_attention_dim=UpperCamelCase   ,     activation_fn=UpperCamelCase   ,     attention_bias=UpperCamelCase   ,     double_self_attention=UpperCamelCase   ,     norm_elementwise_affine=UpperCamelCase   ,     )
                 for d in range(UpperCamelCase   )
             ]   )

         lowerCAmelCase__      :			Any   =	nn.Linear(UpperCamelCase   ,     UpperCamelCase   )






   def 	_lowerCAmelCase   (		self       :		Any   ,     UpperCamelCase       :		int   ,     UpperCamelCase       :		Tuple=None   ,     UpperCamelCase       :		Any=None   ,     UpperCamelCase       :		Tuple=None   ,     UpperCamelCase       :		str=1   ,     UpperCamelCase       :		List[Any]=None   ,     UpperCamelCase       :		bool = True   ,     )			->						Any:

         """simple docstring"""
         lowerCAmelCase__ ,   lowerCAmelCase__ ,   lowerCAmelCase__ ,   lowerCAmelCase__      :			List[Any]   =	hidden_states.shape
         lowerCAmelCase__      :			Union[str, Any]   =	batch_frames // num_frames

         lowerCAmelCase__      :			str   =	hidden_states

         lowerCAmelCase__      :			str   =	hidden_states[None, :].reshape(UpperCamelCase   ,     UpperCamelCase   ,     UpperCamelCase   ,     UpperCamelCase   ,     UpperCamelCase   )
         lowerCAmelCase__      :			Optional[int]   =	hidden_states.permute(0   ,     2   ,     1   ,     3   ,     4   )

         lowerCAmelCase__      :			Tuple   =	self.norm(UpperCamelCase   )
         lowerCAmelCase__      :			Optional[Any]   =	hidden_states.permute(0   ,     3   ,     4   ,     2   ,     1   ).reshape(batch_size * height * width   ,     UpperCamelCase   ,     UpperCamelCase   )

         lowerCAmelCase__      :			List[Any]   =	self.proj_in(UpperCamelCase   )

         # 2. Blocks
         for block in self.transformer_blocks:
               lowerCAmelCase__      :			Any   =	block(
                   UpperCamelCase   ,     encoder_hidden_states=UpperCamelCase   ,     timestep=UpperCamelCase   ,     cross_attention_kwargs=UpperCamelCase   ,     class_labels=UpperCamelCase   ,     )

         # 3. Output
         lowerCAmelCase__      :			Dict   =	self.proj_out(UpperCamelCase   )
         lowerCAmelCase__      :			Tuple   =	(
             hidden_states[None, None, :]
             .reshape(UpperCamelCase   ,     UpperCamelCase   ,     UpperCamelCase   ,     UpperCamelCase   ,     UpperCamelCase   )
             .permute(0   ,     3   ,     4   ,     1   ,     2   )
             .contiguous()
         )
         lowerCAmelCase__      :			Any   =	hidden_states.reshape(UpperCamelCase   ,     UpperCamelCase   ,     UpperCamelCase   ,     UpperCamelCase   )

         lowerCAmelCase__      :			List[str]   =	hidden_states + residual

         if not return_dict:
               return (output,)

         return TransformerTemporalModelOutput(sample=UpperCamelCase   )











"""simple docstring"""


from argparse import ArgumentParser

from . import BaseTransformersCLICommand



def 	lowercase_				(			__UpperCAmelCase				)						->    List[str]:
      return DownloadCommand(args.model    ,		args.cache_dir    ,		args.force    ,		args.trust_remote_code				)


class _lowerCamelCase    (					a_						):






   @staticmethod
   def 	_lowerCAmelCase   (		UpperCamelCase       :		ArgumentParser   )			->						List[Any]:

         """simple docstring"""
         lowerCAmelCase__      :			int   =	parser.add_parser("""download"""   )
         download_parser.add_argument(
             """--cache-dir"""   ,     type=UpperCamelCase   ,     default=UpperCamelCase   ,     help="""Path to location to store the models"""   )
         download_parser.add_argument(
             """--force"""   ,     action="""store_true"""   ,     help="""Force the model to be download even if already in cache-dir"""   )
         download_parser.add_argument(
             """--trust-remote-code"""   ,     action="""store_true"""   ,     help="""Whether or not to allow for custom models defined on the Hub in their own modeling files. Use only if you've reviewed the code as it will execute on your local machine"""   ,     )
         download_parser.add_argument("""model"""   ,     type=UpperCamelCase   ,     help="""Name of the model to download"""   )
         download_parser.set_defaults(func=UpperCamelCase   )






   def __init__(		self       :		Optional[int]   ,     UpperCamelCase       :		str   ,     UpperCamelCase       :		str   ,     UpperCamelCase       :		bool   ,     UpperCamelCase       :		bool   )			->						Any:

         """simple docstring"""
         lowerCAmelCase__      :			int   =	model
         lowerCAmelCase__      :			Union[str, Any]   =	cache
         lowerCAmelCase__      :			Optional[int]   =	force
         lowerCAmelCase__      :			Dict   =	trust_remote_code






   def 	_lowerCAmelCase   (		self       :		int   )			->						Any:

         """simple docstring"""
         from ..models.auto import AutoModel, AutoTokenizer

         AutoModel.from_pretrained(
             self._model   ,     cache_dir=self._cache   ,     force_download=self._force   ,     trust_remote_code=self._trust_remote_code   )
         AutoTokenizer.from_pretrained(
             self._model   ,     cache_dir=self._cache   ,     force_download=self._force   ,     trust_remote_code=self._trust_remote_code   )





