



from collections import OrderedDict
from typing import Mapping

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


SCREAMING_SNAKE_CASE_:Optional[Any]					=						logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_:Dict					=						{
    """distilbert-base-uncased""": """https://huggingface.co/distilbert-base-uncased/resolve/main/config.json""",
    """distilbert-base-uncased-distilled-squad""": (
        """https://huggingface.co/distilbert-base-uncased-distilled-squad/resolve/main/config.json"""
    ),
    """distilbert-base-cased""": """https://huggingface.co/distilbert-base-cased/resolve/main/config.json""",
    """distilbert-base-cased-distilled-squad""": (
        """https://huggingface.co/distilbert-base-cased-distilled-squad/resolve/main/config.json"""
    ),
    """distilbert-base-german-cased""": """https://huggingface.co/distilbert-base-german-cased/resolve/main/config.json""",
    """distilbert-base-multilingual-cased""": (
        """https://huggingface.co/distilbert-base-multilingual-cased/resolve/main/config.json"""
    ),
    """distilbert-base-uncased-finetuned-sst-2-english""": (
        """https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english/resolve/main/config.json"""
    ),
}






class SCREAMING_SNAKE_CASE__					(		SCREAMING_SNAKE_CASE__   ):




    '''simple docstring'''






    __lowerCamelCase      :			Optional[Any] =				"distilbert"
    __lowerCamelCase      :			int =				{
        "hidden_size": "dim",
        "num_attention_heads": "n_heads",
        "num_hidden_layers": "n_layers",
    }






    def __init__(	self,		lowerCamelCase__=3_0522,		lowerCamelCase__=512,		lowerCamelCase__=False,		lowerCamelCase__=6,		lowerCamelCase__=12,		lowerCamelCase__=768,		lowerCamelCase__=4 * 768,		lowerCamelCase__=0.1,		lowerCamelCase__=0.1,		lowerCamelCase__="gelu",		lowerCamelCase__=0.02,		lowerCamelCase__=0.1,		lowerCamelCase__=0.2,		lowerCamelCase__=0,		**lowerCamelCase__,		):
        A			:	Tuple										=       vocab_size
        A			:	List[str]										=       max_position_embeddings
        A			:	Any										=       sinusoidal_pos_embds
        A			:	Tuple										=       n_layers
        A			:	str										=       n_heads
        A			:	Optional[int]										=       dim
        A			:	str										=       hidden_dim
        A			:	Optional[Any]										=       dropout
        A			:	Any										=       attention_dropout
        A			:	Any										=       activation
        A			:	int										=       initializer_range
        A			:	Dict										=       qa_dropout
        A			:	Any										=       seq_classif_dropout
        super().__init__(**lowerCamelCase__,		pad_token_id=lowerCamelCase__		)






class SCREAMING_SNAKE_CASE__					(		SCREAMING_SNAKE_CASE__   ):




    '''simple docstring'''






    @property
    def       _lowerCAmelCase (	self		):
        if self.task == "multiple-choice":
            A			:	int										=       {0: """batch""", 1: """choice""", 2: """sequence"""}
        else:
            A			:	Dict										=       {0: """batch""", 1: """sequence"""}
        return OrderedDict(
            [
                ("""input_ids""", dynamic_axis),
                ("""attention_mask""", dynamic_axis),
            ]		)







import copy
import os
from typing import Union

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


SCREAMING_SNAKE_CASE_:Optional[int]					=						logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_:Dict					=						{
    """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__					(		SCREAMING_SNAKE_CASE__   ):




    '''simple docstring'''






    __lowerCamelCase      :			int =				"altclip_text_model"






    def __init__(	self,		lowerCamelCase__=25_0002,		lowerCamelCase__=1024,		lowerCamelCase__=24,		lowerCamelCase__=16,		lowerCamelCase__=4096,		lowerCamelCase__="gelu",		lowerCamelCase__=0.1,		lowerCamelCase__=0.1,		lowerCamelCase__=514,		lowerCamelCase__=1,		lowerCamelCase__=0.02,		lowerCamelCase__=0.02,		lowerCamelCase__=1e-05,		lowerCamelCase__=1,		lowerCamelCase__=0,		lowerCamelCase__=2,		lowerCamelCase__="absolute",		lowerCamelCase__=True,		lowerCamelCase__=768,		**lowerCamelCase__,		):
        super().__init__(pad_token_id=lowerCamelCase__,		bos_token_id=lowerCamelCase__,		eos_token_id=lowerCamelCase__,		**lowerCamelCase__		)

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






class SCREAMING_SNAKE_CASE__					(		SCREAMING_SNAKE_CASE__   ):




    '''simple docstring'''






    __lowerCamelCase      :			Optional[Any] =				"altclip_vision_model"






    def __init__(	self,		lowerCamelCase__=768,		lowerCamelCase__=3072,		lowerCamelCase__=512,		lowerCamelCase__=12,		lowerCamelCase__=12,		lowerCamelCase__=3,		lowerCamelCase__=224,		lowerCamelCase__=32,		lowerCamelCase__="quick_gelu",		lowerCamelCase__=1e-5,		lowerCamelCase__=0.0,		lowerCamelCase__=0.02,		lowerCamelCase__=1.0,		**lowerCamelCase__,		):
        super().__init__(**lowerCamelCase__		)

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






    @classmethod
    def       _lowerCAmelCase (	cls,		lowerCamelCase__,		**lowerCamelCase__		):
        cls._set_token_in_kwargs(lowerCamelCase__		)

        A					,							A			:	Optional[Any]										=       cls.get_config_dict(lowerCamelCase__,		**lowerCamelCase__		)

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






class SCREAMING_SNAKE_CASE__					(		SCREAMING_SNAKE_CASE__   ):




    '''simple docstring'''






    __lowerCamelCase      :			List[Any] =				"altclip"
    __lowerCamelCase      :			List[Any] =				True






    def __init__(	self,		lowerCamelCase__=None,		lowerCamelCase__=None,		lowerCamelCase__=768,		lowerCamelCase__=2.6592,		**lowerCamelCase__		):
        # 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!).
        A			:	Dict										=       kwargs.pop("""text_config_dict""",		lowerCamelCase__		)
        A			:	str										=       kwargs.pop("""vision_config_dict""",		lowerCamelCase__		)

        super().__init__(**lowerCamelCase__		)

        # 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:
                A			:	Dict										=       {}

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

            # 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:
                A			:	int										=       {}

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

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

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

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

        A			:	Dict										=       AltCLIPTextConfig(**lowerCamelCase__		)
        A			:	Optional[int]										=       AltCLIPVisionConfig(**lowerCamelCase__		)

        A			:	List[str]										=       projection_dim
        A			:	Any										=       logit_scale_init_value
        A			:	Tuple										=       1.0






    @classmethod
    def       _lowerCAmelCase (	cls,		lowerCamelCase__,		lowerCamelCase__,		**lowerCamelCase__		):
        return cls(text_config=text_config.to_dict(),		vision_config=vision_config.to_dict(),		**lowerCamelCase__		)






    def       _lowerCAmelCase (	self		):
        A			:	str										=       copy.deepcopy(self.__dict__		)
        A			:	Any										=       self.text_config.to_dict()
        A			:	List[str]										=       self.vision_config.to_dict()
        A			:	Union[str, Any]										=       self.__class__.model_type
        return output


