"""simple docstring"""




import os
import tempfile
import unittest

from transformers import NezhaConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, require_torch_gpu, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
     import torch

     from transformers import (
         MODEL_FOR_PRETRAINING_MAPPING,
         NezhaForMaskedLM,
         NezhaForMultipleChoice,
         NezhaForNextSentencePrediction,
         NezhaForPreTraining,
         NezhaForQuestionAnswering,
         NezhaForSequenceClassification,
         NezhaForTokenClassification,
         NezhaModel,
     )
     from transformers.models.nezha.modeling_nezha import NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST
class 		__A							:






     def __init__(	self       ,  a__       ,  a__=13       ,  a__=7       ,  a__=True       ,  a__=True       ,  a__=True       ,  a__=True       ,  a__=99       ,  a__=32       ,  a__=5       ,  a__=4       ,  a__=37       ,  a__="gelu"       ,  a__=0.1       ,  a__=0.1       ,  a__=128       ,  a__=32       ,  a__=16       ,  a__=2       ,  a__=0.0_2       ,  a__=3       ,  a__=4       ,  a__=None       ,  ):
       _lowerCAmelCase		: List[str]						    =  parent
       _lowerCAmelCase		: Tuple						    =  batch_size
       _lowerCAmelCase		: Optional[int]						    =  seq_length
       _lowerCAmelCase		: Tuple						    =  is_training
       _lowerCAmelCase		: Dict						    =  use_input_mask
       _lowerCAmelCase		: List[Any]						    =  use_token_type_ids
       _lowerCAmelCase		: Dict						    =  use_labels
       _lowerCAmelCase		: Dict						    =  vocab_size
       _lowerCAmelCase		: Tuple						    =  hidden_size
       _lowerCAmelCase		: Any						    =  num_hidden_layers
       _lowerCAmelCase		: Union[str, Any]						    =  num_attention_heads
       _lowerCAmelCase		: Dict						    =  intermediate_size
       _lowerCAmelCase		: List[Any]						    =  hidden_act
       _lowerCAmelCase		: Dict						    =  hidden_dropout_prob
       _lowerCAmelCase		: int						    =  attention_probs_dropout_prob
       _lowerCAmelCase		: Union[str, Any]						    =  max_position_embeddings
       _lowerCAmelCase		: Optional[Any]						    =  type_vocab_size
       _lowerCAmelCase		: List[Any]						    =  type_sequence_label_size
       _lowerCAmelCase		: List[str]						    =  initializer_range
       _lowerCAmelCase		: Any						    =  num_labels
       _lowerCAmelCase		: Union[str, Any]						    =  num_choices
       _lowerCAmelCase		: List[str]						    =  scope






     def 					__A						(	self						):
       _lowerCAmelCase		: Dict						    =  ids_tensor([self.batch_size, self.seq_length]       ,  self.vocab_size						)

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

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

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

       _lowerCAmelCase		: Any						    =  self.get_config()

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






     def 					__A						(	self						):
       return NezhaConfig(
           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=a__       ,  initializer_range=self.initializer_range       ,  )






     def 					__A						(	self						):
       (
           (
           _lowerCAmelCase
       )    ,			(
           _lowerCAmelCase
       )    ,			(
           _lowerCAmelCase
       )    ,			(
           _lowerCAmelCase
       )    ,			(
           _lowerCAmelCase
       )    ,			(
           _lowerCAmelCase
       )    ,			(
           _lowerCAmelCase
       )    ,			
       )		: Optional[Any]						    =  self.prepare_config_and_inputs()

       _lowerCAmelCase		: int						    =  True
       _lowerCAmelCase		: int						    =  floats_tensor([self.batch_size, self.seq_length, self.hidden_size]						)
       _lowerCAmelCase		: Union[str, Any]						    =  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 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__						):
       _lowerCAmelCase		: Optional[Any]						    =  NezhaModel(config=a__						)
       model.to(a__						)
       model.eval()
       _lowerCAmelCase		: Optional[int]						    =  model(a__       ,  attention_mask=a__       ,  token_type_ids=a__						)
       _lowerCAmelCase		: Dict						    =  model(a__       ,  token_type_ids=a__						)
       _lowerCAmelCase		: Union[str, Any]						    =  model(a__						)
       self.parent.assertEqual(result.last_hidden_state.shape       ,  (self.batch_size, self.seq_length, self.hidden_size)						)
       self.parent.assertEqual(result.pooler_output.shape       ,  (self.batch_size, self.hidden_size)						)






     def 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  ):
       _lowerCAmelCase		: List[str]						    =  True
       _lowerCAmelCase		: int						    =  NezhaModel(a__						)
       model.to(a__						)
       model.eval()
       _lowerCAmelCase		: Dict						    =  model(
           a__       ,  attention_mask=a__       ,  token_type_ids=a__       ,  encoder_hidden_states=a__       ,  encoder_attention_mask=a__       ,  )
       _lowerCAmelCase		: List[Any]						    =  model(
           a__       ,  attention_mask=a__       ,  token_type_ids=a__       ,  encoder_hidden_states=a__       ,  )
       _lowerCAmelCase		: List[str]						    =  model(a__       ,  attention_mask=a__       ,  token_type_ids=a__						)
       self.parent.assertEqual(result.last_hidden_state.shape       ,  (self.batch_size, self.seq_length, self.hidden_size)						)
       self.parent.assertEqual(result.pooler_output.shape       ,  (self.batch_size, self.hidden_size)						)






     def 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__						):
       _lowerCAmelCase		: Union[str, Any]						    =  NezhaForMaskedLM(config=a__						)
       model.to(a__						)
       model.eval()
       _lowerCAmelCase		: int						    =  model(a__       ,  attention_mask=a__       ,  token_type_ids=a__       ,  labels=a__						)
       self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.seq_length, self.vocab_size)						)






     def 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__						):
       _lowerCAmelCase		: Any						    =  NezhaForNextSentencePrediction(config=a__						)
       model.to(a__						)
       model.eval()
       _lowerCAmelCase		: Optional[int]						    =  model(
           a__       ,  attention_mask=a__       ,  token_type_ids=a__       ,  labels=a__       ,  )
       self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, 2)						)






     def 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__						):
       _lowerCAmelCase		: Tuple						    =  NezhaForPreTraining(config=a__						)
       model.to(a__						)
       model.eval()
       _lowerCAmelCase		: Union[str, Any]						    =  model(
           a__       ,  attention_mask=a__       ,  token_type_ids=a__       ,  labels=a__       ,  next_sentence_label=a__       ,  )
       self.parent.assertEqual(result.prediction_logits.shape       ,  (self.batch_size, self.seq_length, self.vocab_size)						)
       self.parent.assertEqual(result.seq_relationship_logits.shape       ,  (self.batch_size, 2)						)






     def 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__						):
       _lowerCAmelCase		: List[str]						    =  NezhaForQuestionAnswering(config=a__						)
       model.to(a__						)
       model.eval()
       _lowerCAmelCase		: Union[str, Any]						    =  model(
           a__       ,  attention_mask=a__       ,  token_type_ids=a__       ,  start_positions=a__       ,  end_positions=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 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__						):
       _lowerCAmelCase		: List[Any]						    =  self.num_labels
       _lowerCAmelCase		: Tuple						    =  NezhaForSequenceClassification(a__						)
       model.to(a__						)
       model.eval()
       _lowerCAmelCase		: Dict						    =  model(a__       ,  attention_mask=a__       ,  token_type_ids=a__       ,  labels=a__						)
       self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.num_labels)						)






     def 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__						):
       _lowerCAmelCase		: Optional[int]						    =  self.num_labels
       _lowerCAmelCase		: Any						    =  NezhaForTokenClassification(config=a__						)
       model.to(a__						)
       model.eval()
       _lowerCAmelCase		: Tuple						    =  model(a__       ,  attention_mask=a__       ,  token_type_ids=a__       ,  labels=a__						)
       self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.seq_length, self.num_labels)						)






     def 					__A						(	self       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__						):
       _lowerCAmelCase		: int						    =  self.num_choices
       _lowerCAmelCase		: int						    =  NezhaForMultipleChoice(config=a__						)
       model.to(a__						)
       model.eval()
       _lowerCAmelCase		: int						    =  input_ids.unsqueeze(1						).expand(-1       ,  self.num_choices       ,  -1						).contiguous()
       _lowerCAmelCase		: Union[str, Any]						    =  token_type_ids.unsqueeze(1						).expand(-1       ,  self.num_choices       ,  -1						).contiguous()
       _lowerCAmelCase		: Dict						    =  input_mask.unsqueeze(1						).expand(-1       ,  self.num_choices       ,  -1						).contiguous()
       _lowerCAmelCase		: str						    =  model(
           a__       ,  attention_mask=a__       ,  token_type_ids=a__       ,  labels=a__       ,  )
       self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.num_choices)						)






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







@require_torch
class 		__A							(				SCREAMING_SNAKE_CASE_					,			SCREAMING_SNAKE_CASE_					,			SCREAMING_SNAKE_CASE_					,			unittest.TestCase	):
     _UpperCamelCase							:    Tuple	      =	(
         (
             NezhaModel,
             NezhaForMaskedLM,
             NezhaForMultipleChoice,
             NezhaForNextSentencePrediction,
             NezhaForPreTraining,
             NezhaForQuestionAnswering,
             NezhaForSequenceClassification,
             NezhaForTokenClassification,
         )
         if is_torch_available()
         else ()
     )
     _UpperCamelCase							:    List[str]	      =	(
         {
             "feature-extraction": NezhaModel,
             "fill-mask": NezhaForMaskedLM,
             "question-answering": NezhaForQuestionAnswering,
             "text-classification": NezhaForSequenceClassification,
             "token-classification": NezhaForTokenClassification,
             "zero-shot": NezhaForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )
     _UpperCamelCase							:    Dict	      =	True






     def 					__A						(	self       ,  a__       ,  a__       ,  a__=False						):
       _lowerCAmelCase		: Optional[Any]						    =  super()._prepare_for_class(a__       ,  a__       ,  return_labels=a__						)

       if return_labels:
         if model_class in get_values(a__						):
           _lowerCAmelCase		: int						    =  torch.zeros(
               (self.model_tester.batch_size, self.model_tester.seq_length)       ,  dtype=torch.long       ,  device=a__						)
           _lowerCAmelCase		: Tuple						    =  torch.zeros(
               self.model_tester.batch_size       ,  dtype=torch.long       ,  device=a__						)
       return inputs_dict






     def 					__A						(	self						):
       _lowerCAmelCase		: Any						    =  NezhaModelTester(self						)
       _lowerCAmelCase		: List[str]						    =  ConfigTester(self       ,  config_class=a__       ,  hidden_size=37						)






     def 					__A						(	self						):
       self.config_tester.run_common_tests()






     def 					__A						(	self						):
       _lowerCAmelCase		: Optional[int]						    =  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*a__						)






     def 					__A						(	self						):
       _lowerCAmelCase		: Optional[Any]						    =  self.model_tester.prepare_config_and_inputs_for_decoder()
       self.model_tester.create_and_check_model_as_decoder(*a__						)






     def 					__A						(	self						):
       # This regression test was failing with PyTorch < 1.3
       (
           (
           _lowerCAmelCase
       )    ,			(
           _lowerCAmelCase
       )    ,			(
           _lowerCAmelCase
       )    ,			(
           _lowerCAmelCase
       )    ,			(
           _lowerCAmelCase
       )    ,			(
           _lowerCAmelCase
       )    ,			(
           _lowerCAmelCase
       )    ,			(
           _lowerCAmelCase
       )    ,			(
           _lowerCAmelCase
       )    ,			
       )		: Optional[Any]						    =  self.model_tester.prepare_config_and_inputs_for_decoder()

       _lowerCAmelCase		: str						    =  None

       self.model_tester.create_and_check_model_as_decoder(
           a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  a__       ,  )






     def 					__A						(	self						):
       _lowerCAmelCase		: int						    =  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_lm(*a__						)






     def 					__A						(	self						):
       _lowerCAmelCase		: Optional[Any]						    =  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_multiple_choice(*a__						)






     def 					__A						(	self						):
       _lowerCAmelCase		: int						    =  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_next_sequence_prediction(*a__						)






     def 					__A						(	self						):
       _lowerCAmelCase		: str						    =  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_pretraining(*a__						)






     def 					__A						(	self						):
       _lowerCAmelCase		: Union[str, Any]						    =  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_question_answering(*a__						)






     def 					__A						(	self						):
       _lowerCAmelCase		: Union[str, Any]						    =  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_sequence_classification(*a__						)






     def 					__A						(	self						):
       _lowerCAmelCase		: List[str]						    =  self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_token_classification(*a__						)






     @slow
     def 					__A						(	self						):
       for model_name in NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         _lowerCAmelCase		: Any						    =  NezhaModel.from_pretrained(a__						)
         self.assertIsNotNone(a__						)






     @slow
     @require_torch_gpu
     def 					__A						(	self						):
       _lowerCAmelCase    ,			_lowerCAmelCase		: Union[str, Any]						    =  self.model_tester.prepare_config_and_inputs_for_common()
       for model_class in self.all_model_classes:
         # NezhaForMultipleChoice behaves incorrectly in JIT environments.
         if model_class == NezhaForMultipleChoice:
           return

         _lowerCAmelCase		: Dict						    =  True
         _lowerCAmelCase		: Tuple						    =  model_class(config=a__						)

         _lowerCAmelCase		: Dict						    =  self._prepare_for_class(a__       ,  a__						)
         _lowerCAmelCase		: int						    =  torch.jit.trace(
             a__       ,  (inputs_dict["""input_ids"""].to("""cpu"""						), inputs_dict["""attention_mask"""].to("""cpu"""						))						)

         with tempfile.TemporaryDirectory() as tmp:
           torch.jit.save(a__       ,  os.path.join(a__       ,  """bert.pt"""						)						)
           _lowerCAmelCase		: str						    =  torch.jit.load(os.path.join(a__       ,  """bert.pt"""						)       ,  map_location=a__						)
           loaded(inputs_dict["""input_ids"""].to(a__						)       ,  inputs_dict["""attention_mask"""].to(a__						)						)







@require_torch
class 		__A							(				unittest.TestCase	):






     @slow
     def 					__A						(	self						):
       _lowerCAmelCase		: Dict						    =  NezhaModel.from_pretrained("""sijunhe/nezha-cn-base"""						)
       _lowerCAmelCase		: Optional[Any]						    =  torch.tensor([[0, 1, 2, 3, 4, 5]]						)
       _lowerCAmelCase		: List[str]						    =  torch.tensor([[0, 1, 1, 1, 1, 1]]						)
       with torch.no_grad():
         _lowerCAmelCase		: Optional[int]						    =  model(a__       ,  attention_mask=a__						)[0]
       _lowerCAmelCase		: str						    =  torch.Size((1, 6, 768)						)
       self.assertEqual(output.shape       ,  a__						)
       _lowerCAmelCase		: List[Any]						    =  torch.tensor([[[0.0_6_8_5, 0.2_4_4_1, 0.1_1_0_2], [0.0_6_0_0, 0.1_9_0_6, 0.1_3_4_9], [0.0_2_2_1, 0.0_8_1_9, 0.0_5_8_6]]]						)

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






     @slow
     def 					__A						(	self						):
       _lowerCAmelCase		: Any						    =  NezhaForMaskedLM.from_pretrained("""sijunhe/nezha-cn-base"""						)
       _lowerCAmelCase		: List[str]						    =  torch.tensor([[0, 1, 2, 3, 4, 5]]						)
       _lowerCAmelCase		: Union[str, Any]						    =  torch.tensor([[1, 1, 1, 1, 1, 1]]						)
       with torch.no_grad():
         _lowerCAmelCase		: Union[str, Any]						    =  model(a__       ,  attention_mask=a__						)[0]
       _lowerCAmelCase		: int						    =  torch.Size((1, 6, 21128)						)
       self.assertEqual(output.shape       ,  a__						)
       _lowerCAmelCase		: Any						    =  torch.tensor(
           [[-2.7_9_3_9, -1.7_9_0_2, -2.2_1_8_9], [-2.8_5_8_5, -1.8_9_0_8, -2.3_7_2_3], [-2.6_4_9_9, -1.7_7_5_0, -2.2_5_5_8]]						)

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





"""simple docstring"""




import gc
import unittest

import numpy as np
import torch

from diffusers import AutoencoderKL, DDIMScheduler, DiTPipeline, DPMSolverMultistepScheduler, TransformeraDModel
from diffusers.utils import is_xformers_available, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import (
    CLASS_CONDITIONED_IMAGE_GENERATION_BATCH_PARAMS,
    CLASS_CONDITIONED_IMAGE_GENERATION_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()
class 		__A							(				SCREAMING_SNAKE_CASE_					,			unittest.TestCase	):
     _UpperCamelCase							:    Optional[int]	      =	DiTPipeline
     _UpperCamelCase							:    Union[str, Any]	      =	CLASS_CONDITIONED_IMAGE_GENERATION_PARAMS
     _UpperCamelCase							:    Union[str, Any]	      =	PipelineTesterMixin.required_optional_params - {
         "latents",
         "num_images_per_prompt",
         "callback",
         "callback_steps",
     }
     _UpperCamelCase							:    Dict	      =	CLASS_CONDITIONED_IMAGE_GENERATION_BATCH_PARAMS
     _UpperCamelCase							:    Union[str, Any]	      =	False






     def 					__A						(	self						):
       torch.manual_seed(0						)
       _lowerCAmelCase		: Tuple						    =  TransformeraDModel(
           sample_size=16       ,  num_layers=2       ,  patch_size=4       ,  attention_head_dim=8       ,  num_attention_heads=2       ,  in_channels=4       ,  out_channels=8       ,  attention_bias=a__       ,  activation_fn="""gelu-approximate"""       ,  num_embeds_ada_norm=1000       ,  norm_type="""ada_norm_zero"""       ,  norm_elementwise_affine=a__       ,  )
       _lowerCAmelCase		: Optional[int]						    =  AutoencoderKL()
       _lowerCAmelCase		: Union[str, Any]						    =  DDIMScheduler()
       _lowerCAmelCase		: Optional[Any]						    =  {"""transformer""": transformer.eval(), """vae""": vae.eval(), """scheduler""": scheduler}
       return components






     def 					__A						(	self       ,  a__       ,  a__=0						):
       if str(a__						).startswith("""mps"""						):
         _lowerCAmelCase		: Any						    =  torch.manual_seed(a__						)
       else:
         _lowerCAmelCase		: Tuple						    =  torch.Generator(device=a__						).manual_seed(a__						)
       _lowerCAmelCase		: Any						    =  {
           """class_labels""": [1],
           """generator""": generator,
           """num_inference_steps""": 2,
           """output_type""": """numpy""",
       }
       return inputs






     def 					__A						(	self						):
       _lowerCAmelCase		: List[Any]						    =  """cpu"""

       _lowerCAmelCase		: Tuple						    =  self.get_dummy_components()
       _lowerCAmelCase		: Optional[int]						    =  self.pipeline_class(**a__						)
       pipe.to(a__						)
       pipe.set_progress_bar_config(disable=a__						)

       _lowerCAmelCase		: Tuple						    =  self.get_dummy_inputs(a__						)
       _lowerCAmelCase		: List[str]						    =  pipe(**a__						).images
       _lowerCAmelCase		: Optional[int]						    =  image[0, -3:, -3:, -1]

       self.assertEqual(image.shape       ,  (1, 16, 16, 3)						)
       _lowerCAmelCase		: List[Any]						    =  np.array([0.2_9_4_6, 0.6_6_0_1, 0.4_3_2_9, 0.3_2_9_6, 0.4_1_4_4, 0.5_3_1_9, 0.7_2_7_3, 0.5_0_1_3, 0.4_4_5_7]						)
       _lowerCAmelCase		: Optional[int]						    =  np.abs(image_slice.flatten() - expected_slice						).max()
       self.assertLessEqual(a__       ,  1e-3						)






     def 					__A						(	self						):
       self._test_inference_batch_single_identical(relax_max_difference=a__       ,  expected_max_diff=1e-3						)






     @unittest.skipIf(
         torch_device != """cuda""" or not is_xformers_available()       ,  reason="""XFormers attention is only available with CUDA and `xformers` installed"""       ,  )
     def 					__A						(	self						):
       self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3						)







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






     def 					__A						(	self						):
       super().tearDown()
       gc.collect()
       torch.cuda.empty_cache()






     def 					__A						(	self						):
       _lowerCAmelCase		: List[str]						    =  torch.manual_seed(0						)

       _lowerCAmelCase		: int						    =  DiTPipeline.from_pretrained("""facebook/DiT-XL-2-256"""						)
       pipe.to("""cuda"""						)

       _lowerCAmelCase		: Dict						    =  ["""vase""", """umbrella""", """white shark""", """white wolf"""]
       _lowerCAmelCase		: Union[str, Any]						    =  pipe.get_label_ids(a__						)

       _lowerCAmelCase		: Any						    =  pipe(a__       ,  generator=a__       ,  num_inference_steps=40       ,  output_type="""np"""						).images

       for word, image in zip(a__       ,  a__						):
         _lowerCAmelCase		: str						    =  load_numpy(
             F"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/dit/{word}.npy"						)
         assert np.abs((expected_image - image).max()						) < 1e-2






     def 					__A						(	self						):
       _lowerCAmelCase		: str						    =  DiTPipeline.from_pretrained("""facebook/DiT-XL-2-512"""						)
       _lowerCAmelCase		: Dict						    =  DPMSolverMultistepScheduler.from_config(pipe.scheduler.config						)
       pipe.to("""cuda"""						)

       _lowerCAmelCase		: List[str]						    =  ["""vase""", """umbrella"""]
       _lowerCAmelCase		: Optional[int]						    =  pipe.get_label_ids(a__						)

       _lowerCAmelCase		: str						    =  torch.manual_seed(0						)
       _lowerCAmelCase		: List[str]						    =  pipe(a__       ,  generator=a__       ,  num_inference_steps=25       ,  output_type="""np"""						).images

       for word, image in zip(a__       ,  a__						):
         _lowerCAmelCase		: str						    =  load_numpy(
             """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
             F"/dit/{word}_512.npy"						)

         assert np.abs((expected_image - image).max()						) < 1e-1




