





'''simple docstring'''




from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

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 (
      TFFunnelBaseModel,
      TFFunnelForMaskedLM,
      TFFunnelForMultipleChoice,
      TFFunnelForPreTraining,
      TFFunnelForQuestionAnswering,
      TFFunnelForSequenceClassification,
      TFFunnelForTokenClassification,
      TFFunnelModel,
  )







class     A_      :




 def __init__(   self			:       List[Any]      ,     snake_case_			:       int      ,     snake_case_			:       List[str]=1_3      ,     snake_case_			:       Any=7      ,     snake_case_			:       Dict=True      ,     snake_case_			:       int=True      ,     snake_case_			:       Any=True      ,     snake_case_			:       Tuple=True      ,     snake_case_			:       Dict=9_9      ,     snake_case_			:       List[Any]=[1, 1, 2]      ,     snake_case_			:       List[str]=1      ,     snake_case_			:       List[str]=3_2      ,     snake_case_			:       Union[str, Any]=4      ,     snake_case_			:       Optional[Any]=8      ,     snake_case_			:       Optional[Any]=3_7      ,     snake_case_			:       str="gelu_new"      ,     snake_case_			:       str=0.1      ,     snake_case_			:       List[str]=0.1      ,     snake_case_			:       Union[str, Any]=0.0      ,     snake_case_			:       Any=5_1_2      ,     snake_case_			:       List[Any]=3      ,     snake_case_			:       Optional[int]=0.0_2      ,     snake_case_			:       List[Any]=3      ,     snake_case_			:       Any=4      ,     snake_case_			:       List[str]=None      ,     snake_case_			:       Optional[Any]=False      ,     ):
      _UpperCAmelCase					=  parent
      _UpperCAmelCase					=  batch_size
      _UpperCAmelCase					=  seq_length
      _UpperCAmelCase					=  is_training
      _UpperCAmelCase					=  use_input_mask
      _UpperCAmelCase					=  use_token_type_ids
      _UpperCAmelCase					=  use_labels
      _UpperCAmelCase					=  vocab_size
      _UpperCAmelCase					=  block_sizes
      _UpperCAmelCase					=  num_decoder_layers
      _UpperCAmelCase					=  d_model
      _UpperCAmelCase					=  n_head
      _UpperCAmelCase					=  d_head
      _UpperCAmelCase					=  d_inner
      _UpperCAmelCase					=  hidden_act
      _UpperCAmelCase					=  hidden_dropout
      _UpperCAmelCase					=  attention_dropout
      _UpperCAmelCase					=  activation_dropout
      _UpperCAmelCase					=  max_position_embeddings
      _UpperCAmelCase					=  type_vocab_size
      _UpperCAmelCase					=  2
      _UpperCAmelCase					=  num_labels
      _UpperCAmelCase					=  num_choices
      _UpperCAmelCase					=  scope
      _UpperCAmelCase					=  initializer_std

      # Used in the tests to check the size of the first attention layer
      _UpperCAmelCase					=  n_head
      # Used in the tests to check the size of the first hidden state
      _UpperCAmelCase					=  self.d_model
      # Used in the tests to check the number of output hidden states/attentions
      _UpperCAmelCase					=  sum(self.block_sizes       ) + (0 if base else self.num_decoder_layers)
      # FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
      # the last hidden state of the first block (which is the first hidden state of the decoder).
      if not base:
           _UpperCAmelCase					=  self.num_hidden_layers + 2




 def 	lowercase      (   self			:       Dict       ):
      _UpperCAmelCase					=  ids_tensor([self.batch_size, self.seq_length]      ,     self.vocab_size       )

      _UpperCAmelCase					=  None
      if self.use_input_mask:
           _UpperCAmelCase					=  random_attention_mask([self.batch_size, self.seq_length]       )

      _UpperCAmelCase					=  None
      if self.use_token_type_ids:
           _UpperCAmelCase					=  ids_tensor([self.batch_size, self.seq_length]      ,     self.type_vocab_size       )

      _UpperCAmelCase					=  None
      _UpperCAmelCase					=  None
      _UpperCAmelCase					=  None
      if self.use_labels:
           _UpperCAmelCase					=  ids_tensor([self.batch_size]      ,     self.type_sequence_label_size       )
           _UpperCAmelCase					=  ids_tensor([self.batch_size, self.seq_length]      ,     self.num_labels       )
           _UpperCAmelCase					=  ids_tensor([self.batch_size]      ,     self.num_choices       )

      _UpperCAmelCase					=  FunnelConfig(
          vocab_size=self.vocab_size      ,     block_sizes=self.block_sizes      ,     num_decoder_layers=self.num_decoder_layers      ,     d_model=self.d_model      ,     n_head=self.n_head      ,     d_head=self.d_head      ,     d_inner=self.d_inner      ,     hidden_act=self.hidden_act      ,     hidden_dropout=self.hidden_dropout      ,     attention_dropout=self.attention_dropout      ,     activation_dropout=self.activation_dropout      ,     max_position_embeddings=self.max_position_embeddings      ,     type_vocab_size=self.type_vocab_size      ,     initializer_std=self.initializer_std      ,     )

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




 def 	lowercase      (   self			:       Any      ,     snake_case_			:       Optional[int]      ,     snake_case_			:       List[Any]      ,     snake_case_			:       List[str]      ,     snake_case_			:       Dict      ,     snake_case_			:       str      ,     snake_case_			:       Union[str, Any]      ,     snake_case_			:       Dict      ,     ):
      _UpperCAmelCase					=  TFFunnelModel(config=snake_case_       )
      _UpperCAmelCase					=  {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
      _UpperCAmelCase					=  model(snake_case_       )

      _UpperCAmelCase					=  [input_ids, input_mask]
      _UpperCAmelCase					=  model(snake_case_       )

      _UpperCAmelCase					=  model(snake_case_       )
      self.parent.assertEqual(result.last_hidden_state.shape      ,     (self.batch_size, self.seq_length, self.d_model)       )

      _UpperCAmelCase					=  False
      _UpperCAmelCase					=  TFFunnelModel(config=snake_case_       )
      _UpperCAmelCase					=  model(snake_case_       )
      self.parent.assertEqual(result.last_hidden_state.shape      ,     (self.batch_size, self.seq_length, self.d_model)       )

      _UpperCAmelCase					=  False
      _UpperCAmelCase					=  TFFunnelModel(config=snake_case_       )
      _UpperCAmelCase					=  model(snake_case_       )
      self.parent.assertEqual(result.last_hidden_state.shape      ,     (self.batch_size, self.seq_length, self.d_model)       )




 def 	lowercase      (   self			:       Optional[int]      ,     snake_case_			:       List[Any]      ,     snake_case_			:       Optional[int]      ,     snake_case_			:       Dict      ,     snake_case_			:       Optional[Any]      ,     snake_case_			:       str      ,     snake_case_			:       int      ,     snake_case_			:       int      ,     ):
      _UpperCAmelCase					=  TFFunnelBaseModel(config=snake_case_       )
      _UpperCAmelCase					=  {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
      _UpperCAmelCase					=  model(snake_case_       )

      _UpperCAmelCase					=  [input_ids, input_mask]
      _UpperCAmelCase					=  model(snake_case_       )

      _UpperCAmelCase					=  model(snake_case_       )
      self.parent.assertEqual(result.last_hidden_state.shape      ,     (self.batch_size, 2, self.d_model)       )

      _UpperCAmelCase					=  False
      _UpperCAmelCase					=  TFFunnelBaseModel(config=snake_case_       )
      _UpperCAmelCase					=  model(snake_case_       )
      self.parent.assertEqual(result.last_hidden_state.shape      ,     (self.batch_size, 3, self.d_model)       )

      _UpperCAmelCase					=  False
      _UpperCAmelCase					=  TFFunnelBaseModel(config=snake_case_       )
      _UpperCAmelCase					=  model(snake_case_       )
      self.parent.assertEqual(result.last_hidden_state.shape      ,     (self.batch_size, 2, self.d_model)       )




 def 	lowercase      (   self			:       List[Any]      ,     snake_case_			:       str      ,     snake_case_			:       str      ,     snake_case_			:       int      ,     snake_case_			:       int      ,     snake_case_			:       List[Any]      ,     snake_case_			:       Tuple      ,     snake_case_			:       Optional[int]      ,     ):
      _UpperCAmelCase					=  TFFunnelForPreTraining(config=snake_case_       )
      _UpperCAmelCase					=  {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
      _UpperCAmelCase					=  model(snake_case_       )
      self.parent.assertEqual(result.logits.shape      ,     (self.batch_size, self.seq_length)       )




 def 	lowercase      (   self			:       Tuple      ,     snake_case_			:       Optional[int]      ,     snake_case_			:       int      ,     snake_case_			:       int      ,     snake_case_			:       Dict      ,     snake_case_			:       Tuple      ,     snake_case_			:       Dict      ,     snake_case_			:       str      ,     ):
      _UpperCAmelCase					=  TFFunnelForMaskedLM(config=snake_case_       )
      _UpperCAmelCase					=  {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
      _UpperCAmelCase					=  model(snake_case_       )
      self.parent.assertEqual(result.logits.shape      ,     (self.batch_size, self.seq_length, self.vocab_size)       )




 def 	lowercase      (   self			:       int      ,     snake_case_			:       Tuple      ,     snake_case_			:       Tuple      ,     snake_case_			:       Optional[Any]      ,     snake_case_			:       Any      ,     snake_case_			:       Any      ,     snake_case_			:       Optional[Any]      ,     snake_case_			:       List[str]      ,     ):
      _UpperCAmelCase					=  self.num_labels
      _UpperCAmelCase					=  TFFunnelForSequenceClassification(config=snake_case_       )
      _UpperCAmelCase					=  {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
      _UpperCAmelCase					=  model(snake_case_       )
      self.parent.assertEqual(result.logits.shape      ,     (self.batch_size, self.num_labels)       )




 def 	lowercase      (   self			:       Any      ,     snake_case_			:       Union[str, Any]      ,     snake_case_			:       Union[str, Any]      ,     snake_case_			:       str      ,     snake_case_			:       Dict      ,     snake_case_			:       Union[str, Any]      ,     snake_case_			:       str      ,     snake_case_			:       Optional[int]      ,     ):
      _UpperCAmelCase					=  self.num_choices
      _UpperCAmelCase					=  TFFunnelForMultipleChoice(config=snake_case_       )
      _UpperCAmelCase					=  tf.tile(tf.expand_dims(snake_case_      ,     1       )      ,     (1, self.num_choices, 1)       )
      _UpperCAmelCase					=  tf.tile(tf.expand_dims(snake_case_      ,     1       )      ,     (1, self.num_choices, 1)       )
      _UpperCAmelCase					=  tf.tile(tf.expand_dims(snake_case_      ,     1       )      ,     (1, self.num_choices, 1)       )
      _UpperCAmelCase					=  {
          "input_ids": multiple_choice_inputs_ids,
          "attention_mask": multiple_choice_input_mask,
          "token_type_ids": multiple_choice_token_type_ids,
      }
      _UpperCAmelCase					=  model(snake_case_       )
      self.parent.assertEqual(result.logits.shape      ,     (self.batch_size, self.num_choices)       )




 def 	lowercase      (   self			:       Optional[Any]      ,     snake_case_			:       List[Any]      ,     snake_case_			:       Dict      ,     snake_case_			:       Tuple      ,     snake_case_			:       str      ,     snake_case_			:       Any      ,     snake_case_			:       Any      ,     snake_case_			:       List[Any]      ,     ):
      _UpperCAmelCase					=  self.num_labels
      _UpperCAmelCase					=  TFFunnelForTokenClassification(config=snake_case_       )
      _UpperCAmelCase					=  {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
      _UpperCAmelCase					=  model(snake_case_       )
      self.parent.assertEqual(result.logits.shape      ,     (self.batch_size, self.seq_length, self.num_labels)       )




 def 	lowercase      (   self			:       Dict      ,     snake_case_			:       List[Any]      ,     snake_case_			:       Dict      ,     snake_case_			:       Dict      ,     snake_case_			:       Any      ,     snake_case_			:       List[Any]      ,     snake_case_			:       List[str]      ,     snake_case_			:       Optional[Any]      ,     ):
      _UpperCAmelCase					=  TFFunnelForQuestionAnswering(config=snake_case_       )
      _UpperCAmelCase					=  {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
      _UpperCAmelCase					=  model(snake_case_       )
      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			:       Any       ):
      _UpperCAmelCase					=  self.prepare_config_and_inputs()
      (
          (
          _UpperCAmelCase			
      )				,    (
          _UpperCAmelCase			
      )				,    (
          _UpperCAmelCase			
      )				,    (
          _UpperCAmelCase			
      )				,    (
          _UpperCAmelCase			
      )				,    (
          _UpperCAmelCase			
      )				,    (
          _UpperCAmelCase			
      )				,    			
      )					=  config_and_inputs
      _UpperCAmelCase					=  {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
      return config, inputs_dict







@require_tf
class     A_      (    _lowercase				,		_lowercase				,		unittest.TestCase     ):
 _lowerCamelCase    :					List[Any]       			=				(
     (
         TFFunnelModel,
         TFFunnelForMaskedLM,
         TFFunnelForPreTraining,
         TFFunnelForQuestionAnswering,
         TFFunnelForTokenClassification,
     )
     if is_tf_available()
     else ()
 )
 _lowerCamelCase    :					List[Any]       			=				(
     {
         '''feature-extraction''': (TFFunnelBaseModel, TFFunnelModel),
         '''fill-mask''': TFFunnelForMaskedLM,
         '''question-answering''': TFFunnelForQuestionAnswering,
         '''text-classification''': TFFunnelForSequenceClassification,
         '''token-classification''': TFFunnelForTokenClassification,
         '''zero-shot''': TFFunnelForSequenceClassification,
     }
     if is_tf_available()
     else {}
 )
 _lowerCamelCase    :					Union[str, Any]       			=				False
 _lowerCamelCase    :					Optional[Any]       			=				False




 def 	lowercase      (   self			:       Any       ):
      _UpperCAmelCase					=  TFFunnelModelTester(self       )
      _UpperCAmelCase					=  ConfigTester(self      ,     config_class=snake_case_       )




 def 	lowercase      (   self			:       int       ):
      self.config_tester.run_common_tests()




 def 	lowercase      (   self			:       Dict       ):
      _UpperCAmelCase					=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*snake_case_       )




 def 	lowercase      (   self			:       Union[str, Any]       ):
      _UpperCAmelCase					=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_pretraining(*snake_case_       )




 def 	lowercase      (   self			:       Any       ):
      _UpperCAmelCase					=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*snake_case_       )




 def 	lowercase      (   self			:       List[str]       ):
      _UpperCAmelCase					=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*snake_case_       )




 def 	lowercase      (   self			:       Optional[int]       ):
      _UpperCAmelCase					=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*snake_case_       )







@require_tf
class     A_      (    _lowercase				,		unittest.TestCase     ):
 _lowerCamelCase    :					List[str]       			=				(
     (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
 )
 _lowerCamelCase    :					Optional[int]       			=				False
 _lowerCamelCase    :					Union[str, Any]       			=				False




 def 	lowercase      (   self			:       List[Any]       ):
      _UpperCAmelCase					=  TFFunnelModelTester(self      ,     base=snake_case_       )
      _UpperCAmelCase					=  ConfigTester(self      ,     config_class=snake_case_       )




 def 	lowercase      (   self			:       int       ):
      self.config_tester.run_common_tests()




 def 	lowercase      (   self			:       int       ):
      _UpperCAmelCase					=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_base_model(*snake_case_       )




 def 	lowercase      (   self			:       Union[str, Any]       ):
      _UpperCAmelCase					=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*snake_case_       )




 def 	lowercase      (   self			:       Optional[Any]       ):
      _UpperCAmelCase					=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_multiple_choice(*snake_case_       )









import gc
import unittest

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

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    StableDiffusionAttendAndExcitePipeline,
    UNetaDConditionModel,
)
from diffusers.utils import load_numpy, skip_mps, slow
from diffusers.utils.testing_utils import require_torch_gpu

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineKarrasSchedulerTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin


a_      :      Optional[int]    =     False
@skip_mps
class    __UpperCamelCase			(       _lowercase	,	_lowercase	,	_lowercase	,	unittest.TestCase				):

 """simple docstring"""



 _lowercase   :    List[Any]      						=					StableDiffusionAttendAndExcitePipeline
 _lowercase   :    str      						=					False
 _lowercase   :    List[str]      						=					TEXT_TO_IMAGE_PARAMS
 _lowercase   :    Optional[int]      						=					TEXT_TO_IMAGE_BATCH_PARAMS.union({'''token_indices'''}				)
 _lowercase   :    Union[str, Any]      						=					TEXT_TO_IMAGE_IMAGE_PARAMS
 _lowercase   :    List[Any]      						=					TEXT_TO_IMAGE_IMAGE_PARAMS

 @classmethod
 def 						_UpperCAmelCase       (	cls      ) ->			Dict:
  super().setUpClass()
  torch.use_deterministic_algorithms(SCREAMING_SNAKE_CASE      )

 @classmethod
 def 						_UpperCAmelCase       (	cls      ) ->			Tuple:
  super().tearDownClass()
  torch.use_deterministic_algorithms(SCREAMING_SNAKE_CASE      )

 def 						_UpperCAmelCase       (	self      ) ->			List[Any]:
  torch.manual_seed(0      )
  a__												= UNetaDConditionModel(
      block_out_channels=(3_2, 6_4)		,				layers_per_block=1		,				sample_size=3_2		,				in_channels=4		,				out_channels=4		,				down_block_types=('''DownBlock2D''', '''CrossAttnDownBlock2D''')		,				up_block_types=('''CrossAttnUpBlock2D''', '''UpBlock2D''')		,				cross_attention_dim=3_2		,				attention_head_dim=(2, 4)		,				use_linear_projection=SCREAMING_SNAKE_CASE		,				)
  a__												= DDIMScheduler(
      beta_start=0.0_00_85		,				beta_end=0.0_12		,				beta_schedule='''scaled_linear'''		,				clip_sample=SCREAMING_SNAKE_CASE		,				set_alpha_to_one=SCREAMING_SNAKE_CASE		,				)
  torch.manual_seed(0      )
  a__												= AutoencoderKL(
      block_out_channels=[3_2, 6_4]		,				in_channels=3		,				out_channels=3		,				down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D''']		,				up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D''']		,				latent_channels=4		,				sample_size=1_2_8		,				)
  torch.manual_seed(0      )
  a__												= CLIPTextConfig(
      bos_token_id=0		,				eos_token_id=2		,				hidden_size=3_2		,				intermediate_size=3_7		,				layer_norm_eps=1e-0_5		,				num_attention_heads=4		,				num_hidden_layers=5		,				pad_token_id=1		,				vocab_size=1_0_0_0		,				hidden_act='''gelu'''		,				projection_dim=5_1_2		,				)
  a__												= CLIPTextModel(SCREAMING_SNAKE_CASE      )
  a__												= CLIPTokenizer.from_pretrained('''hf-internal-testing/tiny-random-clip'''      )

  a__												= {
      '''unet''': unet,
      '''scheduler''': scheduler,
      '''vae''': vae,
      '''text_encoder''': text_encoder,
      '''tokenizer''': tokenizer,
      '''safety_checker''': None,
      '''feature_extractor''': None,
  }

  return components

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE=0      ) ->			Dict:
  if str(SCREAMING_SNAKE_CASE      ).startswith('''mps'''      ):
   a__												= torch.manual_seed(SCREAMING_SNAKE_CASE      )
  else:
   a__												= torch.Generator(device=SCREAMING_SNAKE_CASE      ).manual_seed(SCREAMING_SNAKE_CASE      )
  a__												= a__												= {
      '''prompt''': '''a cat and a frog''',
      '''token_indices''': [2, 5],
      '''generator''': generator,
      '''num_inference_steps''': 1,
      '''guidance_scale''': 6.0,
      '''output_type''': '''numpy''',
      '''max_iter_to_alter''': 2,
      '''thresholds''': {0: 0.7},
  }
  return inputs

 def 						_UpperCAmelCase       (	self      ) ->			str:
  a__												= '''cpu'''

  a__												= self.get_dummy_components()
  a__												= self.pipeline_class(**SCREAMING_SNAKE_CASE      )
  pipe.to(SCREAMING_SNAKE_CASE      )
  pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE      )

  a__												= self.get_dummy_inputs(SCREAMING_SNAKE_CASE      )
  a__												= pipe(**SCREAMING_SNAKE_CASE      ).images
  a__												= image[0, -3:, -3:, -1]

  self.assertEqual(image.shape		,				(1, 6_4, 6_4, 3)      )
  a__												= np.array(
      [0.63_90_53_64, 0.62_89_73_07, 0.48_59_90_17, 0.5_13_36_24, 0.5_55_00_48, 0.45_76_95_16, 0.50_32_69_73, 0.5_02_31_39, 0.45_38_44_96]      )
  a__												= np.abs(image_slice.flatten() - expected_slice      ).max()
  self.assertLessEqual(SCREAMING_SNAKE_CASE		,				1e-3      )

 def 						_UpperCAmelCase       (	self      ) ->			str:
  super().test_cpu_offload_forward_pass(expected_max_diff=5e-4      )

 def 						_UpperCAmelCase       (	self      ) ->			List[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      ) ->			List[Any]:
  self._test_inference_batch_single_identical(batch_size=2		,				expected_max_diff=7e-4      )

 def 						_UpperCAmelCase       (	self      ) ->			int:
  super().test_dict_tuple_outputs_equivalent(expected_max_difference=3e-3      )

 def 						_UpperCAmelCase       (	self      ) ->			Optional[Any]:
  super().test_pt_np_pil_outputs_equivalent(expected_max_diff=5e-4      )

 def 						_UpperCAmelCase       (	self      ) ->			Dict:
  super().test_save_load_local(expected_max_difference=5e-4      )



 def 						_UpperCAmelCase       (	self      ) ->			str:
  super().test_save_load_optional_components(expected_max_difference=4e-4      )





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

 """simple docstring"""



 @classmethod
 def 						_UpperCAmelCase       (	cls      ) ->			Optional[int]:
  super().setUpClass()
  torch.use_deterministic_algorithms(SCREAMING_SNAKE_CASE      )

 @classmethod
 def 						_UpperCAmelCase       (	cls      ) ->			str:
  super().tearDownClass()
  torch.use_deterministic_algorithms(SCREAMING_SNAKE_CASE      )

 def 						_UpperCAmelCase       (	self      ) ->			List[str]:
  super().tearDown()
  gc.collect()
  torch.cuda.empty_cache()



 def 						_UpperCAmelCase       (	self      ) ->			str:
  a__												= torch.manual_seed(5_1      )

  a__												= StableDiffusionAttendAndExcitePipeline.from_pretrained(
      '''CompVis/stable-diffusion-v1-4'''		,				safety_checker=SCREAMING_SNAKE_CASE		,				torch_dtype=torch.floataa      )
  pipe.to('''cuda'''      )

  a__												= '''a painting of an elephant with glasses'''
  a__												= [5, 7]

  a__												= pipe(
      prompt=SCREAMING_SNAKE_CASE		,				token_indices=SCREAMING_SNAKE_CASE		,				guidance_scale=7.5		,				generator=SCREAMING_SNAKE_CASE		,				num_inference_steps=5		,				max_iter_to_alter=5		,				output_type='''numpy'''		,				).images[0]

  a__												= load_numpy(
      '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/attend-and-excite/elephant_glasses.npy'''      )
  assert np.abs((expected_image - image).max()      ) < 5e-1





