code: 
  
  
  
  
  
  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:
         UpperCAmelCase			:			Dict	  = False
  
  
  if is_vision_available():
         from PIL import Image
  else:
  
  
  
  
  
  
  
         class        __lowerCAmelCase :
  
  
  
  
  
  
  
               @staticmethod
               def      _lowercase						(					*lowerCAmelCase__	,   **lowerCAmelCase__							)     ->		Any:
  
  
  
                 '''simple docstring'''
  
  
  
  
                 pass
  
  
  
  
  
  
  
  @is_pipeline_test
  @require_vision
  class        __lowerCAmelCase (					unittest.TestCase):
        _lowercase       :      str        =    MODEL_FOR_VISION_2_SEQ_MAPPING
        _lowercase       :      List[Any]        =    TF_MODEL_FOR_VISION_2_SEQ_MAPPING
  
  
  
  
  
  
  
        def      _lowercase						(					self	,   lowerCAmelCase__	,   lowerCAmelCase__	,   lowerCAmelCase__							)     ->		List[Any]:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      int            =pipeline("image-to-text"	,   model=lowerCAmelCase__	,   tokenizer=lowerCAmelCase__	,   image_processor=lowerCAmelCase__							)
          a__			:      List[str]            =[
              Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"							),
              "./tests/fixtures/tests_samples/COCO/000000039769.png",
          ]
          return pipe, examples
  
  
  
  
  
  
  
        def      _lowercase						(					self	,   lowerCAmelCase__	,   lowerCAmelCase__							)     ->		Tuple:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      List[Any]            =pipe(lowerCAmelCase__							)
          self.assertEqual(
              lowerCAmelCase__	,   [
                  [{"generated_text": ANY(lowerCAmelCase__							)}],
                  [{"generated_text": ANY(lowerCAmelCase__							)}],
              ]	,   )
  
  
  
  
  
  
  
        @require_tf
        def      _lowercase						(					self							)     ->		Union[str, Any]:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      Optional[int]            =pipeline("image-to-text"	,   model="hf-internal-testing/tiny-random-vit-gpt2"	,   framework="tf"							)
          a__			:      Optional[int]            ="./tests/fixtures/tests_samples/COCO/000000039769.png"
  
          a__			:      Dict            =pipe(lowerCAmelCase__							)
          self.assertEqual(
              lowerCAmelCase__	,   [
                  {
                      "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                  },
              ]	,   )
  
          a__			:      Dict            =pipe([image, image]							)
          self.assertEqual(
              lowerCAmelCase__	,   [
                  [
                      {
                          "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                      }
                  ],
                  [
                      {
                          "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                      }
                  ],
              ]	,   )
  
          a__			:      Optional[int]            =pipe(lowerCAmelCase__	,   max_new_tokens=1							)
          self.assertEqual(
              lowerCAmelCase__	,   [{"generated_text": "growth"}]	,   )
  
  
  
  
  
  
  
        @require_torch
        def      _lowercase						(					self							)     ->		Tuple:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      Any            =pipeline("image-to-text"	,   model="hf-internal-testing/tiny-random-vit-gpt2"							)
          a__			:      Optional[Any]            ="./tests/fixtures/tests_samples/COCO/000000039769.png"
  
          a__			:      Any            =pipe(lowerCAmelCase__							)
          self.assertEqual(
              lowerCAmelCase__	,   [
                  {
                      "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                  },
              ]	,   )
  
          a__			:      List[str]            =pipe([image, image]							)
          self.assertEqual(
              lowerCAmelCase__	,   [
                  [
                      {
                          "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                      }
                  ],
                  [
                      {
                          "generated_text": "growthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthgrowthGOGO"
                      }
                  ],
              ]	,   )
  
  
  
  
  
  
  
        @require_torch
        def      _lowercase						(					self							)     ->		Dict:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      Dict            =pipeline("image-to-text"	,   model="hf-internal-testing/tiny-random-BlipForConditionalGeneration"							)
          a__			:      Union[str, Any]            ="./tests/fixtures/tests_samples/COCO/000000039769.png"
          a__			:      Union[str, Any]            ="a photo of"
  
          a__			:      Optional[int]            =pipe(lowerCAmelCase__	,   prompt=lowerCAmelCase__							)
          self.assertTrue(outputs[0]["generated_text"].startswith(lowerCAmelCase__							)							)
  
  
  
  
  
  
  
        @slow
        @require_torch
        def      _lowercase						(					self							)     ->		Union[str, Any]:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      Tuple            =pipeline("image-to-text"	,   model="ydshieh/vit-gpt2-coco-en"							)
          a__			:      Union[str, Any]            ="./tests/fixtures/tests_samples/COCO/000000039769.png"
  
          a__			:      List[str]            =pipe(lowerCAmelCase__							)
          self.assertEqual(lowerCAmelCase__	,   [{"generated_text": "a cat laying on a blanket next to a cat laying on a bed "}]							)
  
          a__			:      int            =pipe([image, image]							)
          self.assertEqual(
              lowerCAmelCase__	,   [
                  [{"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      _lowercase						(					self							)     ->		str:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      List[Any]            =pipeline("image-to-text"	,   model="Salesforce/blip-image-captioning-base"							)
          a__			:      List[str]            ="https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
          a__			:      Union[str, Any]            =Image.open(requests.get(lowerCAmelCase__	,   stream=lowerCAmelCase__							).raw							)
  
          a__			:      List[str]            =pipe(lowerCAmelCase__							)
          self.assertEqual(lowerCAmelCase__	,   [{"generated_text": "a pink pokemon pokemon with a blue shirt and a blue shirt"}]							)
  
  
  
  
  
  
  
        @slow
        @require_torch
        def      _lowercase						(					self							)     ->		Optional[int]:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      Dict            =pipeline("image-to-text"	,   model="microsoft/git-base-coco"							)
          a__			:      Dict            ="https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/pokemon.png"
          a__			:      Union[str, Any]            =Image.open(requests.get(lowerCAmelCase__	,   stream=lowerCAmelCase__							).raw							)
  
          a__			:      int            =pipe(lowerCAmelCase__							)
          self.assertEqual(lowerCAmelCase__	,   [{"generated_text": "a cartoon of a purple character."}]							)
  
  
  
  
  
  
  
        @slow
        @require_torch
        def      _lowercase						(					self							)     ->		Optional[Any]:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      List[Any]            =pipeline("image-to-text"	,   model="Salesforce/blip-image-captioning-base"							)
          a__			:      str            ="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
          a__			:      Optional[Any]            =Image.open(requests.get(lowerCAmelCase__	,   stream=lowerCAmelCase__							).raw							)
  
          a__			:      int            ="a photography of"
  
          a__			:      Any            =pipe(lowerCAmelCase__	,   prompt=lowerCAmelCase__							)
          self.assertEqual(lowerCAmelCase__	,   [{"generated_text": "a photography of a volcano"}]							)
  
          with self.assertRaises(lowerCAmelCase__							):
            a__			:      List[Any]            =pipe([image, image]	,   prompt=[prompt, prompt]							)
  
  
  
  
  
  
  
        @slow
        @require_torch
        def      _lowercase						(					self							)     ->		Tuple:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      int            =pipeline("image-to-text"	,   model="microsoft/git-base-coco"							)
          a__			:      str            ="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
          a__			:      List[str]            =Image.open(requests.get(lowerCAmelCase__	,   stream=lowerCAmelCase__							).raw							)
  
          a__			:      int            ="a photo of a"
  
          a__			:      Dict            =pipe(lowerCAmelCase__	,   prompt=lowerCAmelCase__							)
          self.assertEqual(lowerCAmelCase__	,   [{"generated_text": "a photo of a tent with a tent and a tent in the background."}]							)
  
          with self.assertRaises(lowerCAmelCase__							):
            a__			:      str            =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      _lowercase						(					self							)     ->		List[str]:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      int            =pipeline("image-to-text"	,   model="google/pix2struct-ai2d-base"							)
          a__			:      List[str]            ="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/ai2d-demo.jpg"
          a__			:      Dict            =Image.open(requests.get(lowerCAmelCase__	,   stream=lowerCAmelCase__							).raw							)
  
          a__			:      Union[str, Any]            ="What does the label 15 represent? (1) lava (2) core (3) tunnel (4) ash cloud"
  
          a__			:      int            =pipe(lowerCAmelCase__	,   prompt=lowerCAmelCase__							)
          self.assertEqual(lowerCAmelCase__	,   [{"generated_text": "ash cloud"}]							)
  
          with self.assertRaises(lowerCAmelCase__							):
            a__			:      str            =pipe([image, image]	,   prompt=[prompt, prompt]							)
  
  
  
  
  
  
  
        @slow
        @require_tf
        def      _lowercase						(					self							)     ->		Tuple:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      Union[str, Any]            =pipeline("image-to-text"	,   model="ydshieh/vit-gpt2-coco-en"	,   framework="tf"							)
          a__			:      Optional[int]            ="./tests/fixtures/tests_samples/COCO/000000039769.png"
  
          a__			:      List[Any]            =pipe(lowerCAmelCase__							)
          self.assertEqual(lowerCAmelCase__	,   [{"generated_text": "a cat laying on a blanket next to a cat laying on a bed "}]							)
  
          a__			:      int            =pipe([image, image]							)
          self.assertEqual(
              lowerCAmelCase__	,   [
                  [{"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 "}],
              ]	,   )
  
  
  
  
  
  
  
style_context: 
  
  
  
  
  
  import importlib
  import sys
  from argparse import REMAINDER, ArgumentParser
  from pathlib import Path
  
  import torch_xla.distributed.xla_multiprocessing as xmp
  def   _A (	):
  
  
  
  
  
    """simple docstring"""
  
  
  
    a__			:      Optional[int]            =ArgumentParser(
        description=(
            "PyTorch TPU distributed training launch helper utility that will spawn up multiple distributed processes"
        )		)
  
    # Optional arguments for the launch helper
    parser.add_argument("--num_cores" , type=SCREAMING_SNAKE_CASE , default=1 , help="Number of TPU cores to use (1 or 8)."		)
  
    # positional
    parser.add_argument(
        "training_script" , type=SCREAMING_SNAKE_CASE , help=(
            "The full path to the single TPU training "
            "program/script to be launched in parallel, "
            "followed by all the arguments for the "
            "training script"
        ) , )
  
    # rest from the training program
    parser.add_argument("training_script_args" , nargs=SCREAMING_SNAKE_CASE		)
  
    return parser.parse_args()
  def   _A (	):
  
  
  
  
  
    """simple docstring"""
  
  
  
    a__			:      Optional[Any]            =parse_args()
  
    # Import training_script as a module.
    a__			:      Tuple            =Path(args.training_script		)
    sys.path.append(str(script_fpath.parent.resolve()		)		)
    a__			:      Tuple            =script_fpath.stem
    a__			:      Any            =importlib.import_module(SCREAMING_SNAKE_CASE		)
  
    # Patch sys.argv
    a__			:      List[str]            =[args.training_script] + args.training_script_args + ["--tpu_num_cores", str(args.num_cores		)]
  
    xmp.spawn(mod._mp_fn , args=() , nprocs=args.num_cores		)
  
  
  if __name__ == "__main__":
       main()
  
  
  
  
  
  
  