





'''simple docstring'''


import copy
import os
from typing import Union

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


a__			:					Any       						=						logging.get_logger(__name__)

a__			:					Optional[Any]       						=						{
    'BAAI/AltCLIP': 'https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json',
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}






class     lowerCAmelCase__ (				UpperCAmelCase_    ):

       '''simple docstring'''
       _lowerCamelCase								="altclip_text_model"

       def __init__( self					:				Any       ,     a__					:				Dict=250002       ,     a__					:				int=1024       ,     a__					:				Tuple=24       ,     a__					:				Union[str, Any]=16       ,     a__					:				List[Any]=4096       ,     a__					:				Union[str, Any]="gelu"       ,     a__					:				Optional[Any]=0.1       ,     a__					:				Any=0.1       ,     a__					:				List[Any]=514       ,     a__					:				str=1       ,     a__					:				Tuple=0.02       ,     a__					:				Optional[Any]=0.02       ,     a__					:				int=1e-0_5       ,     a__					:				str=1       ,     a__					:				Tuple=0       ,     a__					:				List[Any]=2       ,     a__					:				List[str]="absolute"       ,     a__					:				Union[str, Any]=True       ,     a__					:				int=768       ,     **a__					:				str       ,     ):
              super().__init__(pad_token_id=a__       ,     bos_token_id=a__       ,     eos_token_id=a__       ,     **a__						)

              UpperCAmelCase  =						vocab_size
              UpperCAmelCase  =						hidden_size
              UpperCAmelCase  =						num_hidden_layers
              UpperCAmelCase  =						num_attention_heads
              UpperCAmelCase  =						hidden_act
              UpperCAmelCase  =						intermediate_size
              UpperCAmelCase  =						hidden_dropout_prob
              UpperCAmelCase  =						attention_probs_dropout_prob
              UpperCAmelCase  =						max_position_embeddings
              UpperCAmelCase  =						type_vocab_size
              UpperCAmelCase  =						initializer_range
              UpperCAmelCase  =						initializer_factor
              UpperCAmelCase  =						layer_norm_eps
              UpperCAmelCase  =						position_embedding_type
              UpperCAmelCase  =						use_cache
              UpperCAmelCase  =						project_dim






class     lowerCAmelCase__ (				UpperCAmelCase_    ):

       '''simple docstring'''
       _lowerCamelCase								="altclip_vision_model"

       def __init__( self					:				Dict       ,     a__					:				Tuple=768       ,     a__					:				Dict=3072       ,     a__					:				Any=512       ,     a__					:				Any=12       ,     a__					:				List[Any]=12       ,     a__					:				int=3       ,     a__					:				Dict=224       ,     a__					:				Any=32       ,     a__					:				Tuple="quick_gelu"       ,     a__					:				Tuple=1e-5       ,     a__					:				Optional[int]=0.0       ,     a__					:				List[Any]=0.02       ,     a__					:				List[Any]=1.0       ,     **a__					:				Dict       ,     ):
              super().__init__(**a__						)

              UpperCAmelCase  =						hidden_size
              UpperCAmelCase  =						intermediate_size
              UpperCAmelCase  =						projection_dim
              UpperCAmelCase  =						num_hidden_layers
              UpperCAmelCase  =						num_attention_heads
              UpperCAmelCase  =						num_channels
              UpperCAmelCase  =						patch_size
              UpperCAmelCase  =						image_size
              UpperCAmelCase  =						initializer_range
              UpperCAmelCase  =						initializer_factor
              UpperCAmelCase  =						attention_dropout
              UpperCAmelCase  =						layer_norm_eps
              UpperCAmelCase  =						hidden_act



       @classmethod
       def 			__snake_case      ( cls					:				Tuple       ,     a__					:				Union[str, os.PathLike]       ,     **a__					:				Optional[int]						):
              cls._set_token_in_kwargs(a__						)

              UpperCAmelCase,					UpperCAmelCase  =						cls.get_config_dict(a__       ,     **a__						)

              # get the vision config dict if we are loading from AltCLIPConfig
              if config_dict.get('''model_type'''						) == "altclip":
                     UpperCAmelCase  =						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(a__       ,     **a__						)






class     lowerCAmelCase__ (				UpperCAmelCase_    ):

       '''simple docstring'''
       _lowerCamelCase								="altclip"
       _lowerCamelCase								=True

       def __init__( self					:				Optional[Any]       ,     a__					:				List[Any]=None       ,     a__					:				Any=None       ,     a__					:				Optional[Any]=768       ,     a__					:				List[Any]=2.6_592       ,     **a__					:				str						):
              # If `_config_dict` exist, we use them for the backward compatibility.
              # We pop out these 2 attributes before calling `super().__init__` to avoid them being saved (which causes a lot
              # of confusion!).
              UpperCAmelCase  =						kwargs.pop('''text_config_dict'''       ,     a__						)
              UpperCAmelCase  =						kwargs.pop('''vision_config_dict'''       ,     a__						)

              super().__init__(**a__						)

              # Instead of simply assigning `[text|vision]_config_dict` to `[text|vision]_config`, we use the values in
              # `[text|vision]_config_dict` to update the values in `[text|vision]_config`. The values should be same in most
              # cases, but we don't want to break anything regarding `_config_dict` that existed before commit `8827e1b2`.
              if text_config_dict is not None:
                     if text_config is None:
                            UpperCAmelCase  =						{}

                     # This is the complete result when using `text_config_dict`.
                     UpperCAmelCase  =						AltCLIPTextConfig(**a__						).to_dict()

                     # Give a warning if the values exist in both `_text_config_dict` and `text_config` but being different.
                     for key, value in _text_config_dict.items():
                            if key in text_config and value != text_config[key] and key not in ["transformers_version"]:
                                   # If specified in `text_config_dict`
                                   if key in text_config_dict:
                                          UpperCAmelCase  =						(
                                              f"`{key}` is found in both `text_config_dict` and `text_config` but with different values. "
                                              f"The value `text_config_dict[\"{key}\"]` will be used instead."
                                          )
                                   # If inferred from default argument values (just to be super careful)
                                   else:
                                          UpperCAmelCase  =						(
                                              f"`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The "
                                              f"value `text_config[\"{key}\"]` will be overriden."
                                          )
                                   logger.warning(a__						)

            # Update all values in `text_config` with the ones in `_text_config_dict`.
                     text_config.update(_text_config_dict						)

              if vision_config_dict is not None:
                     if vision_config is None:
                            UpperCAmelCase  =						{}

                     # This is the complete result when using `vision_config_dict`.
                     UpperCAmelCase  =						AltCLIPVisionConfig(**a__						).to_dict()
                     # convert keys to string instead of integer
                     if "id2label" in _vision_config_dict:
                            UpperCAmelCase  =						{
                                str(a__						): value for key, value in _vision_config_dict['''id2label'''].items()
                            }

                     # Give a warning if the values exist in both `_vision_config_dict` and `vision_config` but being different.
                     for key, value in _vision_config_dict.items():
                            if key in vision_config and value != vision_config[key] and key not in ["transformers_version"]:
                                   # If specified in `vision_config_dict`
                                   if key in vision_config_dict:
                                          UpperCAmelCase  =						(
                                              f"`{key}` is found in both `vision_config_dict` and `vision_config` but with different "
                                              f"values. The value `vision_config_dict[\"{key}\"]` will be used instead."
                                          )
                                   # If inferred from default argument values (just to be super careful)
                                   else:
                                          UpperCAmelCase  =						(
                                              f"`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. "
                                              f"The value `vision_config[\"{key}\"]` will be overriden."
                                          )
                                   logger.warning(a__						)

            # Update all values in `vision_config` with the ones in `_vision_config_dict`.
                     vision_config.update(_vision_config_dict						)

              if text_config is None:
                     UpperCAmelCase  =						{}
                     logger.info('''`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values.'''						)

              if vision_config is None:
                     UpperCAmelCase  =						{}
                     logger.info('''`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values.'''						)

              UpperCAmelCase  =						AltCLIPTextConfig(**a__						)
              UpperCAmelCase  =						AltCLIPVisionConfig(**a__						)

              UpperCAmelCase  =						projection_dim
              UpperCAmelCase  =						logit_scale_init_value
              UpperCAmelCase  =						1.0

       @classmethod
       def 			__snake_case      ( cls					:				int       ,     a__					:				AltCLIPTextConfig       ,     a__					:				AltCLIPVisionConfig       ,     **a__					:				Any						):
              return cls(text_config=text_config.to_dict()       ,     vision_config=vision_config.to_dict()       ,     **a__						)



       def 			__snake_case      ( self					:				Optional[Any]						):
              UpperCAmelCase  =						copy.deepcopy(self.__dict__						)
              UpperCAmelCase  =						self.text_config.to_dict()
              UpperCAmelCase  =						self.vision_config.to_dict()
              UpperCAmelCase  =						self.__class__.model_type
              return output




'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCAmelCase					:    Union[str, Any]           = {
    'configuration_git': ['GIT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'GitConfig', 'GitVisionConfig'],
    'processing_git': ['GitProcessor'],
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCAmelCase					:    List[Any]           = [
						    'GIT_PRETRAINED_MODEL_ARCHIVE_LIST',
						    'GitForCausalLM',
						    'GitModel',
						    'GitPreTrainedModel',
						    'GitVisionModel',
						]

if TYPE_CHECKING:
						from .configuration_git import GIT_PRETRAINED_CONFIG_ARCHIVE_MAP, GitConfig, GitVisionConfig
						from .processing_git import GitProcessor

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_git import (
												    GIT_PRETRAINED_MODEL_ARCHIVE_LIST,
												    GitForCausalLM,
												    GitModel,
												    GitPreTrainedModel,
												    GitVisionModel,
												)

else:
						import sys

						lowerCAmelCase					:    Optional[Any]           = _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)




