
"""simple docstring"""





import copy
import os
from typing import Union

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


UpperCamelCase_					:						List[str]				= logging.get_logger(__name__)

UpperCamelCase_					:						int				= {
    '''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"""







   snake_case	      =				"altclip_text_model"




   def __init__(				self						:					int       ,   _snake_case						:					List[str]=250_002       ,   _snake_case						:					List[Any]=1_024       ,   _snake_case						:					Dict=24       ,   _snake_case						:					Optional[int]=16       ,   _snake_case						:					List[Any]=4_096       ,   _snake_case						:					str="gelu"       ,   _snake_case						:					Dict=0.1       ,   _snake_case						:					Optional[Any]=0.1       ,   _snake_case						:					str=514       ,   _snake_case						:					List[str]=1       ,   _snake_case						:					Optional[int]=0.0_2       ,   _snake_case						:					Optional[Any]=0.0_2       ,   _snake_case						:					Tuple=1e-05       ,   _snake_case						:					Dict=1       ,   _snake_case						:					Optional[int]=0       ,   _snake_case						:					List[str]=2       ,   _snake_case						:					List[str]="absolute"       ,   _snake_case						:					Union[str, Any]=True       ,   _snake_case						:					Union[str, Any]=768       ,   **_snake_case						:					str       ,   )      -> str:







        """simple docstring"""
        super().__init__(pad_token_id=_UpperCAmelCase       ,   bos_token_id=_UpperCAmelCase       ,   eos_token_id=_UpperCAmelCase       ,   **_UpperCAmelCase	)

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





class __lowerCAmelCase				(					_UpperCamelCase      ):




   """simple docstring"""







   snake_case	      =				"altclip_vision_model"




   def __init__(				self						:					List[str]       ,   _snake_case						:					Any=768       ,   _snake_case						:					Union[str, Any]=3_072       ,   _snake_case						:					Dict=512       ,   _snake_case						:					List[Any]=12       ,   _snake_case						:					Dict=12       ,   _snake_case						:					Tuple=3       ,   _snake_case						:					List[str]=224       ,   _snake_case						:					List[Any]=32       ,   _snake_case						:					List[Any]="quick_gelu"       ,   _snake_case						:					str=1e-5       ,   _snake_case						:					Dict=0.0       ,   _snake_case						:					Optional[Any]=0.0_2       ,   _snake_case						:					int=1.0       ,   **_snake_case						:					Union[str, Any]       ,   )      -> Dict:







        """simple docstring"""
        super().__init__(**_UpperCAmelCase	)

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






   @classmethod
   def      lowerCamelCase__     (				cls						:					Optional[int]       ,   _snake_case						:					List[str]       ,   **_snake_case						:					Optional[Any]	)      -> Optional[int]:







        """simple docstring"""
        cls._set_token_in_kwargs(_UpperCAmelCase	)

        A_				 =						cls.get_config_dict(_UpperCAmelCase       ,   **_UpperCAmelCase	)

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




   """simple docstring"""







   snake_case	      =				"altclip"
   snake_case	      =				True




   def __init__(				self						:					str       ,   _snake_case						:					Tuple=None       ,   _snake_case						:					List[Any]=None       ,   _snake_case						:					Optional[int]=768       ,   _snake_case						:					List[Any]=2.6_5_9_2       ,   **_snake_case						:					str	)      -> Optional[Any]:







        """simple docstring"""
        # 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_				 =						kwargs.pop("text_config_dict"       ,   _UpperCAmelCase	)
        A_				 =						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:
                  A_				 =						{}

             # This is the complete result when using `text_config_dict`.
             A_				 =						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:
                            A_				 =						(
                                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_				 =						(
                                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:
                  A_				 =						{}

             # This is the complete result when using `vision_config_dict`.
             A_				 =						AltCLIPVisionConfig(**_UpperCAmelCase	).to_dict()
             # convert keys to string instead of integer
             if "id2label" in _vision_config_dict:
                  A_				 =						{
                      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:
                            A_				 =						(
                                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_				 =						(
                                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:
             A_				 =						{}
             logger.info("`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values."	)

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

        A_				 =						AltCLIPTextConfig(**_UpperCAmelCase	)
        A_				 =						AltCLIPVisionConfig(**_UpperCAmelCase	)

        A_				 =						projection_dim
        A_				 =						logit_scale_init_value
        A_				 =						1.0




   @classmethod
   def      lowerCamelCase__     (				cls						:					List[Any]       ,   _snake_case						:					List[str]       ,   _snake_case						:					Tuple       ,   **_snake_case						:					Optional[int]	)      -> Any:







        """simple docstring"""
        return cls(text_config=text_config.to_dict()       ,   vision_config=vision_config.to_dict()       ,   **_UpperCAmelCase	)






   def      lowerCamelCase__     (				self						:					Optional[Any]	)      -> List[Any]:







        """simple docstring"""
        A_				 =						copy.deepcopy(self.__dict__	)
        A_				 =						self.text_config.to_dict()
        A_				 =						self.vision_config.to_dict()
        A_				 =						self.__class__.model_type
        return output






"""simple docstring"""





import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


UpperCamelCase_					:						int				= '''
Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.

In March 2021, Hugging Face raised $40 million in a Series B funding round.[3]

On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]
'''



class __lowerCAmelCase				(					unittest.TestCase     ,				_lowercase      ):




			"""simple docstring"""







			def      lowerCamelCase__     (				self						:					str	)      -> Dict:







								"""simple docstring"""
								A_				 =						load_tool("text-question-answering"	)
								self.tool.setup()
								A_				 =						load_tool("text-question-answering"       ,   remote=_snake_case	)




			def      lowerCamelCase__     (				self						:					Union[str, Any]	)      -> Any:







								"""simple docstring"""
								A_				 =						self.tool(_snake_case       ,   "What did Hugging Face do in April 2021?"	)
								self.assertEqual(_snake_case       ,   "launched the BigScience Research Workshop"	)




			def      lowerCamelCase__     (				self						:					Union[str, Any]	)      -> int:







								"""simple docstring"""
								A_				 =						self.remote_tool(_snake_case       ,   "What did Hugging Face do in April 2021?"	)
								self.assertEqual(_snake_case       ,   "launched the BigScience Research Workshop"	)




			def      lowerCamelCase__     (				self						:					Optional[Any]	)      -> Optional[Any]:







								"""simple docstring"""
								A_				 =						self.tool(text=_snake_case       ,   question="What did Hugging Face do in April 2021?"	)
								self.assertEqual(_snake_case       ,   "launched the BigScience Research Workshop"	)






			def      lowerCamelCase__     (				self						:					str	)      -> Optional[Any]:







								"""simple docstring"""
								A_				 =						self.remote_tool(text=_snake_case       ,   question="What did Hugging Face do in April 2021?"	)
								self.assertEqual(_snake_case       ,   "launched the BigScience Research Workshop"	)




