"""simple docstring"""






import unittest

import requests

from transformers import MODEL_FOR_VISION_2_SEQ_MAPPING, TF_MODEL_FOR_VISION_2_SEQ_MAPPING, is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    is_torch_available,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_torch_available():
       from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_11
else:
       __A         =				False


if is_vision_available():
       from PIL import Image
else:


       class 					UpperCAmelCase		:



           """simple docstring"""

           @staticmethod
           def _snake_case    (     *_UpperCAmelCase					,    **_UpperCAmelCase							):
              pass


@is_pipeline_test
@require_vision
class 					UpperCAmelCase		(unittest.TestCase						):



    """simple docstring"""

    _UpperCAmelCase			:List[str]							=				MODEL_FOR_VISION_2_SEQ_MAPPING
    _UpperCAmelCase			:Optional[int]							=				TF_MODEL_FOR_VISION_2_SEQ_MAPPING






    def _snake_case    (     self					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase							):
       lowercase__:     Dict      =   pipeline('''image-to-text'''					,    model=_UpperCAmelCase					,    tokenizer=_UpperCAmelCase					,    image_processor=_UpperCAmelCase							)
       lowercase__:     Dict      =   [
           Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							),
           '''./tests/fixtures/tests_samples/COCO/000000039769.png''',
       ]
       return pipe, examples






    def _snake_case    (     self					,    _UpperCAmelCase					,    _UpperCAmelCase							):
       lowercase__:     List[str]      =   pipe(_UpperCAmelCase							)
       self.assertEqual(
           _UpperCAmelCase					,    [
               [{'''generated_text''': ANY(_UpperCAmelCase							)}],
               [{'''generated_text''': ANY(_UpperCAmelCase							)}],
           ]					,    )






    @require_tf
    def _snake_case    (     self							):
       lowercase__:     int      =   pipeline('''image-to-text'''					,    model='''hf-internal-testing/tiny-random-vit-gpt2'''					,    framework='''tf'''							)
       lowercase__:     List[str]      =   '''./tests/fixtures/tests_samples/COCO/000000039769.png'''

       lowercase__:     Dict      =   pipe(_UpperCAmelCase							)
       self.assertEqual(
           _UpperCAmelCase					,    [
               {
                   '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
               },
           ]					,    )

       lowercase__:     List[str]      =   pipe([image, image]							)
       self.assertEqual(
           _UpperCAmelCase					,    [
               [
                   {
                       '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                   }
               ],
               [
                   {
                       '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                   }
               ],
           ]					,    )

       lowercase__:     Union[str, Any]      =   pipe(_UpperCAmelCase					,    max_new_tokens=1							)
       self.assertEqual(
           _UpperCAmelCase					,    [{'''generated_text''': '''growth'''}]					,    )






    @require_torch
    def _snake_case    (     self							):
       lowercase__:     Any      =   pipeline('''image-to-text'''					,    model='''hf-internal-testing/tiny-random-vit-gpt2'''							)
       lowercase__:     Optional[int]      =   '''./tests/fixtures/tests_samples/COCO/000000039769.png'''

       lowercase__:     List[str]      =   pipe(_UpperCAmelCase							)
       self.assertEqual(
           _UpperCAmelCase					,    [
               {
                   '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
               },
           ]					,    )

       lowercase__:     Any      =   pipe([image, image]							)
       self.assertEqual(
           _UpperCAmelCase					,    [
               [
                   {
                       '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                   }
               ],
               [
                   {
                       '''generated_text''': '''growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO'''
                   }
               ],
           ]					,    )






    @require_torch
    def _snake_case    (     self							):
       lowercase__:     Tuple      =   pipeline('''image-to-text'''					,    model='''hf-internal-testing/tiny-random-BlipForConditionalGeneration'''							)
       lowercase__:     Optional[Any]      =   '''./tests/fixtures/tests_samples/COCO/000000039769.png'''
       lowercase__:     Union[str, Any]      =   '''a photo of'''

       lowercase__:     Optional[int]      =   pipe(_UpperCAmelCase					,    prompt=_UpperCAmelCase							)
       self.assertTrue(outputs[0]['''generated_text'''].startswith(_UpperCAmelCase							)							)






    @slow
    @require_torch
    def _snake_case    (     self							):
       lowercase__:     Tuple      =   pipeline('''image-to-text'''					,    model='''ydshieh/vit-gpt2-coco-en'''							)
       lowercase__:     Tuple      =   '''./tests/fixtures/tests_samples/COCO/000000039769.png'''

       lowercase__:     Dict      =   pipe(_UpperCAmelCase							)
       self.assertEqual(_UpperCAmelCase					,    [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}]							)

       lowercase__:     Dict      =   pipe([image, image]							)
       self.assertEqual(
           _UpperCAmelCase					,    [
               [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}],
               [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}],
           ]					,    )






    @slow
    @require_torch
    def _snake_case    (     self							):
       lowercase__:     int      =   pipeline('''image-to-text'''					,    model='''Salesforce/blip-image-captioning-base'''							)
       lowercase__:     Optional[Any]      =   '''https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png'''
       lowercase__:     str      =   Image.open(requests.get(_UpperCAmelCase					,    stream=_UpperCAmelCase							).raw							)

       lowercase__:     Optional[Any]      =   pipe(_UpperCAmelCase							)
       self.assertEqual(_UpperCAmelCase					,    [{'''generated_text''': '''a pink pokemon pokemon with a blue shirt and a blue shirt'''}]							)






    @slow
    @require_torch
    def _snake_case    (     self							):
       lowercase__:     Dict      =   pipeline('''image-to-text'''					,    model='''microsoft/git-base-coco'''							)
       lowercase__:     int      =   '''https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png'''
       lowercase__:     List[str]      =   Image.open(requests.get(_UpperCAmelCase					,    stream=_UpperCAmelCase							).raw							)

       lowercase__:     Tuple      =   pipe(_UpperCAmelCase							)
       self.assertEqual(_UpperCAmelCase					,    [{'''generated_text''': '''a cartoon of a purple character.'''}]							)






    @slow
    @require_torch
    def _snake_case    (     self							):
       lowercase__:     Tuple      =   pipeline('''image-to-text'''					,    model='''Salesforce/blip-image-captioning-base'''							)
       lowercase__:     Optional[Any]      =   '''https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'''
       lowercase__:     List[str]      =   Image.open(requests.get(_UpperCAmelCase					,    stream=_UpperCAmelCase							).raw							)

       lowercase__:     Any      =   '''a photography of'''

       lowercase__:     str      =   pipe(_UpperCAmelCase					,    prompt=_UpperCAmelCase							)
       self.assertEqual(_UpperCAmelCase					,    [{'''generated_text''': '''a photography of a volcano'''}]							)

       with self.assertRaises(_UpperCAmelCase							):
          lowercase__:     List[str]      =   pipe([image, image]					,    prompt=[prompt, prompt]							)






    @slow
    @require_torch
    def _snake_case    (     self							):
       lowercase__:     Optional[Any]      =   pipeline('''image-to-text'''					,    model='''microsoft/git-base-coco'''							)
       lowercase__:     Optional[int]      =   '''https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'''
       lowercase__:     List[str]      =   Image.open(requests.get(_UpperCAmelCase					,    stream=_UpperCAmelCase							).raw							)

       lowercase__:     int      =   '''a photo of a'''

       lowercase__:     str      =   pipe(_UpperCAmelCase					,    prompt=_UpperCAmelCase							)
       self.assertEqual(_UpperCAmelCase					,    [{'''generated_text''': '''a photo of a tent with a tent and a tent in the background.'''}]							)

       with self.assertRaises(_UpperCAmelCase							):
          lowercase__:     List[Any]      =   pipe([image, image]					,    prompt=[prompt, prompt]							)






    @unittest.skipIf(
        not is_torch_greater_or_equal_than_1_11					,    reason='''`Pix2StructImageProcessor` requires `torch>=1.11.0`.'''							)
    @slow
    @require_torch
    def _snake_case    (     self							):
       lowercase__:     List[Any]      =   pipeline('''image-to-text'''					,    model='''google/pix2struct-ai2d-base'''							)
       lowercase__:     Optional[Any]      =   '''https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg'''
       lowercase__:     int      =   Image.open(requests.get(_UpperCAmelCase					,    stream=_UpperCAmelCase							).raw							)

       lowercase__:     List[Any]      =   '''What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud'''

       lowercase__:     int      =   pipe(_UpperCAmelCase					,    prompt=_UpperCAmelCase							)
       self.assertEqual(_UpperCAmelCase					,    [{'''generated_text''': '''ash cloud'''}]							)

       with self.assertRaises(_UpperCAmelCase							):
          lowercase__:     Any      =   pipe([image, image]					,    prompt=[prompt, prompt]							)






    @slow
    @require_tf
    def _snake_case    (     self							):
       lowercase__:     Optional[int]      =   pipeline('''image-to-text'''					,    model='''ydshieh/vit-gpt2-coco-en'''					,    framework='''tf'''							)
       lowercase__:     Union[str, Any]      =   '''./tests/fixtures/tests_samples/COCO/000000039769.png'''

       lowercase__:     List[Any]      =   pipe(_UpperCAmelCase							)
       self.assertEqual(_UpperCAmelCase					,    [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}]							)

       lowercase__:     Optional[Any]      =   pipe([image, image]							)
       self.assertEqual(
           _UpperCAmelCase					,    [
               [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}],
               [{'''generated_text''': '''a cat laying on a blanket next to a cat laying on a bed '''}],
           ]					,    )

"""simple docstring"""






from ...configuration_utils import PretrainedConfig
from ...utils import logging


__A         =				logging.get_logger(__name__)

__A         =				{
    "uw-madison/yoso-4096": "https://huggingface.co/uw-madison/yoso-4096/resolve/main/config.json",
    # See all YOSO models at https://huggingface.co/models?filter=yoso
}


class 					UpperCAmelCase		(_UpperCAmelCase						):



    """simple docstring"""

    _UpperCAmelCase			:Tuple							=				"yoso"






    def __init__(     self					,    _UpperCAmelCase=50265					,    _UpperCAmelCase=768					,    _UpperCAmelCase=12					,    _UpperCAmelCase=12					,    _UpperCAmelCase=3072					,    _UpperCAmelCase="gelu"					,    _UpperCAmelCase=0.1					,    _UpperCAmelCase=0.1					,    _UpperCAmelCase=4096					,    _UpperCAmelCase=1					,    _UpperCAmelCase=0.02					,    _UpperCAmelCase=1e-1_2					,    _UpperCAmelCase="absolute"					,    _UpperCAmelCase=True					,    _UpperCAmelCase=9					,    _UpperCAmelCase=64					,    _UpperCAmelCase=None					,    _UpperCAmelCase=True					,    _UpperCAmelCase=True					,    _UpperCAmelCase=1					,    _UpperCAmelCase=0					,    _UpperCAmelCase=2					,    **_UpperCAmelCase					,    ):
       super().__init__(pad_token_id=_UpperCAmelCase					,    bos_token_id=_UpperCAmelCase					,    eos_token_id=_UpperCAmelCase					,    **_UpperCAmelCase							)

       lowercase__:     int      =   vocab_size
       lowercase__:     List[str]      =   max_position_embeddings
       lowercase__:     Tuple      =   hidden_size
       lowercase__:     Optional[Any]      =   num_hidden_layers
       lowercase__:     Optional[int]      =   num_attention_heads
       lowercase__:     List[Any]      =   intermediate_size
       lowercase__:     Union[str, Any]      =   hidden_act
       lowercase__:     int      =   hidden_dropout_prob
       lowercase__:     Optional[Any]      =   attention_probs_dropout_prob
       lowercase__:     List[Any]      =   initializer_range
       lowercase__:     Optional[Any]      =   type_vocab_size
       lowercase__:     int      =   layer_norm_eps
       lowercase__:     Optional[Any]      =   position_embedding_type
       lowercase__:     int      =   use_expectation
       lowercase__:     List[str]      =   hash_code_len
       lowercase__:     Union[str, Any]      =   num_hash
       lowercase__:     Any      =   conv_window
       lowercase__:     Dict      =   use_fast_hash
       lowercase__:     Dict      =   lsh_backward
