






import copy
import os
from typing import Union

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


__a:     int   					=					logging.get_logger(__name__)

__a:     List[str]   					=					{
    """Salesforce/blip-vqa-base""": """https://huggingface.co/Salesforce/blip-vqa-base/resolve/main/config.json""",
    """Salesforce/blip-vqa-capfit-large""": (
        """https://huggingface.co/Salesforce/blip-vqa-base-capfit/resolve/main/config.json"""
    ),
    """Salesforce/blip-image-captioning-base""": (
        """https://huggingface.co/Salesforce/blip-image-captioning-base/resolve/main/config.json"""
    ),
    """Salesforce/blip-image-captioning-large""": (
        """https://huggingface.co/Salesforce/blip-image-captioning-large/resolve/main/config.json"""
    ),
    """Salesforce/blip-itm-base-coco""": """https://huggingface.co/Salesforce/blip-itm-base-coco/resolve/main/config.json""",
    """Salesforce/blip-itm-large-coco""": """https://huggingface.co/Salesforce/blip-itm-large-coco/resolve/main/config.json""",
    """Salesforce/blip-itm-base-flikr""": """https://huggingface.co/Salesforce/blip-itm-base-flikr/resolve/main/config.json""",
    """Salesforce/blip-itm-large-flikr""": (
        """https://huggingface.co/Salesforce/blip-itm-large-flikr/resolve/main/config.json"""
    ),
}
class 		SCREAMING_SNAKE_CASE__	(  __lowercase     ):

  '''simple docstring'''







  _lowerCamelCase    =  '''blip_text_model'''


  def __init__(      self		:			List[Any]       ,				lowerCamelCase		:			str=3_0524       ,				lowerCamelCase		:			Union[str, Any]=768       ,				lowerCamelCase		:			List[str]=768       ,				lowerCamelCase		:			List[str]=3072       ,				lowerCamelCase		:			Optional[int]=768       ,				lowerCamelCase		:			Any=12       ,				lowerCamelCase		:			List[str]=8       ,				lowerCamelCase		:			int=512       ,				lowerCamelCase		:			Tuple="gelu"       ,				lowerCamelCase		:			List[str]=1E-12       ,				lowerCamelCase		:			int=0.0       ,				lowerCamelCase		:			Optional[int]=0.0       ,				lowerCamelCase		:			Optional[int]=0.02       ,				lowerCamelCase		:			List[Any]=3_0522       ,				lowerCamelCase		:			Union[str, Any]=2       ,				lowerCamelCase		:			Optional[int]=0       ,				lowerCamelCase		:			str=102       ,				lowerCamelCase		:			Tuple=True       ,				lowerCamelCase		:			Tuple=True       ,				**lowerCamelCase		:			int       ,				)						->	str:


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

         _UpperCAmelCase							=    vocab_size
         _UpperCAmelCase							=    hidden_size
         _UpperCAmelCase							=    encoder_hidden_size
         _UpperCAmelCase							=    intermediate_size
         _UpperCAmelCase							=    projection_dim
         _UpperCAmelCase							=    hidden_dropout_prob
         _UpperCAmelCase							=    num_hidden_layers
         _UpperCAmelCase							=    num_attention_heads
         _UpperCAmelCase							=    max_position_embeddings
         _UpperCAmelCase							=    layer_norm_eps
         _UpperCAmelCase							=    hidden_act
         _UpperCAmelCase							=    initializer_range
         _UpperCAmelCase							=    attention_probs_dropout_prob
         _UpperCAmelCase							=    is_decoder
         _UpperCAmelCase							=    use_cache





  @classmethod
  def  lowerCamelCase       (      cls		:			Any       ,				lowerCamelCase		:			Tuple       ,				**lowerCamelCase		:			int							)						->	Any:


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

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

         # get the text config dict if we are loading from BlipConfig
         if config_dict.get("""model_type"""							) == "blip":
                _UpperCAmelCase							=    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 		SCREAMING_SNAKE_CASE__	(  __lowercase     ):

  '''simple docstring'''







  _lowerCamelCase    =  '''blip_vision_model'''


  def __init__(      self		:			int       ,				lowerCamelCase		:			Any=768       ,				lowerCamelCase		:			int=3072       ,				lowerCamelCase		:			List[Any]=512       ,				lowerCamelCase		:			Optional[int]=12       ,				lowerCamelCase		:			str=12       ,				lowerCamelCase		:			int=384       ,				lowerCamelCase		:			List[Any]=16       ,				lowerCamelCase		:			List[str]="gelu"       ,				lowerCamelCase		:			Optional[Any]=1E-5       ,				lowerCamelCase		:			Dict=0.0       ,				lowerCamelCase		:			int=1E-10       ,				**lowerCamelCase		:			List[Any]       ,				)						->	Tuple:


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

         _UpperCAmelCase							=    hidden_size
         _UpperCAmelCase							=    intermediate_size
         _UpperCAmelCase							=    projection_dim
         _UpperCAmelCase							=    num_hidden_layers
         _UpperCAmelCase							=    num_attention_heads
         _UpperCAmelCase							=    patch_size
         _UpperCAmelCase							=    image_size
         _UpperCAmelCase							=    initializer_range
         _UpperCAmelCase							=    attention_dropout
         _UpperCAmelCase							=    layer_norm_eps
         _UpperCAmelCase							=    hidden_act





  @classmethod
  def  lowerCamelCase       (      cls		:			Optional[Any]       ,				lowerCamelCase		:			List[Any]       ,				**lowerCamelCase		:			Union[str, Any]							)						->	str:


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

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

         # get the vision config dict if we are loading from BlipConfig
         if config_dict.get("""model_type"""							) == "blip":
                _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(_lowerCAmelCase       ,				**_lowerCAmelCase							)



class 		SCREAMING_SNAKE_CASE__	(  __lowercase     ):

  '''simple docstring'''







  _lowerCamelCase    =  '''blip'''
  _lowerCamelCase    =  True


  def __init__(      self		:			Optional[Any]       ,				lowerCamelCase		:			Dict=None       ,				lowerCamelCase		:			Any=None       ,				lowerCamelCase		:			int=512       ,				lowerCamelCase		:			int=2.6592       ,				lowerCamelCase		:			Dict=256       ,				**lowerCamelCase		:			Dict       ,				)						->	List[Any]:


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

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

         if vision_config is None:
                _UpperCAmelCase							=    {}
                logger.info("""`vision_config` is `None`. Initializing the `BlipVisionConfig` with default values."""							)

         _UpperCAmelCase							=    BlipTextConfig(**_lowerCAmelCase							)
         _UpperCAmelCase							=    BlipVisionConfig(**_lowerCAmelCase							)

         _UpperCAmelCase							=    self.vision_config.hidden_size

         _UpperCAmelCase							=    projection_dim
         _UpperCAmelCase							=    logit_scale_init_value
         _UpperCAmelCase							=    1.0
         _UpperCAmelCase							=    0.02
         _UpperCAmelCase							=    image_text_hidden_size


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


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





  def  lowerCamelCase       (      self		:			Dict							)						->	List[Any]:


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






import unittest
from dataclasses import dataclass

import pytest

from accelerate.commands.config.config_args import SageMakerConfig
from accelerate.utils import ComputeEnvironment
from accelerate.utils.launch import _convert_nargs_to_dict





@dataclass
class 				a			(      __lowercase			):
				SCREAMING_SNAKE_CASE__     :   Any		      =     ComputeEnvironment.AMAZON_SAGEMAKER
				SCREAMING_SNAKE_CASE__     :   Optional[int]		      =     True
				SCREAMING_SNAKE_CASE__     :   int		      =     '''ml.p3.2xlarge'''
				SCREAMING_SNAKE_CASE__     :   Union[str, Any]		      =     '''accelerate_sagemaker_execution_role'''
				SCREAMING_SNAKE_CASE__     :   List[Any]		      =     '''hf-sm'''
				SCREAMING_SNAKE_CASE__     :   Any		      =     '''us-east-1'''
				SCREAMING_SNAKE_CASE__     :   Any		      =     1
				SCREAMING_SNAKE_CASE__     :   Dict		      =     '''accelerate-sagemaker-1'''
				SCREAMING_SNAKE_CASE__     :   Dict		      =     '''1.6'''
				SCREAMING_SNAKE_CASE__     :   int		      =     '''4.4'''
				SCREAMING_SNAKE_CASE__     :   int		      =     '''train.py'''
				SCREAMING_SNAKE_CASE__     :   Tuple		      =     [
				    '''--model_name_or_path''',
				    '''bert''',
				    '''--do_train''',
				    '''False''',
				    '''--epochs''',
				    '''3''',
				    '''--learning_rate''',
				    '''5e-5''',
				    '''--max_steps''',
				    '''50.5''',
				]
				SCREAMING_SNAKE_CASE__     :   List[str]		      =     [
				    '''--model_name_or_path''',
				    '''bert''',
				    '''--do_train''',
				    '''--do_test''',
				    '''False''',
				    '''--do_predict''',
				    '''--epochs''',
				    '''3''',
				    '''--learning_rate''',
				    '''5e-5''',
				    '''--max_steps''',
				    '''50.5''',
				]





class 				a			(      unittest.TestCase			):






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   _convert_nargs_to_dict(MockLaunchConfig.success_training_script_args					)
										assert isinstance(converted_args['''model_name_or_path''']			, _lowerCAmelCase					)
										assert isinstance(converted_args['''do_train''']			, _lowerCAmelCase					)
										assert isinstance(converted_args['''epochs''']			, _lowerCAmelCase					)
										assert isinstance(converted_args['''learning_rate''']			, _lowerCAmelCase					)
										assert isinstance(converted_args['''max_steps''']			, _lowerCAmelCase					)

										with pytest.raises(_lowerCAmelCase					):
																_convert_nargs_to_dict(MockLaunchConfig.fail_training_script_args					)



