






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


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

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


class       __SCREAMING_SNAKE_CASE   (				__lowercase):
						_SCREAMING_SNAKE_CASE		:    Optional[int]						=   '''instructblip_vision_model'''






						def __init__(		self       ,  _UpperCamelCase=14_08       ,  _UpperCamelCase=61_44       ,  _UpperCamelCase=39       ,  _UpperCamelCase=16       ,  _UpperCamelCase=2_24       ,  _UpperCamelCase=14       ,  _UpperCamelCase="gelu"       ,  _UpperCamelCase=1E-6       ,  _UpperCamelCase=0.0       ,  _UpperCamelCase=1E-10       ,  _UpperCamelCase=True       ,  **_UpperCamelCase       ,  ):






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

												lowerCAmelCase__        =  hidden_size
												lowerCAmelCase__        =  intermediate_size
												lowerCAmelCase__        =  num_hidden_layers
												lowerCAmelCase__        =  num_attention_heads
												lowerCAmelCase__        =  patch_size
												lowerCAmelCase__        =  image_size
												lowerCAmelCase__        =  initializer_range
												lowerCAmelCase__        =  attention_dropout
												lowerCAmelCase__        =  layer_norm_eps
												lowerCAmelCase__        =  hidden_act
												lowerCAmelCase__        =  qkv_bias







						@classmethod
						def  UpperCamelCase__ (		cls       ,  _UpperCamelCase       ,  **_UpperCamelCase				):






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

												lowerCAmelCase__  ,    lowerCAmelCase__        =  cls.get_config_dict(_UpperCamelCase       ,  **_UpperCamelCase				)

												# get the vision config dict if we are loading from InstructBlipConfig
												if config_dict.get('model_type'				) == "instructblip":
																		lowerCAmelCase__        =  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   (				__lowercase):
						_SCREAMING_SNAKE_CASE		:    str						=   '''instructblip_qformer'''






						def __init__(		self       ,  _UpperCamelCase=3_05_22       ,  _UpperCamelCase=7_68       ,  _UpperCamelCase=12       ,  _UpperCamelCase=12       ,  _UpperCamelCase=30_72       ,  _UpperCamelCase="gelu"       ,  _UpperCamelCase=0.1       ,  _UpperCamelCase=0.1       ,  _UpperCamelCase=5_12       ,  _UpperCamelCase=0.02       ,  _UpperCamelCase=1E-12       ,  _UpperCamelCase=0       ,  _UpperCamelCase="absolute"       ,  _UpperCamelCase=2       ,  _UpperCamelCase=14_08       ,  **_UpperCamelCase       ,  ):






												"""simple docstring"""
												super().__init__(pad_token_id=_UpperCamelCase       ,  **_UpperCamelCase				)

												lowerCAmelCase__        =  vocab_size
												lowerCAmelCase__        =  hidden_size
												lowerCAmelCase__        =  num_hidden_layers
												lowerCAmelCase__        =  num_attention_heads
												lowerCAmelCase__        =  hidden_act
												lowerCAmelCase__        =  intermediate_size
												lowerCAmelCase__        =  hidden_dropout_prob
												lowerCAmelCase__        =  attention_probs_dropout_prob
												lowerCAmelCase__        =  max_position_embeddings
												lowerCAmelCase__        =  initializer_range
												lowerCAmelCase__        =  layer_norm_eps
												lowerCAmelCase__        =  position_embedding_type
												lowerCAmelCase__        =  cross_attention_frequency
												lowerCAmelCase__        =  encoder_hidden_size







						@classmethod
						def  UpperCamelCase__ (		cls       ,  _UpperCamelCase       ,  **_UpperCamelCase				):






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

												lowerCAmelCase__  ,    lowerCAmelCase__        =  cls.get_config_dict(_UpperCamelCase       ,  **_UpperCamelCase				)

												# get the qformer config dict if we are loading from InstructBlipConfig
												if config_dict.get('model_type'				) == "instructblip":
																		lowerCAmelCase__        =  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   (				__lowercase):
						_SCREAMING_SNAKE_CASE		:    List[str]						=   '''instructblip'''
						_SCREAMING_SNAKE_CASE		:    List[str]						=   True






						def __init__(		self       ,  _UpperCamelCase=None       ,  _UpperCamelCase=None       ,  _UpperCamelCase=None       ,  _UpperCamelCase=32       ,  **_UpperCamelCase				):






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

												if vision_config is None:
																		lowerCAmelCase__        =  {}
																		logger.info('vision_config is None. initializing the InstructBlipVisionConfig with default values.'				)

												if qformer_config is None:
																		lowerCAmelCase__        =  {}
																		logger.info('qformer_config is None. Initializing the InstructBlipQFormerConfig with default values.'				)

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

												lowerCAmelCase__        =  InstructBlipVisionConfig(**_UpperCamelCase				)
												lowerCAmelCase__        =  InstructBlipQFormerConfig(**_UpperCamelCase				)
												lowerCAmelCase__        =  text_config['model_type'] if 'model_type' in text_config else 'opt'
												lowerCAmelCase__        =  CONFIG_MAPPING[text_model_type](**_UpperCamelCase				)

												lowerCAmelCase__        =  self.text_config.tie_word_embeddings
												lowerCAmelCase__        =  self.text_config.is_encoder_decoder

												lowerCAmelCase__        =  num_query_tokens
												lowerCAmelCase__        =  self.vision_config.hidden_size
												lowerCAmelCase__        =  self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
												lowerCAmelCase__        =  1.0
												lowerCAmelCase__        =  0.02






						@classmethod
						def  UpperCamelCase__ (		cls       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  _UpperCamelCase       ,  **_UpperCamelCase       ,  ):






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







						def  UpperCamelCase__ (		self				):






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













import qiskit







def 		_UpperCamelCase				(      UpperCamelCase_    :   int      ,    UpperCamelCase_    :   int						)					->				qiskit.result.counts.Counts:

						"""simple docstring"""



						lowerCAmelCase__        =  qiskit.Aer.get_backend('aer_simulator'						)

						# Create a Quantum Circuit acting on the q register
						lowerCAmelCase__        =  qiskit.QuantumCircuit(UpperCamelCase_      ,    UpperCamelCase_						)

						# Map the quantum measurement to the classical bits
						circuit.measure([0]      ,    [0]						)

						# Execute the circuit on the simulator
						lowerCAmelCase__        =  qiskit.execute(UpperCamelCase_      ,    UpperCamelCase_      ,    shots=1000						)

						# Return the histogram data of the results of the experiment.
						return job.result().get_counts(UpperCamelCase_						)


if __name__ == "__main__":
					print(f'Total count for various states are: {single_qubit_measure(1, 1)}')





