





import inspect
import unittest

from transformers import MobileViTVaConfig
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
     import torch

     from transformers import MobileViTVaForImageClassification, MobileViTVaForSemanticSegmentation, MobileViTVaModel
     from transformers.models.mobilevitva.modeling_mobilevitva import (
         MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST,
         make_divisible,
     )


if is_vision_available():
     from PIL import Image

     from transformers import MobileViTImageProcessor



class      _SCREAMING_SNAKE_CASE		(			__SCREAMING_SNAKE_CASE					):







 '''simple docstring'''

 def 							SCREAMING_SNAKE_CASE_      (self       :     Dict) ->int:



   '''simple docstring'''



   lowerCamelCase__:   int    						=self.config_class(**self.inputs_dict)
   self.parent.assertTrue(hasattr(UpperCAmelCase_ ,				"width_multiplier"))



class      _SCREAMING_SNAKE_CASE		:







 '''simple docstring'''

 def __init__(self       :     int ,				UpperCAmelCase_       :     List[str] ,				UpperCAmelCase_       :     Any=13 ,				UpperCAmelCase_       :     Any=64 ,				UpperCAmelCase_       :     int=2 ,				UpperCAmelCase_       :     Optional[Any]=3 ,				UpperCAmelCase_       :     Tuple="swish" ,				UpperCAmelCase_       :     Optional[Any]=3 ,				UpperCAmelCase_       :     int=32 ,				UpperCAmelCase_       :     str=0.1 ,				UpperCAmelCase_       :     Union[str, Any]=0.02 ,				UpperCAmelCase_       :     List[str]=True ,				UpperCAmelCase_       :     List[Any]=True ,				UpperCAmelCase_       :     str=10 ,				UpperCAmelCase_       :     List[str]=None ,				UpperCAmelCase_       :     Optional[Any]=0.25 ,				UpperCAmelCase_       :     Optional[int]=0.0 ,				UpperCAmelCase_       :     Dict=0.0 ,				) ->Optional[Any]:



   '''simple docstring'''



   lowerCamelCase__:   str    						=parent
   lowerCamelCase__:   Optional[Any]    						=batch_size
   lowerCamelCase__:   Optional[Any]    						=image_size
   lowerCamelCase__:   List[str]    						=patch_size
   lowerCamelCase__:   Any    						=num_channels
   lowerCamelCase__:   int    						=make_divisible(512 * width_multiplier ,				divisor=8)
   lowerCamelCase__:   str    						=hidden_act
   lowerCamelCase__:   Dict    						=conv_kernel_size
   lowerCamelCase__:   int    						=output_stride
   lowerCamelCase__:   Optional[int]    						=classifier_dropout_prob
   lowerCamelCase__:   Optional[Any]    						=use_labels
   lowerCamelCase__:   Optional[int]    						=is_training
   lowerCamelCase__:   Optional[Any]    						=num_labels
   lowerCamelCase__:   Any    						=initializer_range
   lowerCamelCase__:   Optional[int]    						=scope
   lowerCamelCase__:   str    						=width_multiplier
   lowerCamelCase__:   int    						=ffn_dropout
   lowerCamelCase__:   Tuple    						=attn_dropout

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



   '''simple docstring'''



   lowerCamelCase__:   int    						=floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

   lowerCamelCase__:   Optional[Any]    						=None
   lowerCamelCase__:   str    						=None
   if self.use_labels:
     lowerCamelCase__:   Tuple    						=ids_tensor([self.batch_size] ,				self.num_labels)
     lowerCamelCase__:   Dict    						=ids_tensor([self.batch_size, self.image_size, self.image_size] ,				self.num_labels)

   lowerCamelCase__:   str    						=self.get_config()

   return config, pixel_values, labels, pixel_labels

 def 							SCREAMING_SNAKE_CASE_      (self       :     Dict) ->int:



   '''simple docstring'''



   return MobileViTVaConfig(
       image_size=self.image_size ,				patch_size=self.patch_size ,				num_channels=self.num_channels ,				hidden_act=self.hidden_act ,				conv_kernel_size=self.conv_kernel_size ,				output_stride=self.output_stride ,				classifier_dropout_prob=self.classifier_dropout_prob ,				initializer_range=self.initializer_range ,				width_multiplier=self.width_multiplier ,				ffn_dropout=self.ffn_dropout_prob ,				attn_dropout=self.attn_dropout_prob ,				)

 def 							SCREAMING_SNAKE_CASE_      (self       :     Union[str, Any] ,				UpperCAmelCase_       :     List[str] ,				UpperCAmelCase_       :     Any ,				UpperCAmelCase_       :     Union[str, Any] ,				UpperCAmelCase_       :     List[str]) ->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__:   int    						=MobileViTVaModel(config=UpperCAmelCase_)
   model.to(UpperCAmelCase_)
   model.eval()
   lowerCamelCase__:   str    						=model(UpperCAmelCase_)
   self.parent.assertEqual(
       result.last_hidden_state.shape ,				(
           self.batch_size,
           self.last_hidden_size,
           self.image_size // self.output_stride,
           self.image_size // self.output_stride,
       ) ,				)

 def 							SCREAMING_SNAKE_CASE_      (self       :     Union[str, Any] ,				UpperCAmelCase_       :     Any ,				UpperCAmelCase_       :     Union[str, Any] ,				UpperCAmelCase_       :     Any ,				UpperCAmelCase_       :     str) ->Tuple:



   '''simple docstring'''



   lowerCamelCase__:   Optional[Any]    						=self.num_labels
   lowerCamelCase__:   str    						=MobileViTVaForImageClassification(UpperCAmelCase_)
   model.to(UpperCAmelCase_)
   model.eval()
   lowerCamelCase__:   Tuple    						=model(UpperCAmelCase_ ,				labels=UpperCAmelCase_)
   self.parent.assertEqual(result.logits.shape ,				(self.batch_size, self.num_labels))

 def 							SCREAMING_SNAKE_CASE_      (self       :     List[str] ,				UpperCAmelCase_       :     Optional[int] ,				UpperCAmelCase_       :     Dict ,				UpperCAmelCase_       :     str ,				UpperCAmelCase_       :     int) ->Union[str, Any]:



   '''simple docstring'''



   lowerCamelCase__:   Union[str, Any]    						=self.num_labels
   lowerCamelCase__:   Dict    						=MobileViTVaForSemanticSegmentation(UpperCAmelCase_)
   model.to(UpperCAmelCase_)
   model.eval()
   lowerCamelCase__:   List[str]    						=model(UpperCAmelCase_)
   self.parent.assertEqual(
       result.logits.shape ,				(
           self.batch_size,
           self.num_labels,
           self.image_size // self.output_stride,
           self.image_size // self.output_stride,
       ) ,				)
   lowerCamelCase__:   List[Any]    						=model(UpperCAmelCase_ ,				labels=UpperCAmelCase_)
   self.parent.assertEqual(
       result.logits.shape ,				(
           self.batch_size,
           self.num_labels,
           self.image_size // self.output_stride,
           self.image_size // self.output_stride,
       ) ,				)







 def 							SCREAMING_SNAKE_CASE_      (self       :     Optional[Any]) ->int:



   '''simple docstring'''



   lowerCamelCase__:   List[Any]    						=self.prepare_config_and_inputs()
   lowerCamelCase__:   Union[str, Any]    						=config_and_inputs
   lowerCamelCase__:   int    						={"pixel_values": pixel_values}
   return config, inputs_dict



@require_torch
class      _SCREAMING_SNAKE_CASE		(			__SCREAMING_SNAKE_CASE					,							__SCREAMING_SNAKE_CASE					,							unittest.TestCase					):







 '''simple docstring'''
 lowercase_	=    (
     (MobileViTVaModel, MobileViTVaForImageClassification, MobileViTVaForSemanticSegmentation)
     if is_torch_available()
     else ()
 )

 lowercase_	=    (
     {
         "feature-extraction": MobileViTVaModel,
         "image-classification": MobileViTVaForImageClassification,
         "image-segmentation": MobileViTVaForSemanticSegmentation,
     }
     if is_torch_available()
     else {}
 )

 lowercase_	=    False
 lowercase_	=    False
 lowercase_	=    False
 lowercase_	=    False

 def 							SCREAMING_SNAKE_CASE_      (self       :     List[Any]) ->List[Any]:



   '''simple docstring'''



   lowerCamelCase__:   Tuple    						=MobileViTVaModelTester(self)
   lowerCamelCase__:   List[Any]    						=MobileViTVaConfigTester(self ,				config_class=UpperCAmelCase_ ,				has_text_modality=UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_      (self       :     Dict) ->List[str]:



   '''simple docstring'''



   self.config_tester.run_common_tests()

 @unittest.skip(reason="MobileViTV2 does not use inputs_embeds")
 def 							SCREAMING_SNAKE_CASE_      (self       :     List[str]) ->str:



   '''simple docstring'''



   pass

 @unittest.skip(reason="MobileViTV2 does not support input and output embeddings")
 def 							SCREAMING_SNAKE_CASE_      (self       :     List[Any]) ->Union[str, Any]:



   '''simple docstring'''



   pass

 @unittest.skip(reason="MobileViTV2 does not output attentions")
 def 							SCREAMING_SNAKE_CASE_      (self       :     Dict) ->Optional[Any]:



   '''simple docstring'''



   pass

 @require_torch_multi_gpu
 @unittest.skip(reason="Got `CUDA error: misaligned address` for tests after this one being run.")
 def 							SCREAMING_SNAKE_CASE_      (self       :     Union[str, Any]) ->Optional[Any]:



   '''simple docstring'''



   pass

 @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests.")
 def 							SCREAMING_SNAKE_CASE_      (self       :     Optional[Any]) ->Dict:



   '''simple docstring'''



   pass

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



   '''simple docstring'''



   lowerCamelCase__:   Dict    						=self.model_tester.prepare_config_and_inputs_for_common()

   for model_class in self.all_model_classes:
     lowerCamelCase__:   Union[str, Any]    						=model_class(UpperCAmelCase_)
     lowerCamelCase__:   Union[str, Any]    						=inspect.signature(model.forward)
     # signature.parameters is an OrderedDict => so arg_names order is deterministic
     lowerCamelCase__:   Dict    						=[*signature.parameters.keys()]

     lowerCamelCase__:   List[Any]    						=["pixel_values"]
     self.assertListEqual(arg_names[:1] ,				UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_      (self       :     Any) ->Any:



   '''simple docstring'''



   lowerCamelCase__:   Union[str, Any]    						=self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_model(*UpperCAmelCase_)

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



   '''simple docstring'''



   def check_hidden_states_output(UpperCAmelCase_       :     List[str] ,				UpperCAmelCase_       :     Optional[Any] ,				UpperCAmelCase_       :     Optional[Any]):
     lowerCamelCase__:   Dict    						=model_class(UpperCAmelCase_)
     model.to(UpperCAmelCase_)
     model.eval()

     with torch.no_grad():
       lowerCamelCase__:   Optional[int]    						=model(**self._prepare_for_class(UpperCAmelCase_ ,				UpperCAmelCase_))

     lowerCamelCase__:   Any    						=outputs.hidden_states

     lowerCamelCase__:   str    						=5
     self.assertEqual(len(UpperCAmelCase_) ,				UpperCAmelCase_)

     # MobileViTV2's feature maps are of shape (batch_size, num_channels, height, width)
     # with the width and height being successively divided by 2.
     lowerCamelCase__:   Tuple    						=2
     for i in range(len(UpperCAmelCase_)):
       self.assertListEqual(
           list(hidden_states[i].shape[-2:]) ,				[self.model_tester.image_size // divisor, self.model_tester.image_size // divisor] ,				)
       divisor *= 2

     self.assertEqual(self.model_tester.output_stride ,				divisor // 2)

   lowerCamelCase__:   List[str]    						=self.model_tester.prepare_config_and_inputs_for_common()

   for model_class in self.all_model_classes:
     lowerCamelCase__:   str    						=True
     check_hidden_states_output(UpperCAmelCase_ ,				UpperCAmelCase_ ,				UpperCAmelCase_)

     # check that output_hidden_states also work using config
     del inputs_dict["output_hidden_states"]
     lowerCamelCase__:   int    						=True

     check_hidden_states_output(UpperCAmelCase_ ,				UpperCAmelCase_ ,				UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_      (self       :     Optional[int]) ->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__:   Any    						=self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_image_classification(*UpperCAmelCase_)

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



   '''simple docstring'''



   lowerCamelCase__:   Any    						=self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_semantic_segmentation(*UpperCAmelCase_)







 @slow
 def 							SCREAMING_SNAKE_CASE_      (self       :     str) ->Union[str, Any]:



   '''simple docstring'''



   for model_name in MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
     lowerCamelCase__:   Optional[Any]    						=MobileViTVaModel.from_pretrained(UpperCAmelCase_)
     self.assertIsNotNone(UpperCAmelCase_)





def   lowerCAmelCase_				( )  ->	Dict:







  """simple docstring"""





  lowerCamelCase__:   Dict    						=Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"	)
  return image





@require_torch
@require_vision
class      _SCREAMING_SNAKE_CASE		(			unittest.TestCase					):







 '''simple docstring'''

 @cached_property
 def 							SCREAMING_SNAKE_CASE_      (self       :     Any) ->int:



   '''simple docstring'''



   return (
       MobileViTImageProcessor.from_pretrained("apple/mobilevitv2-1.0-imagenet1k-256")
       if is_vision_available()
       else None
   )

 @slow
 def 							SCREAMING_SNAKE_CASE_      (self       :     int) ->Union[str, Any]:



   '''simple docstring'''



   lowerCamelCase__:   Union[str, Any]    						=MobileViTVaForImageClassification.from_pretrained("apple/mobilevitv2-1.0-imagenet1k-256").to(
       UpperCAmelCase_)

   lowerCamelCase__:   Dict    						=self.default_image_processor
   lowerCamelCase__:   str    						=prepare_img()
   lowerCamelCase__:   Union[str, Any]    						=image_processor(images=UpperCAmelCase_ ,				return_tensors="pt").to(UpperCAmelCase_)

   # forward pass
   with torch.no_grad():
     lowerCamelCase__:   int    						=model(**UpperCAmelCase_)

   # verify the logits
   lowerCamelCase__:   Any    						=torch.Size((1, 1_000))
   self.assertEqual(outputs.logits.shape ,				UpperCAmelCase_)

   lowerCamelCase__:   List[str]    						=torch.tensor([-1.6_3_3_6E0_0, -7.3_2_0_4E-0_2, -5.1_8_8_3E-0_1]).to(UpperCAmelCase_)

   self.assertTrue(torch.allclose(outputs.logits[0, :3] ,				UpperCAmelCase_ ,				atol=1E-4))

 @slow
 def 							SCREAMING_SNAKE_CASE_      (self       :     Optional[Any]) ->List[str]:



   '''simple docstring'''



   lowerCamelCase__:   Union[str, Any]    						=MobileViTVaForSemanticSegmentation.from_pretrained("shehan97/mobilevitv2-1.0-voc-deeplabv3")
   lowerCamelCase__:   List[Any]    						=model.to(UpperCAmelCase_)

   lowerCamelCase__:   Any    						=MobileViTImageProcessor.from_pretrained("shehan97/mobilevitv2-1.0-voc-deeplabv3")

   lowerCamelCase__:   Optional[Any]    						=prepare_img()
   lowerCamelCase__:   Tuple    						=image_processor(images=UpperCAmelCase_ ,				return_tensors="pt").to(UpperCAmelCase_)

   # forward pass
   with torch.no_grad():
     lowerCamelCase__:   Tuple    						=model(**UpperCAmelCase_)
   lowerCamelCase__:   Dict    						=outputs.logits

   # verify the logits
   lowerCamelCase__:   Union[str, Any]    						=torch.Size((1, 21, 32, 32))
   self.assertEqual(logits.shape ,				UpperCAmelCase_)

   lowerCamelCase__:   Tuple    						=torch.tensor(
       [
           [[7.0863, 7.1525, 6.8201], [6.6931, 6.8770, 6.8933], [6.2978, 7.0366, 6.9636]],
           [[-3.7134, -3.6712, -3.6675], [-3.5825, -3.3549, -3.4777], [-3.3435, -3.3979, -3.2857]],
           [[-2.9329, -2.8003, -2.7369], [-3.0564, -2.4780, -2.0207], [-2.6889, -1.9298, -1.7640]],
       ] ,				device=UpperCAmelCase_ ,				)

   self.assertTrue(torch.allclose(logits[0, :3, :3, :3] ,				UpperCAmelCase_ ,				atol=1E-4))







 @slow
 def 							SCREAMING_SNAKE_CASE_      (self       :     List[str]) ->Union[str, Any]:



   '''simple docstring'''



   lowerCamelCase__:   Tuple    						=MobileViTVaForSemanticSegmentation.from_pretrained("shehan97/mobilevitv2-1.0-voc-deeplabv3")
   lowerCamelCase__:   Any    						=model.to(UpperCAmelCase_)

   lowerCamelCase__:   Optional[int]    						=MobileViTImageProcessor.from_pretrained("shehan97/mobilevitv2-1.0-voc-deeplabv3")

   lowerCamelCase__:   Union[str, Any]    						=prepare_img()
   lowerCamelCase__:   str    						=image_processor(images=UpperCAmelCase_ ,				return_tensors="pt").to(UpperCAmelCase_)

   # forward pass
   with torch.no_grad():
     lowerCamelCase__:   Any    						=model(**UpperCAmelCase_)

   lowerCamelCase__:   Any    						=outputs.logits.detach().cpu()

   lowerCamelCase__:   Dict    						=image_processor.post_process_semantic_segmentation(outputs=UpperCAmelCase_ ,				target_sizes=[(50, 60)])
   lowerCamelCase__:   Union[str, Any]    						=torch.Size((50, 60))
   self.assertEqual(segmentation[0].shape ,				UpperCAmelCase_)

   lowerCamelCase__:   Optional[int]    						=image_processor.post_process_semantic_segmentation(outputs=UpperCAmelCase_)
   lowerCamelCase__:   Optional[int]    						=torch.Size((32, 32))
   self.assertEqual(segmentation[0].shape ,				UpperCAmelCase_)








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


__A             =       logging.get_logger(__name__)

__A             =       {
    "salesforce/blip2-opt-2.7b": "https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json",
}



class      _SCREAMING_SNAKE_CASE		(			__SCREAMING_SNAKE_CASE					):







 '''simple docstring'''
 lowercase_	=    "blip_2_vision_model"

 def __init__(self       :     Union[str, Any] ,				UpperCAmelCase_       :     int=1_408 ,				UpperCAmelCase_       :     List[str]=6_144 ,				UpperCAmelCase_       :     List[Any]=39 ,				UpperCAmelCase_       :     Tuple=16 ,				UpperCAmelCase_       :     List[str]=224 ,				UpperCAmelCase_       :     Any=14 ,				UpperCAmelCase_       :     Dict="gelu" ,				UpperCAmelCase_       :     str=0.0_0001 ,				UpperCAmelCase_       :     List[str]=0.0 ,				UpperCAmelCase_       :     str=1E-1_0 ,				UpperCAmelCase_       :     Any=True ,				**UpperCAmelCase_       :     Optional[Any] ,				) ->Optional[int]:



   '''simple docstring'''



   super().__init__(**UpperCAmelCase_)

   lowerCamelCase__:   Any    						=hidden_size
   lowerCamelCase__:   Any    						=intermediate_size
   lowerCamelCase__:   Union[str, Any]    						=num_hidden_layers
   lowerCamelCase__:   Optional[Any]    						=num_attention_heads
   lowerCamelCase__:   Dict    						=patch_size
   lowerCamelCase__:   List[Any]    						=image_size
   lowerCamelCase__:   Union[str, Any]    						=initializer_range
   lowerCamelCase__:   Optional[Any]    						=attention_dropout
   lowerCamelCase__:   Union[str, Any]    						=layer_norm_eps
   lowerCamelCase__:   Dict    						=hidden_act
   lowerCamelCase__:   Union[str, Any]    						=qkv_bias







 @classmethod
 def 							SCREAMING_SNAKE_CASE_      (cls       :     Optional[int] ,				UpperCAmelCase_       :     Union[str, os.PathLike] ,				**UpperCAmelCase_       :     List[Any]) ->"PretrainedConfig":



   '''simple docstring'''



   cls._set_token_in_kwargs(UpperCAmelCase_)

   lowerCamelCase__						,      lowerCamelCase__:   str    						=cls.get_config_dict(UpperCAmelCase_ ,				**UpperCAmelCase_)

   # get the vision config dict if we are loading from Blip2Config
   if config_dict.get("model_type") == "blip-2":
     lowerCamelCase__:   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		(			__SCREAMING_SNAKE_CASE					):







 '''simple docstring'''
 lowercase_	=    "blip_2_qformer"

 def __init__(self       :     str ,				UpperCAmelCase_       :     Any=30_522 ,				UpperCAmelCase_       :     Union[str, Any]=768 ,				UpperCAmelCase_       :     Tuple=12 ,				UpperCAmelCase_       :     Union[str, Any]=12 ,				UpperCAmelCase_       :     Optional[int]=3_072 ,				UpperCAmelCase_       :     Any="gelu" ,				UpperCAmelCase_       :     Optional[int]=0.1 ,				UpperCAmelCase_       :     List[Any]=0.1 ,				UpperCAmelCase_       :     Optional[int]=512 ,				UpperCAmelCase_       :     List[Any]=0.02 ,				UpperCAmelCase_       :     Optional[Any]=1E-1_2 ,				UpperCAmelCase_       :     Dict=0 ,				UpperCAmelCase_       :     Optional[int]="absolute" ,				UpperCAmelCase_       :     List[Any]=2 ,				UpperCAmelCase_       :     int=1_408 ,				**UpperCAmelCase_       :     Optional[int] ,				) ->List[str]:



   '''simple docstring'''



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

   lowerCamelCase__:   Optional[int]    						=vocab_size
   lowerCamelCase__:   Dict    						=hidden_size
   lowerCamelCase__:   Tuple    						=num_hidden_layers
   lowerCamelCase__:   List[Any]    						=num_attention_heads
   lowerCamelCase__:   Optional[Any]    						=hidden_act
   lowerCamelCase__:   Optional[Any]    						=intermediate_size
   lowerCamelCase__:   Dict    						=hidden_dropout_prob
   lowerCamelCase__:   Any    						=attention_probs_dropout_prob
   lowerCamelCase__:   Union[str, Any]    						=max_position_embeddings
   lowerCamelCase__:   Optional[Any]    						=initializer_range
   lowerCamelCase__:   List[Any]    						=layer_norm_eps
   lowerCamelCase__:   Tuple    						=position_embedding_type
   lowerCamelCase__:   List[Any]    						=cross_attention_frequency
   lowerCamelCase__:   Tuple    						=encoder_hidden_size







 @classmethod
 def 							SCREAMING_SNAKE_CASE_      (cls       :     Union[str, Any] ,				UpperCAmelCase_       :     Union[str, os.PathLike] ,				**UpperCAmelCase_       :     List[Any]) ->"PretrainedConfig":



   '''simple docstring'''



   cls._set_token_in_kwargs(UpperCAmelCase_)

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

   # get the qformer config dict if we are loading from Blip2Config
   if config_dict.get("model_type") == "blip-2":
     lowerCamelCase__:   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(UpperCAmelCase_ ,				**UpperCAmelCase_)



class      _SCREAMING_SNAKE_CASE		(			__SCREAMING_SNAKE_CASE					):







 '''simple docstring'''
 lowercase_	=    "blip-2"
 lowercase_	=    True

 def __init__(self       :     Any ,				UpperCAmelCase_       :     Optional[int]=None ,				UpperCAmelCase_       :     Tuple=None ,				UpperCAmelCase_       :     List[str]=None ,				UpperCAmelCase_       :     int=32 ,				**UpperCAmelCase_       :     str) ->List[str]:



   '''simple docstring'''



   super().__init__(**UpperCAmelCase_)

   if vision_config is None:
     lowerCamelCase__:   Optional[int]    						={}
     logger.info("vision_config is None. initializing the Blip2VisionConfig with default values.")

   if qformer_config is None:
     lowerCamelCase__:   str    						={}
     logger.info("qformer_config is None. Initializing the Blip2QFormerConfig with default values.")

   if text_config is None:
     lowerCamelCase__:   Union[str, Any]    						={}
     logger.info("text_config is None. Initializing the text config with default values (`OPTConfig`).")

   lowerCamelCase__:   Optional[Any]    						=BlipaVisionConfig(**UpperCAmelCase_)
   lowerCamelCase__:   Optional[int]    						=BlipaQFormerConfig(**UpperCAmelCase_)
   lowerCamelCase__:   Union[str, Any]    						=text_config["model_type"] if "model_type" in text_config else "opt"
   lowerCamelCase__:   Dict    						=CONFIG_MAPPING[text_model_type](**UpperCAmelCase_)

   lowerCamelCase__:   Optional[int]    						=self.text_config.tie_word_embeddings
   lowerCamelCase__:   List[str]    						=self.text_config.is_encoder_decoder

   lowerCamelCase__:   Dict    						=num_query_tokens
   lowerCamelCase__:   Optional[Any]    						=self.vision_config.hidden_size
   lowerCamelCase__:   Tuple    						=self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
   lowerCamelCase__:   List[Any]    						=1.0
   lowerCamelCase__:   Union[str, Any]    						=0.02

 @classmethod
 def 							SCREAMING_SNAKE_CASE_      (cls       :     Any ,				UpperCAmelCase_       :     BlipaVisionConfig ,				UpperCAmelCase_       :     BlipaQFormerConfig ,				UpperCAmelCase_       :     PretrainedConfig ,				**UpperCAmelCase_       :     int ,				) ->Optional[int]:



   '''simple docstring'''



   return cls(
       vision_config=vision_config.to_dict() ,				qformer_config=qformer_config.to_dict() ,				text_config=text_config.to_dict() ,				**UpperCAmelCase_ ,				)







 def 							SCREAMING_SNAKE_CASE_      (self       :     List[str]) ->int:



   '''simple docstring'''



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

