



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


__snake_case						:Any      		=     logging.get_logger(__name__)

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

class     _A       (	__UpperCAmelCase      ,__UpperCAmelCase    ):
       UpperCamelCase__  :    Any											=						'''focalnet'''



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


           '''simple docstring'''

           super().__init__(**__SCREAMING_SNAKE_CASE)

           __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=__SCREAMING_SNAKE_CASE     ,		out_indices=__SCREAMING_SNAKE_CASE     ,		stage_names=self.stage_names)









from typing import Union

import fire
import torch
from tqdm import tqdm



def 	lowerCAmelCase       (						lowerCAmelCase_       ,      lowerCAmelCase_ = "cpu"       ,      lowerCAmelCase_ = None       )->       None:
				lowerCAmelCase_       :					str			 = torch.load(lowerCAmelCase_       ,      map_location=lowerCAmelCase_       )
				for k, v in tqdm(state_dict.items()       ):
								if not isinstance(lowerCAmelCase_       ,      torch.Tensor       ):
												raise TypeError('''FP16 conversion only works on paths that are saved state dicts, like pytorch_model.bin'''       )
								lowerCAmelCase_       :					int			 = v.half()
				if save_path is None:  # overwrite src_path
								lowerCAmelCase_       :					Tuple			 = src_path
				torch.save(lowerCAmelCase_       ,      lowerCAmelCase_       )


if __name__ == "__main__":
						fire.Fire(convert)