



'''simple docstring'''



import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..bit import BitConfig


lowerCAmelCase	:		Any				=   logging.get_logger(__name__)

lowerCAmelCase	:		Optional[int]				=   {
    '''Intel/dpt-large''': '''https://huggingface.co/Intel/dpt-large/resolve/main/config.json''',
    # See all DPT models at https://huggingface.co/models?filter=dpt
}






class 					UpperCAmelCase__	(		UpperCamelCase__ ):
					a      :     str        =							"""dpt"""



					def __init__(    self			,				UpperCamelCase=768			,				UpperCamelCase=12			,				UpperCamelCase=12			,				UpperCamelCase=3072			,				UpperCamelCase="gelu"			,				UpperCamelCase=0.0			,				UpperCamelCase=0.0			,				UpperCamelCase=0.02			,				UpperCamelCase=1E-12			,				UpperCamelCase=384			,				UpperCamelCase=16			,				UpperCamelCase=3			,				UpperCamelCase=False			,				UpperCamelCase=True			,				UpperCamelCase=[2, 5, 8, 11]			,				UpperCamelCase="project"			,				UpperCamelCase=[4, 2, 1, 0.5]			,				UpperCamelCase=[96, 192, 384, 768]			,				UpperCamelCase=256			,				UpperCamelCase=-1			,				UpperCamelCase=False			,				UpperCamelCase=True			,				UpperCamelCase=0.4			,				UpperCamelCase=255			,				UpperCamelCase=0.1			,				UpperCamelCase=[1, 1024, 24, 24]			,				UpperCamelCase=[0, 1]			,				UpperCamelCase=None			,				**UpperCamelCase			,				)     ->			Optional[Any]:
						super().__init__(**UpperCamelCase     )

						__lowerCAmelCase												=  hidden_size
						__lowerCAmelCase												=  is_hybrid

						if self.is_hybrid:
							if backbone_config is None:
								logger.info("Initializing the config with a `BiT` backbone."     )
								__lowerCAmelCase												=  {
								    "global_padding": "same",
								    "layer_type": "bottleneck",
								    "depths": [3, 4, 9],
								    "out_features": ["stage1", "stage2", "stage3"],
								    "embedding_dynamic_padding": True,
								}
								__lowerCAmelCase												=  BitConfig(**UpperCamelCase     )
							elif isinstance(UpperCamelCase			,				UpperCamelCase     ):
								logger.info("Initializing the config with a `BiT` backbone."     )
								__lowerCAmelCase												=  BitConfig(**UpperCamelCase     )
							elif isinstance(UpperCamelCase			,				UpperCamelCase     ):
								__lowerCAmelCase												=  backbone_config
							else:
								raise ValueError(
								    F'''backbone_config must be a dictionary or a `PretrainedConfig`, got {backbone_config.__class__}.'''     )

							__lowerCAmelCase												=  backbone_featmap_shape
							__lowerCAmelCase												=  neck_ignore_stages

							if readout_type != "project":
								raise ValueError("Readout type must be 'project' when using `DPT-hybrid` mode."     )
						else:
							__lowerCAmelCase												=  None
							__lowerCAmelCase												=  None
							__lowerCAmelCase												=  []

						__lowerCAmelCase												=  num_hidden_layers
						__lowerCAmelCase												=  num_attention_heads
						__lowerCAmelCase												=  intermediate_size
						__lowerCAmelCase												=  hidden_act
						__lowerCAmelCase												=  hidden_dropout_prob
						__lowerCAmelCase												=  attention_probs_dropout_prob
						__lowerCAmelCase												=  initializer_range
						__lowerCAmelCase												=  layer_norm_eps
						__lowerCAmelCase												=  image_size
						__lowerCAmelCase												=  patch_size
						__lowerCAmelCase												=  num_channels
						__lowerCAmelCase												=  qkv_bias
						__lowerCAmelCase												=  backbone_out_indices
						if readout_type not in ["ignore", "add", "project"]:
							raise ValueError("Readout_type must be one of ['ignore', 'add', 'project']"     )
						__lowerCAmelCase												=  readout_type
						__lowerCAmelCase												=  reassemble_factors
						__lowerCAmelCase												=  neck_hidden_sizes
						__lowerCAmelCase												=  fusion_hidden_size
						__lowerCAmelCase												=  head_in_index
						__lowerCAmelCase												=  use_batch_norm_in_fusion_residual
						# auxiliary head attributes (semantic segmentation)
						__lowerCAmelCase												=  use_auxiliary_head
						__lowerCAmelCase												=  auxiliary_loss_weight
						__lowerCAmelCase												=  semantic_loss_ignore_index
						__lowerCAmelCase												=  semantic_classifier_dropout



					def        UpperCAmelCase_ (    self     )     ->			Any:
						__lowerCAmelCase												=  copy.deepcopy(self.__dict__     )

						if output["backbone_config"] is not None:
							__lowerCAmelCase												=  self.backbone_config.to_dict()

						__lowerCAmelCase												=  self.__class__.model_type
						return output




'''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__ ):
					a      :     torch.FloatTensor






class 					UpperCAmelCase__	(		UpperCamelCase__							,       UpperCamelCase__ ):



					@register_to_config
					def __init__(    self			,				UpperCamelCase = 16			,				UpperCamelCase = 88			,				UpperCamelCase = None			,				UpperCamelCase = None			,				UpperCamelCase = 1			,				UpperCamelCase = 0.0			,				UpperCamelCase = 32			,				UpperCamelCase = None			,				UpperCamelCase = False			,				UpperCamelCase = None			,				UpperCamelCase = "geglu"			,				UpperCamelCase = True			,				UpperCamelCase = True			,				)     ->			List[str]:
						super().__init__()
						__lowerCAmelCase												=  num_attention_heads
						__lowerCAmelCase												=  attention_head_dim
						__lowerCAmelCase												=  num_attention_heads * attention_head_dim

						__lowerCAmelCase												=  in_channels

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

						# 3. Define transformers blocks
						__lowerCAmelCase												=  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												=  nn.Linear(UpperCamelCase			,				UpperCamelCase     )



					def        UpperCAmelCase_ (    self			,				UpperCamelCase			,				UpperCamelCase=None			,				UpperCamelCase=None			,				UpperCamelCase=None			,				UpperCamelCase=1			,				UpperCamelCase=None			,				UpperCamelCase = True			,				)     ->			List[str]:
						__lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase												=  hidden_states.shape
						__lowerCAmelCase												=  batch_frames // num_frames

						__lowerCAmelCase												=  hidden_states

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

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

						__lowerCAmelCase												=  self.proj_in(UpperCamelCase     )

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

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

						__lowerCAmelCase												=  hidden_states + residual

						if not return_dict:
							return (output,)

						return TransformerTemporalModelOutput(sample=UpperCamelCase     )