


"""simple docstring"""






import unittest

from transformers import MraConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_torch_available():
  import torch

  from transformers import (
      MraForMaskedLM,
      MraForMultipleChoice,
      MraForQuestionAnswering,
      MraForSequenceClassification,
      MraForTokenClassification,
      MraModel,
  )
  from transformers.models.mra.modeling_mra import MRA_PRETRAINED_MODEL_ARCHIVE_LIST




class 							A_      :


  def __init__(			self:						Optional[int]							,__lowerCAmelCase:						List[str]							,__lowerCAmelCase:						int=2							,__lowerCAmelCase:						Dict=8							,__lowerCAmelCase:						List[Any]=True							,__lowerCAmelCase:						List[str]=True							,__lowerCAmelCase:						List[Any]=True							,__lowerCAmelCase:						Dict=True							,__lowerCAmelCase:						Any=99							,__lowerCAmelCase:						int=16							,__lowerCAmelCase:						List[Any]=5							,__lowerCAmelCase:						List[str]=2							,__lowerCAmelCase:						str=36							,__lowerCAmelCase:						List[str]="gelu"							,__lowerCAmelCase:						Any=0.0							,__lowerCAmelCase:						List[str]=0.0							,__lowerCAmelCase:						Any=512							,__lowerCAmelCase:						Union[str, Any]=16							,__lowerCAmelCase:						str=2							,__lowerCAmelCase:						str=0.02							,__lowerCAmelCase:						Dict=3							,__lowerCAmelCase:						List[str]=4							,__lowerCAmelCase:						Tuple=None							,):







     '''simple docstring'''







     _lowerCamelCase   :				Tuple							=     parent
     _lowerCamelCase   :				Union[str, Any]							=     batch_size
     _lowerCamelCase   :				Optional[Any]							=     seq_length
     _lowerCamelCase   :				int							=     is_training
     _lowerCamelCase   :				List[Any]							=     use_input_mask
     _lowerCamelCase   :				Dict							=     use_token_type_ids
     _lowerCamelCase   :				Tuple							=     use_labels
     _lowerCamelCase   :				List[str]							=     vocab_size
     _lowerCamelCase   :				List[str]							=     hidden_size
     _lowerCamelCase   :				List[Any]							=     num_hidden_layers
     _lowerCamelCase   :				List[str]							=     num_attention_heads
     _lowerCamelCase   :				Dict							=     intermediate_size
     _lowerCamelCase   :				List[str]							=     hidden_act
     _lowerCamelCase   :				List[Any]							=     hidden_dropout_prob
     _lowerCamelCase   :				Optional[int]							=     attention_probs_dropout_prob
     _lowerCamelCase   :				List[str]							=     max_position_embeddings
     _lowerCamelCase   :				Optional[Any]							=     type_vocab_size
     _lowerCamelCase   :				Dict							=     type_sequence_label_size
     _lowerCamelCase   :				Dict							=     initializer_range
     _lowerCamelCase   :				List[Any]							=     num_labels
     _lowerCamelCase   :				Any							=     num_choices
     _lowerCamelCase   :				List[Any]							=     scope


  def 							_lowercase					(			self:						List[Any]    ):







     '''simple docstring'''







     _lowerCamelCase   :				List[Any]							=     ids_tensor([self.batch_size, self.seq_length]							,self.vocab_size    )

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

     _lowerCamelCase   :				Optional[int]							=     None
     if self.use_token_type_ids:
        _lowerCamelCase   :				Dict							=     ids_tensor([self.batch_size, self.seq_length]							,self.type_vocab_size    )

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

     _lowerCamelCase   :				List[Any]							=     self.get_config()

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


  def 							_lowercase					(			self:						Union[str, Any]    ):







     '''simple docstring'''







     return MraConfig(
         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							,is_decoder=__lowerCAmelCase							,initializer_range=self.initializer_range							,)


  def 							_lowercase					(			self:						int    ):







     '''simple docstring'''







     _lowerCamelCase   :				str							=     self.get_config()
     _lowerCamelCase   :				Dict							=     300
     return config


  def 							_lowercase					(			self:						Union[str, Any]    ):







     '''simple docstring'''







     (
         (
         _lowerCamelCase
     ),					(
         _lowerCamelCase
     ),					(
         _lowerCamelCase
     ),					(
         _lowerCamelCase
     ),					(
         _lowerCamelCase
     ),					(
         _lowerCamelCase
     ),					(
         _lowerCamelCase
     ),					
     )   :				int							=     self.prepare_config_and_inputs()

     _lowerCamelCase   :				Tuple							=     True
     _lowerCamelCase   :				int							=     floats_tensor([self.batch_size, self.seq_length, self.hidden_size]    )
     _lowerCamelCase   :				List[str]							=     ids_tensor([self.batch_size, self.seq_length]							,vocab_size=2    )

     return (
         config,
         input_ids,
         token_type_ids,
         input_mask,
         sequence_labels,
         token_labels,
         choice_labels,
         encoder_hidden_states,
         encoder_attention_mask,
     )


  def 							_lowercase					(			self:						List[Any]							,__lowerCAmelCase:						Tuple							,__lowerCAmelCase:						Optional[int]							,__lowerCAmelCase:						str							,__lowerCAmelCase:						Dict							,__lowerCAmelCase:						int							,__lowerCAmelCase:						Optional[Any]							,__lowerCAmelCase:						Tuple    ):







     '''simple docstring'''







     _lowerCamelCase   :				Optional[Any]							=     MraModel(config=__lowerCAmelCase    )
     model.to(__lowerCAmelCase    )
     model.eval()
     _lowerCamelCase   :				Optional[int]							=     model(__lowerCAmelCase							,attention_mask=__lowerCAmelCase							,token_type_ids=__lowerCAmelCase    )
     _lowerCamelCase   :				Union[str, Any]							=     model(__lowerCAmelCase							,token_type_ids=__lowerCAmelCase    )
     _lowerCamelCase   :				List[Any]							=     model(__lowerCAmelCase    )
     self.parent.assertEqual(result.last_hidden_state.shape							,(self.batch_size, self.seq_length, self.hidden_size)    )


  def 							_lowercase					(			self:						Union[str, Any]							,__lowerCAmelCase:						Any							,__lowerCAmelCase:						Union[str, Any]							,__lowerCAmelCase:						Tuple							,__lowerCAmelCase:						Tuple							,__lowerCAmelCase:						int							,__lowerCAmelCase:						Any							,__lowerCAmelCase:						Optional[int]							,__lowerCAmelCase:						Tuple							,__lowerCAmelCase:						List[str]							,):







     '''simple docstring'''







     _lowerCamelCase   :				List[Any]							=     True
     _lowerCamelCase   :				int							=     MraModel(__lowerCAmelCase    )
     model.to(__lowerCAmelCase    )
     model.eval()
     _lowerCamelCase   :				int							=     model(
         __lowerCAmelCase							,attention_mask=__lowerCAmelCase							,token_type_ids=__lowerCAmelCase							,encoder_hidden_states=__lowerCAmelCase							,encoder_attention_mask=__lowerCAmelCase							,)
     _lowerCamelCase   :				str							=     model(
         __lowerCAmelCase							,attention_mask=__lowerCAmelCase							,token_type_ids=__lowerCAmelCase							,encoder_hidden_states=__lowerCAmelCase							,)
     _lowerCamelCase   :				Optional[int]							=     model(__lowerCAmelCase							,attention_mask=__lowerCAmelCase							,token_type_ids=__lowerCAmelCase    )
     self.parent.assertEqual(result.last_hidden_state.shape							,(self.batch_size, self.seq_length, self.hidden_size)    )


  def 							_lowercase					(			self:						int							,__lowerCAmelCase:						Any							,__lowerCAmelCase:						Union[str, Any]							,__lowerCAmelCase:						Union[str, Any]							,__lowerCAmelCase:						Optional[Any]							,__lowerCAmelCase:						Tuple							,__lowerCAmelCase:						int							,__lowerCAmelCase:						List[str]    ):







     '''simple docstring'''







     _lowerCamelCase   :				Tuple							=     MraForMaskedLM(config=__lowerCAmelCase    )
     model.to(__lowerCAmelCase    )
     model.eval()
     _lowerCamelCase   :				Any							=     model(__lowerCAmelCase							,attention_mask=__lowerCAmelCase							,token_type_ids=__lowerCAmelCase							,labels=__lowerCAmelCase    )
     self.parent.assertEqual(result.logits.shape							,(self.batch_size, self.seq_length, self.vocab_size)    )


  def 							_lowercase					(			self:						Union[str, Any]							,__lowerCAmelCase:						Dict							,__lowerCAmelCase:						int							,__lowerCAmelCase:						List[str]							,__lowerCAmelCase:						List[Any]							,__lowerCAmelCase:						Optional[int]							,__lowerCAmelCase:						List[Any]							,__lowerCAmelCase:						Optional[int]    ):







     '''simple docstring'''







     _lowerCamelCase   :				Dict							=     MraForQuestionAnswering(config=__lowerCAmelCase    )
     model.to(__lowerCAmelCase    )
     model.eval()
     _lowerCamelCase   :				int							=     model(
         __lowerCAmelCase							,attention_mask=__lowerCAmelCase							,token_type_ids=__lowerCAmelCase							,start_positions=__lowerCAmelCase							,end_positions=__lowerCAmelCase							,)
     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 							_lowercase					(			self:						Tuple							,__lowerCAmelCase:						Optional[int]							,__lowerCAmelCase:						str							,__lowerCAmelCase:						Union[str, Any]							,__lowerCAmelCase:						Tuple							,__lowerCAmelCase:						Optional[Any]							,__lowerCAmelCase:						Union[str, Any]							,__lowerCAmelCase:						Optional[int]    ):







     '''simple docstring'''







     _lowerCamelCase   :				Union[str, Any]							=     self.num_labels
     _lowerCamelCase   :				Any							=     MraForSequenceClassification(__lowerCAmelCase    )
     model.to(__lowerCAmelCase    )
     model.eval()
     _lowerCamelCase   :				str							=     model(__lowerCAmelCase							,attention_mask=__lowerCAmelCase							,token_type_ids=__lowerCAmelCase							,labels=__lowerCAmelCase    )
     self.parent.assertEqual(result.logits.shape							,(self.batch_size, self.num_labels)    )


  def 							_lowercase					(			self:						str							,__lowerCAmelCase:						Dict							,__lowerCAmelCase:						Dict							,__lowerCAmelCase:						int							,__lowerCAmelCase:						List[Any]							,__lowerCAmelCase:						Optional[int]							,__lowerCAmelCase:						List[Any]							,__lowerCAmelCase:						str    ):







     '''simple docstring'''







     _lowerCamelCase   :				Union[str, Any]							=     self.num_labels
     _lowerCamelCase   :				int							=     MraForTokenClassification(config=__lowerCAmelCase    )
     model.to(__lowerCAmelCase    )
     model.eval()
     _lowerCamelCase   :				str							=     model(__lowerCAmelCase							,attention_mask=__lowerCAmelCase							,token_type_ids=__lowerCAmelCase							,labels=__lowerCAmelCase    )
     self.parent.assertEqual(result.logits.shape							,(self.batch_size, self.seq_length, self.num_labels)    )


  def 							_lowercase					(			self:						Optional[int]							,__lowerCAmelCase:						Optional[Any]							,__lowerCAmelCase:						Any							,__lowerCAmelCase:						Tuple							,__lowerCAmelCase:						Tuple							,__lowerCAmelCase:						Union[str, Any]							,__lowerCAmelCase:						Union[str, Any]							,__lowerCAmelCase:						Tuple    ):







     '''simple docstring'''







     _lowerCamelCase   :				Optional[Any]							=     self.num_choices
     _lowerCamelCase   :				Optional[Any]							=     MraForMultipleChoice(config=__lowerCAmelCase    )
     model.to(__lowerCAmelCase    )
     model.eval()
     _lowerCamelCase   :				Optional[Any]							=     input_ids.unsqueeze(1    ).expand(-1							,self.num_choices							,-1    ).contiguous()
     _lowerCamelCase   :				List[str]							=     token_type_ids.unsqueeze(1    ).expand(-1							,self.num_choices							,-1    ).contiguous()
     _lowerCamelCase   :				List[str]							=     input_mask.unsqueeze(1    ).expand(-1							,self.num_choices							,-1    ).contiguous()
     _lowerCamelCase   :				List[Any]							=     model(
         __lowerCAmelCase							,attention_mask=__lowerCAmelCase							,token_type_ids=__lowerCAmelCase							,labels=__lowerCAmelCase							,)
     self.parent.assertEqual(result.logits.shape							,(self.batch_size, self.num_choices)    )






  def 							_lowercase					(			self:						Optional[Any]    ):







     '''simple docstring'''







     _lowerCamelCase   :				Optional[Any]							=     self.prepare_config_and_inputs()
     (
         (
         _lowerCamelCase
     ),					(
         _lowerCamelCase
     ),					(
         _lowerCamelCase
     ),					(
         _lowerCamelCase
     ),					(
         _lowerCamelCase
     ),					(
         _lowerCamelCase
     ),					(
         _lowerCamelCase
     ),					
     )   :				Any							=     config_and_inputs
     _lowerCamelCase   :				Union[str, Any]							=     {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
     return config, inputs_dict




@require_torch
class 							A_      (       _a     ,	unittest.TestCase ):
  lowerCAmelCase__      			=	(
      (
          MraModel,
          MraForMaskedLM,
          MraForMultipleChoice,
          MraForQuestionAnswering,
          MraForSequenceClassification,
          MraForTokenClassification,
      )
      if is_torch_available()
      else ()
  )
  lowerCAmelCase__      			=	False
  lowerCAmelCase__      			=	False
  lowerCAmelCase__      			=	False
  lowerCAmelCase__      			=	False

  lowerCAmelCase__      			=	()


  def 							_lowercase					(			self:						Dict    ):







     '''simple docstring'''







     _lowerCamelCase   :				str							=     MraModelTester(self    )
     _lowerCamelCase   :				List[str]							=     ConfigTester(self							,config_class=__lowerCAmelCase							,hidden_size=37    )


  def 							_lowercase					(			self:						Union[str, Any]    ):







     '''simple docstring'''







     self.config_tester.run_common_tests()


  def 							_lowercase					(			self:						Dict    ):







     '''simple docstring'''







     _lowerCamelCase   :				Union[str, Any]							=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*__lowerCAmelCase    )


  def 							_lowercase					(			self:						Union[str, Any]    ):







     '''simple docstring'''







     _lowerCamelCase   :				Optional[int]							=     self.model_tester.prepare_config_and_inputs()
     for type in ["absolute", "relative_key", "relative_key_query"]:
        _lowerCamelCase   :				Dict							=     type
        self.model_tester.create_and_check_model(*__lowerCAmelCase    )


  def 							_lowercase					(			self:						Union[str, Any]    ):







     '''simple docstring'''







     _lowerCamelCase   :				Dict							=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_masked_lm(*__lowerCAmelCase    )


  def 							_lowercase					(			self:						int    ):







     '''simple docstring'''







     _lowerCamelCase   :				List[str]							=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_multiple_choice(*__lowerCAmelCase    )


  def 							_lowercase					(			self:						Tuple    ):







     '''simple docstring'''







     _lowerCamelCase   :				Tuple							=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_question_answering(*__lowerCAmelCase    )


  def 							_lowercase					(			self:						Dict    ):







     '''simple docstring'''







     _lowerCamelCase   :				Optional[int]							=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_sequence_classification(*__lowerCAmelCase    )


  def 							_lowercase					(			self:						List[Any]    ):







     '''simple docstring'''







     _lowerCamelCase   :				List[Any]							=     self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_token_classification(*__lowerCAmelCase    )


  @slow
  def 							_lowercase					(			self:						Tuple    ):







     '''simple docstring'''







     for model_name in MRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        _lowerCamelCase   :				Dict							=     MraModel.from_pretrained(__lowerCAmelCase    )
        self.assertIsNotNone(__lowerCAmelCase    )






  @unittest.skip(reason="MRA does not output attentions"    )
  def 							_lowercase					(			self:						str    ):







     '''simple docstring'''







     return




@require_torch
class 							A_      (       unittest.TestCase ):


  @slow
  def 							_lowercase					(			self:						Any    ):







     '''simple docstring'''







     _lowerCamelCase   :				Dict							=     MraModel.from_pretrained("uw-madison/mra-base-512-4"    )
     _lowerCamelCase   :				List[Any]							=     torch.arange(256    ).unsqueeze(0    )

     with torch.no_grad():
        _lowerCamelCase   :				List[str]							=     model(__lowerCAmelCase    )[0]

     _lowerCamelCase   :				str							=     torch.Size((1, 256, 768)    )
     self.assertEqual(output.shape							,__lowerCAmelCase    )

     _lowerCamelCase   :				List[Any]							=     torch.tensor(
         [[[-0.01_40, 0.08_30, -0.03_81], [0.15_46, 0.14_02, 0.02_20], [0.11_62, 0.08_51, 0.01_65]]]    )

     self.assertTrue(torch.allclose(output[:, :3, :3]							,__lowerCAmelCase							,atol=1e-4    )    )


  @slow
  def 							_lowercase					(			self:						Optional[int]    ):







     '''simple docstring'''







     _lowerCamelCase   :				List[Any]							=     MraForMaskedLM.from_pretrained("uw-madison/mra-base-512-4"    )
     _lowerCamelCase   :				List[str]							=     torch.arange(256    ).unsqueeze(0    )

     with torch.no_grad():
        _lowerCamelCase   :				Dict							=     model(__lowerCAmelCase    )[0]

     _lowerCamelCase   :				Optional[Any]							=     50_265

     _lowerCamelCase   :				Dict							=     torch.Size((1, 256, vocab_size)    )
     self.assertEqual(output.shape							,__lowerCAmelCase    )

     _lowerCamelCase   :				Optional[int]							=     torch.tensor(
         [[[9.25_95, -3.60_38, 11.88_19], [9.38_69, -3.26_93, 11.09_56], [11.85_24, -3.49_38, 13.12_10]]]    )

     self.assertTrue(torch.allclose(output[:, :3, :3]							,__lowerCAmelCase							,atol=1e-4    )    )






  @slow
  def 							_lowercase					(			self:						Dict    ):







     '''simple docstring'''







     _lowerCamelCase   :				Any							=     MraForMaskedLM.from_pretrained("uw-madison/mra-base-4096-8-d3"    )
     _lowerCamelCase   :				str							=     torch.arange(4_096    ).unsqueeze(0    )

     with torch.no_grad():
        _lowerCamelCase   :				Any							=     model(__lowerCAmelCase    )[0]

     _lowerCamelCase   :				Any							=     50_265

     _lowerCamelCase   :				Dict							=     torch.Size((1, 4_096, vocab_size)    )
     self.assertEqual(output.shape							,__lowerCAmelCase    )

     _lowerCamelCase   :				int							=     torch.tensor(
         [[[5.47_89, -2.35_64, 7.50_64], [7.90_67, -1.33_69, 9.96_68], [9.07_12, -1.81_06, 7.03_80]]]    )

     self.assertTrue(torch.allclose(output[:, :3, :3]							,__lowerCAmelCase							,atol=1e-4    )    )
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_     (       __lowercase,  unittest.TestCase ):
							UpperCAmelCase				   =     ShapEPipeline
							UpperCAmelCase				   =     ["prompt"]
							UpperCAmelCase				   =     ["prompt"]
							UpperCAmelCase				   =     [
							    "num_images_per_prompt",
							    "num_inference_steps",
							    "generator",
							    "latents",
							    "guidance_scale",
							    "frame_size",
							    "output_type",
							    "return_dict",
							]
							UpperCAmelCase				   =     False







							@property
							def  UpperCamelCase_						(   self      :     Union[str, Any]		):
												return 32







							@property
							def  UpperCamelCase_						(   self      :     int		):
												return 32







							@property
							def  UpperCamelCase_						(   self      :     List[str]		):
												return self.time_input_dim * 4







							@property
							def  UpperCamelCase_						(   self      :     Optional[Any]		):
												return 8







							@property
							def  UpperCamelCase_						(   self      :     int		):
												_UpperCamelCase			     =     CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''		)
												return tokenizer







							@property
							def  UpperCamelCase_						(   self      :     List[Any]		):
												torch.manual_seed(0		)
												_UpperCamelCase			     =     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(_A		)







							@property
							def  UpperCamelCase_						(   self      :     int		):
												torch.manual_seed(0		)

												_UpperCamelCase			     =     {
												    '''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			     =     PriorTransformer(**_A		)
												return model







							@property
							def  UpperCamelCase_						(   self      :     Union[str, Any]		):
												torch.manual_seed(0		)

												_UpperCamelCase			     =     {
												    '''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			     =     ShapERenderer(**_A		)
												return model







							def  UpperCamelCase_						(   self      :     str		):
												_UpperCamelCase			     =     self.dummy_prior
												_UpperCamelCase			     =     self.dummy_text_encoder
												_UpperCamelCase			     =     self.dummy_tokenizer
												_UpperCamelCase			     =     self.dummy_renderer

												_UpperCamelCase			     =     HeunDiscreteScheduler(
												    beta_schedule='''exp''' ,			num_train_timesteps=1024 ,			prediction_type='''sample''' ,			use_karras_sigmas=_A ,			clip_sample=_A ,			clip_sample_range=1.0 ,			)
												_UpperCamelCase			     =     {
												    '''prior''': prior,
												    '''text_encoder''': text_encoder,
												    '''tokenizer''': tokenizer,
												    '''renderer''': renderer,
												    '''scheduler''': scheduler,
												}

												return components







							def  UpperCamelCase_						(   self      :     Tuple ,			_A      :     Tuple ,			_A      :     Optional[int]=0		):
												if str(_A		).startswith('''mps'''		):
																	_UpperCamelCase			     =     torch.manual_seed(_A		)
												else:
																	_UpperCamelCase			     =     torch.Generator(device=_A		).manual_seed(_A		)
												_UpperCamelCase			     =     {
												    '''prompt''': '''horse''',
												    '''generator''': generator,
												    '''num_inference_steps''': 1,
												    '''frame_size''': 32,
												    '''output_type''': '''np''',
												}
												return inputs







							def  UpperCamelCase_						(   self      :     Any		):
												_UpperCamelCase			     =     '''cpu'''

												_UpperCamelCase			     =     self.get_dummy_components()

												_UpperCamelCase			     =     self.pipeline_class(**_A		)
												_UpperCamelCase			     =     pipe.to(_A		)

												pipe.set_progress_bar_config(disable=_A		)

												_UpperCamelCase			     =     pipe(**self.get_dummy_inputs(_A		)		)
												_UpperCamelCase			     =     output.images[0]
												_UpperCamelCase			     =     image[0, -3:, -3:, -1]

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

												_UpperCamelCase			     =     np.array(
												    [
												        0.0003_9216,
												        0.0003_9216,
												        0.0003_9216,
												        0.0003_9216,
												        0.0003_9216,
												        0.0003_9216,
												        0.0003_9216,
												        0.0003_9216,
												        0.0003_9216,
												    ]		)

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







							def  UpperCamelCase_						(   self      :     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  UpperCamelCase_						(   self      :     Any		):
												_UpperCamelCase			     =     torch_device == '''cpu'''
												_UpperCamelCase			     =     True

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







							def  UpperCamelCase_						(   self      :     Any		):
												_UpperCamelCase			     =     self.get_dummy_components()
												_UpperCamelCase			     =     self.pipeline_class(**_A		)
												_UpperCamelCase			     =     pipe.to(_A		)
												pipe.set_progress_bar_config(disable=_A		)

												_UpperCamelCase			     =     1
												_UpperCamelCase			     =     2

												_UpperCamelCase			     =     self.get_dummy_inputs(_A		)

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

												_UpperCamelCase			     =     pipe(**_A ,			num_images_per_prompt=_A		)[0]

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




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







							def  UpperCamelCase_						(   self      :     str		):
												# clean up the VRAM after each test
												super().tearDown()
												gc.collect()
												torch.cuda.empty_cache()







							def  UpperCamelCase_						(   self      :     List[str]		):
												_UpperCamelCase			     =     load_numpy(
												    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main'''
												    '''/shap_e/test_shap_e_np_out.npy'''		)
												_UpperCamelCase			     =     ShapEPipeline.from_pretrained('''openai/shap-e'''		)
												_UpperCamelCase			     =     pipe.to(_A		)
												pipe.set_progress_bar_config(disable=_A		)

												_UpperCamelCase			     =     torch.Generator(device=_A		).manual_seed(0		)

												_UpperCamelCase			     =     pipe(
												    '''a shark''' ,			generator=_A ,			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(_A ,			_A		)
