






import copy
import os
from typing import Union

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


snake_case    				=		logging.get_logger(__name__)

snake_case    				=		{
    """BAAI/AltCLIP""": """https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json""",
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}


class  SCREAMING_SNAKE_CASE			(			lowerCAmelCase					):
     '''simple docstring'''


     UpperCamelCase_							:		int			=	'''altclip_text_model'''


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

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





class  SCREAMING_SNAKE_CASE			(			lowerCAmelCase					):
     '''simple docstring'''


     UpperCamelCase_							:		int			=	'''altclip_vision_model'''


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

       SCREAMING_SNAKE_CASE       :      int							=    hidden_size
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    intermediate_size
       SCREAMING_SNAKE_CASE       :      Tuple							=    projection_dim
       SCREAMING_SNAKE_CASE       :      Tuple							=    num_hidden_layers
       SCREAMING_SNAKE_CASE       :      str							=    num_attention_heads
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    num_channels
       SCREAMING_SNAKE_CASE       :      Dict							=    patch_size
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    image_size
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    initializer_range
       SCREAMING_SNAKE_CASE       :      Dict							=    initializer_factor
       SCREAMING_SNAKE_CASE       :      List[str]							=    attention_dropout
       SCREAMING_SNAKE_CASE       :      Any							=    layer_norm_eps
       SCREAMING_SNAKE_CASE       :      Dict							=    hidden_act






     @classmethod
     def 				_A       (				cls       :	Tuple					, UpperCAmelCase_       :	Union[str, os.PathLike]					, **UpperCAmelCase_       :	Tuple      ):
       cls._set_token_in_kwargs(UpperCAmelCase_      )

       SCREAMING_SNAKE_CASE						,  SCREAMING_SNAKE_CASE       :      Tuple							=    cls.get_config_dict(UpperCAmelCase_					, **UpperCAmelCase_      )

       # get the vision config dict if we are loading from AltCLIPConfig
       if config_dict.get("model_type"      ) == "altclip":
         SCREAMING_SNAKE_CASE       :      Optional[Any]							=    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(UpperCAmelCase_					, **UpperCAmelCase_      )





class  SCREAMING_SNAKE_CASE			(			lowerCAmelCase					):
     '''simple docstring'''


     UpperCamelCase_							:		Tuple			=	'''altclip'''
     UpperCamelCase_							:		Tuple			=	True


     def __init__(				self       :	List[Any]					, UpperCAmelCase_       :	Tuple=None					, UpperCAmelCase_       :	Union[str, Any]=None					, UpperCAmelCase_       :	Any=768					, UpperCAmelCase_       :	Any=2.6_592					, **UpperCAmelCase_       :	Optional[int]      ):
       # 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!).
       SCREAMING_SNAKE_CASE       :      Any							=    kwargs.pop("text_config_dict"					, UpperCAmelCase_      )
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    kwargs.pop("vision_config_dict"					, UpperCAmelCase_      )

       super().__init__(**UpperCAmelCase_      )

       # 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:
           SCREAMING_SNAKE_CASE       :      Optional[int]							=    {}

         # This is the complete result when using `text_config_dict`.
         SCREAMING_SNAKE_CASE       :      Optional[int]							=    AltCLIPTextConfig(**UpperCAmelCase_      ).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:
               SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    (
                   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:
               SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    (
                   f'''`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The '''
                   f'''value `text_config["{key}"]` will be overriden.'''
               )
             logger.warning(UpperCAmelCase_      )

            # 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:
           SCREAMING_SNAKE_CASE       :      str							=    {}

         # This is the complete result when using `vision_config_dict`.
         SCREAMING_SNAKE_CASE       :      List[Any]							=    AltCLIPVisionConfig(**UpperCAmelCase_      ).to_dict()
         # convert keys to string instead of integer
         if "id2label" in _vision_config_dict:
           SCREAMING_SNAKE_CASE       :      Optional[Any]							=    {
               str(UpperCAmelCase_      ): 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:
               SCREAMING_SNAKE_CASE       :      Optional[Any]							=    (
                   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:
               SCREAMING_SNAKE_CASE       :      Dict							=    (
                   f'''`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. '''
                   f'''The value `vision_config["{key}"]` will be overriden.'''
               )
             logger.warning(UpperCAmelCase_      )

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

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

       if vision_config is None:
         SCREAMING_SNAKE_CASE       :      List[Any]							=    {}
         logger.info("`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values."      )

       SCREAMING_SNAKE_CASE       :      Tuple							=    AltCLIPTextConfig(**UpperCAmelCase_      )
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    AltCLIPVisionConfig(**UpperCAmelCase_      )

       SCREAMING_SNAKE_CASE       :      Any							=    projection_dim
       SCREAMING_SNAKE_CASE       :      Dict							=    logit_scale_init_value
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    1.0


     @classmethod
     def 				_A       (				cls       :	Optional[Any]					, UpperCAmelCase_       :	AltCLIPTextConfig					, UpperCAmelCase_       :	AltCLIPVisionConfig					, **UpperCAmelCase_       :	Any      ):
       return cls(text_config=text_config.to_dict()					, vision_config=vision_config.to_dict()					, **UpperCAmelCase_      )






     def 				_A       (				self       :	Any      ):
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    copy.deepcopy(self.__dict__      )
       SCREAMING_SNAKE_CASE       :      Any							=    self.text_config.to_dict()
       SCREAMING_SNAKE_CASE       :      Tuple							=    self.vision_config.to_dict()
       SCREAMING_SNAKE_CASE       :      str							=    self.__class__.model_type
       return output














from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


snake_case    				=		logging.get_logger(__name__)

snake_case    				=		{
    """camembert-base""": """https://huggingface.co/camembert-base/resolve/main/config.json""",
    """umberto-commoncrawl-cased-v1""": (
        """https://huggingface.co/Musixmatch/umberto-commoncrawl-cased-v1/resolve/main/config.json"""
    ),
    """umberto-wikipedia-uncased-v1""": (
        """https://huggingface.co/Musixmatch/umberto-wikipedia-uncased-v1/resolve/main/config.json"""
    ),
}


class  SCREAMING_SNAKE_CASE			(			lowerCAmelCase					):
     '''simple docstring'''


     UpperCamelCase_							:		Dict			=	'''camembert'''


     def __init__(				self       :	str					, UpperCAmelCase_       :	Optional[Any]=3_0522					, UpperCAmelCase_       :	Optional[int]=768					, UpperCAmelCase_       :	List[Any]=12					, UpperCAmelCase_       :	Union[str, Any]=12					, UpperCAmelCase_       :	Optional[Any]=3072					, UpperCAmelCase_       :	Optional[int]="gelu"					, UpperCAmelCase_       :	List[Any]=0.1					, UpperCAmelCase_       :	Dict=0.1					, UpperCAmelCase_       :	List[str]=512					, UpperCAmelCase_       :	List[Any]=2					, UpperCAmelCase_       :	Optional[int]=0.02					, UpperCAmelCase_       :	List[str]=1E-12					, UpperCAmelCase_       :	int=1					, UpperCAmelCase_       :	Union[str, Any]=0					, UpperCAmelCase_       :	List[str]=2					, UpperCAmelCase_       :	int="absolute"					, UpperCAmelCase_       :	Tuple=True					, UpperCAmelCase_       :	Optional[Any]=None					, **UpperCAmelCase_       :	Optional[int]					, ):
       super().__init__(pad_token_id=UpperCAmelCase_					, bos_token_id=UpperCAmelCase_					, eos_token_id=UpperCAmelCase_					, **UpperCAmelCase_      )

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





class  SCREAMING_SNAKE_CASE			(			lowerCAmelCase					):
     '''simple docstring'''


     @property
     def 				_A       (				self       :	Optional[int]      ):
       if self.task == "multiple-choice":
         SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    {0: "batch", 1: "choice", 2: "sequence"}
       else:
         SCREAMING_SNAKE_CASE       :      Optional[Any]							=    {0: "batch", 1: "sequence"}
       return OrderedDict(
           [
               ("input_ids", dynamic_axis),
               ("attention_mask", dynamic_axis),
           ]      )






