



"""simple docstring"""





class    _lowerCAmelCase    :





		"""simple docstring"""






		def __init__(					self							,    _lowercase   ) ->						None:







								'''simple docstring'''

								snake_case_   : Any						=			size
								snake_case_   : Tuple						=			[0] * size
								snake_case_   : Dict						=			[0] * size





		@staticmethod
		def    UpperCAmelCase__							(					_lowercase   ) ->						int:







								'''simple docstring'''

								return index | (index + 1)





		@staticmethod
		def    UpperCAmelCase__							(					_lowercase   ) ->						int:







								'''simple docstring'''

								return (index & (index + 1)) - 1





		def    UpperCAmelCase__							(					self							,    _lowercase							,    _lowercase   ) ->						None:







								'''simple docstring'''

								snake_case_   : List[str]						=			value
								while index < self.size:
														snake_case_   : Any						=			self.get_prev(_lowercase   ) + 1
														if current_left_border == index:
																				snake_case_   : Tuple						=			value
														else:
																				snake_case_   : Dict						=			max(_lowercase							,    _lowercase							,    _lowercase   )
														snake_case_   : str						=			self.get_next(_lowercase   )





		def    UpperCAmelCase__							(					self							,    _lowercase							,    _lowercase   ) ->						int:







								'''simple docstring'''

								right -= 1  # Because of right is exclusive
								snake_case_   : Tuple						=			0
								while left <= right:
														snake_case_   : str						=			self.get_prev(_lowercase   )
														if left <= current_left:
																				snake_case_   : int						=			max(_lowercase							,    self.tree[right]   )
																				snake_case_   : Dict						=			current_left
														else:
																				snake_case_   : List[Any]						=			max(_lowercase							,    self.arr[right]   )
																				right -= 1
								return result


if __name__ == "__main__":
					import doctest

					doctest.testmod()






"""simple docstring"""





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


__lowerCAmelCase       :					str      					=					logging.get_logger(__name__)

__lowerCAmelCase       :					Tuple      					=					{
    '''shi-labs/nat-mini-in1k-224''': '''https://huggingface.co/shi-labs/nat-mini-in1k-224/resolve/main/config.json''',
    # See all Nat models at https://huggingface.co/models?filter=nat
}



class    _lowerCAmelCase    (				SCREAMING_SNAKE_CASE__  ,				SCREAMING_SNAKE_CASE__		):





		"""simple docstring"""






		_lowerCamelCase			  =       '''nat'''

		_lowerCamelCase			  =       {
		    '''num_attention_heads''': '''num_heads''',
		    '''num_hidden_layers''': '''num_layers''',
		}





		def __init__(					self							,    _lowercase=4							,    _lowercase=3							,    _lowercase=6_4							,    _lowercase=[3, 4, 6, 5]							,    _lowercase=[2, 4, 8, 1_6]							,    _lowercase=7							,    _lowercase=3.0							,    _lowercase=True							,    _lowercase=0.0							,    _lowercase=0.0							,    _lowercase=0.1							,    _lowercase="gelu"							,    _lowercase=0.02							,    _lowercase=1E-5							,    _lowercase=0.0							,    _lowercase=None							,    _lowercase=None							,    **_lowercase							,    ) ->						Optional[Any]:







								'''simple docstring'''

								super().__init__(**_lowercase   )

								snake_case_   : Any						=			patch_size
								snake_case_   : Optional[Any]						=			num_channels
								snake_case_   : Optional[Any]						=			embed_dim
								snake_case_   : Tuple						=			depths
								snake_case_   : int						=			len(_lowercase   )
								snake_case_   : Optional[int]						=			num_heads
								snake_case_   : List[str]						=			kernel_size
								snake_case_   : str						=			mlp_ratio
								snake_case_   : str						=			qkv_bias
								snake_case_   : str						=			hidden_dropout_prob
								snake_case_   : Tuple						=			attention_probs_dropout_prob
								snake_case_   : Tuple						=			drop_path_rate
								snake_case_   : Dict						=			hidden_act
								snake_case_   : Union[str, Any]						=			layer_norm_eps
								snake_case_   : Tuple						=			initializer_range
								# we set the hidden_size attribute in order to make Nat work with VisionEncoderDecoderModel
								# this indicates the channel dimension after the last stage of the model
								snake_case_   : Union[str, Any]						=			int(embed_dim * 2 ** (len(_lowercase   ) - 1)   )
								snake_case_   : Union[str, Any]						=			layer_scale_init_value
								snake_case_   : Optional[Any]						=			["""stem"""] + [f'stage{idx}' for idx in range(1							,    len(_lowercase   ) + 1   )]
								snake_case_			,		snake_case_   : Any						=			get_aligned_output_features_output_indices(
								    out_features=_lowercase							,    out_indices=_lowercase							,    stage_names=self.stage_names   )

