





import argparse
import json
import os

import fairseq
import torch
from fairseq.data import Dictionary

from transformers import (
    WavaVecaConfig,
    WavaVecaCTCTokenizer,
    WavaVecaFeatureExtractor,
    WavaVecaForCTC,
    WavaVecaForPreTraining,
    WavaVecaProcessor,
    logging,
)
from transformers.models.wavaveca.modeling_wavaveca import WavaVecaForSequenceClassification


logging.set_verbosity_info()
UpperCamelCase__      =logging.get_logger(__name__)

UpperCamelCase__      ={
    'post_extract_proj': 'feature_projection.projection',
    'encoder.pos_conv.0': 'encoder.pos_conv_embed.conv',
    'self_attn.k_proj': 'encoder.layers.*.attention.k_proj',
    'self_attn.v_proj': 'encoder.layers.*.attention.v_proj',
    'self_attn.q_proj': 'encoder.layers.*.attention.q_proj',
    'self_attn.out_proj': 'encoder.layers.*.attention.out_proj',
    'self_attn_layer_norm': 'encoder.layers.*.layer_norm',
    'fc1': 'encoder.layers.*.feed_forward.intermediate_dense',
    'fc2': 'encoder.layers.*.feed_forward.output_dense',
    'final_layer_norm': 'encoder.layers.*.final_layer_norm',
    'encoder.layer_norm': 'encoder.layer_norm',
    'adapter_layer': 'encoder.layers.*.adapter_layer',
    'w2v_model.layer_norm': 'feature_projection.layer_norm',
    'quantizer.weight_proj': 'quantizer.weight_proj',
    'quantizer.vars': 'quantizer.codevectors',
    'project_q': 'project_q',
    'final_proj': 'project_hid',
    'w2v_encoder.proj': 'lm_head',
    'mask_emb': 'masked_spec_embed',
    'pooling_layer.linear': 'projector',
    'pooling_layer.projection': 'classifier',
}
UpperCamelCase__      =[
    'lm_head',
    'quantizer.weight_proj',
    'quantizer.codevectors',
    'project_q',
    'project_hid',
    'projector',
    'classifier',
]






def     lowerCamelCase__			(__lowerCamelCase	):
     _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							{}
     with open(__lowerCAmelCase,       "r"	) as file:
          for line_number, line in enumerate(__lowerCAmelCase	):
               _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							line.strip()
               if line:
                    _SCREAMING_SNAKE_CASE       :	Tuple						    =							line.split()
                    _SCREAMING_SNAKE_CASE       :	Any						    =							line_number
                    _SCREAMING_SNAKE_CASE       :	Any						    =							words[0]
                    _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							value
     return result






def     lowerCamelCase__			(__lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase	):
     for attribute in key.split("."	):
          _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							getattr(__lowerCAmelCase,       __lowerCAmelCase	)

     _SCREAMING_SNAKE_CASE       :	Any						    =							None
     for param_key in PARAM_MAPPING.keys():
          if full_name.endswith(__lowerCAmelCase	):
               _SCREAMING_SNAKE_CASE       :	str						    =							PARAM_MAPPING[full_name.split("."	)[-1]]
               _SCREAMING_SNAKE_CASE       :	int						    =							"param"

     if weight_type is not None and weight_type != "param":
          _SCREAMING_SNAKE_CASE       :	List[Any]						    =							getattr(__lowerCAmelCase,       __lowerCAmelCase	).shape
     elif weight_type is not None and weight_type == "param":
          _SCREAMING_SNAKE_CASE       :	int						    =							hf_pointer
          for attribute in hf_param_name.split("."	):
               _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							getattr(__lowerCAmelCase,       __lowerCAmelCase	)
          _SCREAMING_SNAKE_CASE       :	List[str]						    =							shape_pointer.shape

          # let's reduce dimension
          _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							value[0]
     else:
          _SCREAMING_SNAKE_CASE       :	Dict						    =							hf_pointer.shape

     if hf_shape != value.shape:
          raise ValueError(
              f"""Shape of hf {key + '.' + weight_type if weight_type is not None else ''} is {hf_shape}, but should be"""
              f""" {value.shape} for {full_name}"""	)

     if weight_type == "weight":
          _SCREAMING_SNAKE_CASE       :	Tuple						    =							value
     elif weight_type == "weight_g":
          _SCREAMING_SNAKE_CASE       :	Dict						    =							value
     elif weight_type == "weight_v":
          _SCREAMING_SNAKE_CASE       :	Any						    =							value
     elif weight_type == "bias":
          _SCREAMING_SNAKE_CASE       :	Dict						    =							value
     elif weight_type == "param":
          for attribute in hf_param_name.split("."	):
               _SCREAMING_SNAKE_CASE       :	List[str]						    =							getattr(__lowerCAmelCase,       __lowerCAmelCase	)
          _SCREAMING_SNAKE_CASE       :	int						    =							value
     else:
          _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							value

     logger.info(f"""{key + '.' + weight_type if weight_type is not None else ''} was initialized from {full_name}."""	)






def     lowerCamelCase__			(__lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase	):
     _SCREAMING_SNAKE_CASE       :	Dict						    =							None
     for param_key in PARAM_MAPPING.keys():
          if full_name.endswith(__lowerCAmelCase	):
               _SCREAMING_SNAKE_CASE       :	Tuple						    =							PARAM_MAPPING[full_name.split("."	)[-1]]
               _SCREAMING_SNAKE_CASE       :	List[Any]						    =							"param"

     if weight_type is not None and weight_type != "param":
          _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							".".join([key, weight_type]	)
     elif weight_type is not None and weight_type == "param":
          _SCREAMING_SNAKE_CASE       :	List[Any]						    =							".".join([key, hf_param_name]	)
     else:
          _SCREAMING_SNAKE_CASE       :	Any						    =							key

     _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							value if "lm_head" in full_key else value[0]


UpperCamelCase__      ={
    'W_a': 'linear_1.weight',
    'W_b': 'linear_2.weight',
    'b_a': 'linear_1.bias',
    'b_b': 'linear_2.bias',
    'ln_W': 'norm.weight',
    'ln_b': 'norm.bias',
}






def     lowerCamelCase__			(__lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase=None,       __lowerCamelCase=None	):
     _SCREAMING_SNAKE_CASE       :	Tuple						    =							False
     for key, mapped_key in MAPPING.items():
          _SCREAMING_SNAKE_CASE       :	Any						    =							"wav2vec2." + mapped_key if mapped_key not in TOP_LEVEL_KEYS else mapped_key
          if key in name or key.split("w2v_model."	)[-1] == name.split("."	)[0]:
               _SCREAMING_SNAKE_CASE       :	List[str]						    =							True
               if "*" in mapped_key:
                    _SCREAMING_SNAKE_CASE       :	Dict						    =							name.split(__lowerCAmelCase	)[0].split("."	)[-2]
                    _SCREAMING_SNAKE_CASE       :	str						    =							mapped_key.replace("*",       __lowerCAmelCase	)
               if "weight_g" in name:
                    _SCREAMING_SNAKE_CASE       :	Dict						    =							"weight_g"
               elif "weight_v" in name:
                    _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							"weight_v"
               elif "bias" in name:
                    _SCREAMING_SNAKE_CASE       :	Tuple						    =							"bias"
               elif "weight" in name:
                    # TODO: don't match quantizer.weight_proj
                    _SCREAMING_SNAKE_CASE       :	Tuple						    =							"weight"
               else:
                    _SCREAMING_SNAKE_CASE       :	Any						    =							None
               if hf_dict is not None:
                    rename_dict(__lowerCAmelCase,       __lowerCAmelCase,       __lowerCAmelCase,       __lowerCAmelCase,       __lowerCAmelCase	)
               else:
                    set_recursively(__lowerCAmelCase,       __lowerCAmelCase,       __lowerCAmelCase,       __lowerCAmelCase,       __lowerCAmelCase	)
               return is_used
     return is_used






def     lowerCamelCase__			(__lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase	):
     _SCREAMING_SNAKE_CASE       :	str						    =							[]
     _SCREAMING_SNAKE_CASE       :	Tuple						    =							fairseq_model.state_dict()

     _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							hf_model.wavaveca.feature_extractor

     for name, value in fairseq_dict.items():
          _SCREAMING_SNAKE_CASE       :	List[str]						    =							False
          if "conv_layers" in name:
               load_conv_layer(
                   __lowerCAmelCase,       __lowerCAmelCase,       __lowerCAmelCase,       __lowerCAmelCase,       hf_model.config.feat_extract_norm == "group",       )
               _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							True
          else:
               _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							load_wavaveca_layer(__lowerCAmelCase,       __lowerCAmelCase,       __lowerCAmelCase	)
          if not is_used:
               unused_weights.append(__lowerCAmelCase	)

     logger.warning(f"""Unused weights: {unused_weights}"""	)






def     lowerCamelCase__			(__lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase	):
     _SCREAMING_SNAKE_CASE       :	Any						    =							full_name.split("conv_layers."	)[-1]
     _SCREAMING_SNAKE_CASE       :	List[str]						    =							name.split("."	)
     _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							int(items[0]	)
     _SCREAMING_SNAKE_CASE       :	Any						    =							int(items[1]	)

     if type_id == 0:
          if "bias" in name:
               if value.shape != feature_extractor.conv_layers[layer_id].conv.bias.data.shape:
                    raise ValueError(
                        f"""{full_name} has size {value.shape}, but"""
                        f""" {feature_extractor.conv_layers[layer_id].conv.bias.data.shape} was found."""	)
               _SCREAMING_SNAKE_CASE       :	List[str]						    =							value
               logger.info(f"""Feat extract conv layer {layer_id} was initialized from {full_name}."""	)
          elif "weight" in name:
               if value.shape != feature_extractor.conv_layers[layer_id].conv.weight.data.shape:
                    raise ValueError(
                        f"""{full_name} has size {value.shape}, but"""
                        f""" {feature_extractor.conv_layers[layer_id].conv.weight.data.shape} was found."""	)
               _SCREAMING_SNAKE_CASE       :	List[str]						    =							value
               logger.info(f"""Feat extract conv layer {layer_id} was initialized from {full_name}."""	)
     elif (type_id == 2 and not use_group_norm) or (type_id == 2 and layer_id == 0 and use_group_norm):
          if "bias" in name:
               if value.shape != feature_extractor.conv_layers[layer_id].layer_norm.bias.data.shape:
                    raise ValueError(
                        f"""{full_name} has size {value.shape}, but"""
                        f""" {feature_extractor.conv_layers[layer_id].layer_norm.bias.data.shape} was found."""	)
               _SCREAMING_SNAKE_CASE       :	Dict						    =							value
               logger.info(f"""Feat extract layer norm weight of layer {layer_id} was initialized from {full_name}."""	)
          elif "weight" in name:
               if value.shape != feature_extractor.conv_layers[layer_id].layer_norm.weight.data.shape:
                    raise ValueError(
                        f"""{full_name} has size {value.shape}, but"""
                        f""" {feature_extractor.conv_layers[layer_id].layer_norm.weight.data.shape} was found."""	)
               _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							value
               logger.info(f"""Feat extract layer norm weight of layer {layer_id} was initialized from {full_name}."""	)
     else:
          unused_weights.append(__lowerCAmelCase	)






@torch.no_grad()
def     lowerCamelCase__			(__lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase=None,       __lowerCamelCase=None,       __lowerCamelCase=True,       __lowerCamelCase=False	):
     if config_path is not None:
          _SCREAMING_SNAKE_CASE       :	List[Any]						    =							WavaVecaConfig.from_pretrained(__lowerCAmelCase	)
     else:
          _SCREAMING_SNAKE_CASE       :	List[str]						    =							WavaVecaConfig()

     if is_seq_class:
          _SCREAMING_SNAKE_CASE       :	int						    =							read_txt_into_dict(__lowerCAmelCase	)
          _SCREAMING_SNAKE_CASE       :	str						    =							idalabel
          _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							WavaVecaForSequenceClassification(__lowerCAmelCase	)
          _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							WavaVecaFeatureExtractor(
              feature_size=1,       sampling_rate=16000,       padding_value=0,       do_normalize=__lowerCAmelCase,       return_attention_mask=__lowerCAmelCase,       )
          feature_extractor.save_pretrained(__lowerCAmelCase	)

     elif is_finetuned:
          if dict_path:
               _SCREAMING_SNAKE_CASE       :	List[str]						    =							Dictionary.load(__lowerCAmelCase	)

               # important change bos & pad token id since CTC symbol is <pad> and
               # not <s> as in fairseq
               _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							target_dict.pad_index
               _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							target_dict.bos_index
               _SCREAMING_SNAKE_CASE       :	str						    =							target_dict.eos_index
               _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							len(target_dict.symbols	)
               _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							os.path.join(__lowerCAmelCase,       "vocab.json"	)
               if not os.path.isdir(__lowerCAmelCase	):
                    logger.error("--pytorch_dump_folder_path ({}) should be a directory".format(__lowerCAmelCase	)	)
                    return
               os.makedirs(__lowerCAmelCase,       exist_ok=__lowerCAmelCase	)
               _SCREAMING_SNAKE_CASE       :	Dict						    =							target_dict.indices

               # fairseq has the <pad> and <s> switched
               _SCREAMING_SNAKE_CASE       :	Any						    =							0
               _SCREAMING_SNAKE_CASE       :	Tuple						    =							1
               with open(__lowerCAmelCase,       "w",       encoding="utf-8"	) as vocab_handle:
                    json.dump(__lowerCAmelCase,       __lowerCAmelCase	)
               _SCREAMING_SNAKE_CASE       :	Any						    =							WavaVecaCTCTokenizer(
                   __lowerCAmelCase,       unk_token=target_dict.unk_word,       pad_token=target_dict.pad_word,       bos_token=target_dict.bos_word,       eos_token=target_dict.eos_word,       word_delimiter_token="|",       do_lower_case=__lowerCAmelCase,       )
               _SCREAMING_SNAKE_CASE       :	int						    =							True if config.feat_extract_norm == "layer" else False
               _SCREAMING_SNAKE_CASE       :	List[Any]						    =							WavaVecaFeatureExtractor(
                   feature_size=1,       sampling_rate=16000,       padding_value=0,       do_normalize=__lowerCAmelCase,       return_attention_mask=__lowerCAmelCase,       )
               _SCREAMING_SNAKE_CASE       :	List[str]						    =							WavaVecaProcessor(feature_extractor=__lowerCAmelCase,       tokenizer=__lowerCAmelCase	)
               processor.save_pretrained(__lowerCAmelCase	)

          _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							WavaVecaForCTC(__lowerCAmelCase	)
     else:
          _SCREAMING_SNAKE_CASE       :	Tuple						    =							WavaVecaForPreTraining(__lowerCAmelCase	)

     if is_finetuned or is_seq_class:
          _SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE       :	Optional[int]						    =							fairseq.checkpoint_utils.load_model_ensemble_and_task(
              [checkpoint_path],       arg_overrides={"data": "/".join(dict_path.split("/"	)[:-1]	)}	)
     else:
          _SCREAMING_SNAKE_CASE       :	Any						    =							argparse.Namespace(task="audio_pretraining"	)
          _SCREAMING_SNAKE_CASE       :	Dict						    =							fairseq.tasks.setup_task(__lowerCAmelCase	)

          _SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE       :	int						    =							fairseq.checkpoint_utils.load_model_ensemble_and_task([checkpoint_path],       task=__lowerCAmelCase	)

     _SCREAMING_SNAKE_CASE       :	int						    =							model[0].eval()

     recursively_load_weights(__lowerCAmelCase,       __lowerCAmelCase,       not is_finetuned	)

     hf_wavavec.save_pretrained(__lowerCAmelCase	)


if __name__ == "__main__":
       UpperCamelCase__      =argparse.ArgumentParser()
       parser.add_argument('--pytorch_dump_folder_path', default=None, type=str, help='Path to the output PyTorch model.')
       parser.add_argument('--checkpoint_path', default=None, type=str, help='Path to fairseq checkpoint')
       parser.add_argument('--dict_path', default=None, type=str, help='Path to dict of fine-tuned model')
       parser.add_argument('--config_path', default=None, type=str, help='Path to hf config.json of model to convert')
       parser.add_argument(
           '--not_finetuned', action='store_true', help='Whether the model to convert is a fine-tuned model or not'
       )
       parser.add_argument(
           '--is_seq_class',
           action='store_true',
           help='Whether the model to convert is a fine-tuned sequence classification model or not',
       )
       UpperCamelCase__      =parser.parse_args()

       UpperCamelCase__      =not args.not_finetuned and not args.is_seq_class
       convert_wavaveca_checkpoint(
           args.checkpoint_path,
           args.pytorch_dump_folder_path,
           args.config_path,
           args.dict_path,
           is_finetuned,
           args.is_seq_class,
       )






import copy
import os
from typing import TYPE_CHECKING, List, Union


if TYPE_CHECKING:
       pass

from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase__      =logging.get_logger(__name__)

UpperCamelCase__      ={
    'kakaobrain/align-base': 'https://huggingface.co/kakaobrain/align-base/resolve/main/config.json',
}





class 			lowerCAmelCase__( __lowercase    ):






       '''simple docstring'''


       __snake_case 			=    'align_text_model'




       def __init__(      self    ,						__lowerCamelCase=3_0_5_2_2    ,						__lowerCamelCase=7_6_8    ,						__lowerCamelCase=1_2    ,						__lowerCamelCase=1_2    ,						__lowerCamelCase=3_0_7_2    ,						__lowerCamelCase="gelu"    ,						__lowerCamelCase=0.1    ,						__lowerCamelCase=0.1    ,						__lowerCamelCase=5_1_2    ,						__lowerCamelCase=2    ,						__lowerCamelCase=0.02    ,						__lowerCamelCase=1E-12    ,						__lowerCamelCase=0    ,						__lowerCamelCase="absolute"    ,						__lowerCamelCase=True    ,						**__lowerCamelCase    ,						)			->     List[Any]:
            super().__init__(**__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	Tuple						    =							vocab_size
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							hidden_size
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							num_hidden_layers
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							num_attention_heads
            _SCREAMING_SNAKE_CASE       :	int						    =							hidden_act
            _SCREAMING_SNAKE_CASE       :	Any						    =							intermediate_size
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							hidden_dropout_prob
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							attention_probs_dropout_prob
            _SCREAMING_SNAKE_CASE       :	Dict						    =							max_position_embeddings
            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							type_vocab_size
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							initializer_range
            _SCREAMING_SNAKE_CASE       :	Dict						    =							layer_norm_eps
            _SCREAMING_SNAKE_CASE       :	str						    =							position_embedding_type
            _SCREAMING_SNAKE_CASE       :	Dict						    =							use_cache
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							pad_token_id







       @classmethod
       def     UpperCamelCase_			(      cls    ,						__lowerCamelCase    ,						**__lowerCamelCase							)			->     "PretrainedConfig":
            cls._set_token_in_kwargs(__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE       :	List[Any]						    =							cls.get_config_dict(__lowerCamelCase    ,						**__lowerCamelCase							)

            # get the text config dict if we are loading from AlignConfig
            if config_dict.get("model_type"							) == "align":
                 _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							config_dict["text_config"]

            if "model_type" in config_dict and hasattr(cls    ,						"model_type"							) and config_dict["model_type"] != cls.model_type:
                 logger.warning(
                     F"""You are using a model of type {config_dict['model_type']} to instantiate a model of type """
                     F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""							)

            return cls.from_dict(__lowerCamelCase    ,						**__lowerCamelCase							)





class 			lowerCAmelCase__( __lowercase    ):






       '''simple docstring'''


       __snake_case 			=    'align_vision_model'




       def __init__(      self    ,						__lowerCamelCase = 3    ,						__lowerCamelCase = 6_0_0    ,						__lowerCamelCase = 2.0    ,						__lowerCamelCase = 3.1    ,						__lowerCamelCase = 8    ,						__lowerCamelCase = [3, 3, 5, 3, 5, 5, 3]    ,						__lowerCamelCase = [3_2, 1_6, 2_4, 4_0, 8_0, 1_1_2, 1_9_2]    ,						__lowerCamelCase = [1_6, 2_4, 4_0, 8_0, 1_1_2, 1_9_2, 3_2_0]    ,						__lowerCamelCase = []    ,						__lowerCamelCase = [1, 2, 2, 2, 1, 2, 1]    ,						__lowerCamelCase = [1, 2, 2, 3, 3, 4, 1]    ,						__lowerCamelCase = [1, 6, 6, 6, 6, 6, 6]    ,						__lowerCamelCase = 0.25    ,						__lowerCamelCase = "swish"    ,						__lowerCamelCase = 2_5_6_0    ,						__lowerCamelCase = "mean"    ,						__lowerCamelCase = 0.02    ,						__lowerCamelCase = 0.001    ,						__lowerCamelCase = 0.99    ,						__lowerCamelCase = 0.2    ,						**__lowerCamelCase    ,						)			->     Dict:
            super().__init__(**__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	int						    =							num_channels
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							image_size
            _SCREAMING_SNAKE_CASE       :	Dict						    =							width_coefficient
            _SCREAMING_SNAKE_CASE       :	str						    =							depth_coefficient
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							depth_divisor
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							kernel_sizes
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							in_channels
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							out_channels
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							depthwise_padding
            _SCREAMING_SNAKE_CASE       :	str						    =							strides
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							num_block_repeats
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							expand_ratios
            _SCREAMING_SNAKE_CASE       :	int						    =							squeeze_expansion_ratio
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							hidden_act
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							hidden_dim
            _SCREAMING_SNAKE_CASE       :	Dict						    =							pooling_type
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							initializer_range
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							batch_norm_eps
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							batch_norm_momentum
            _SCREAMING_SNAKE_CASE       :	int						    =							drop_connect_rate
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							sum(__lowerCamelCase							) * 4







       @classmethod
       def     UpperCamelCase_			(      cls    ,						__lowerCamelCase    ,						**__lowerCamelCase							)			->     "PretrainedConfig":
            cls._set_token_in_kwargs(__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE       :	int						    =							cls.get_config_dict(__lowerCamelCase    ,						**__lowerCamelCase							)

            # get the vision config dict if we are loading from AlignConfig
            if config_dict.get("model_type"							) == "align":
                 _SCREAMING_SNAKE_CASE       :	int						    =							config_dict["vision_config"]

            if "model_type" in config_dict and hasattr(cls    ,						"model_type"							) and config_dict["model_type"] != cls.model_type:
                 logger.warning(
                     F"""You are using a model of type {config_dict['model_type']} to instantiate a model of type """
                     F"""{cls.model_type}. This is not supported for all configurations of models and can yield errors."""							)

            return cls.from_dict(__lowerCamelCase    ,						**__lowerCamelCase							)





class 			lowerCAmelCase__( __lowercase    ):






       '''simple docstring'''


       __snake_case 			=    'align'
       __snake_case 			=    True




       def __init__(      self    ,						__lowerCamelCase=None    ,						__lowerCamelCase=None    ,						__lowerCamelCase=6_4_0    ,						__lowerCamelCase=1.0    ,						__lowerCamelCase=0.02    ,						**__lowerCamelCase    ,						)			->     List[Any]:
            super().__init__(**__lowerCamelCase							)

            if text_config is None:
                 _SCREAMING_SNAKE_CASE       :	List[Any]						    =							{}
                 logger.info("text_config is None. Initializing the AlignTextConfig with default values."							)

            if vision_config is None:
                 _SCREAMING_SNAKE_CASE       :	List[str]						    =							{}
                 logger.info("vision_config is None. Initializing the AlignVisionConfig with default values."							)

            _SCREAMING_SNAKE_CASE       :	Dict						    =							AlignTextConfig(**__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	Any						    =							AlignVisionConfig(**__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	int						    =							projection_dim
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							temperature_init_value
            _SCREAMING_SNAKE_CASE       :	Any						    =							initializer_range




       @classmethod
       def     UpperCamelCase_			(      cls    ,						__lowerCamelCase    ,						__lowerCamelCase    ,						**__lowerCamelCase							)			->     List[str]:
            return cls(text_config=text_config.to_dict()    ,						vision_config=vision_config.to_dict()    ,						**__lowerCamelCase							)







       def     UpperCamelCase_			(      self							)			->     Union[str, Any]:
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							copy.deepcopy(self.__dict__							)
            _SCREAMING_SNAKE_CASE       :	Any						    =							self.text_config.to_dict()
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							self.vision_config.to_dict()
            _SCREAMING_SNAKE_CASE       :	Dict						    =							self.__class__.model_type
            return output