

'''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 				_snake_case					(   unittest.TestCase			):

  @property
  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      torch.manual_seed(0	)
      lowerCAmelCase 						=							UNetaDModel(
          block_out_channels=(32, 64)      , layers_per_block=2      , sample_size=32      , in_channels=3      , out_channels=3      , down_block_types=('DownBlock2D', 'AttnDownBlock2D')      , up_block_types=('AttnUpBlock2D', 'UpBlock2D')      , )
      return model


  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.dummy_uncond_unet
      lowerCAmelCase 						=							KarrasVeScheduler()

      lowerCAmelCase 						=							KarrasVePipeline(unet=_SCREAMING_SNAKE_CASE      , scheduler=_SCREAMING_SNAKE_CASE	)
      pipe.to(_SCREAMING_SNAKE_CASE	)
      pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE	)

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

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

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

      assert image.shape == (1, 32, 32, 3)
      lowerCAmelCase 						=							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 				_snake_case					(   unittest.TestCase			):

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							'google/ncsnpp-celebahq-256'
      lowerCAmelCase 						=							UNetaDModel.from_pretrained(_SCREAMING_SNAKE_CASE	)
      lowerCAmelCase 						=							KarrasVeScheduler()

      lowerCAmelCase 						=							KarrasVePipeline(unet=_SCREAMING_SNAKE_CASE      , scheduler=_SCREAMING_SNAKE_CASE	)
      pipe.to(_SCREAMING_SNAKE_CASE	)
      pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE	)

      lowerCAmelCase 						=							torch.manual_seed(0	)
      lowerCAmelCase 						=							pipe(num_inference_steps=20      , generator=_SCREAMING_SNAKE_CASE      , output_type='numpy'	).images

      lowerCAmelCase 						=							image[0, -3:, -3:, -1]
      assert image.shape == (1, 2_56, 2_56, 3)
      lowerCAmelCase 						=							np.array([0.578, 0.5_811, 0.5_924, 0.5_809, 0.587, 0.5_886, 0.5_861, 0.5_802, 0.586]	)

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








'''simple docstring'''



def       snake_case   (	snake_case      : int					,		snake_case      : int					,		snake_case      : int			) ->  int:


    """simple docstring"""


    if exponent == 1:
        return base
    if exponent % 2 == 0:
        lowerCAmelCase 						=							_modexpt(snake_case					,		exponent // 2					,		snake_case			) % modulo_value
        return (x * x) % modulo_value
    else:
        return (base * _modexpt(snake_case					,		exponent - 1					,		snake_case			)) % modulo_value


def       snake_case   (	snake_case      : int = 1777					,		snake_case      : int = 1855					,		snake_case      : int = 8			) ->  int:


    """simple docstring"""


    lowerCAmelCase 						=							base
    for _ in range(1					,		snake_case			):
        lowerCAmelCase 						=							_modexpt(snake_case					,		snake_case					,		10**digits			)

    return result


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





