




'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


_SCREAMING_SNAKE_CASE							:       Union[str, Any]						=			{
    "configuration_perceiver": ["PERCEIVER_PRETRAINED_CONFIG_ARCHIVE_MAP", "PerceiverConfig", "PerceiverOnnxConfig"],
    "tokenization_perceiver": ["PerceiverTokenizer"],
}

try:
  if not is_vision_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  _SCREAMING_SNAKE_CASE							:       Tuple						=			["PerceiverFeatureExtractor"]
  _SCREAMING_SNAKE_CASE							:       Union[str, Any]						=			["PerceiverImageProcessor"]

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  _SCREAMING_SNAKE_CASE							:       Dict						=			[
      "PERCEIVER_PRETRAINED_MODEL_ARCHIVE_LIST",
      "PerceiverForImageClassificationConvProcessing",
      "PerceiverForImageClassificationFourier",
      "PerceiverForImageClassificationLearned",
      "PerceiverForMaskedLM",
      "PerceiverForMultimodalAutoencoding",
      "PerceiverForOpticalFlow",
      "PerceiverForSequenceClassification",
      "PerceiverLayer",
      "PerceiverModel",
      "PerceiverPreTrainedModel",
  ]


if TYPE_CHECKING:
  from .configuration_perceiver import PERCEIVER_PRETRAINED_CONFIG_ARCHIVE_MAP, PerceiverConfig, PerceiverOnnxConfig
  from .tokenization_perceiver import PerceiverTokenizer

  try:
    if not is_vision_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .feature_extraction_perceiver import PerceiverFeatureExtractor
    from .image_processing_perceiver import PerceiverImageProcessor

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_perceiver import (
        PERCEIVER_PRETRAINED_MODEL_ARCHIVE_LIST,
        PerceiverForImageClassificationConvProcessing,
        PerceiverForImageClassificationFourier,
        PerceiverForImageClassificationLearned,
        PerceiverForMaskedLM,
        PerceiverForMultimodalAutoencoding,
        PerceiverForOpticalFlow,
        PerceiverForSequenceClassification,
        PerceiverLayer,
        PerceiverModel,
        PerceiverPreTrainedModel,
    )

else:
  import sys

  _SCREAMING_SNAKE_CASE							:       int						=			_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)










'''simple docstring'''





import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionImageVariationPipeline
from diffusers.utils.testing_utils import load_image, require_torch_gpu, slow, torch_device


_SCREAMING_SNAKE_CASE							:       Any						=			False




class 			_snake_case		(     unittest.TestCase							):
			pass




@slow
@require_torch_gpu
class 			_snake_case		(     unittest.TestCase							):




			def        lowerCAmelCase__    ( self							)    ->    List[Any]:

										'''simple docstring'''




										snake_case_      =				VersatileDiffusionImageVariationPipeline.from_pretrained("shi-labs/versatile-diffusion"							)
										pipe.to(a__							)
										pipe.set_progress_bar_config(disable=a__							)

										snake_case_      =				load_image(
										    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"							)
										snake_case_      =				torch.manual_seed(0							)
										snake_case_      =				pipe(
										    image=a__    ,							generator=a__    ,							guidance_scale=7.5    ,							num_inference_steps=50    ,							output_type="numpy"    ,							).images

										snake_case_      =				image[0, 253:256, 253:256, -1]

										assert image.shape == (1, 512, 512, 3)
										snake_case_      =				np.array([0.0_4_4_1, 0.0_4_6_9, 0.0_5_0_7, 0.0_5_7_5, 0.0_6_3_2, 0.0_6_5_0, 0.0_8_6_5, 0.0_9_0_9, 0.0_9_4_5]							)

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




