





'''simple docstring'''






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


__UpperCamelCase					    =	logging.get_logger(__name__)

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




class  _A (					lowercase_		):
		lowercase__:   Dict				     =   '''instructblip_vision_model'''

		def __init__(   self					:   Dict  ,      __magic_name__					:   int=14_08  ,      __magic_name__					:   int=61_44  ,      __magic_name__					:   List[str]=39  ,      __magic_name__					:   List[str]=16  ,      __magic_name__					:   Optional[Any]=2_24  ,      __magic_name__					:   List[str]=14  ,      __magic_name__					:   List[str]="gelu"  ,      __magic_name__					:   Optional[int]=1E-6  ,      __magic_name__					:   List[Any]=0.0  ,      __magic_name__					:   List[Any]=1E-10  ,      __magic_name__					:   Union[str, Any]=True  ,      **__magic_name__					:   int  ,      )					->    Dict:


					"""simple docstring"""

					super().__init__(**lowerCamelCase_			)

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

		@classmethod
		def 	lowercase__     (   cls					:   Union[str, Any]  ,      __magic_name__					:   Union[str, os.PathLike]  ,      **__magic_name__					:   str			)					->    Dict:


					"""simple docstring"""

					cls._set_token_in_kwargs(lowerCamelCase_			)

					__snake_case					:      str							      =     cls.get_config_dict(lowerCamelCase_  ,      **lowerCamelCase_			)

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





class  _A (					lowercase_		):
		lowercase__:   Optional[int]				     =   '''instructblip_qformer'''

		def __init__(   self					:   Tuple  ,      __magic_name__					:   List[str]=3_05_22  ,      __magic_name__					:   int=7_68  ,      __magic_name__					:   int=12  ,      __magic_name__					:   str=12  ,      __magic_name__					:   Optional[int]=30_72  ,      __magic_name__					:   int="gelu"  ,      __magic_name__					:   str=0.1  ,      __magic_name__					:   List[str]=0.1  ,      __magic_name__					:   Union[str, Any]=5_12  ,      __magic_name__					:   List[Any]=0.02  ,      __magic_name__					:   int=1E-12  ,      __magic_name__					:   Tuple=0  ,      __magic_name__					:   Any="absolute"  ,      __magic_name__					:   Dict=2  ,      __magic_name__					:   int=14_08  ,      **__magic_name__					:   Union[str, Any]  ,      )					->    int:


					"""simple docstring"""

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

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

		@classmethod
		def 	lowercase__     (   cls					:   Dict  ,      __magic_name__					:   Union[str, os.PathLike]  ,      **__magic_name__					:   Dict			)					->    List[Any]:


					"""simple docstring"""

					cls._set_token_in_kwargs(lowerCamelCase_			)

					__snake_case					:      Optional[int]							      =     cls.get_config_dict(lowerCamelCase_  ,      **lowerCamelCase_			)

					# get the qformer config dict if we are loading from InstructBlipConfig
					if config_dict.get("""model_type"""			) == "instructblip":
								__snake_case					:      Dict							      =     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(lowerCamelCase_  ,      **lowerCamelCase_			)





class  _A (					lowercase_		):
		lowercase__:   Any				     =   '''instructblip'''
		lowercase__:   List[Any]				     =   True

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


					"""simple docstring"""

					super().__init__(**lowerCamelCase_			)

					if vision_config is None:
								__snake_case					:      Union[str, Any]							      =     {}
								logger.info("""vision_config is None. initializing the InstructBlipVisionConfig with default values."""			)

					if qformer_config is None:
								__snake_case					:      Optional[Any]							      =     {}
								logger.info("""qformer_config is None. Initializing the InstructBlipQFormerConfig with default values."""			)

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

					__snake_case					:      Dict							      =     InstructBlipVisionConfig(**lowerCamelCase_			)
					__snake_case					:      Tuple							      =     InstructBlipQFormerConfig(**lowerCamelCase_			)
					__snake_case					:      Tuple							      =     text_config["""model_type"""] if """model_type""" in text_config else """opt"""
					__snake_case					:      Optional[Any]							      =     CONFIG_MAPPING[text_model_type](**lowerCamelCase_			)

					__snake_case					:      Union[str, Any]							      =     self.text_config.tie_word_embeddings
					__snake_case					:      List[str]							      =     self.text_config.is_encoder_decoder

					__snake_case					:      List[str]							      =     num_query_tokens
					__snake_case					:      int							      =     self.vision_config.hidden_size
					__snake_case					:      List[str]							      =     self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
					__snake_case					:      Optional[Any]							      =     1.0
					__snake_case					:      List[str]							      =     0.02

		@classmethod
		def 	lowercase__     (   cls					:   Tuple  ,      __magic_name__					:   InstructBlipVisionConfig  ,      __magic_name__					:   InstructBlipQFormerConfig  ,      __magic_name__					:   PretrainedConfig  ,      **__magic_name__					:   Optional[int]  ,      )					->    List[Any]:


					"""simple docstring"""

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

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


					"""simple docstring"""

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









'''simple docstring'''




from __future__ import annotations



def 		__A		(  lowerCamelCase_			,			lowerCamelCase_	):


		"""simple docstring"""



		if partitions <= 0:
				raise ValueError("""partitions must be a positive number!"""	)
		if partitions > number_of_bytes:
				raise ValueError("""partitions can not > number_of_bytes!"""	)
		SCREAMING_SNAKE_CASE :				int		=			number_of_bytes // partitions
		SCREAMING_SNAKE_CASE :				int		=			[]
		for i in range(lowerCamelCase_	):
				SCREAMING_SNAKE_CASE :				Optional[Any]		=			i * bytes_per_partition + 1
				SCREAMING_SNAKE_CASE :				Optional[int]		=			(
				    number_of_bytes if i == partitions - 1 else (i + 1) * bytes_per_partition
				)
				allocation_list.append(f'''{start_bytes}-{end_bytes}'''	)
		return allocation_list


if __name__ == "__main__":
							import doctest

							doctest.testmod()



