





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







  '''simple docstring'''


  SCREAMING_SNAKE_CASE__							:torch.FloatTensor





class      __SCREAMING_SNAKE_CASE    (						_UpperCamelCase		,  _UpperCamelCase   ):







  '''simple docstring'''


  @register_to_config
  def __init__(		self   :       Optional[Any]					,   __a   :       int = 16					,   __a   :       int = 88					,   __a   :       Optional[int] = None					,   __a   :       Optional[int] = None					,   __a   :       int = 1					,   __a   :       float = 0.0					,   __a   :       int = 32					,   __a   :       Optional[int] = None					,   __a   :       bool = False					,   __a   :       Optional[int] = None					,   __a   :       str = "geglu"					,   __a   :       bool = True					,   __a   :       bool = True					,   )		->				str:
        super().__init__()
        _UpperCamelCase      :	List[str]						=       num_attention_heads
        _UpperCamelCase      :	List[str]						=       attention_head_dim
        _UpperCamelCase      :	Optional[int]						=       num_attention_heads * attention_head_dim

        _UpperCamelCase      :	List[str]						=       in_channels

        _UpperCamelCase      :	str						=       torch.nn.GroupNorm(num_groups=__a					,   num_channels=__a					,   eps=1e-6					,   affine=__a	)
        _UpperCamelCase      :	List[str]						=       nn.Linear(__a					,   __a	)

        # 3. Define transformers blocks
        _UpperCamelCase      :	str						=       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	)
            ]	)

        _UpperCamelCase      :	List[Any]						=       nn.Linear(__a					,   __a	)


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

        _UpperCamelCase      :	int						=       hidden_states

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

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

        _UpperCamelCase      :	Optional[Any]						=       self.proj_in(__a	)

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

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

        _UpperCamelCase      :	Optional[int]						=       hidden_states + residual

        if not return_dict:
              return (output,)

        return TransformerTemporalModelOutput(sample=__a	)







"""simple docstring"""


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


lowerCamelCase__				  =   {
    "configuration_mask2former": [
        "MASK2FORMER_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "Mask2FormerConfig",
    ],
}

try:
  if not is_vision_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowerCamelCase__				  =   ["Mask2FormerImageProcessor"]

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowerCamelCase__				  =   [
      "MASK2FORMER_PRETRAINED_MODEL_ARCHIVE_LIST",
      "Mask2FormerForUniversalSegmentation",
      "Mask2FormerModel",
      "Mask2FormerPreTrainedModel",
  ]

if TYPE_CHECKING:
  from .configuration_maskaformer import MASK2FORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, MaskaFormerConfig

  try:
    if not is_vision_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .image_processing_maskaformer import MaskaFormerImageProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_maskaformer import (
        MASK2FORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
        MaskaFormerForUniversalSegmentation,
        MaskaFormerModel,
        MaskaFormerPreTrainedModel,
    )


else:
  import sys

  lowerCamelCase__				  =   _LazyModule(__name__, globals()["__file__"], _import_structure)
