



"""simple docstring"""




import inspect
import unittest

from transformers import MobileViTVaConfig
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers import MobileViTVaForImageClassification, MobileViTVaForSemanticSegmentation, MobileViTVaModel
    from transformers.models.mobilevitva.modeling_mobilevitva import (
        MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST,
        make_divisible,
    )


if is_vision_available():
    from PIL import Image

    from transformers import MobileViTImageProcessor



class     lowerCAmelCase_		(  UpperCamelCase__							):
       def  snake_case_	(      self	)					->		Union[str, Any]:
          UpperCamelCase   :  Any						     =     self.config_class(**self.inputs_dict	)
          self.parent.assertTrue(hasattr(__a,      'width_multiplier'	)	)






class     lowerCAmelCase_		:
       def __init__(      self,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_=13,      SCREAMING_SNAKE_CASE_=64,      SCREAMING_SNAKE_CASE_=2,      SCREAMING_SNAKE_CASE_=3,      SCREAMING_SNAKE_CASE_="swish",      SCREAMING_SNAKE_CASE_=3,      SCREAMING_SNAKE_CASE_=32,      SCREAMING_SNAKE_CASE_=0.1,      SCREAMING_SNAKE_CASE_=0.02,      SCREAMING_SNAKE_CASE_=True,      SCREAMING_SNAKE_CASE_=True,      SCREAMING_SNAKE_CASE_=10,      SCREAMING_SNAKE_CASE_=None,      SCREAMING_SNAKE_CASE_=0.25,      SCREAMING_SNAKE_CASE_=0.0,      SCREAMING_SNAKE_CASE_=0.0,      )					->		Union[str, Any]:
          UpperCamelCase   :  int						     =     parent
          UpperCamelCase   :  int						     =     batch_size
          UpperCamelCase   :  Optional[Any]						     =     image_size
          UpperCamelCase   :  List[Any]						     =     patch_size
          UpperCamelCase   :  List[str]						     =     num_channels
          UpperCamelCase   :  Any						     =     make_divisible(512 * width_multiplier,      divisor=8	)
          UpperCamelCase   :  int						     =     hidden_act
          UpperCamelCase   :  Union[str, Any]						     =     conv_kernel_size
          UpperCamelCase   :  Tuple						     =     output_stride
          UpperCamelCase   :  Any						     =     classifier_dropout_prob
          UpperCamelCase   :  Optional[int]						     =     use_labels
          UpperCamelCase   :  List[Any]						     =     is_training
          UpperCamelCase   :  Dict						     =     num_labels
          UpperCamelCase   :  Tuple						     =     initializer_range
          UpperCamelCase   :  Optional[Any]						     =     scope
          UpperCamelCase   :  Optional[Any]						     =     width_multiplier
          UpperCamelCase   :  str						     =     ffn_dropout
          UpperCamelCase   :  Dict						     =     attn_dropout
       def  snake_case_	(      self	)					->		str:
          UpperCamelCase   :  Optional[Any]						     =     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]	)

          UpperCamelCase   :  List[Any]						     =     None
          UpperCamelCase   :  Optional[Any]						     =     None
          if self.use_labels:
             UpperCamelCase   :  Tuple						     =     ids_tensor([self.batch_size],      self.num_labels	)
             UpperCamelCase   :  List[Any]						     =     ids_tensor([self.batch_size, self.image_size, self.image_size],      self.num_labels	)

          UpperCamelCase   :  Optional[Any]						     =     self.get_config()

          return config, pixel_values, labels, pixel_labels
       def  snake_case_	(      self	)					->		Tuple:
          return MobileViTVaConfig(
              image_size=self.image_size,      patch_size=self.patch_size,      num_channels=self.num_channels,      hidden_act=self.hidden_act,      conv_kernel_size=self.conv_kernel_size,      output_stride=self.output_stride,      classifier_dropout_prob=self.classifier_dropout_prob,      initializer_range=self.initializer_range,      width_multiplier=self.width_multiplier,      ffn_dropout=self.ffn_dropout_prob,      attn_dropout=self.attn_dropout_prob,      )
       def  snake_case_	(      self,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_	)					->		Optional[Any]:
          UpperCamelCase   :  Optional[Any]						     =     MobileViTVaModel(config=__a	)
          model.to(__a	)
          model.eval()
          UpperCamelCase   :  List[str]						     =     model(__a	)
          self.parent.assertEqual(
              result.last_hidden_state.shape,      (
                  self.batch_size,
                  self.last_hidden_size,
                  self.image_size // self.output_stride,
                  self.image_size // self.output_stride,
              ),      )
       def  snake_case_	(      self,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_	)					->		Tuple:
          UpperCamelCase   :  Dict						     =     self.num_labels
          UpperCamelCase   :  str						     =     MobileViTVaForImageClassification(__a	)
          model.to(__a	)
          model.eval()
          UpperCamelCase   :  List[Any]						     =     model(__a,      labels=__a	)
          self.parent.assertEqual(result.logits.shape,      (self.batch_size, self.num_labels)	)
       def  snake_case_	(      self,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_	)					->		int:
          UpperCamelCase   :  Tuple						     =     self.num_labels
          UpperCamelCase   :  List[Any]						     =     MobileViTVaForSemanticSegmentation(__a	)
          model.to(__a	)
          model.eval()
          UpperCamelCase   :  str						     =     model(__a	)
          self.parent.assertEqual(
              result.logits.shape,      (
                  self.batch_size,
                  self.num_labels,
                  self.image_size // self.output_stride,
                  self.image_size // self.output_stride,
              ),      )
          UpperCamelCase   :  Optional[Any]						     =     model(__a,      labels=__a	)
          self.parent.assertEqual(
              result.logits.shape,      (
                  self.batch_size,
                  self.num_labels,
                  self.image_size // self.output_stride,
                  self.image_size // self.output_stride,
              ),      )






       def  snake_case_	(      self	)					->		Tuple:
          UpperCamelCase   :  str						     =     self.prepare_config_and_inputs()
          UpperCamelCase     ,					UpperCamelCase     ,					UpperCamelCase     ,					UpperCamelCase   :  Optional[Any]						     =     config_and_inputs
          UpperCamelCase   :  Optional[int]						     =     {'pixel_values': pixel_values}
          return config, inputs_dict






@require_torch
class     lowerCAmelCase_		(  UpperCamelCase__	,   UpperCamelCase__	,   unittest.TestCase							):
       UpperCAmelCase__    : str       					=  (
           (MobileViTVaModel, MobileViTVaForImageClassification, MobileViTVaForSemanticSegmentation)
           if is_torch_available()
           else ()
       )

       UpperCAmelCase__    : Any       					=  (
           {
               """feature-extraction""": MobileViTVaModel,
               """image-classification""": MobileViTVaForImageClassification,
               """image-segmentation""": MobileViTVaForSemanticSegmentation,
           }
           if is_torch_available()
           else {}
       )

       UpperCAmelCase__    : List[Any]       					=  False
       UpperCAmelCase__    : str       					=  False
       UpperCAmelCase__    : Union[str, Any]       					=  False
       UpperCAmelCase__    : int       					=  False
       def  snake_case_	(      self	)					->		List[str]:
          UpperCamelCase   :  int						     =     MobileViTVaModelTester(self	)
          UpperCamelCase   :  List[Any]						     =     MobileViTVaConfigTester(self,      config_class=__a,      has_text_modality=__a	)
       def  snake_case_	(      self	)					->		List[Any]:
          self.config_tester.run_common_tests()
       @unittest.skip(reason='MobileViTV2 does not use inputs_embeds'	)
       def  snake_case_	(      self	)					->		Optional[Any]:
          pass
       @unittest.skip(reason='MobileViTV2 does not support input and output embeddings'	)
       def  snake_case_	(      self	)					->		Optional[int]:
          pass
       @unittest.skip(reason='MobileViTV2 does not output attentions'	)
       def  snake_case_	(      self	)					->		int:
          pass
       @require_torch_multi_gpu
       @unittest.skip(reason='Got `CUDA error: misaligned address` for tests after this one being run.'	)
       def  snake_case_	(      self	)					->		List[Any]:
          pass
       @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'	)
       def  snake_case_	(      self	)					->		Union[str, Any]:
          pass
       def  snake_case_	(      self	)					->		Union[str, Any]:
          UpperCamelCase     ,					UpperCamelCase   :  List[Any]						     =     self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
             UpperCamelCase   :  List[Any]						     =     model_class(__a	)
             UpperCamelCase   :  str						     =     inspect.signature(model.forward	)
             # signature.parameters is an OrderedDict => so arg_names order is deterministic
             UpperCamelCase   :  Dict						     =     [*signature.parameters.keys()]

             UpperCamelCase   :  List[Any]						     =     ['pixel_values']
             self.assertListEqual(arg_names[:1],      __a	)
       def  snake_case_	(      self	)					->		Optional[Any]:
          UpperCamelCase   :  Dict						     =     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*__a	)
       def  snake_case_	(      self	)					->		Any:
          def check_hidden_states_output(SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_	):
             UpperCamelCase   :  List[str]						     =     model_class(__a	)
             model.to(__a	)
             model.eval()

             with torch.no_grad():
                UpperCamelCase   :  Union[str, Any]						     =     model(**self._prepare_for_class(__a,      __a	)	)

             UpperCamelCase   :  Union[str, Any]						     =     outputs.hidden_states

             UpperCamelCase   :  Tuple						     =     5
             self.assertEqual(len(__a	),      __a	)

             # MobileViTV2's feature maps are of shape (batch_size, num_channels, height, width)
             # with the width and height being successively divided by 2.
             UpperCamelCase   :  Tuple						     =     2
             for i in range(len(__a	)	):
                self.assertListEqual(
                    list(hidden_states[i].shape[-2:]	),      [self.model_tester.image_size // divisor, self.model_tester.image_size // divisor],      )
                divisor *= 2

             self.assertEqual(self.model_tester.output_stride,      divisor // 2	)

          UpperCamelCase     ,					UpperCamelCase   :  Dict						     =     self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
             UpperCamelCase   :  str						     =     True
             check_hidden_states_output(__a,      __a,      __a	)

             # check that output_hidden_states also work using config
             del inputs_dict["output_hidden_states"]
             UpperCamelCase   :  Tuple						     =     True

             check_hidden_states_output(__a,      __a,      __a	)
       def  snake_case_	(      self	)					->		int:
          UpperCamelCase   :  Optional[int]						     =     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_image_classification(*__a	)
       def  snake_case_	(      self	)					->		List[Any]:
          UpperCamelCase   :  Tuple						     =     self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_semantic_segmentation(*__a	)






       @slow
       def  snake_case_	(      self	)					->		Dict:
          for model_name in MOBILEVITV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             UpperCamelCase   :  Union[str, Any]						     =     MobileViTVaModel.from_pretrained(__a	)
             self.assertIsNotNone(__a	)






def 		UpperCamelCase     (       )     ->					int:
   UpperCamelCase   :  int						     =     Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'     )
   return image



@require_torch
@require_vision
class     lowerCAmelCase_		(  unittest.TestCase							):
       @cached_property
       def  snake_case_	(      self	)					->		Tuple:
          return (
              MobileViTImageProcessor.from_pretrained('apple/mobilevitv2-1.0-imagenet1k-256'	)
              if is_vision_available()
              else None
          )
       @slow
       def  snake_case_	(      self	)					->		int:
          UpperCamelCase   :  str						     =     MobileViTVaForImageClassification.from_pretrained('apple/mobilevitv2-1.0-imagenet1k-256'	).to(
              __a	)

          UpperCamelCase   :  Optional[int]						     =     self.default_image_processor
          UpperCamelCase   :  List[Any]						     =     prepare_img()
          UpperCamelCase   :  str						     =     image_processor(images=__a,      return_tensors='pt'	).to(__a	)

          # forward pass
          with torch.no_grad():
             UpperCamelCase   :  Any						     =     model(**__a	)

          # verify the logits
          UpperCamelCase   :  Optional[int]						     =     torch.Size((1, 1000)	)
          self.assertEqual(outputs.logits.shape,      __a	)

          UpperCamelCase   :  Any						     =     torch.tensor([-1.6336e00, -7.3204e-02, -5.1883e-01]	).to(__a	)

          self.assertTrue(torch.allclose(outputs.logits[0, :3],      __a,      atol=1e-4	)	)
       @slow
       def  snake_case_	(      self	)					->		List[Any]:
          UpperCamelCase   :  Dict						     =     MobileViTVaForSemanticSegmentation.from_pretrained('shehan97/mobilevitv2-1.0-voc-deeplabv3'	)
          UpperCamelCase   :  List[Any]						     =     model.to(__a	)

          UpperCamelCase   :  int						     =     MobileViTImageProcessor.from_pretrained('shehan97/mobilevitv2-1.0-voc-deeplabv3'	)

          UpperCamelCase   :  Union[str, Any]						     =     prepare_img()
          UpperCamelCase   :  Optional[Any]						     =     image_processor(images=__a,      return_tensors='pt'	).to(__a	)

          # forward pass
          with torch.no_grad():
             UpperCamelCase   :  Union[str, Any]						     =     model(**__a	)
          UpperCamelCase   :  List[str]						     =     outputs.logits

          # verify the logits
          UpperCamelCase   :  int						     =     torch.Size((1, 21, 32, 32)	)
          self.assertEqual(logits.shape,      __a	)

          UpperCamelCase   :  Optional[Any]						     =     torch.tensor(
              [
                  [[7.08_63, 7.15_25, 6.82_01], [6.69_31, 6.87_70, 6.89_33], [6.29_78, 7.03_66, 6.96_36]],
                  [[-3.71_34, -3.67_12, -3.66_75], [-3.58_25, -3.35_49, -3.47_77], [-3.34_35, -3.39_79, -3.28_57]],
                  [[-2.93_29, -2.80_03, -2.73_69], [-3.05_64, -2.47_80, -2.02_07], [-2.68_89, -1.92_98, -1.76_40]],
              ],      device=__a,      )

          self.assertTrue(torch.allclose(logits[0, :3, :3, :3],      __a,      atol=1e-4	)	)






       @slow
       def  snake_case_	(      self	)					->		Any:
          UpperCamelCase   :  Tuple						     =     MobileViTVaForSemanticSegmentation.from_pretrained('shehan97/mobilevitv2-1.0-voc-deeplabv3'	)
          UpperCamelCase   :  Dict						     =     model.to(__a	)

          UpperCamelCase   :  List[str]						     =     MobileViTImageProcessor.from_pretrained('shehan97/mobilevitv2-1.0-voc-deeplabv3'	)

          UpperCamelCase   :  Optional[Any]						     =     prepare_img()
          UpperCamelCase   :  List[Any]						     =     image_processor(images=__a,      return_tensors='pt'	).to(__a	)

          # forward pass
          with torch.no_grad():
             UpperCamelCase   :  Any						     =     model(**__a	)

          UpperCamelCase   :  Optional[Any]						     =     outputs.logits.detach().cpu()

          UpperCamelCase   :  Union[str, Any]						     =     image_processor.post_process_semantic_segmentation(outputs=__a,      target_sizes=[(50, 60)]	)
          UpperCamelCase   :  List[str]						     =     torch.Size((50, 60)	)
          self.assertEqual(segmentation[0].shape,      __a	)

          UpperCamelCase   :  Any						     =     image_processor.post_process_semantic_segmentation(outputs=__a	)
          UpperCamelCase   :  Dict						     =     torch.Size((32, 32)	)
          self.assertEqual(segmentation[0].shape,      __a	)








import gc
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModelWithProjection, CLIPTokenizer

from diffusers import HeunDiscreteScheduler, PriorTransformer, ShapEPipeline
from diffusers.pipelines.shap_e import ShapERenderer
from diffusers.utils import load_numpy, slow
from diffusers.utils.testing_utils import require_torch_gpu, torch_device

from ..test_pipelines_common import PipelineTesterMixin, assert_mean_pixel_difference



class     lowerCAmelCase_		(  a__	,   unittest.TestCase							):
       UpperCAmelCase__    : Union[str, Any]       					=  ShapEPipeline
       UpperCAmelCase__    : List[Any]       					=  ["prompt"]
       UpperCAmelCase__    : List[str]       					=  ["prompt"]
       UpperCAmelCase__    : int       					=  [
           "num_images_per_prompt",
           "num_inference_steps",
           "generator",
           "latents",
           "guidance_scale",
           "frame_size",
           "output_type",
           "return_dict",
       ]
       UpperCAmelCase__    : Union[str, Any]       					=  False
       @property
       def  snake_case_	(      self	)					->		Union[str, Any]:
          return 32
       @property
       def  snake_case_	(      self	)					->		List[str]:
          return 32
       @property
       def  snake_case_	(      self	)					->		int:
          return self.time_input_dim * 4
       @property
       def  snake_case_	(      self	)					->		Optional[int]:
          return 8
       @property
       def  snake_case_	(      self	)					->		str:
          UpperCamelCase   :  Union[str, Any]						     =     CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'	)
          return tokenizer
       @property
       def  snake_case_	(      self	)					->		Optional[Any]:
          torch.manual_seed(0	)
          UpperCamelCase   :  Dict						     =     CLIPTextConfig(
              bos_token_id=0,      eos_token_id=2,      hidden_size=self.text_embedder_hidden_size,      projection_dim=self.text_embedder_hidden_size,      intermediate_size=37,      layer_norm_eps=1e-05,      num_attention_heads=4,      num_hidden_layers=5,      pad_token_id=1,      vocab_size=1000,      )
          return CLIPTextModelWithProjection(SCREAMING_SNAKE_CASE_	)
       @property
       def  snake_case_	(      self	)					->		Dict:
          torch.manual_seed(0	)

          UpperCamelCase   :  int						     =     {
              'num_attention_heads': 2,
              'attention_head_dim': 16,
              'embedding_dim': self.time_input_dim,
              'num_embeddings': 32,
              'embedding_proj_dim': self.text_embedder_hidden_size,
              'time_embed_dim': self.time_embed_dim,
              'num_layers': 1,
              'clip_embed_dim': self.time_input_dim * 2,
              'additional_embeddings': 0,
              'time_embed_act_fn': 'gelu',
              'norm_in_type': 'layer',
              'encoder_hid_proj_type': None,
              'added_emb_type': None,
          }

          UpperCamelCase   :  Any						     =     PriorTransformer(**SCREAMING_SNAKE_CASE_	)
          return model
       @property
       def  snake_case_	(      self	)					->		Tuple:
          torch.manual_seed(0	)

          UpperCamelCase   :  Any						     =     {
              'param_shapes': (
                  (self.renderer_dim, 93),
                  (self.renderer_dim, 8),
                  (self.renderer_dim, 8),
                  (self.renderer_dim, 8),
              ),
              'd_latent': self.time_input_dim,
              'd_hidden': self.renderer_dim,
              'n_output': 12,
              'background': (
                  0.1,
                  0.1,
                  0.1,
              ),
          }
          UpperCamelCase   :  Dict						     =     ShapERenderer(**SCREAMING_SNAKE_CASE_	)
          return model
       def  snake_case_	(      self	)					->		Tuple:
          UpperCamelCase   :  List[Any]						     =     self.dummy_prior
          UpperCamelCase   :  int						     =     self.dummy_text_encoder
          UpperCamelCase   :  Dict						     =     self.dummy_tokenizer
          UpperCamelCase   :  List[str]						     =     self.dummy_renderer

          UpperCamelCase   :  str						     =     HeunDiscreteScheduler(
              beta_schedule='exp',      num_train_timesteps=1024,      prediction_type='sample',      use_karras_sigmas=SCREAMING_SNAKE_CASE_,      clip_sample=SCREAMING_SNAKE_CASE_,      clip_sample_range=1.0,      )
          UpperCamelCase   :  List[str]						     =     {
              'prior': prior,
              'text_encoder': text_encoder,
              'tokenizer': tokenizer,
              'renderer': renderer,
              'scheduler': scheduler,
          }

          return components
       def  snake_case_	(      self,      SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_=0	)					->		Any:
          if str(SCREAMING_SNAKE_CASE_	).startswith('mps'	):
             UpperCamelCase   :  Optional[int]						     =     torch.manual_seed(SCREAMING_SNAKE_CASE_	)
          else:
             UpperCamelCase   :  Any						     =     torch.Generator(device=SCREAMING_SNAKE_CASE_	).manual_seed(SCREAMING_SNAKE_CASE_	)
          UpperCamelCase   :  str						     =     {
              'prompt': 'horse',
              'generator': generator,
              'num_inference_steps': 1,
              'frame_size': 32,
              'output_type': 'np',
          }
          return inputs
       def  snake_case_	(      self	)					->		int:
          UpperCamelCase   :  str						     =     'cpu'

          UpperCamelCase   :  Optional[int]						     =     self.get_dummy_components()

          UpperCamelCase   :  int						     =     self.pipeline_class(**SCREAMING_SNAKE_CASE_	)
          UpperCamelCase   :  Optional[Any]						     =     pipe.to(SCREAMING_SNAKE_CASE_	)

          pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE_	)

          UpperCamelCase   :  str						     =     pipe(**self.get_dummy_inputs(SCREAMING_SNAKE_CASE_	)	)
          UpperCamelCase   :  Optional[int]						     =     output.images[0]
          UpperCamelCase   :  Union[str, Any]						     =     image[0, -3:, -3:, -1]

          assert image.shape == (20, 32, 32, 3)

          UpperCamelCase   :  List[str]						     =     np.array(
              [
                  0.00_03_92_16,
                  0.00_03_92_16,
                  0.00_03_92_16,
                  0.00_03_92_16,
                  0.00_03_92_16,
                  0.00_03_92_16,
                  0.00_03_92_16,
                  0.00_03_92_16,
                  0.00_03_92_16,
              ]	)

          assert np.abs(image_slice.flatten() - expected_slice	).max() < 1e-2
       def  snake_case_	(      self	)					->		int:
          # NOTE: Larger batch sizes cause this test to timeout, only test on smaller batches
          self._test_inference_batch_consistent(batch_sizes=[1, 2]	)
       def  snake_case_	(      self	)					->		str:
          UpperCamelCase   :  str						     =     torch_device == 'cpu'
          UpperCamelCase   :  Optional[int]						     =     True

          self._test_inference_batch_single_identical(
              batch_size=2,      test_max_difference=SCREAMING_SNAKE_CASE_,      relax_max_difference=SCREAMING_SNAKE_CASE_,      )






       def  snake_case_	(      self	)					->		List[Any]:
          UpperCamelCase   :  List[Any]						     =     self.get_dummy_components()
          UpperCamelCase   :  str						     =     self.pipeline_class(**SCREAMING_SNAKE_CASE_	)
          UpperCamelCase   :  Optional[int]						     =     pipe.to(SCREAMING_SNAKE_CASE_	)
          pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE_	)

          UpperCamelCase   :  Optional[Any]						     =     1
          UpperCamelCase   :  Union[str, Any]						     =     2

          UpperCamelCase   :  Union[str, Any]						     =     self.get_dummy_inputs(SCREAMING_SNAKE_CASE_	)

          for key in inputs.keys():
             if key in self.batch_params:
                UpperCamelCase   :  List[Any]						     =     batch_size * [inputs[key]]

          UpperCamelCase   :  int						     =     pipe(**SCREAMING_SNAKE_CASE_,      num_images_per_prompt=SCREAMING_SNAKE_CASE_	)[0]

          assert images.shape[0] == batch_size * num_images_per_prompt






@slow
@require_torch_gpu
class     lowerCAmelCase_		(  unittest.TestCase							):
       def  snake_case_	(      self	)					->		str:
          # clean up the VRAM after each test
          super().tearDown()
          gc.collect()
          torch.cuda.empty_cache()






       def  snake_case_	(      self	)					->		Tuple:
          UpperCamelCase   :  Optional[int]						     =     load_numpy(
              'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'
              '/shap_e/test_shap_e_np_out.npy'	)
          UpperCamelCase   :  Optional[int]						     =     ShapEPipeline.from_pretrained('openai/shap-e'	)
          UpperCamelCase   :  Optional[int]						     =     pipe.to(SCREAMING_SNAKE_CASE_	)
          pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE_	)

          UpperCamelCase   :  str						     =     torch.Generator(device=SCREAMING_SNAKE_CASE_	).manual_seed(0	)

          UpperCamelCase   :  Dict						     =     pipe(
              'a shark',      generator=SCREAMING_SNAKE_CASE_,      guidance_scale=15.0,      num_inference_steps=64,      frame_size=64,      output_type='np',      ).images[0]

          assert images.shape == (20, 64, 64, 3)

          assert_mean_pixel_difference(SCREAMING_SNAKE_CASE_,      SCREAMING_SNAKE_CASE_	)



