


import unittest

import numpy as np
import torch

from diffusers import PNDMPipeline, PNDMScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()


class   a__	(						unittest.TestCase    ):

       @property
       def 						UpperCAmelCase(   self      :     Union[str, Any]    ):
            torch.manual_seed(0    )
            a_    :     int										=    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 						UpperCAmelCase(   self      :     Tuple    ):
            a_    :     List[Any]										=    self.dummy_uncond_unet
            a_    :     List[str]										=    PNDMScheduler()

            a_    :     Union[str, Any]										=    PNDMPipeline(unet=lowerCamelCase_      ,							scheduler=lowerCamelCase_    )
            pndm.to(lowerCamelCase_    )
            pndm.set_progress_bar_config(disable=lowerCamelCase_    )

            a_    :     Any										=    torch.manual_seed(0    )
            a_    :     Optional[Any]										=    pndm(generator=lowerCamelCase_      ,							num_inference_steps=2_0      ,							output_type="""numpy"""    ).images

            a_    :     Dict										=    torch.manual_seed(0    )
            a_    :     List[str]										=    pndm(generator=lowerCamelCase_      ,							num_inference_steps=2_0      ,							output_type="""numpy"""      ,							return_dict=lowerCamelCase_    )[0]

            a_    :     Union[str, Any]										=    image[0, -3:, -3:, -1]
            a_    :     Tuple										=    image_from_tuple[0, -3:, -3:, -1]

            assert image.shape == (1, 3_2, 3_2, 3)
            a_    :     Optional[Any]										=    np.array([1.0, 1.0, 0.0, 1.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   a__	(						unittest.TestCase    ):

       def 						UpperCAmelCase(   self      :     Union[str, Any]    ):
            a_    :     List[Any]										=    """google/ddpm-cifar10-32"""

            a_    :     Tuple										=    UNetaDModel.from_pretrained(lowerCamelCase_    )
            a_    :     Any										=    PNDMScheduler()

            a_    :     Optional[Any]										=    PNDMPipeline(unet=lowerCamelCase_      ,							scheduler=lowerCamelCase_    )
            pndm.to(lowerCamelCase_    )
            pndm.set_progress_bar_config(disable=lowerCamelCase_    )
            a_    :     Tuple										=    torch.manual_seed(0    )
            a_    :     Tuple										=    pndm(generator=lowerCamelCase_      ,							output_type="""numpy"""    ).images

            a_    :     Optional[int]										=    image[0, -3:, -3:, -1]

            assert image.shape == (1, 3_2, 3_2, 3)
            a_    :     str										=    np.array([0.1_5_6_4, 0.1_4_6_4_5, 0.1_4_0_6, 0.1_4_7_1_5, 0.1_2_4_2_5, 0.1_4_0_4_5, 0.1_3_1_1_5, 0.1_2_1_7_5, 0.1_2_5]    )

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







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   a__	(						lowerCAmelCase_						,       lowerCAmelCase_    ):
       lowerCamelCase__:     str							    =     """convnextv2"""

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

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



