



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    __UpperCamelCase			(       _a	,	unittest.TestCase				):

 """simple docstring"""



 _lowercase   :    List[str]      						=					DiTPipeline
 _lowercase   :    Dict      						=					CLASS_CONDITIONED_IMAGE_GENERATION_PARAMS
 _lowercase   :    str      						=					PipelineTesterMixin.required_optional_params - {
     '''latents''',
     '''num_images_per_prompt''',
     '''callback''',
     '''callback_steps''',
 }
 _lowercase   :    List[str]      						=					CLASS_CONDITIONED_IMAGE_GENERATION_BATCH_PARAMS
 _lowercase   :    Tuple      						=					False

 def 						_UpperCAmelCase       (	self      ) ->			str:
  torch.manual_seed(0      )
  a__												= TransformeraDModel(
      sample_size=1_6		,				num_layers=2		,				patch_size=4		,				attention_head_dim=8		,				num_attention_heads=2		,				in_channels=4		,				out_channels=8		,				attention_bias=snake_case_		,				activation_fn='''gelu-approximate'''		,				num_embeds_ada_norm=1_0_0_0		,				norm_type='''ada_norm_zero'''		,				norm_elementwise_affine=snake_case_		,				)
  a__												= AutoencoderKL()
  a__												= DDIMScheduler()
  a__												= {"""transformer""": transformer.eval(), """vae""": vae.eval(), """scheduler""": scheduler}
  return components

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE=0      ) ->			Optional[int]:
  if str(snake_case_      ).startswith('''mps'''      ):
   a__												= torch.manual_seed(snake_case_      )
  else:
   a__												= torch.Generator(device=snake_case_      ).manual_seed(snake_case_      )
  a__												= {
      """class_labels""": [1],
      """generator""": generator,
      """num_inference_steps""": 2,
      """output_type""": """numpy""",
  }
  return inputs

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

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

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

  self.assertEqual(image.shape		,				(1, 1_6, 1_6, 3)      )
  a__												= np.array([0.29_46, 0.66_01, 0.43_29, 0.32_96, 0.41_44, 0.53_19, 0.72_73, 0.50_13, 0.44_57]      )
  a__												= np.abs(image_slice.flatten() - expected_slice      ).max()
  self.assertLessEqual(snake_case_		,				1e-3      )

 def 						_UpperCAmelCase       (	self      ) ->			int:
  self._test_inference_batch_single_identical(relax_max_difference=snake_case_		,				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 						_UpperCAmelCase       (	self      ) ->			Optional[Any]:
  self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3      )





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

 """simple docstring"""



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

 def 						_UpperCAmelCase       (	self      ) ->			Tuple:
  a__												= torch.manual_seed(0      )

  a__												= DiTPipeline.from_pretrained('''facebook/DiT-XL-2-256'''      )
  pipe.to('''cuda'''      )

  a__												= ["""vase""", """umbrella""", """white shark""", """white wolf"""]
  a__												= pipe.get_label_ids(snake_case_      )

  a__												= pipe(snake_case_		,				generator=snake_case_		,				num_inference_steps=4_0		,				output_type='''np'''      ).images

  for word, image in zip(snake_case_		,				snake_case_      ):
   a__												= 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 						_UpperCAmelCase       (	self      ) ->			Optional[int]:
  a__												= DiTPipeline.from_pretrained('''facebook/DiT-XL-2-512'''      )
  a__												= DPMSolverMultistepScheduler.from_config(pipe.scheduler.config      )
  pipe.to('''cuda'''      )

  a__												= ["""vase""", """umbrella"""]
  a__												= pipe.get_label_ids(snake_case_      )

  a__												= torch.manual_seed(0      )
  a__												= pipe(snake_case_		,				generator=snake_case_		,				num_inference_steps=2_5		,				output_type='''np'''      ).images

  for word, image in zip(snake_case_		,				snake_case_      ):
   a__												= 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










'''simple docstring'''





import sys

__a  			=						(
    "73167176531330624919225119674426574742355349194934"
    "96983520312774506326239578318016984801869478851843"
    "85861560789112949495459501737958331952853208805511"
    "12540698747158523863050715693290963295227443043557"
    "66896648950445244523161731856403098711121722383113"
    "62229893423380308135336276614282806444486645238749"
    "30358907296290491560440772390713810515859307960866"
    "70172427121883998797908792274921901699720888093776"
    "65727333001053367881220235421809751254540594752243"
    "52584907711670556013604839586446706324415722155397"
    "53697817977846174064955149290862569321978468622482"
    "83972241375657056057490261407972968652414535100474"
    "82166370484403199890008895243450658541227588666881"
    "16427171479924442928230863465674813919123162824586"
    "17866458359124566529476545682848912883142607690042"
    "24219022671055626321111109370544217506941658960408"
    "07198403850962455444362981230987879927244284909188"
    "84580156166097919133875499200524063689912560717606"
    "05886116467109405077541002256983155200055935729725"
    "71636269561882670428252483600823257530420752963450"
)





def 		__snake_case(							_lowerCAmelCase = N						)						->					int:
      snake_case__    :       Dict       		= -sys.maxsize - 1
      for i in range(len(_lowerCAmelCase						) - 12						):
            snake_case__    :       Any       		= 1
            for j in range(13						):
                  product *= int(n[i + j]						)
            if product > largest_product:
                  snake_case__    :       List[str]       		= product
      return largest_product


if __name__ == "__main__":
       print(F"{solution() = }")
