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






   '''simple docstring'''







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







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







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  StableDiffusionKDiffusionPipeline.from_pretrained('''CompVis/stable-diffusion-v1-4'''   )
      UpperCamelCase       =  sd_pipe.to(__a   )
      sd_pipe.set_progress_bar_config(disable=__a   )

      sd_pipe.set_scheduler('''sample_euler'''   )

      UpperCamelCase       =  'A painting of a squirrel eating a burger'
      UpperCamelCase       =  torch.manual_seed(0   )
      UpperCamelCase       =  sd_pipe([prompt] ,   generator=__a ,   guidance_scale=9.0 ,   num_inference_steps=2_0 ,   output_type='''np'''   )

      UpperCamelCase       =  output.images

      UpperCamelCase       =  image[0, -3:, -3:, -1]

      assert image.shape == (1, 5_1_2, 5_1_2, 3)
      UpperCamelCase       =  np.array([0.0447, 0.0492, 0.0468, 0.0408, 0.0383, 0.0408, 0.0354, 0.0380, 0.0339]   )

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







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''   )
      UpperCamelCase       =  sd_pipe.to(__a   )
      sd_pipe.set_progress_bar_config(disable=__a   )

      sd_pipe.set_scheduler('''sample_euler'''   )

      UpperCamelCase       =  'A painting of a squirrel eating a burger'
      UpperCamelCase       =  torch.manual_seed(0   )
      UpperCamelCase       =  sd_pipe([prompt] ,   generator=__a ,   guidance_scale=9.0 ,   num_inference_steps=2_0 ,   output_type='''np'''   )

      UpperCamelCase       =  output.images

      UpperCamelCase       =  image[0, -3:, -3:, -1]

      assert image.shape == (1, 5_1_2, 5_1_2, 3)
      UpperCamelCase       =  np.array([0.1237, 0.1320, 0.1438, 0.1359, 0.1390, 0.1132, 0.1277, 0.1175, 0.1112]   )

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







   def       UpperCAmelCase				(			self   ):

      '''simple docstring'''







      UpperCamelCase       =  StableDiffusionKDiffusionPipeline.from_pretrained('''stabilityai/stable-diffusion-2-1-base'''   )
      UpperCamelCase       =  sd_pipe.to(__a   )
      sd_pipe.set_progress_bar_config(disable=__a   )

      sd_pipe.set_scheduler('''sample_dpmpp_2m'''   )

      UpperCamelCase       =  'A painting of a squirrel eating a burger'
      UpperCamelCase       =  torch.manual_seed(0   )
      UpperCamelCase       =  sd_pipe(
          [prompt] ,   generator=__a ,   guidance_scale=7.5 ,   num_inference_steps=1_5 ,   output_type='''np''' ,   use_karras_sigmas=__a ,   )

      UpperCamelCase       =  output.images

      UpperCamelCase       =  image[0, -3:, -3:, -1]

      assert image.shape == (1, 5_1_2, 5_1_2, 3)
      UpperCamelCase       =  np.array(
          [0.11381689, 0.12112921, 0.1389457, 0.12549606, 0.1244964, 0.10831517, 0.11562866, 0.10867816, 0.10499048]   )

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







'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


snake_case_ :  List[Any]     =					{
    'configuration_data2vec_audio': ['DATA2VEC_AUDIO_PRETRAINED_CONFIG_ARCHIVE_MAP', 'Data2VecAudioConfig'],
    'configuration_data2vec_text': [
        'DATA2VEC_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'Data2VecTextConfig',
        'Data2VecTextOnnxConfig',
    ],
    'configuration_data2vec_vision': [
        'DATA2VEC_VISION_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'Data2VecVisionConfig',
        'Data2VecVisionOnnxConfig',
    ],
}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   snake_case_ :  Union[str, Any]     =					[
       'DATA2VEC_AUDIO_PRETRAINED_MODEL_ARCHIVE_LIST',
       'Data2VecAudioForAudioFrameClassification',
       'Data2VecAudioForCTC',
       'Data2VecAudioForSequenceClassification',
       'Data2VecAudioForXVector',
       'Data2VecAudioModel',
       'Data2VecAudioPreTrainedModel',
   ]
   snake_case_ :  str     =					[
       'DATA2VEC_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST',
       'Data2VecTextForCausalLM',
       'Data2VecTextForMaskedLM',
       'Data2VecTextForMultipleChoice',
       'Data2VecTextForQuestionAnswering',
       'Data2VecTextForSequenceClassification',
       'Data2VecTextForTokenClassification',
       'Data2VecTextModel',
       'Data2VecTextPreTrainedModel',
   ]
   snake_case_ :  Optional[int]     =					[
       'DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST',
       'Data2VecVisionForImageClassification',
       'Data2VecVisionForMaskedImageModeling',
       'Data2VecVisionForSemanticSegmentation',
       'Data2VecVisionModel',
       'Data2VecVisionPreTrainedModel',
   ]

if is_tf_available():
   snake_case_ :  List[str]     =					[
       'TFData2VecVisionForImageClassification',
       'TFData2VecVisionForSemanticSegmentation',
       'TFData2VecVisionModel',
       'TFData2VecVisionPreTrainedModel',
   ]

if TYPE_CHECKING:
   from .configuration_dataavec_audio import DATA2VEC_AUDIO_PRETRAINED_CONFIG_ARCHIVE_MAP, DataaVecAudioConfig
   from .configuration_dataavec_text import (
       DATA2VEC_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP,
       DataaVecTextConfig,
       DataaVecTextOnnxConfig,
   )
   from .configuration_dataavec_vision import (
       DATA2VEC_VISION_PRETRAINED_CONFIG_ARCHIVE_MAP,
       DataaVecVisionConfig,
       DataaVecVisionOnnxConfig,
   )

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_dataavec_audio import (
          DATA2VEC_AUDIO_PRETRAINED_MODEL_ARCHIVE_LIST,
          DataaVecAudioForAudioFrameClassification,
          DataaVecAudioForCTC,
          DataaVecAudioForSequenceClassification,
          DataaVecAudioForXVector,
          DataaVecAudioModel,
          DataaVecAudioPreTrainedModel,
      )
      from .modeling_dataavec_text import (
          DATA2VEC_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
          DataaVecTextForCausalLM,
          DataaVecTextForMaskedLM,
          DataaVecTextForMultipleChoice,
          DataaVecTextForQuestionAnswering,
          DataaVecTextForSequenceClassification,
          DataaVecTextForTokenClassification,
          DataaVecTextModel,
          DataaVecTextPreTrainedModel,
      )
      from .modeling_dataavec_vision import (
          DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST,
          DataaVecVisionForImageClassification,
          DataaVecVisionForMaskedImageModeling,
          DataaVecVisionForSemanticSegmentation,
          DataaVecVisionModel,
          DataaVecVisionPreTrainedModel,
      )
   if is_tf_available():
      from .modeling_tf_dataavec_vision import (
          TFDataaVecVisionForImageClassification,
          TFDataaVecVisionForSemanticSegmentation,
          TFDataaVecVisionModel,
          TFDataaVecVisionPreTrainedModel,
      )

else:
   import sys

   snake_case_ :  int     =					_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





