
import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...models.auto.modeling_auto import MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
from ...utils import logging
from ..auto import CONFIG_MAPPING


lowercase  :					int						    =							logging.get_logger(__name__)

lowercase  :					Tuple						    =							{
    """Salesforce/instruct-blip-flan-t5""": """https://huggingface.co/Salesforce/instruct-blip-flan-t5/resolve/main/config.json""",
}

class __snake_case		(      lowerCAmelCase     ):
    _a		:						str=				"instructblip_vision_model"
    def __init__(  self		,snake_case=1408		,snake_case=6144		,snake_case=39		,snake_case=16		,snake_case=224		,snake_case=14		,snake_case="gelu"		,snake_case=1e-6		,snake_case=0.0		,snake_case=1e-10		,snake_case=True		,**snake_case		,):



           '''simple docstring'''







           super().__init__(**snake_case      )

           lowercase							:     Any       	=      hidden_size
           lowercase							:     Optional[int]       	=      intermediate_size
           lowercase							:     Optional[int]       	=      num_hidden_layers
           lowercase							:     str       	=      num_attention_heads
           lowercase							:     List[Any]       	=      patch_size
           lowercase							:     Any       	=      image_size
           lowercase							:     List[Any]       	=      initializer_range
           lowercase							:     Optional[Any]       	=      attention_dropout
           lowercase							:     str       	=      layer_norm_eps
           lowercase							:     Optional[int]       	=      hidden_act
           lowercase							:     Union[str, Any]       	=      qkv_bias
    @classmethod
    def       _SCREAMING_SNAKE_CASE       (  cls		,snake_case		,**snake_case      ):



           '''simple docstring'''







           cls._set_token_in_kwargs(snake_case      )

           lowercase	,			lowercase							:     Optional[int]       	=      cls.get_config_dict(snake_case		,**snake_case      )

           # get the vision config dict if we are loading from InstructBlipConfig
           if config_dict.get("""model_type"""      ) == "instructblip":
                  lowercase							:     Tuple       	=      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(snake_case		,**snake_case      )






class __snake_case		(      lowerCAmelCase     ):
    _a		:						List[str]=				"instructblip_qformer"
    def __init__(  self		,snake_case=30522		,snake_case=768		,snake_case=12		,snake_case=12		,snake_case=3072		,snake_case="gelu"		,snake_case=0.1		,snake_case=0.1		,snake_case=512		,snake_case=0.02		,snake_case=1e-12		,snake_case=0		,snake_case="absolute"		,snake_case=2		,snake_case=1408		,**snake_case		,):



           '''simple docstring'''







           super().__init__(pad_token_id=snake_case		,**snake_case      )

           lowercase							:     Tuple       	=      vocab_size
           lowercase							:     str       	=      hidden_size
           lowercase							:     Optional[Any]       	=      num_hidden_layers
           lowercase							:     List[str]       	=      num_attention_heads
           lowercase							:     List[str]       	=      hidden_act
           lowercase							:     Optional[int]       	=      intermediate_size
           lowercase							:     str       	=      hidden_dropout_prob
           lowercase							:     Dict       	=      attention_probs_dropout_prob
           lowercase							:     Optional[Any]       	=      max_position_embeddings
           lowercase							:     Any       	=      initializer_range
           lowercase							:     List[Any]       	=      layer_norm_eps
           lowercase							:     Optional[Any]       	=      position_embedding_type
           lowercase							:     Dict       	=      cross_attention_frequency
           lowercase							:     int       	=      encoder_hidden_size
    @classmethod
    def       _SCREAMING_SNAKE_CASE       (  cls		,snake_case		,**snake_case      ):



           '''simple docstring'''







           cls._set_token_in_kwargs(snake_case      )

           lowercase	,			lowercase							:     Tuple       	=      cls.get_config_dict(snake_case		,**snake_case      )

           # get the qformer config dict if we are loading from InstructBlipConfig
           if config_dict.get("""model_type"""      ) == "instructblip":
                  lowercase							:     Any       	=      config_dict["""qformer_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(snake_case		,**snake_case      )






class __snake_case		(      lowerCAmelCase     ):
    _a		:						List[str]=				"instructblip"
    _a		:						List[Any]=				True
    def __init__(  self		,snake_case=None		,snake_case=None		,snake_case=None		,snake_case=32		,**snake_case      ):



           '''simple docstring'''







           super().__init__(**snake_case      )

           if vision_config is None:
                  lowercase							:     int       	=      {}
                  logger.info("""vision_config is None. initializing the InstructBlipVisionConfig with default values."""      )

           if qformer_config is None:
                  lowercase							:     Tuple       	=      {}
                  logger.info("""qformer_config is None. Initializing the InstructBlipQFormerConfig with default values."""      )

           if text_config is None:
                  lowercase							:     Tuple       	=      {}
                  logger.info("""text_config is None. Initializing the text config with default values (`OPTConfig`)."""      )

           lowercase							:     Dict       	=      InstructBlipVisionConfig(**snake_case      )
           lowercase							:     Optional[Any]       	=      InstructBlipQFormerConfig(**snake_case      )
           lowercase							:     Optional[int]       	=      text_config["""model_type"""] if """model_type""" in text_config else """opt"""
           lowercase							:     Optional[Any]       	=      CONFIG_MAPPING[text_model_type](**snake_case      )

           lowercase							:     Union[str, Any]       	=      self.text_config.tie_word_embeddings
           lowercase							:     Optional[int]       	=      self.text_config.is_encoder_decoder

           lowercase							:     Tuple       	=      num_query_tokens
           lowercase							:     int       	=      self.vision_config.hidden_size
           lowercase							:     Optional[Any]       	=      self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
           lowercase							:     Tuple       	=      1.0
           lowercase							:     int       	=      0.02
    @classmethod
    def       _SCREAMING_SNAKE_CASE       (  cls		,snake_case		,snake_case		,snake_case		,**snake_case		,):



           '''simple docstring'''







           return cls(
               vision_config=vision_config.to_dict()		,qformer_config=qformer_config.to_dict()		,text_config=text_config.to_dict()		,**snake_case		,)
    def       _SCREAMING_SNAKE_CASE       (  self      ):



           '''simple docstring'''







           lowercase							:     Optional[int]       	=      copy.deepcopy(self.__dict__      )
           lowercase							:     str       	=      self.vision_config.to_dict()
           lowercase							:     int       	=      self.qformer_config.to_dict()
           lowercase							:     List[Any]       	=      self.text_config.to_dict()
           lowercase							:     Optional[int]       	=      self.__class__.model_type
           return output






'''simple docstring'''

# tests directory-specific settings - this file is run automatically
# by pytest before any tests are run

import doctest
import sys
import warnings
from os.path import abspath, dirname, join

import _pytest

from transformers.testing_utils import HfDoctestModule, HfDocTestParser


# allow having multiple repository checkouts and not needing to remember to rerun
# 'pip install -e .[dev]' when switching between checkouts and running tests.
a  :				int									=  abspath(join(dirname(__file__), 'src'))
sys.path.insert(1, git_repo_path)

# silence FutureWarning warnings in tests since often we can't act on them until
# they become normal warnings - i.e. the tests still need to test the current functionality
warnings.simplefilter(action='ignore', category=FutureWarning)


def 		__magic_name__    (	__UpperCAmelCase	)		->					Optional[int]:

					'''simple docstring'''

					config.addinivalue_line(
					    '''markers''',      '''is_pt_tf_cross_test: mark test to run only when PT and TF interactions are tested'''	)
					config.addinivalue_line(
					    '''markers''',      '''is_pt_flax_cross_test: mark test to run only when PT and FLAX interactions are tested'''	)
					config.addinivalue_line('''markers''',      '''is_pipeline_test: mark test to run only when pipelines are tested'''	)
					config.addinivalue_line('''markers''',      '''is_staging_test: mark test to run only in the staging environment'''	)
					config.addinivalue_line('''markers''',      '''accelerate_tests: mark test that require accelerate'''	)
					config.addinivalue_line('''markers''',      '''tool_tests: mark the tool tests that are run on their specific schedule'''	)


def 		__magic_name__    (	__UpperCAmelCase	)		->					int:

					'''simple docstring'''

					from transformers.testing_utils import pytest_addoption_shared

					pytest_addoption_shared(__UpperCAmelCase	)


def 		__magic_name__    (	__UpperCAmelCase	)		->					Union[str, Any]:

					'''simple docstring'''

					from transformers.testing_utils import pytest_terminal_summary_main

					snake_case_									=				terminalreporter.config.getoption('''--make-reports'''	)
					if make_reports:
										pytest_terminal_summary_main(__UpperCAmelCase,      id=__UpperCAmelCase	)


def 		__magic_name__    (	__UpperCAmelCase,      __UpperCAmelCase	)		->					Optional[int]:

					'''simple docstring'''

					if exitstatus == 5:
										snake_case_									=				0


# Doctest custom flag to ignore output.
a  :				Union[str, Any]									=  doctest.register_optionflag('IGNORE_RESULT')

a  :				Optional[int]									=  doctest.OutputChecker






class 						a				(   _lowerCamelCase     ):


				def   A_ (		self    :					List[Any]       ,				lowercase_    :					int       ,				lowercase_    :					Tuple       ,				lowercase_    :					Optional[int]					):
									if IGNORE_RESULT & optionflags:
														return True
									return OutputChecker.check_output(self       ,				lowercase_       ,				lowercase_       ,				lowercase_					)







a  :				List[Any]									=  CustomOutputChecker
a  :				Optional[int]									=  HfDoctestModule

a  :				Tuple									=  HfDocTestParser

