



import os
from typing import List, Optional, Union

from ...image_processing_utils import BatchFeature
from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType
from ..auto import AutoTokenizer



class  __lowerCAmelCase     (	lowerCAmelCase__   ):
 lowerCAmelCase__       					=  ["""image_processor""", """tokenizer"""]
 lowerCAmelCase__       					=  """BlipImageProcessor"""
 lowerCAmelCase__       					=  """AutoTokenizer"""




 def __init__(						self	,				__UpperCAmelCase	,				__UpperCAmelCase	,				__UpperCAmelCase				):



    '''simple docstring'''
    super().__init__(__UpperCAmelCase	,				__UpperCAmelCase				)

    # add QFormer tokenizer
    __lowerCamelCase													=    qformer_tokenizer




 def __call__(						self	,				__UpperCAmelCase = None	,				__UpperCAmelCase = None	,				__UpperCAmelCase = True	,				__UpperCAmelCase = False	,				__UpperCAmelCase = None	,				__UpperCAmelCase = None	,				__UpperCAmelCase = 0	,				__UpperCAmelCase = None	,				__UpperCAmelCase = None	,				__UpperCAmelCase = False	,				__UpperCAmelCase = False	,				__UpperCAmelCase = False	,				__UpperCAmelCase = False	,				__UpperCAmelCase = False	,				__UpperCAmelCase = True	,				__UpperCAmelCase = None	,				**__UpperCAmelCase	,				):



    '''simple docstring'''
    if images is None and text is None:
       raise ValueError('''You have to specify at least images or text.'''				)

    __lowerCamelCase													=    BatchFeature()

    if text is not None:
       __lowerCamelCase													=    self.tokenizer(
           text=__UpperCAmelCase	,				add_special_tokens=__UpperCAmelCase	,				padding=__UpperCAmelCase	,				truncation=__UpperCAmelCase	,				max_length=__UpperCAmelCase	,				stride=__UpperCAmelCase	,				pad_to_multiple_of=__UpperCAmelCase	,				return_attention_mask=__UpperCAmelCase	,				return_overflowing_tokens=__UpperCAmelCase	,				return_special_tokens_mask=__UpperCAmelCase	,				return_offsets_mapping=__UpperCAmelCase	,				return_token_type_ids=__UpperCAmelCase	,				return_length=__UpperCAmelCase	,				verbose=__UpperCAmelCase	,				return_tensors=__UpperCAmelCase	,				**__UpperCAmelCase	,				)
       encoding.update(__UpperCAmelCase				)
       __lowerCamelCase													=    self.qformer_tokenizer(
           text=__UpperCAmelCase	,				add_special_tokens=__UpperCAmelCase	,				padding=__UpperCAmelCase	,				truncation=__UpperCAmelCase	,				max_length=__UpperCAmelCase	,				stride=__UpperCAmelCase	,				pad_to_multiple_of=__UpperCAmelCase	,				return_attention_mask=__UpperCAmelCase	,				return_overflowing_tokens=__UpperCAmelCase	,				return_special_tokens_mask=__UpperCAmelCase	,				return_offsets_mapping=__UpperCAmelCase	,				return_token_type_ids=__UpperCAmelCase	,				return_length=__UpperCAmelCase	,				verbose=__UpperCAmelCase	,				return_tensors=__UpperCAmelCase	,				**__UpperCAmelCase	,				)
       __lowerCamelCase													=    qformer_text_encoding.pop('''input_ids'''				)
       __lowerCamelCase													=    qformer_text_encoding.pop('''attention_mask'''				)

    if images is not None:
       __lowerCamelCase													=    self.image_processor(__UpperCAmelCase	,				return_tensors=__UpperCAmelCase				)
       encoding.update(__UpperCAmelCase				)

    return encoding




 def        lowerCamelCase      (						self	,				*__UpperCAmelCase	,				**__UpperCAmelCase				):



    '''simple docstring'''
    return self.tokenizer.batch_decode(*__UpperCAmelCase	,				**__UpperCAmelCase				)




 def        lowerCamelCase      (						self	,				*__UpperCAmelCase	,				**__UpperCAmelCase				):



    '''simple docstring'''
    return self.tokenizer.decode(*__UpperCAmelCase	,				**__UpperCAmelCase				)




 @property
 # Copied from transformers.models.blip.processing_blip.BlipProcessor.model_input_names
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    __lowerCamelCase													=    self.tokenizer.model_input_names
    __lowerCamelCase													=    self.image_processor.model_input_names
    return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names				)				)




 def        lowerCamelCase      (						self	,				__UpperCAmelCase	,				**__UpperCAmelCase				):



    '''simple docstring'''
    if os.path.isfile(__UpperCAmelCase				):
       raise ValueError(F"""Provided path ({save_directory}) should be a directory, not a file"""				)
    os.makedirs(__UpperCAmelCase	,				exist_ok=__UpperCAmelCase				)
    __lowerCamelCase													=    os.path.join(__UpperCAmelCase	,				'''qformer_tokenizer'''				)
    self.qformer_tokenizer.save_pretrained(__UpperCAmelCase				)
    return super().save_pretrained(__UpperCAmelCase	,				**__UpperCAmelCase				)




 @classmethod
 def        lowerCamelCase      (						cls	,				__UpperCAmelCase	,				**__UpperCAmelCase				):



    '''simple docstring'''
    __lowerCamelCase													=    AutoTokenizer.from_pretrained(__UpperCAmelCase	,				subfolder='''qformer_tokenizer'''				)
    __lowerCamelCase													=    cls._get_arguments_from_pretrained(__UpperCAmelCase	,				**__UpperCAmelCase				)
    args.append(__UpperCAmelCase				)
    return cls(*__UpperCAmelCase				)











from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


a_			=					logging.get_logger(__name__)

a_			=					{
    """sail/poolformer_s12""": """https://huggingface.co/sail/poolformer_s12/resolve/main/config.json""",
    # See all PoolFormer models at https://huggingface.co/models?filter=poolformer
}



class  __lowerCAmelCase     (	lowerCAmelCase__   ):
 lowerCAmelCase__       					=  """poolformer"""




 def __init__(						self	,				__UpperCAmelCase=3	,				__UpperCAmelCase=16	,				__UpperCAmelCase=16	,				__UpperCAmelCase=3	,				__UpperCAmelCase=4.0	,				__UpperCAmelCase=[2, 2, 6, 2]	,				__UpperCAmelCase=[64, 128, 320, 512]	,				__UpperCAmelCase=[7, 3, 3, 3]	,				__UpperCAmelCase=[4, 2, 2, 2]	,				__UpperCAmelCase=[2, 1, 1, 1]	,				__UpperCAmelCase=4	,				__UpperCAmelCase=0.0	,				__UpperCAmelCase="gelu"	,				__UpperCAmelCase=True	,				__UpperCAmelCase=1E-5	,				__UpperCAmelCase=0.02	,				**__UpperCAmelCase	,				):



    '''simple docstring'''
    __lowerCamelCase													=    num_channels
    __lowerCamelCase													=    patch_size
    __lowerCamelCase													=    stride
    __lowerCamelCase													=    padding
    __lowerCamelCase													=    pool_size
    __lowerCamelCase													=    hidden_sizes
    __lowerCamelCase													=    mlp_ratio
    __lowerCamelCase													=    depths
    __lowerCamelCase													=    patch_sizes
    __lowerCamelCase													=    strides
    __lowerCamelCase													=    num_encoder_blocks
    __lowerCamelCase													=    drop_path_rate
    __lowerCamelCase													=    hidden_act
    __lowerCamelCase													=    use_layer_scale
    __lowerCamelCase													=    layer_scale_init_value
    __lowerCamelCase													=    initializer_range
    super().__init__(**__UpperCAmelCase				)



class  __lowerCAmelCase     (	lowerCAmelCase__   ):
 lowerCAmelCase__       					=  version.parse("""1.11"""   )




 @property
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    return OrderedDict(
        [
            ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
        ]				)




 @property
 def        lowerCamelCase      (						self				):



    '''simple docstring'''
    return 2E-3






