

'''simple docstring'''






import unittest

import numpy as np
import torch

from diffusers import KarrasVePipeline, KarrasVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()






class 			lowercase_	(unittest.TestCase      ):




  """simple docstring"""




  @property
  def 					SCREAMING_SNAKE_CASE      (      self   :     int			):
   torch.manual_seed(0			)
   __lowercase							  = UNetaDModel(
       block_out_channels=(3_2, 6_4)					,layers_per_block=2					,sample_size=3_2					,in_channels=3					,out_channels=3					,down_block_types=('''DownBlock2D''', '''AttnDownBlock2D''')					,up_block_types=('''AttnUpBlock2D''', '''UpBlock2D''')					,)
   return model






  def 					SCREAMING_SNAKE_CASE      (      self   :     int			):
   __lowercase							  = self.dummy_uncond_unet
   __lowercase							  = KarrasVeScheduler()

   __lowercase							  = KarrasVePipeline(unet=lowercase__					,scheduler=lowercase__			)
   pipe.to(lowercase__			)
   pipe.set_progress_bar_config(disable=lowercase__			)

   __lowercase							  = torch.manual_seed(0			)
   __lowercase							  = pipe(num_inference_steps=2					,generator=lowercase__					,output_type='''numpy'''			).images

   __lowercase							  = torch.manual_seed(0			)
   __lowercase							  = pipe(num_inference_steps=2					,generator=lowercase__					,output_type='''numpy'''					,return_dict=lowercase__			)[0]

   __lowercase							  = image[0, -3:, -3:, -1]
   __lowercase							  = image_from_tuple[0, -3:, -3:, -1]

   assert image.shape == (1, 3_2, 3_2, 3)
   __lowercase							  = np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]			)

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






@slow
@require_torch
class 			lowercase_	(unittest.TestCase      ):




  """simple docstring"""




  def 					SCREAMING_SNAKE_CASE      (      self   :     List[Any]			):
   __lowercase							  = '''google/ncsnpp-celebahq-256'''
   __lowercase							  = UNetaDModel.from_pretrained(lowercase__			)
   __lowercase							  = KarrasVeScheduler()

   __lowercase							  = KarrasVePipeline(unet=lowercase__					,scheduler=lowercase__			)
   pipe.to(lowercase__			)
   pipe.set_progress_bar_config(disable=lowercase__			)

   __lowercase							  = torch.manual_seed(0			)
   __lowercase							  = pipe(num_inference_steps=2_0					,generator=lowercase__					,output_type='''numpy'''			).images

   __lowercase							  = image[0, -3:, -3:, -1]
   assert image.shape == (1, 2_5_6, 2_5_6, 3)
   __lowercase							  = np.array([0.5_7_8, 0.5_8_1_1, 0.5_9_2_4, 0.5_8_0_9, 0.5_8_7, 0.5_8_8_6, 0.5_8_6_1, 0.5_8_0_2, 0.5_8_6]			)

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




'''simple docstring'''






from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


lowerCAmelCase__											=	logging.get_logger(__name__)

lowerCAmelCase__											=	{
    '''facebook/convnextv2-tiny-1k-224''': '''https://huggingface.co/facebook/convnextv2-tiny-1k-224/resolve/main/config.json''',
}






class 			lowercase_	(lowerCamelCase__				,       lowerCamelCase__      ):




  """simple docstring"""




  SCREAMING_SNAKE_CASE    :  List[str]							=			'convnextv2'






  def __init__(      self   :     Tuple					,lowercase__   :     Dict=3					,lowercase__   :     int=4					,lowercase__   :     Optional[int]=4					,lowercase__   :     Optional[Any]=None					,lowercase__   :     List[str]=None					,lowercase__   :     Tuple="gelu"					,lowercase__   :     Dict=0.0_2					,lowercase__   :     List[Any]=1e-1_2					,lowercase__   :     Optional[int]=0.0					,lowercase__   :     int=2_2_4					,lowercase__   :     int=None					,lowercase__   :     Tuple=None					,**lowercase__   :     List[str]					,):
   super().__init__(**lowercase__			)

   __lowercase							  = num_channels
   __lowercase							  = patch_size
   __lowercase							  = num_stages
   __lowercase							  = [9_6, 1_9_2, 3_8_4, 7_6_8] if hidden_sizes is None else hidden_sizes
   __lowercase							  = [3, 3, 9, 3] if depths is None else depths
   __lowercase							  = hidden_act
   __lowercase							  = initializer_range
   __lowercase							  = layer_norm_eps
   __lowercase							  = drop_path_rate
   __lowercase							  = image_size
   __lowercase							  = ['''stem'''] + [F"stage{idx}" for idx in range(1					,len(self.depths			) + 1			)]
   __lowercase  ,	__lowercase							  = get_aligned_output_features_output_indices(
       out_features=lowercase__					,out_indices=lowercase__					,stage_names=self.stage_names			)

