





from typing import Optional, Union

import torch
from torch import nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...modeling_outputs import BaseModelOutputWithPoolingAndNoAttention, ImageClassifierOutputWithNoAttention
from ...modeling_utils import PreTrainedModel
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_mobilenet_va import MobileNetVaConfig


UpperCamelCase__      =logging.get_logger(__name__)


# General docstring
UpperCamelCase__      ='MobileNetV1Config'

# Base docstring
UpperCamelCase__      ='google/mobilenet_v1_1.0_224'
UpperCamelCase__      =[1, 1024, 7, 7]

# Image classification docstring
UpperCamelCase__      ='google/mobilenet_v1_1.0_224'
UpperCamelCase__      ='tabby, tabby cat'


UpperCamelCase__      =[
    'google/mobilenet_v1_1.0_224',
    'google/mobilenet_v1_0.75_192',
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
]






def     lowerCamelCase__			(__lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase=None	):
     _SCREAMING_SNAKE_CASE       :	int						    =							{}

     if isinstance(__lowerCamelCase,       __lowerCamelCase	):
          _SCREAMING_SNAKE_CASE       :	List[Any]						    =							model.mobilenet_va
     else:
          _SCREAMING_SNAKE_CASE       :	List[Any]						    =							model

     _SCREAMING_SNAKE_CASE       :	List[str]						    =							"MobilenetV1/Conv2d_0/"
     _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							backbone.conv_stem.convolution.weight
     _SCREAMING_SNAKE_CASE       :	Any						    =							backbone.conv_stem.normalization.bias
     _SCREAMING_SNAKE_CASE       :	Dict						    =							backbone.conv_stem.normalization.weight
     _SCREAMING_SNAKE_CASE       :	str						    =							backbone.conv_stem.normalization.running_mean
     _SCREAMING_SNAKE_CASE       :	Dict						    =							backbone.conv_stem.normalization.running_var

     for i in range(13	):
          _SCREAMING_SNAKE_CASE       :	Tuple						    =							i + 1
          _SCREAMING_SNAKE_CASE       :	str						    =							i * 2

          _SCREAMING_SNAKE_CASE       :	Dict						    =							backbone.layer[pt_index]
          _SCREAMING_SNAKE_CASE       :	Any						    =							f"""MobilenetV1/Conv2d_{tf_index}_depthwise/"""
          _SCREAMING_SNAKE_CASE       :	Any						    =							pointer.convolution.weight
          _SCREAMING_SNAKE_CASE       :	str						    =							pointer.normalization.bias
          _SCREAMING_SNAKE_CASE       :	List[str]						    =							pointer.normalization.weight
          _SCREAMING_SNAKE_CASE       :	Tuple						    =							pointer.normalization.running_mean
          _SCREAMING_SNAKE_CASE       :	Any						    =							pointer.normalization.running_var

          _SCREAMING_SNAKE_CASE       :	Tuple						    =							backbone.layer[pt_index + 1]
          _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							f"""MobilenetV1/Conv2d_{tf_index}_pointwise/"""
          _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							pointer.convolution.weight
          _SCREAMING_SNAKE_CASE       :	str						    =							pointer.normalization.bias
          _SCREAMING_SNAKE_CASE       :	Dict						    =							pointer.normalization.weight
          _SCREAMING_SNAKE_CASE       :	int						    =							pointer.normalization.running_mean
          _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							pointer.normalization.running_var

     if isinstance(__lowerCamelCase,       __lowerCamelCase	):
          _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							"MobilenetV1/Logits/Conv2d_1c_1x1/"
          _SCREAMING_SNAKE_CASE       :	Tuple						    =							model.classifier.weight
          _SCREAMING_SNAKE_CASE       :	List[str]						    =							model.classifier.bias

     return tf_to_pt_map






def     lowerCamelCase__			(__lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase	):
     try:
          import numpy as np
          import tensorflow as tf
     except ImportError:
          logger.error(
              "Loading a TensorFlow models in PyTorch, requires TensorFlow to be installed. Please see "
              "https://www.tensorflow.org/install/ for installation instructions."	)
          raise

     # Load weights from TF model
     _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							tf.train.list_variables(__lowerCamelCase	)
     _SCREAMING_SNAKE_CASE       :	str						    =							{}
     for name, shape in init_vars:
          logger.info(f"""Loading TF weight {name} with shape {shape}"""	)
          _SCREAMING_SNAKE_CASE       :	Dict						    =							tf.train.load_variable(__lowerCamelCase,       __lowerCamelCase	)
          _SCREAMING_SNAKE_CASE       :	List[str]						    =							array

     # Build TF to PyTorch weights loading map
     _SCREAMING_SNAKE_CASE       :	str						    =							_build_tf_to_pytorch_map(__lowerCamelCase,       __lowerCamelCase,       __lowerCamelCase	)

     for name, pointer in tf_to_pt_map.items():
          logger.info(f"""Importing {name}"""	)
          if name not in tf_weights:
               logger.info(f"""{name} not in tf pre-trained weights, skipping"""	)
               continue

          _SCREAMING_SNAKE_CASE       :	str						    =							tf_weights[name]

          if "depthwise_weights" in name:
               logger.info("Transposing depthwise"	)
               _SCREAMING_SNAKE_CASE       :	List[Any]						    =							np.transpose(__lowerCamelCase,       (2, 3, 0, 1)	)
          elif "weights" in name:
               logger.info("Transposing"	)
               if len(pointer.shape	) == 2:  # copying into linear layer
                    _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							array.squeeze().transpose()
               else:
                    _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							np.transpose(__lowerCamelCase,       (3, 2, 0, 1)	)

          if pointer.shape != array.shape:
               raise ValueError(f"""Pointer shape {pointer.shape} and array shape {array.shape} mismatched"""	)

          logger.info(f"""Initialize PyTorch weight {name} {array.shape}"""	)
          _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							torch.from_numpy(__lowerCamelCase	)

          tf_weights.pop(__lowerCamelCase,       __lowerCamelCase	)
          tf_weights.pop(name + "/RMSProp",       __lowerCamelCase	)
          tf_weights.pop(name + "/RMSProp_1",       __lowerCamelCase	)
          tf_weights.pop(name + "/ExponentialMovingAverage",       __lowerCamelCase	)

     logger.info(f"""Weights not copied to PyTorch model: {', '.join(tf_weights.keys()	)}"""	)
     return model






def     lowerCamelCase__			(__lowerCamelCase,       __lowerCamelCase	):
     _SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE       :	int						    =							features.shape[-2:]
     _SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE       :	Any						    =							conv_layer.stride
     _SCREAMING_SNAKE_CASE    ,			_SCREAMING_SNAKE_CASE       :	int						    =							conv_layer.kernel_size

     if in_height % stride_height == 0:
          _SCREAMING_SNAKE_CASE       :	List[str]						    =							max(kernel_height - stride_height,       0	)
     else:
          _SCREAMING_SNAKE_CASE       :	Any						    =							max(kernel_height - (in_height % stride_height),       0	)

     if in_width % stride_width == 0:
          _SCREAMING_SNAKE_CASE       :	List[str]						    =							max(kernel_width - stride_width,       0	)
     else:
          _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							max(kernel_width - (in_width % stride_width),       0	)

     _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							pad_along_width // 2
     _SCREAMING_SNAKE_CASE       :	str						    =							pad_along_width - pad_left
     _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							pad_along_height // 2
     _SCREAMING_SNAKE_CASE       :	Tuple						    =							pad_along_height - pad_top

     _SCREAMING_SNAKE_CASE       :	Any						    =							(pad_left, pad_right, pad_top, pad_bottom)
     return nn.functional.pad(__lowerCamelCase,       __lowerCamelCase,       "constant",       0.0	)





class 			lowerCAmelCase__( nn.Module    ):






       '''simple docstring'''


       def __init__(      self    ,						__lowerCamelCase    ,						__lowerCamelCase    ,						__lowerCamelCase    ,						__lowerCamelCase    ,						__lowerCamelCase = 1    ,						__lowerCamelCase = 1    ,						__lowerCamelCase = False    ,						__lowerCamelCase = True    ,						__lowerCamelCase = True    ,						)			->     None:
            super().__init__()
            _SCREAMING_SNAKE_CASE       :	Dict						    =							config

            if in_channels % groups != 0:
                 raise ValueError(F"""Input channels ({in_channels}) are not divisible by {groups} groups."""							)
            if out_channels % groups != 0:
                 raise ValueError(F"""Output channels ({out_channels}) are not divisible by {groups} groups."""							)

            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							0 if config.tf_padding else int((kernel_size - 1) / 2							)

            _SCREAMING_SNAKE_CASE       :	Dict						    =							nn.Convad(
                in_channels=__lowerCamelCase    ,						out_channels=__lowerCamelCase    ,						kernel_size=__lowerCamelCase    ,						stride=__lowerCamelCase    ,						padding=__lowerCamelCase    ,						groups=__lowerCamelCase    ,						bias=__lowerCamelCase    ,						padding_mode="zeros"    ,						)

            if use_normalization:
                 _SCREAMING_SNAKE_CASE       :	int						    =							nn.BatchNormad(
                     num_features=__lowerCamelCase    ,						eps=config.layer_norm_eps    ,						momentum=0.9997    ,						affine=__lowerCamelCase    ,						track_running_stats=__lowerCamelCase    ,						)
            else:
                 _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							None

            if use_activation:
                 if isinstance(__lowerCamelCase    ,						__lowerCamelCase							):
                      _SCREAMING_SNAKE_CASE       :	str						    =							ACTaFN[use_activation]
                 elif isinstance(config.hidden_act    ,						__lowerCamelCase							):
                      _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							ACTaFN[config.hidden_act]
                 else:
                      _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							config.hidden_act
            else:
                 _SCREAMING_SNAKE_CASE       :	int						    =							None







       def     UpperCamelCase_			(      self    ,						__lowerCamelCase							)			->     torch.Tensor:
            if self.config.tf_padding:
                 _SCREAMING_SNAKE_CASE       :	List[str]						    =							apply_tf_padding(__lowerCamelCase    ,						self.convolution							)
            _SCREAMING_SNAKE_CASE       :	str						    =							self.convolution(__lowerCamelCase							)
            if self.normalization is not None:
                 _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							self.normalization(__lowerCamelCase							)
            if self.activation is not None:
                 _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							self.activation(__lowerCamelCase							)
            return features





class 			lowerCAmelCase__( __lowercase    ):






       '''simple docstring'''


       __snake_case 			=    MobileNetVaConfig
       __snake_case 			=    load_tf_weights_in_mobilenet_va
       __snake_case 			=    'mobilenet_v1'
       __snake_case 			=    'pixel_values'
       __snake_case 			=    False




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase							)			->     None:
            if isinstance(__lowerCamelCase    ,						(nn.Linear, nn.Convad)							):
                 module.weight.data.normal_(mean=0.0    ,						std=self.config.initializer_range							)
                 if module.bias is not None:
                      module.bias.data.zero_()
            elif isinstance(__lowerCamelCase    ,						nn.BatchNormad							):
                 module.bias.data.zero_()
                 module.weight.data.fill_(1.0							)
UpperCamelCase__      =R'\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it\n    as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\n        config ([`MobileNetV1Config`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.\n'

UpperCamelCase__      =R'\n    Args:\n        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`MobileNetV1ImageProcessor.__call__`] for details.\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n'





@add_start_docstrings(
    'The bare MobileNetV1 model outputting raw hidden-states without any specific head on top.'  ,     __lowercase  ,     )
class 			lowerCAmelCase__( __lowercase    ):






       '''simple docstring'''


       def __init__(      self    ,						__lowerCamelCase    ,						__lowerCamelCase = True							)			->     str:
            super().__init__(__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							config

            _SCREAMING_SNAKE_CASE       :	Dict						    =							3_2
            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							max(int(depth * config.depth_multiplier							)    ,						config.min_depth							)

            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							MobileNetVaConvLayer(
                __lowerCamelCase    ,						in_channels=config.num_channels    ,						out_channels=__lowerCamelCase    ,						kernel_size=3    ,						stride=2    ,						)

            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							[1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 2, 1]

            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							nn.ModuleList()
            for i in range(1_3							):
                 _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							out_channels

                 if strides[i] == 2 or i == 0:
                      depth *= 2
                      _SCREAMING_SNAKE_CASE       :	Any						    =							max(int(depth * config.depth_multiplier							)    ,						config.min_depth							)

                 self.layer.append(
                     MobileNetVaConvLayer(
                         __lowerCamelCase    ,						in_channels=__lowerCamelCase    ,						out_channels=__lowerCamelCase    ,						kernel_size=3    ,						stride=strides[i]    ,						groups=__lowerCamelCase    ,						)							)

                 self.layer.append(
                     MobileNetVaConvLayer(
                         __lowerCamelCase    ,						in_channels=__lowerCamelCase    ,						out_channels=__lowerCamelCase    ,						kernel_size=1    ,						)							)

            _SCREAMING_SNAKE_CASE       :	Any						    =							nn.AdaptiveAvgPoolad((1, 1)							) if add_pooling_layer else None

            # Initialize weights and apply final processing
            self.post_init()




       def     UpperCamelCase_			(      self    ,						__lowerCamelCase							)			->     int:
            raise NotImplementedError







       @add_start_docstrings_to_model_forward(__lowerCamelCase							)
       @add_code_sample_docstrings(
           checkpoint=_CHECKPOINT_FOR_DOC    ,						output_type=__lowerCamelCase    ,						config_class=_CONFIG_FOR_DOC    ,						modality="vision"    ,						expected_output=_EXPECTED_OUTPUT_SHAPE    ,						)
       def     UpperCamelCase_			(      self    ,						__lowerCamelCase = None    ,						__lowerCamelCase = None    ,						__lowerCamelCase = None    ,						)			->     Union[tuple, BaseModelOutputWithPoolingAndNoAttention]:
            _SCREAMING_SNAKE_CASE       :	int						    =							(
                output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
            )
            _SCREAMING_SNAKE_CASE       :	Tuple						    =							return_dict if return_dict is not None else self.config.use_return_dict

            if pixel_values is None:
                 raise ValueError("You have to specify pixel_values"							)

            _SCREAMING_SNAKE_CASE       :	Dict						    =							self.conv_stem(__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							() if output_hidden_states else None

            for i, layer_module in enumerate(self.layer							):
                 _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							layer_module(__lowerCamelCase							)

                 if output_hidden_states:
                      _SCREAMING_SNAKE_CASE       :	str						    =							all_hidden_states + (hidden_states,)

            _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							hidden_states

            if self.pooler is not None:
                 _SCREAMING_SNAKE_CASE       :	Tuple						    =							torch.flatten(self.pooler(__lowerCamelCase							)    ,						start_dim=1							)
            else:
                 _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							None

            if not return_dict:
                 return tuple(v for v in [last_hidden_state, pooled_output, all_hidden_states] if v is not None							)

            return BaseModelOutputWithPoolingAndNoAttention(
                last_hidden_state=__lowerCamelCase    ,						pooler_output=__lowerCamelCase    ,						hidden_states=__lowerCamelCase    ,						)





@add_start_docstrings(
    '\n    MobileNetV1 model with an image classification head on top (a linear layer on top of the pooled features), e.g. for\n    ImageNet.\n    '  ,     __lowercase  ,     )
class 			lowerCAmelCase__( __lowercase    ):






       '''simple docstring'''


       def __init__(      self    ,						__lowerCamelCase							)			->     None:
            super().__init__(__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	Union[str, Any]						    =							config.num_labels
            _SCREAMING_SNAKE_CASE       :	Dict						    =							MobileNetVaModel(__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	str						    =							self.mobilenet_va.layer[-1].convolution.out_channels

            # Classifier head
            _SCREAMING_SNAKE_CASE       :	List[str]						    =							nn.Dropout(config.classifier_dropout_prob    ,						inplace=__lowerCamelCase							)
            _SCREAMING_SNAKE_CASE       :	List[Any]						    =							nn.Linear(__lowerCamelCase    ,						config.num_labels							) if config.num_labels > 0 else nn.Identity()

            # Initialize weights and apply final processing
            self.post_init()







       @add_start_docstrings_to_model_forward(__lowerCamelCase							)
       @add_code_sample_docstrings(
           checkpoint=_IMAGE_CLASS_CHECKPOINT    ,						output_type=__lowerCamelCase    ,						config_class=_CONFIG_FOR_DOC    ,						expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT    ,						)
       def     UpperCamelCase_			(      self    ,						__lowerCamelCase = None    ,						__lowerCamelCase = None    ,						__lowerCamelCase = None    ,						__lowerCamelCase = None    ,						)			->     Union[tuple, ImageClassifierOutputWithNoAttention]:
            _SCREAMING_SNAKE_CASE       :	Any						    =							return_dict if return_dict is not None else self.config.use_return_dict

            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							self.mobilenet_va(__lowerCamelCase    ,						output_hidden_states=__lowerCamelCase    ,						return_dict=__lowerCamelCase							)

            _SCREAMING_SNAKE_CASE       :	List[str]						    =							outputs.pooler_output if return_dict else outputs[1]

            _SCREAMING_SNAKE_CASE       :	str						    =							self.classifier(self.dropout(__lowerCamelCase							)							)

            _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							None
            if labels is not None:
                 if self.config.problem_type is None:
                      if self.num_labels == 1:
                           _SCREAMING_SNAKE_CASE       :	Optional[Any]						    =							"regression"
                      elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
                           _SCREAMING_SNAKE_CASE       :	List[str]						    =							"single_label_classification"
                      else:
                           _SCREAMING_SNAKE_CASE       :	Tuple						    =							"multi_label_classification"

                 if self.config.problem_type == "regression":
                      _SCREAMING_SNAKE_CASE       :	Dict						    =							MSELoss()
                      if self.num_labels == 1:
                           _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							loss_fct(logits.squeeze()    ,						labels.squeeze()							)
                      else:
                           _SCREAMING_SNAKE_CASE       :	List[Any]						    =							loss_fct(__lowerCamelCase    ,						__lowerCamelCase							)
                 elif self.config.problem_type == "single_label_classification":
                      _SCREAMING_SNAKE_CASE       :	Dict						    =							CrossEntropyLoss()
                      _SCREAMING_SNAKE_CASE       :	List[Any]						    =							loss_fct(logits.view(-1    ,						self.num_labels							)    ,						labels.view(-1							)							)
                 elif self.config.problem_type == "multi_label_classification":
                      _SCREAMING_SNAKE_CASE       :	Any						    =							BCEWithLogitsLoss()
                      _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							loss_fct(__lowerCamelCase    ,						__lowerCamelCase							)

            if not return_dict:
                 _SCREAMING_SNAKE_CASE       :	Optional[int]						    =							(logits,) + outputs[2:]
                 return ((loss,) + output) if loss is not None else output

            return ImageClassifierOutputWithNoAttention(
                loss=__lowerCamelCase    ,						logits=__lowerCamelCase    ,						hidden_states=outputs.hidden_states    ,						)






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