






import torch
import torch.nn as nn
from transformers.modeling_utils import ModuleUtilsMixin
from transformers.models.ta.modeling_ta import TaBlock, TaConfig, TaLayerNorm

from ...configuration_utils import ConfigMixin, register_to_config
from ...models import ModelMixin



class 		_lowercase		(       UpperCAmelCase__,   UpperCAmelCase__,   UpperCAmelCase__	):

   @register_to_config
   def __init__(      self			:       Any							,   __lowerCAmelCase			:       int							,   __lowerCAmelCase			:       int							,   __lowerCAmelCase			:       int							,   __lowerCAmelCase			:       float							,   __lowerCAmelCase			:       int							,   __lowerCAmelCase			:       int							,   __lowerCAmelCase			:       int							,   __lowerCAmelCase			:       int							,   __lowerCAmelCase			:       str							,   __lowerCAmelCase			:       bool = False							,   )       ->				Union[str, Any]:


    """simple docstring"""






    super().__init__()

    a						=		nn.Embedding(__UpperCamelCase							,   __UpperCamelCase							)

    a						=		nn.Embedding(__UpperCamelCase							,   __UpperCamelCase							)
    a						=		False

    a						=		nn.Dropout(p=__UpperCamelCase							)

    a						=		TaConfig(
        vocab_size=__UpperCamelCase							,   d_model=__UpperCamelCase							,   num_heads=__UpperCamelCase							,   d_kv=__UpperCamelCase							,   d_ff=__UpperCamelCase							,   dropout_rate=__UpperCamelCase							,   feed_forward_proj=__UpperCamelCase							,   is_decoder=__UpperCamelCase							,   is_encoder_decoder=__UpperCamelCase							,   )

    a						=		nn.ModuleList()
    for lyr_num in range(__UpperCamelCase							):
     a						=		TaBlock(__UpperCamelCase							)
     self.encoders.append(__UpperCamelCase							)

    a						=		TaLayerNorm(__UpperCamelCase							)
    a						=		nn.Dropout(p=__UpperCamelCase							)




   def 		A							(      self			:       List[str]							,   __lowerCAmelCase			:       Optional[int]							,   __lowerCAmelCase			:       Optional[Any]							)       ->				int:


    """simple docstring"""






    a						=		self.token_embedder(__UpperCamelCase							)

    a						=		encoder_input_tokens.shape[1]
    a						=		torch.arange(__UpperCamelCase							,   device=encoder_input_tokens.device							)
    x += self.position_encoding(__UpperCamelCase							)

    a						=		self.dropout_pre(__UpperCamelCase							)

    # inverted the attention mask
    a						=		encoder_input_tokens.size()
    a						=		self.get_extended_attention_mask(__UpperCamelCase							,   __UpperCamelCase							)

    for lyr in self.encoders:
     a						=		lyr(__UpperCamelCase							,   __UpperCamelCase							)[0]
    a						=		self.layer_norm(__UpperCamelCase							)

    return self.dropout_post(__UpperCamelCase							), encoder_inputs_mask






from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


A_		:     int        =     logging.get_logger(__name__)

A_		:     str        =     {
    '''microsoft/focalnet-tiny''': '''https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json''',
}



class 		_lowercase		(       UpperCAmelCase__,   UpperCAmelCase__	):
   _UpperCAmelCase     	=			'''focalnet'''

   def __init__(      self			:       int							,   __lowerCAmelCase			:       Optional[Any]=224							,   __lowerCAmelCase			:       Any=4							,   __lowerCAmelCase			:       Any=3							,   __lowerCAmelCase			:       Tuple=96							,   __lowerCAmelCase			:       Dict=False							,   __lowerCAmelCase			:       Optional[int]=[192, 384, 768, 768]							,   __lowerCAmelCase			:       Union[str, Any]=[2, 2, 6, 2]							,   __lowerCAmelCase			:       Optional[int]=[2, 2, 2, 2]							,   __lowerCAmelCase			:       Union[str, Any]=[3, 3, 3, 3]							,   __lowerCAmelCase			:       str="gelu"							,   __lowerCAmelCase			:       Any=4.0							,   __lowerCAmelCase			:       Optional[int]=0.0							,   __lowerCAmelCase			:       Tuple=0.1							,   __lowerCAmelCase			:       str=False							,   __lowerCAmelCase			:       Optional[int]=1E-4							,   __lowerCAmelCase			:       Optional[Any]=False							,   __lowerCAmelCase			:       Union[str, Any]=False							,   __lowerCAmelCase			:       str=False							,   __lowerCAmelCase			:       Any=0.0_2							,   __lowerCAmelCase			:       str=1E-5							,   __lowerCAmelCase			:       Optional[Any]=32							,   __lowerCAmelCase			:       Dict=None							,   __lowerCAmelCase			:       str=None							,   **__lowerCAmelCase			:       Any							,   )       ->				List[str]:


    """simple docstring"""






    super().__init__(**__lowerCAmelCase							)

    a						=		image_size
    a						=		patch_size
    a						=		num_channels
    a						=		embed_dim
    a						=		use_conv_embed
    a						=		hidden_sizes
    a						=		depths
    a						=		focal_levels
    a						=		focal_windows
    a						=		hidden_act
    a						=		mlp_ratio
    a						=		hidden_dropout_prob
    a						=		drop_path_rate
    a						=		use_layerscale
    a						=		layerscale_value
    a						=		use_post_layernorm
    a						=		use_post_layernorm_in_modulation
    a						=		normalize_modulator
    a						=		initializer_range
    a						=		layer_norm_eps
    a						=		encoder_stride
    a						=		["stem"] + [f"""stage{idx}""" for idx in range(1							,   len(self.depths							) + 1							)]
    a		,  a						=		get_aligned_output_features_output_indices(
        out_features=__lowerCAmelCase							,   out_indices=__lowerCAmelCase							,   stage_names=self.stage_names							)

