




'''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


_snake_case				:				str       							=    logging.get_logger(__name__)

_snake_case				:				Optional[Any]       							=    {
    'Salesforce/instruct-blip-flan-t5': 'https://huggingface.co/Salesforce/instruct-blip-flan-t5/resolve/main/config.json',
}

class       A   (		__lowerCAmelCase   ):
							lowercase_          =    '''instructblip_vision_model'''







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


														"""simple docstring"""


														super().__init__(**lowerCAmelCase_ )

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







							@classmethod
							def        __lowerCAmelCase      (  cls	:  List[str]							,      lowerCAmelCase_	:  List[Any]							,      **lowerCAmelCase_	:  Any )      ->							"PretrainedConfig":


														"""simple docstring"""


														cls._set_token_in_kwargs(lowerCAmelCase_ )

														_a					,							_a     					=    cls.get_config_dict(lowerCAmelCase_							,      **lowerCAmelCase_ )

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







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


														"""simple docstring"""


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

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







							@classmethod
							def        __lowerCAmelCase      (  cls	:  Optional[Any]							,      lowerCAmelCase_	:  Tuple							,      **lowerCAmelCase_	:  Optional[int] )      ->							"PretrainedConfig":


														"""simple docstring"""


														cls._set_token_in_kwargs(lowerCAmelCase_ )

														_a					,							_a     					=    cls.get_config_dict(lowerCAmelCase_							,      **lowerCAmelCase_ )

														# get the qformer config dict if we are loading from InstructBlipConfig
														if config_dict.get('''model_type''' ) == "instructblip":
																					_a     					=    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   (		__lowerCAmelCase   ):
							lowercase_          =    '''instructblip'''
							lowercase_          =    True







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


														"""simple docstring"""


														super().__init__(**lowerCAmelCase_ )

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

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

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

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

														_a     					=    self.text_config.tie_word_embeddings
														_a     					=    self.text_config.is_encoder_decoder

														_a     					=    num_query_tokens
														_a     					=    self.vision_config.hidden_size
														_a     					=    self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
														_a     					=    1.0
														_a     					=    0.0_2







							@classmethod
							def        __lowerCAmelCase      (  cls	:  List[Any]							,      lowerCAmelCase_	:  List[Any]							,      lowerCAmelCase_	:  int							,      lowerCAmelCase_	:  Any							,      **lowerCAmelCase_	:  List[str]							,      )      ->							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        __lowerCAmelCase      (  self	:  Union[str, Any] )      ->							Any:


														"""simple docstring"""


														_a     					=    copy.deepcopy(self.__dict__ )
														_a     					=    self.vision_config.to_dict()
														_a     					=    self.qformer_config.to_dict()
														_a     					=    self.text_config.to_dict()
														_a     					=    self.__class__.model_type
														return output







'''simple docstring'''


import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_bert import BertTokenizer


_snake_case				:				Any       							=		logging.get_logger(__name__)

_snake_case				:				Any       							=		{'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

_snake_case				:				List[str]       							=		{
    'vocab_file': {
        'bert-base-uncased': 'https://huggingface.co/bert-base-uncased/resolve/main/vocab.txt',
        'bert-large-uncased': 'https://huggingface.co/bert-large-uncased/resolve/main/vocab.txt',
        'bert-base-cased': 'https://huggingface.co/bert-base-cased/resolve/main/vocab.txt',
        'bert-large-cased': 'https://huggingface.co/bert-large-cased/resolve/main/vocab.txt',
        'bert-base-multilingual-uncased': (
            'https://huggingface.co/bert-base-multilingual-uncased/resolve/main/vocab.txt'
        ),
        'bert-base-multilingual-cased': 'https://huggingface.co/bert-base-multilingual-cased/resolve/main/vocab.txt',
        'bert-base-chinese': 'https://huggingface.co/bert-base-chinese/resolve/main/vocab.txt',
        'bert-base-german-cased': 'https://huggingface.co/bert-base-german-cased/resolve/main/vocab.txt',
        'bert-large-uncased-whole-word-masking': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/vocab.txt'
        ),
        'bert-large-cased-whole-word-masking': (
            'https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/vocab.txt'
        ),
        'bert-large-uncased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt'
        ),
        'bert-large-cased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt'
        ),
        'bert-base-cased-finetuned-mrpc': (
            'https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/vocab.txt'
        ),
        'bert-base-german-dbmdz-cased': 'https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/vocab.txt',
        'bert-base-german-dbmdz-uncased': (
            'https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/vocab.txt'
        ),
        'TurkuNLP/bert-base-finnish-cased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/vocab.txt'
        ),
        'TurkuNLP/bert-base-finnish-uncased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/vocab.txt'
        ),
        'wietsedv/bert-base-dutch-cased': (
            'https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/vocab.txt'
        ),
    },
    'tokenizer_file': {
        'bert-base-uncased': 'https://huggingface.co/bert-base-uncased/resolve/main/tokenizer.json',
        'bert-large-uncased': 'https://huggingface.co/bert-large-uncased/resolve/main/tokenizer.json',
        'bert-base-cased': 'https://huggingface.co/bert-base-cased/resolve/main/tokenizer.json',
        'bert-large-cased': 'https://huggingface.co/bert-large-cased/resolve/main/tokenizer.json',
        'bert-base-multilingual-uncased': (
            'https://huggingface.co/bert-base-multilingual-uncased/resolve/main/tokenizer.json'
        ),
        'bert-base-multilingual-cased': (
            'https://huggingface.co/bert-base-multilingual-cased/resolve/main/tokenizer.json'
        ),
        'bert-base-chinese': 'https://huggingface.co/bert-base-chinese/resolve/main/tokenizer.json',
        'bert-base-german-cased': 'https://huggingface.co/bert-base-german-cased/resolve/main/tokenizer.json',
        'bert-large-uncased-whole-word-masking': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/tokenizer.json'
        ),
        'bert-large-cased-whole-word-masking': (
            'https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/tokenizer.json'
        ),
        'bert-large-uncased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json'
        ),
        'bert-large-cased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json'
        ),
        'bert-base-cased-finetuned-mrpc': (
            'https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/tokenizer.json'
        ),
        'bert-base-german-dbmdz-cased': (
            'https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/tokenizer.json'
        ),
        'bert-base-german-dbmdz-uncased': (
            'https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/tokenizer.json'
        ),
        'TurkuNLP/bert-base-finnish-cased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/tokenizer.json'
        ),
        'TurkuNLP/bert-base-finnish-uncased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/tokenizer.json'
        ),
        'wietsedv/bert-base-dutch-cased': (
            'https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/tokenizer.json'
        ),
    },
}

_snake_case				:				int       							=		{
    'bert-base-uncased': 512,
    'bert-large-uncased': 512,
    'bert-base-cased': 512,
    'bert-large-cased': 512,
    'bert-base-multilingual-uncased': 512,
    'bert-base-multilingual-cased': 512,
    'bert-base-chinese': 512,
    'bert-base-german-cased': 512,
    'bert-large-uncased-whole-word-masking': 512,
    'bert-large-cased-whole-word-masking': 512,
    'bert-large-uncased-whole-word-masking-finetuned-squad': 512,
    'bert-large-cased-whole-word-masking-finetuned-squad': 512,
    'bert-base-cased-finetuned-mrpc': 512,
    'bert-base-german-dbmdz-cased': 512,
    'bert-base-german-dbmdz-uncased': 512,
    'TurkuNLP/bert-base-finnish-cased-v1': 512,
    'TurkuNLP/bert-base-finnish-uncased-v1': 512,
    'wietsedv/bert-base-dutch-cased': 512,
}

_snake_case				:				int       							=		{
    'bert-base-uncased': {'do_lower_case': True},
    'bert-large-uncased': {'do_lower_case': True},
    'bert-base-cased': {'do_lower_case': False},
    'bert-large-cased': {'do_lower_case': False},
    'bert-base-multilingual-uncased': {'do_lower_case': True},
    'bert-base-multilingual-cased': {'do_lower_case': False},
    'bert-base-chinese': {'do_lower_case': False},
    'bert-base-german-cased': {'do_lower_case': False},
    'bert-large-uncased-whole-word-masking': {'do_lower_case': True},
    'bert-large-cased-whole-word-masking': {'do_lower_case': False},
    'bert-large-uncased-whole-word-masking-finetuned-squad': {'do_lower_case': True},
    'bert-large-cased-whole-word-masking-finetuned-squad': {'do_lower_case': False},
    'bert-base-cased-finetuned-mrpc': {'do_lower_case': False},
    'bert-base-german-dbmdz-cased': {'do_lower_case': False},
    'bert-base-german-dbmdz-uncased': {'do_lower_case': True},
    'TurkuNLP/bert-base-finnish-cased-v1': {'do_lower_case': False},
    'TurkuNLP/bert-base-finnish-uncased-v1': {'do_lower_case': True},
    'wietsedv/bert-base-dutch-cased': {'do_lower_case': False},
}

class       A   (		_a   ):
							lowercase_          =    VOCAB_FILES_NAMES
							lowercase_          =    PRETRAINED_VOCAB_FILES_MAP
							lowercase_          =    PRETRAINED_INIT_CONFIGURATION
							lowercase_          =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							lowercase_          =    BertTokenizer







							def __init__(  self	:  str							,      lowerCAmelCase_	:  Union[str, Any]=None							,      lowerCAmelCase_	:  str=None							,      lowerCAmelCase_	:  List[Any]=True							,      lowerCAmelCase_	:  Any="[UNK]"							,      lowerCAmelCase_	:  Union[str, Any]="[SEP]"							,      lowerCAmelCase_	:  Tuple="[PAD]"							,      lowerCAmelCase_	:  Tuple="[CLS]"							,      lowerCAmelCase_	:  Optional[int]="[MASK]"							,      lowerCAmelCase_	:  Dict=True							,      lowerCAmelCase_	:  Union[str, Any]=None							,      **lowerCAmelCase_	:  Union[str, Any]							,      )      ->							Union[str, Any]:


														"""simple docstring"""


														super().__init__(
														    lowerCAmelCase_							,      tokenizer_file=lowerCAmelCase_							,      do_lower_case=lowerCAmelCase_							,      unk_token=lowerCAmelCase_							,      sep_token=lowerCAmelCase_							,      pad_token=lowerCAmelCase_							,      cls_token=lowerCAmelCase_							,      mask_token=lowerCAmelCase_							,      tokenize_chinese_chars=lowerCAmelCase_							,      strip_accents=lowerCAmelCase_							,      **lowerCAmelCase_							,      )

														_a     					=    json.loads(self.backend_tokenizer.normalizer.__getstate__() )
														if (
														    normalizer_state.get('''lowercase'''							,      lowerCAmelCase_ ) != do_lower_case
														    or normalizer_state.get('''strip_accents'''							,      lowerCAmelCase_ ) != strip_accents
														    or normalizer_state.get('''handle_chinese_chars'''							,      lowerCAmelCase_ ) != tokenize_chinese_chars
														):
																					_a     					=    getattr(lowerCAmelCase_							,      normalizer_state.pop('''type''' ) )
																					_a     					=    do_lower_case
																					_a     					=    strip_accents
																					_a     					=    tokenize_chinese_chars
																					_a     					=    normalizer_class(**lowerCAmelCase_ )

														_a     					=    do_lower_case







							def        __lowerCAmelCase      (  self	:  str							,      lowerCAmelCase_	:  Dict							,      lowerCAmelCase_	:  int=None )      ->							List[str]:


														"""simple docstring"""


														_a     					=    [self.cls_token_id] + token_ids_a + [self.sep_token_id]

														if token_ids_a:
																					output += token_ids_a + [self.sep_token_id]

														return output







							def        __lowerCAmelCase      (  self	:  Any							,      lowerCAmelCase_	:  List[int]							,      lowerCAmelCase_	:  Optional[List[int]] = None )      ->							List[int]:


														"""simple docstring"""


														_a     					=    [self.sep_token_id]
														_a     					=    [self.cls_token_id]
														if token_ids_a is None:
																					return len(cls + token_ids_a + sep ) * [0]
														return len(cls + token_ids_a + sep ) * [0] + len(token_ids_a + sep ) * [1]







							def        __lowerCAmelCase      (  self	:  List[Any]							,      lowerCAmelCase_	:  str							,      lowerCAmelCase_	:  Optional[str] = None )      ->							Tuple[str]:


														"""simple docstring"""


														_a     					=    self._tokenizer.model.save(lowerCAmelCase_							,      name=lowerCAmelCase_ )
														return tuple(lowerCAmelCase_ )

