






"""simple docstring"""
from __future__ import annotations

import os
import tempfile
import unittest

from transformers import ConvBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
			import tensorflow as tf

			from transformers import (
			    TFConvBertForMaskedLM,
			    TFConvBertForMultipleChoice,
			    TFConvBertForQuestionAnswering,
			    TFConvBertForSequenceClassification,
			    TFConvBertForTokenClassification,
			    TFConvBertModel,
			)







class     UpperCamelCase_ :





	def __init__(   self      :				int			,			lowerCAmelCase_      :				Any			,			lowerCAmelCase_      :				Dict=13			,			lowerCAmelCase_      :				List[Any]=7			,			lowerCAmelCase_      :				str=True			,			lowerCAmelCase_      :				Union[str, Any]=True			,			lowerCAmelCase_      :				Dict=True			,			lowerCAmelCase_      :				Dict=True			,			lowerCAmelCase_      :				Dict=99			,			lowerCAmelCase_      :				Any=32			,			lowerCAmelCase_      :				Optional[int]=2			,			lowerCAmelCase_      :				Any=4			,			lowerCAmelCase_      :				List[str]=37			,			lowerCAmelCase_      :				Optional[Any]="gelu"			,			lowerCAmelCase_      :				Optional[int]=0.1			,			lowerCAmelCase_      :				Tuple=0.1			,			lowerCAmelCase_      :				Union[str, Any]=512			,			lowerCAmelCase_      :				Optional[Any]=16			,			lowerCAmelCase_      :				List[Any]=2			,			lowerCAmelCase_      :				int=0.0_2			,			lowerCAmelCase_      :				Dict=3			,			lowerCAmelCase_      :				Tuple=4			,			lowerCAmelCase_      :				Union[str, Any]=None			,			)		->    Any:
				UpperCAmelCase_  :				str      =      parent
				UpperCAmelCase_  :				Dict      =      13
				UpperCAmelCase_  :				Dict      =      7
				UpperCAmelCase_  :				int      =      True
				UpperCAmelCase_  :				Dict      =      True
				UpperCAmelCase_  :				Optional[Any]      =      True
				UpperCAmelCase_  :				Any      =      True
				UpperCAmelCase_  :				Tuple      =      99
				UpperCAmelCase_  :				int      =      384
				UpperCAmelCase_  :				Optional[Any]      =      2
				UpperCAmelCase_  :				List[str]      =      4
				UpperCAmelCase_  :				Optional[Any]      =      37
				UpperCAmelCase_  :				Dict      =      "gelu"
				UpperCAmelCase_  :				Dict      =      0.1
				UpperCAmelCase_  :				str      =      0.1
				UpperCAmelCase_  :				List[Any]      =      512
				UpperCAmelCase_  :				Any      =      16
				UpperCAmelCase_  :				List[Any]      =      2
				UpperCAmelCase_  :				Dict      =      0.0_2
				UpperCAmelCase_  :				str      =      3
				UpperCAmelCase_  :				Optional[int]      =      4
				UpperCAmelCase_  :				Dict      =      128
				UpperCAmelCase_  :				Dict      =      2
				UpperCAmelCase_  :				Any      =      9
				UpperCAmelCase_  :				List[Any]      =      1
				UpperCAmelCase_  :				List[str]      =      None





	def   _SCREAMING_SNAKE_CASE   (   self      :				Dict		)		->    List[str]:
				UpperCAmelCase_  :				str      =      ids_tensor([self.batch_size, self.seq_length]			,			self.vocab_size		)

				UpperCAmelCase_  :				Tuple      =      None
				if self.use_input_mask:
							UpperCAmelCase_  :				Any      =      random_attention_mask([self.batch_size, self.seq_length]		)

				UpperCAmelCase_  :				List[Any]      =      None
				if self.use_token_type_ids:
							UpperCAmelCase_  :				Tuple      =      ids_tensor([self.batch_size, self.seq_length]			,			self.type_vocab_size		)

				UpperCAmelCase_  :				Any      =      None
				UpperCAmelCase_  :				Dict      =      None
				UpperCAmelCase_  :				Union[str, Any]      =      None
				if self.use_labels:
							UpperCAmelCase_  :				int      =      ids_tensor([self.batch_size]			,			self.type_sequence_label_size		)
							UpperCAmelCase_  :				str      =      ids_tensor([self.batch_size, self.seq_length]			,			self.num_labels		)
							UpperCAmelCase_  :				Tuple      =      ids_tensor([self.batch_size]			,			self.num_choices		)

				UpperCAmelCase_  :				Union[str, Any]      =      ConvBertConfig(
				    vocab_size=self.vocab_size			,			hidden_size=self.hidden_size			,			num_hidden_layers=self.num_hidden_layers			,			num_attention_heads=self.num_attention_heads			,			intermediate_size=self.intermediate_size			,			hidden_act=self.hidden_act			,			hidden_dropout_prob=self.hidden_dropout_prob			,			attention_probs_dropout_prob=self.attention_probs_dropout_prob			,			max_position_embeddings=self.max_position_embeddings			,			type_vocab_size=self.type_vocab_size			,			initializer_range=self.initializer_range			,			return_dict=A_			,			)

				return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels





	def   _SCREAMING_SNAKE_CASE   (   self      :				Dict			,			lowerCAmelCase_      :				Union[str, Any]			,			lowerCAmelCase_      :				Optional[Any]			,			lowerCAmelCase_      :				List[str]			,			lowerCAmelCase_      :				Any			,			lowerCAmelCase_      :				str			,			lowerCAmelCase_      :				List[Any]			,			lowerCAmelCase_      :				Optional[Any]		)		->    Optional[int]:
				UpperCAmelCase_  :				List[str]      =      TFConvBertModel(config=A_		)
				UpperCAmelCase_  :				int      =      {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

				UpperCAmelCase_  :				List[str]      =      [input_ids, input_mask]
				UpperCAmelCase_  :				Optional[Any]      =      model(A_		)

				UpperCAmelCase_  :				Dict      =      model(A_		)

				self.parent.assertEqual(result.last_hidden_state.shape			,			(self.batch_size, self.seq_length, self.hidden_size)		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				List[Any]			,			lowerCAmelCase_      :				Any			,			lowerCAmelCase_      :				List[Any]			,			lowerCAmelCase_      :				int			,			lowerCAmelCase_      :				Tuple			,			lowerCAmelCase_      :				Tuple			,			lowerCAmelCase_      :				Union[str, Any]			,			lowerCAmelCase_      :				int		)		->    Any:
				UpperCAmelCase_  :				Tuple      =      TFConvBertForMaskedLM(config=A_		)
				UpperCAmelCase_  :				str      =      {
				    "input_ids": input_ids,
				    "attention_mask": input_mask,
				    "token_type_ids": token_type_ids,
				}
				UpperCAmelCase_  :				List[Any]      =      model(A_		)
				self.parent.assertEqual(result.logits.shape			,			(self.batch_size, self.seq_length, self.vocab_size)		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Optional[Any]			,			lowerCAmelCase_      :				Tuple			,			lowerCAmelCase_      :				Union[str, Any]			,			lowerCAmelCase_      :				List[str]			,			lowerCAmelCase_      :				Optional[Any]			,			lowerCAmelCase_      :				Optional[Any]			,			lowerCAmelCase_      :				List[str]			,			lowerCAmelCase_      :				List[str]		)		->    List[str]:
				UpperCAmelCase_  :				Union[str, Any]      =      self.num_labels
				UpperCAmelCase_  :				int      =      TFConvBertForSequenceClassification(config=A_		)
				UpperCAmelCase_  :				Any      =      {
				    "input_ids": input_ids,
				    "attention_mask": input_mask,
				    "token_type_ids": token_type_ids,
				}

				UpperCAmelCase_  :				Dict      =      model(A_		)
				self.parent.assertEqual(result.logits.shape			,			(self.batch_size, self.num_labels)		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				str			,			lowerCAmelCase_      :				Any			,			lowerCAmelCase_      :				Optional[int]			,			lowerCAmelCase_      :				List[str]			,			lowerCAmelCase_      :				Tuple			,			lowerCAmelCase_      :				List[Any]			,			lowerCAmelCase_      :				Any			,			lowerCAmelCase_      :				int		)		->    Tuple:
				UpperCAmelCase_  :				int      =      self.num_choices
				UpperCAmelCase_  :				Optional[int]      =      TFConvBertForMultipleChoice(config=A_		)
				UpperCAmelCase_  :				Union[str, Any]      =      tf.tile(tf.expand_dims(A_			,			1		)			,			(1, self.num_choices, 1)		)
				UpperCAmelCase_  :				int      =      tf.tile(tf.expand_dims(A_			,			1		)			,			(1, self.num_choices, 1)		)
				UpperCAmelCase_  :				Optional[Any]      =      tf.tile(tf.expand_dims(A_			,			1		)			,			(1, self.num_choices, 1)		)
				UpperCAmelCase_  :				List[Any]      =      {
				    "input_ids": multiple_choice_inputs_ids,
				    "attention_mask": multiple_choice_input_mask,
				    "token_type_ids": multiple_choice_token_type_ids,
				}
				UpperCAmelCase_  :				Any      =      model(A_		)
				self.parent.assertEqual(result.logits.shape			,			(self.batch_size, self.num_choices)		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Dict			,			lowerCAmelCase_      :				Dict			,			lowerCAmelCase_      :				Optional[Any]			,			lowerCAmelCase_      :				int			,			lowerCAmelCase_      :				Any			,			lowerCAmelCase_      :				List[Any]			,			lowerCAmelCase_      :				Union[str, Any]			,			lowerCAmelCase_      :				Optional[Any]		)		->    str:
				UpperCAmelCase_  :				Optional[Any]      =      self.num_labels
				UpperCAmelCase_  :				List[str]      =      TFConvBertForTokenClassification(config=A_		)
				UpperCAmelCase_  :				List[str]      =      {
				    "input_ids": input_ids,
				    "attention_mask": input_mask,
				    "token_type_ids": token_type_ids,
				}
				UpperCAmelCase_  :				Optional[int]      =      model(A_		)
				self.parent.assertEqual(result.logits.shape			,			(self.batch_size, self.seq_length, self.num_labels)		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Dict			,			lowerCAmelCase_      :				int			,			lowerCAmelCase_      :				str			,			lowerCAmelCase_      :				int			,			lowerCAmelCase_      :				Dict			,			lowerCAmelCase_      :				List[str]			,			lowerCAmelCase_      :				List[str]			,			lowerCAmelCase_      :				Optional[Any]		)		->    Optional[Any]:
				UpperCAmelCase_  :				Union[str, Any]      =      TFConvBertForQuestionAnswering(config=A_		)
				UpperCAmelCase_  :				Optional[Any]      =      {
				    "input_ids": input_ids,
				    "attention_mask": input_mask,
				    "token_type_ids": token_type_ids,
				}

				UpperCAmelCase_  :				Optional[Any]      =      model(A_		)
				self.parent.assertEqual(result.start_logits.shape			,			(self.batch_size, self.seq_length)		)
				self.parent.assertEqual(result.end_logits.shape			,			(self.batch_size, self.seq_length)		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Any		)		->    str:
				UpperCAmelCase_  :				Optional[Any]      =      self.prepare_config_and_inputs()
				(
				    (
				    UpperCAmelCase_						
				)  ,			(
				    UpperCAmelCase_						
				)  ,			(
				    UpperCAmelCase_						
				)  ,			(
				    UpperCAmelCase_						
				)  ,			(
				    UpperCAmelCase_						
				)  ,			(
				    UpperCAmelCase_						
				)  ,			(
				    UpperCAmelCase_						
				)  ,									
				)  :				int      =      config_and_inputs
				UpperCAmelCase_  :				List[str]      =      {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
				return config, inputs_dict







@require_tf
class     UpperCamelCase_ (_SCREAMING_SNAKE_CASE       ,		_SCREAMING_SNAKE_CASE       ,		unittest.TestCase  ):
	__magic_name__			   =       (
	    (
	        TFConvBertModel,
	        TFConvBertForMaskedLM,
	        TFConvBertForQuestionAnswering,
	        TFConvBertForSequenceClassification,
	        TFConvBertForTokenClassification,
	        TFConvBertForMultipleChoice,
	    )
	    if is_tf_available()
	    else ()
	)
	__magic_name__			   =       (
	    {
	        "feature-extraction": TFConvBertModel,
	        "fill-mask": TFConvBertForMaskedLM,
	        "question-answering": TFConvBertForQuestionAnswering,
	        "text-classification": TFConvBertForSequenceClassification,
	        "token-classification": TFConvBertForTokenClassification,
	        "zero-shot": TFConvBertForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)
	__magic_name__			   =       False
	__magic_name__			   =       False
	__magic_name__			   =       False





	def   _SCREAMING_SNAKE_CASE   (   self      :				List[Any]		)		->    Union[str, Any]:
				UpperCAmelCase_  :				Tuple      =      TFConvBertModelTester(self		)
				UpperCAmelCase_  :				List[Any]      =      ConfigTester(self			,			config_class=A_			,			hidden_size=37		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				List[str]		)		->    Optional[Any]:
				self.config_tester.run_common_tests()





	def   _SCREAMING_SNAKE_CASE   (   self      :				List[Any]		)		->    Dict:
				UpperCAmelCase_  :				Optional[int]      =      self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*A_		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Dict		)		->    Tuple:
				UpperCAmelCase_  :				str      =      self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_masked_lm(*A_		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Dict		)		->    List[Any]:
				UpperCAmelCase_  :				List[str]      =      self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_multiple_choice(*A_		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				List[str]		)		->    str:
				UpperCAmelCase_  :				Optional[Any]      =      self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_question_answering(*A_		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Optional[Any]		)		->    Any:
				UpperCAmelCase_  :				Any      =      self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_sequence_classification(*A_		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				Dict		)		->    Union[str, Any]:
				UpperCAmelCase_  :				Optional[Any]      =      self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_token_classification(*A_		)





	@slow
	def   _SCREAMING_SNAKE_CASE   (   self      :				Optional[Any]		)		->    int:
				UpperCAmelCase_  ,			UpperCAmelCase_  :				Any      =      self.model_tester.prepare_config_and_inputs_for_common()
				UpperCAmelCase_  :				str      =      True
				UpperCAmelCase_  :				List[Any]      =      True

				if hasattr(A_			,			"use_cache"		):
							UpperCAmelCase_  :				Tuple      =      True

				UpperCAmelCase_  :				Dict      =      getattr(self.model_tester			,			"encoder_seq_length"			,			self.model_tester.seq_length		)
				UpperCAmelCase_  :				List[Any]      =      getattr(self.model_tester			,			"key_length"			,			A_		)

				for model_class in self.all_model_classes:
							UpperCAmelCase_  :				Optional[int]      =      self._prepare_for_class(A_			,			A_		)
							UpperCAmelCase_  :				List[str]      =      model_class(A_		)
							UpperCAmelCase_  :				List[str]      =      len(model(A_		)		)

							with tempfile.TemporaryDirectory() as tmpdirname:
										model.save_pretrained(A_			,			saved_model=A_		)
										UpperCAmelCase_  :				Any      =      os.path.join(A_			,			"saved_model"			,			"1"		)
										UpperCAmelCase_  :				List[Any]      =      tf.keras.models.load_model(A_		)
										UpperCAmelCase_  :				Any      =      model(A_		)

										if self.is_encoder_decoder:
													UpperCAmelCase_  :				List[Any]      =      outputs["encoder_hidden_states"]
													UpperCAmelCase_  :				Dict      =      outputs["encoder_attentions"]
										else:
													UpperCAmelCase_  :				Optional[Any]      =      outputs["hidden_states"]
													UpperCAmelCase_  :				str      =      outputs["attentions"]

										self.assertEqual(len(A_		)			,			A_		)

										UpperCAmelCase_  :				str      =      getattr(
										    self.model_tester			,			"expected_num_hidden_layers"			,			self.model_tester.num_hidden_layers + 1		)

										self.assertEqual(len(A_		)			,			A_		)
										self.assertListEqual(
										    list(output_hidden_states[0].shape[-2:]		)			,			[self.model_tester.seq_length, self.model_tester.hidden_size]			,			)

										self.assertEqual(len(A_		)			,			self.model_tester.num_hidden_layers		)
										self.assertListEqual(
										    list(output_attentions[0].shape[-3:]		)			,			[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]			,			)





	@slow
	def   _SCREAMING_SNAKE_CASE   (   self      :				str		)		->    Optional[int]:
				UpperCAmelCase_  :				Union[str, Any]      =      TFConvBertModel.from_pretrained("YituTech/conv-bert-base"		)
				self.assertIsNotNone(A_		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				str		)		->    Any:
				UpperCAmelCase_  ,			UpperCAmelCase_  :				List[Any]      =      self.model_tester.prepare_config_and_inputs_for_common()
				UpperCAmelCase_  :				List[str]      =      True
				UpperCAmelCase_  :				Any      =      getattr(self.model_tester			,			"decoder_seq_length"			,			self.model_tester.seq_length		)
				UpperCAmelCase_  :				Tuple      =      getattr(self.model_tester			,			"encoder_seq_length"			,			self.model_tester.seq_length		)
				UpperCAmelCase_  :				str      =      getattr(self.model_tester			,			"key_length"			,			A_		)
				UpperCAmelCase_  :				List[Any]      =      getattr(self.model_tester			,			"key_length"			,			A_		)

				def check_decoder_attentions_output(lowerCAmelCase_      :				Union[str, Any]		):
							UpperCAmelCase_  :				Union[str, Any]      =      len(A_		)
							self.assertEqual(out_len % 2			,			0		)
							UpperCAmelCase_  :				Optional[int]      =      outputs.decoder_attentions
							self.assertEqual(len(A_		)			,			self.model_tester.num_hidden_layers		)
							self.assertListEqual(
							    list(decoder_attentions[0].shape[-3:]		)			,			[self.model_tester.num_attention_heads / 2, decoder_seq_length, decoder_key_length]			,			)

				def check_encoder_attentions_output(lowerCAmelCase_      :				List[str]		):
							UpperCAmelCase_  :				Optional[int]      =      [
							    t.numpy() for t in (outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions)
							]
							self.assertEqual(len(A_		)			,			self.model_tester.num_hidden_layers		)
							self.assertListEqual(
							    list(attentions[0].shape[-3:]		)			,			[self.model_tester.num_attention_heads / 2, encoder_seq_length, encoder_key_length]			,			)

				for model_class in self.all_model_classes:
							UpperCAmelCase_  :				int      =      True
							UpperCAmelCase_  :				Tuple      =      False
							UpperCAmelCase_  :				str      =      model_class(A_		)
							UpperCAmelCase_  :				List[Any]      =      model(self._prepare_for_class(A_			,			A_		)		)
							UpperCAmelCase_  :				Optional[int]      =      len(A_		)
							self.assertEqual(config.output_hidden_states			,			A_		)
							check_encoder_attentions_output(A_		)

							if self.is_encoder_decoder:
										UpperCAmelCase_  :				Tuple      =      model_class(A_		)
										UpperCAmelCase_  :				int      =      model(self._prepare_for_class(A_			,			A_		)		)
										self.assertEqual(config.output_hidden_states			,			A_		)
										check_decoder_attentions_output(A_		)

							# Check that output attentions can also be changed via the config
							del inputs_dict["output_attentions"]
							UpperCAmelCase_  :				Union[str, Any]      =      True
							UpperCAmelCase_  :				str      =      model_class(A_		)
							UpperCAmelCase_  :				int      =      model(self._prepare_for_class(A_			,			A_		)		)
							self.assertEqual(config.output_hidden_states			,			A_		)
							check_encoder_attentions_output(A_		)

							# Check attention is always last and order is fine
							UpperCAmelCase_  :				Any      =      True
							UpperCAmelCase_  :				List[str]      =      True
							UpperCAmelCase_  :				Union[str, Any]      =      model_class(A_		)
							UpperCAmelCase_  :				str      =      model(self._prepare_for_class(A_			,			A_		)		)

							self.assertEqual(out_len + (2 if self.is_encoder_decoder else 1)			,			len(A_		)		)
							self.assertEqual(model.config.output_hidden_states			,			A_		)
							check_encoder_attentions_output(A_		)







@require_tf
class     UpperCamelCase_ (unittest.TestCase  ):





	@slow
	def   _SCREAMING_SNAKE_CASE   (   self      :				Union[str, Any]		)		->    List[Any]:
				UpperCAmelCase_  :				Any      =      TFConvBertModel.from_pretrained("YituTech/conv-bert-base"		)
				UpperCAmelCase_  :				Tuple      =      tf.constant([[0, 1, 2, 3, 4, 5]]		)
				UpperCAmelCase_  :				Dict      =      model(A_		)[0]

				UpperCAmelCase_  :				Optional[int]      =      [1, 6, 768]
				self.assertEqual(output.shape			,			A_		)

				UpperCAmelCase_  :				int      =      tf.constant(
				    [
				        [
				            [-0.0_3_4_7_5_4_9_3, -0.4_6_8_6_0_3_4, -0.3_0_6_3_8_8_3_2],
				            [0.2_2_6_3_7_2_4_8, -0.2_6_9_8_8_6_4_6, -0.7_4_2_3_4_2_4],
				            [0.1_0_3_2_4_8_6_8, -0.4_5_0_1_3_5_0_8, -0.5_8_2_8_0_7_8_4],
				        ]
				    ]		)
				tf.debugging.assert_near(output[:, :3, :3]			,			A_			,			atol=1e-4		)











"""simple docstring"""
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     UpperCamelCase_ (__A       ,		unittest.TestCase  ):
	__magic_name__			   =       ShapEPipeline
	__magic_name__			   =       ['''prompt''']
	__magic_name__			   =       ['''prompt''']
	__magic_name__			   =       [
	    '''num_images_per_prompt''',
	    '''num_inference_steps''',
	    '''generator''',
	    '''latents''',
	    '''guidance_scale''',
	    '''frame_size''',
	    '''output_type''',
	    '''return_dict''',
	]
	__magic_name__			   =       False





	@property
	def   _SCREAMING_SNAKE_CASE   (   self      :				Union[str, Any]		)		->    Dict:
				return 32





	@property
	def   _SCREAMING_SNAKE_CASE   (   self      :				List[str]		)		->    Tuple:
				return 32





	@property
	def   _SCREAMING_SNAKE_CASE   (   self      :				List[Any]		)		->    Optional[int]:
				return self.time_input_dim * 4





	@property
	def   _SCREAMING_SNAKE_CASE   (   self      :				Union[str, Any]		)		->    List[Any]:
				return 8





	@property
	def   _SCREAMING_SNAKE_CASE   (   self      :				Dict		)		->    int:
				UpperCAmelCase_  :				str      =      CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"		)
				return tokenizer





	@property
	def   _SCREAMING_SNAKE_CASE   (   self      :				Union[str, Any]		)		->    List[str]:
				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=1_000			,			)
				return CLIPTextModelWithProjection(lowerCAmelCase_		)





	@property
	def   _SCREAMING_SNAKE_CASE   (   self      :				Dict		)		->    Optional[Any]:
				torch.manual_seed(0		)

				UpperCAmelCase_  :				str      =      {
				    "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_  :				List[Any]      =      PriorTransformer(**lowerCAmelCase_		)
				return model





	@property
	def   _SCREAMING_SNAKE_CASE   (   self      :				Optional[Any]		)		->    int:
				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_  :				Tuple      =      ShapERenderer(**lowerCAmelCase_		)
				return model





	def   _SCREAMING_SNAKE_CASE   (   self      :				List[str]		)		->    Tuple:
				UpperCAmelCase_  :				str      =      self.dummy_prior
				UpperCAmelCase_  :				Dict      =      self.dummy_text_encoder
				UpperCAmelCase_  :				Any      =      self.dummy_tokenizer
				UpperCAmelCase_  :				int      =      self.dummy_renderer

				UpperCAmelCase_  :				Optional[int]      =      HeunDiscreteScheduler(
				    beta_schedule="exp"			,			num_train_timesteps=1_024			,			prediction_type="sample"			,			use_karras_sigmas=lowerCAmelCase_			,			clip_sample=lowerCAmelCase_			,			clip_sample_range=1.0			,			)
				UpperCAmelCase_  :				str      =      {
				    "prior": prior,
				    "text_encoder": text_encoder,
				    "tokenizer": tokenizer,
				    "renderer": renderer,
				    "scheduler": scheduler,
				}

				return components





	def   _SCREAMING_SNAKE_CASE   (   self      :				Any			,			lowerCAmelCase_      :				int			,			lowerCAmelCase_      :				Any=0		)		->    Union[str, Any]:
				if str(lowerCAmelCase_		).startswith("mps"		):
							UpperCAmelCase_  :				str      =      torch.manual_seed(lowerCAmelCase_		)
				else:
							UpperCAmelCase_  :				Union[str, Any]      =      torch.Generator(device=lowerCAmelCase_		).manual_seed(lowerCAmelCase_		)
				UpperCAmelCase_  :				List[Any]      =      {
				    "prompt": "horse",
				    "generator": generator,
				    "num_inference_steps": 1,
				    "frame_size": 32,
				    "output_type": "np",
				}
				return inputs





	def   _SCREAMING_SNAKE_CASE   (   self      :				str		)		->    List[Any]:
				UpperCAmelCase_  :				Any      =      "cpu"

				UpperCAmelCase_  :				Union[str, Any]      =      self.get_dummy_components()

				UpperCAmelCase_  :				Tuple      =      self.pipeline_class(**lowerCAmelCase_		)
				UpperCAmelCase_  :				Union[str, Any]      =      pipe.to(lowerCAmelCase_		)

				pipe.set_progress_bar_config(disable=lowerCAmelCase_		)

				UpperCAmelCase_  :				int      =      pipe(**self.get_dummy_inputs(lowerCAmelCase_		)		)
				UpperCAmelCase_  :				Dict      =      output.images[0]
				UpperCAmelCase_  :				Any      =      image[0, -3:, -3:, -1]

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

				UpperCAmelCase_  :				Optional[int]      =      np.array(
				    [
				        0.0_0_0_3_9_2_1_6,
				        0.0_0_0_3_9_2_1_6,
				        0.0_0_0_3_9_2_1_6,
				        0.0_0_0_3_9_2_1_6,
				        0.0_0_0_3_9_2_1_6,
				        0.0_0_0_3_9_2_1_6,
				        0.0_0_0_3_9_2_1_6,
				        0.0_0_0_3_9_2_1_6,
				        0.0_0_0_3_9_2_1_6,
				    ]		)

				assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-2





	def   _SCREAMING_SNAKE_CASE   (   self      :				List[str]		)		->    Optional[Any]:
				# NOTE: Larger batch sizes cause this test to timeout, only test on smaller batches
				self._test_inference_batch_consistent(batch_sizes=[1, 2]		)





	def   _SCREAMING_SNAKE_CASE   (   self      :				int		)		->    List[str]:
				UpperCAmelCase_  :				Optional[Any]      =      torch_device == "cpu"
				UpperCAmelCase_  :				Dict      =      True

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





	def   _SCREAMING_SNAKE_CASE   (   self      :				Any		)		->    List[str]:
				UpperCAmelCase_  :				int      =      self.get_dummy_components()
				UpperCAmelCase_  :				Tuple      =      self.pipeline_class(**lowerCAmelCase_		)
				UpperCAmelCase_  :				List[str]      =      pipe.to(lowerCAmelCase_		)
				pipe.set_progress_bar_config(disable=lowerCAmelCase_		)

				UpperCAmelCase_  :				List[str]      =      1
				UpperCAmelCase_  :				List[Any]      =      2

				UpperCAmelCase_  :				int      =      self.get_dummy_inputs(lowerCAmelCase_		)

				for key in inputs.keys():
							if key in self.batch_params:
										UpperCAmelCase_  :				int      =      batch_size * [inputs[key]]

				UpperCAmelCase_  :				int      =      pipe(**lowerCAmelCase_			,			num_images_per_prompt=lowerCAmelCase_		)[0]

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







@slow
@require_torch_gpu
class     UpperCamelCase_ (unittest.TestCase  ):





	def   _SCREAMING_SNAKE_CASE   (   self      :				Union[str, Any]		)		->    Any:
				# clean up the VRAM after each test
				super().tearDown()
				gc.collect()
				torch.cuda.empty_cache()





	def   _SCREAMING_SNAKE_CASE   (   self      :				str		)		->    Union[str, Any]:
				UpperCAmelCase_  :				Any      =      load_numpy(
				    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
				    "/shap_e/test_shap_e_np_out.npy"		)
				UpperCAmelCase_  :				str      =      ShapEPipeline.from_pretrained("openai/shap-e"		)
				UpperCAmelCase_  :				Union[str, Any]      =      pipe.to(lowerCAmelCase_		)
				pipe.set_progress_bar_config(disable=lowerCAmelCase_		)

				UpperCAmelCase_  :				Union[str, Any]      =      torch.Generator(device=lowerCAmelCase_		).manual_seed(0		)

				UpperCAmelCase_  :				Optional[int]      =      pipe(
				    "a shark"			,			generator=lowerCAmelCase_			,			guidance_scale=1_5.0			,			num_inference_steps=64			,			frame_size=64			,			output_type="np"			,			).images[0]

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

				assert_mean_pixel_difference(lowerCAmelCase_			,			lowerCAmelCase_		)



