





"""simple docstring"""





import gc
import unittest

import numpy as np
import torch

from diffusers import StableDiffusionKDiffusionPipeline
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()






@slow
@require_torch_gpu
class    _lowerCAmelCase  (	unittest.TestCase			):
       """simple docstring"""




       def 	snake_case		(       self ):



         '''simple docstring'''

         super().tearDown()
         gc.collect()
         torch.cuda.empty_cache()






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :int											=				StableDiffusionKDiffusionPipeline.from_pretrained('CompVis/stable-diffusion-v1-4' )
         lowerCAmelCase__     :int											=				sd_pipe.to(__UpperCAmelCase )
         sd_pipe.set_progress_bar_config(disable=__UpperCAmelCase )

         sd_pipe.set_scheduler('sample_euler' )

         lowerCAmelCase__     :Optional[Any]											=				'A painting of a squirrel eating a burger'
         lowerCAmelCase__     :Union[str, Any]											=				torch.manual_seed(0 )
         lowerCAmelCase__     :Tuple											=				sd_pipe([prompt]       ,					generator=__UpperCAmelCase       ,					guidance_scale=9.0       ,					num_inference_steps=2_0       ,					output_type='np' )

         lowerCAmelCase__     :Optional[Any]											=				output.images

         lowerCAmelCase__     :Any											=				image[0, -3:, -3:, -1]

         assert image.shape == (1, 5_1_2, 5_1_2, 3)
         lowerCAmelCase__     :Tuple											=				np.array([0.04_47, 0.04_92, 0.04_68, 0.04_08, 0.03_83, 0.04_08, 0.03_54, 0.03_80, 0.03_39] )

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






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[Any]											=				StableDiffusionKDiffusionPipeline.from_pretrained('stabilityai/stable-diffusion-2-1-base' )
         lowerCAmelCase__     :List[Any]											=				sd_pipe.to(__UpperCAmelCase )
         sd_pipe.set_progress_bar_config(disable=__UpperCAmelCase )

         sd_pipe.set_scheduler('sample_euler' )

         lowerCAmelCase__     :Tuple											=				'A painting of a squirrel eating a burger'
         lowerCAmelCase__     :str											=				torch.manual_seed(0 )
         lowerCAmelCase__     :Any											=				sd_pipe([prompt]       ,					generator=__UpperCAmelCase       ,					guidance_scale=9.0       ,					num_inference_steps=2_0       ,					output_type='np' )

         lowerCAmelCase__     :Optional[Any]											=				output.images

         lowerCAmelCase__     :Optional[Any]											=				image[0, -3:, -3:, -1]

         assert image.shape == (1, 5_1_2, 5_1_2, 3)
         lowerCAmelCase__     :Dict											=				np.array([0.12_37, 0.13_20, 0.14_38, 0.13_59, 0.13_90, 0.11_32, 0.12_77, 0.11_75, 0.11_12] )

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






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :List[Any]											=				StableDiffusionKDiffusionPipeline.from_pretrained('stabilityai/stable-diffusion-2-1-base' )
         lowerCAmelCase__     :Optional[int]											=				sd_pipe.to(__UpperCAmelCase )
         sd_pipe.set_progress_bar_config(disable=__UpperCAmelCase )

         sd_pipe.set_scheduler('sample_dpmpp_2m' )

         lowerCAmelCase__     :List[Any]											=				'A painting of a squirrel eating a burger'
         lowerCAmelCase__     :Optional[Any]											=				torch.manual_seed(0 )
         lowerCAmelCase__     :Any											=				sd_pipe(
             [prompt]       ,					generator=__UpperCAmelCase       ,					guidance_scale=7.5       ,					num_inference_steps=1_5       ,					output_type='np'       ,					use_karras_sigmas=__UpperCAmelCase       ,					)

         lowerCAmelCase__     :Tuple											=				output.images

         lowerCAmelCase__     :int											=				image[0, -3:, -3:, -1]

         assert image.shape == (1, 5_1_2, 5_1_2, 3)
         lowerCAmelCase__     :Union[str, Any]											=				np.array(
             [0.11_38_16_89, 0.12_11_29_21, 0.1_38_94_57, 0.12_54_96_06, 0.1_24_49_64, 0.10_83_15_17, 0.11_56_28_66, 0.10_86_78_16, 0.10_49_90_48] )

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







'''simple docstring'''






# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


lowerCAmelCase									=   {"""configuration_mra""": ["""MRA_PRETRAINED_CONFIG_ARCHIVE_MAP""", """MraConfig"""]}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowerCAmelCase									=   [
					    """MRA_PRETRAINED_MODEL_ARCHIVE_LIST""",
					    """MraForMaskedLM""",
					    """MraForMultipleChoice""",
					    """MraForQuestionAnswering""",
					    """MraForSequenceClassification""",
					    """MraForTokenClassification""",
					    """MraLayer""",
					    """MraModel""",
					    """MraPreTrainedModel""",
					]


if TYPE_CHECKING:
					from .configuration_mra import MRA_PRETRAINED_CONFIG_ARCHIVE_MAP, MraConfig

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_mra import (
										    MRA_PRETRAINED_MODEL_ARCHIVE_LIST,
										    MraForMaskedLM,
										    MraForMultipleChoice,
										    MraForQuestionAnswering,
										    MraForSequenceClassification,
										    MraForTokenClassification,
										    MraLayer,
										    MraModel,
										    MraPreTrainedModel,
										)
else:
					import sys

					lowerCAmelCase									=   _LazyModule(__name__, globals()["""__file__"""], _import_structure)



