




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/instruct-blip-flan-t5': 'https://huggingface.co/Salesforce/instruct-blip-flan-t5/resolve/main/config.json',
}

class     __a(	_a  ):






    """simple docstring"""





    lowerCAmelCase         = '''instructblip_vision_model'''





    def __init__( self  ,_SCREAMING_SNAKE_CASE=1_408  ,_SCREAMING_SNAKE_CASE=6_144  ,_SCREAMING_SNAKE_CASE=39  ,_SCREAMING_SNAKE_CASE=16  ,_SCREAMING_SNAKE_CASE=224  ,_SCREAMING_SNAKE_CASE=14  ,_SCREAMING_SNAKE_CASE="gelu"  ,_SCREAMING_SNAKE_CASE=1e-6  ,_SCREAMING_SNAKE_CASE=0.0  ,_SCREAMING_SNAKE_CASE=1e-10  ,_SCREAMING_SNAKE_CASE=True  ,**_SCREAMING_SNAKE_CASE  ,)					->						Any:
         super().__init__(**_SCREAMING_SNAKE_CASE    )

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





    @classmethod
    def 				a__ ( cls  ,_SCREAMING_SNAKE_CASE  ,**_SCREAMING_SNAKE_CASE    )					->						"PretrainedConfig":
         cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE    )

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

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


class     __a(	_a  ):






    """simple docstring"""





    lowerCAmelCase         = '''instructblip_qformer'''





    def __init__( self  ,_SCREAMING_SNAKE_CASE=30_522  ,_SCREAMING_SNAKE_CASE=768  ,_SCREAMING_SNAKE_CASE=12  ,_SCREAMING_SNAKE_CASE=12  ,_SCREAMING_SNAKE_CASE=3_072  ,_SCREAMING_SNAKE_CASE="gelu"  ,_SCREAMING_SNAKE_CASE=0.1  ,_SCREAMING_SNAKE_CASE=0.1  ,_SCREAMING_SNAKE_CASE=512  ,_SCREAMING_SNAKE_CASE=0.02  ,_SCREAMING_SNAKE_CASE=1e-12  ,_SCREAMING_SNAKE_CASE=0  ,_SCREAMING_SNAKE_CASE="absolute"  ,_SCREAMING_SNAKE_CASE=2  ,_SCREAMING_SNAKE_CASE=1_408  ,**_SCREAMING_SNAKE_CASE  ,)					->						int:
         super().__init__(pad_token_id=_SCREAMING_SNAKE_CASE  ,**_SCREAMING_SNAKE_CASE    )

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





    @classmethod
    def 				a__ ( cls  ,_SCREAMING_SNAKE_CASE  ,**_SCREAMING_SNAKE_CASE    )					->						"PretrainedConfig":
         cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE    )

         UpperCAmelCase_,       UpperCAmelCase_     :				Optional[int]  =     cls.get_config_dict(_SCREAMING_SNAKE_CASE  ,**_SCREAMING_SNAKE_CASE    )

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


class     __a(	_a  ):






    """simple docstring"""





    lowerCAmelCase         = '''instructblip'''
    lowerCAmelCase         = True





    def __init__( self  ,_SCREAMING_SNAKE_CASE=None  ,_SCREAMING_SNAKE_CASE=None  ,_SCREAMING_SNAKE_CASE=None  ,_SCREAMING_SNAKE_CASE=32  ,**_SCREAMING_SNAKE_CASE    )					->						List[str]:
         super().__init__(**_SCREAMING_SNAKE_CASE    )

         if vision_config is None:
              UpperCAmelCase_     :				List[Any]  =     {}
              logger.info('''vision_config is None. initializing the InstructBlipVisionConfig with default values.'''    )

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

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

         UpperCAmelCase_     :				List[str]  =     InstructBlipVisionConfig(**_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				Optional[Any]  =     InstructBlipQFormerConfig(**_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				Dict  =     text_config['''model_type'''] if '''model_type''' in text_config else '''opt'''
         UpperCAmelCase_     :				List[Any]  =     CONFIG_MAPPING[text_model_type](**_SCREAMING_SNAKE_CASE    )

         UpperCAmelCase_     :				Tuple  =     self.text_config.tie_word_embeddings
         UpperCAmelCase_     :				List[Any]  =     self.text_config.is_encoder_decoder

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





    @classmethod
    def 				a__ ( cls  ,_SCREAMING_SNAKE_CASE  ,_SCREAMING_SNAKE_CASE  ,_SCREAMING_SNAKE_CASE  ,**_SCREAMING_SNAKE_CASE  ,)					->						Optional[Any]:
         return cls(
             vision_config=vision_config.to_dict()  ,qformer_config=qformer_config.to_dict()  ,text_config=text_config.to_dict()  ,**_SCREAMING_SNAKE_CASE  ,)





    def 				a__ ( self    )					->						str:
         UpperCAmelCase_     :				Union[str, Any]  =     copy.deepcopy(self.__dict__    )
         UpperCAmelCase_     :				Any  =     self.vision_config.to_dict()
         UpperCAmelCase_     :				List[str]  =     self.qformer_config.to_dict()
         UpperCAmelCase_     :				Dict  =     self.text_config.to_dict()
         UpperCAmelCase_     :				Optional[Any]  =     self.__class__.model_type
         return output





# Lint as: python3
# pylint: enable=line-too-long
# pylint: disable=g-import-not-at-top,g-bad-import-order,wrong-import-position

__a							     =					'2.13.1'

import platform

import pyarrow
from packaging import version


if version.parse(platform.python_version()) < version.parse('3.7'):
     raise ImportWarning(
         'To use `datasets`, Python>=3.7 is required, and the current version of Python doesn\'t match this condition.'
     )

if version.parse(pyarrow.__version__).major < 8:
     raise ImportWarning(
         'To use `datasets`, the module `pyarrow>=8.0.0` is required, and the current version of `pyarrow` doesn\'t match this condition.\n'
         'If you are running this in a Google Colab, you should probably just restart the runtime to use the right version of `pyarrow`.'
     )

del platform
del pyarrow
del version

from .arrow_dataset import Dataset
from .arrow_reader import ReadInstruction
from .builder import ArrowBasedBuilder, BeamBasedBuilder, BuilderConfig, DatasetBuilder, GeneratorBasedBuilder
from .combine import concatenate_datasets, interleave_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .download import *
from .features import *
from .fingerprint import disable_caching, enable_caching, is_caching_enabled, set_caching_enabled
from .info import DatasetInfo, MetricInfo
from .inspect import (
    get_dataset_config_info,
    get_dataset_config_names,
    get_dataset_infos,
    get_dataset_split_names,
    inspect_dataset,
    inspect_metric,
    list_datasets,
    list_metrics,
)
from .iterable_dataset import IterableDataset
from .load import load_dataset, load_dataset_builder, load_from_disk, load_metric
from .metric import Metric
from .splits import (
    NamedSplit,
    NamedSplitAll,
    Split,
    SplitBase,
    SplitDict,
    SplitGenerator,
    SplitInfo,
    SubSplitInfo,
    percent,
)
from .tasks import *
from .utils import *
from .utils import logging


# deprecated modules
from datasets import arrow_dataset as _arrow_dataset  # isort:skip
from datasets import utils as _utils  # isort:skip
from datasets.utils import download_manager as _deprecated_download_manager  # isort:skip

__a							     =					concatenate_datasets
__a							     =					DownloadConfig
__a							     =					DownloadManager
__a							     =					DownloadMode
__a							     =					DownloadConfig
__a							     =					DownloadMode
__a							     =					DownloadManager

del _arrow_dataset, _utils, _deprecated_download_manager