
'''simple docstring'''





UpperCAmelCase            = {
    "kilogram": 1,
    "gram": pow(10, 3),
    "milligram": pow(10, 6),
    "metric-ton": pow(10, -3),
    "long-ton": 0.00_0984_2073,
    "short-ton": 0.00_1102_3122,
    "pound": 2.20_4624_4202,
    "stone": 0.15_7473_1728,
    "ounce": 35.2_7399_0723,
    "carrat": 5_000,
    "atomic-mass-unit": 6.0_22_13_66_52e26,
}

UpperCAmelCase            = {
    "kilogram": 1,
    "gram": pow(10, -3),
    "milligram": pow(10, -6),
    "metric-ton": pow(10, 3),
    "long-ton": 1_016.04_608,
    "short-ton": 907.184,
    "pound": 0.45_3592,
    "stone": 6.3_5029,
    "ounce": 0.028_3495,
    "carrat": 0.0002,
    "atomic-mass-unit": 1.6_60_54_01_99e-27,
}

def   A			(							A_				:       str     ,				A_				:       str     ,				A_				:       float							):






						if to_type not in KILOGRAM_CHART or from_type not in WEIGHT_TYPE_CHART:
												snake_case							:  str			=     (
												    F"""Invalid 'from_type' or 'to_type' value: {from_type!r}, {to_type!r}\n"""
												    F"""Supported values are: {', '.join(__lowerCamelCase							)}"""
												)
												raise ValueError(__lowerCamelCase							)
						return value * KILOGRAM_CHART[to_type] * WEIGHT_TYPE_CHART[from_type]


if __name__ == "__main__":
						import doctest

						doctest.testmod()





'''simple docstring'''

import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionDualGuidedPipeline
from diffusers.utils.testing_utils import load_image, nightly, require_torch_gpu, torch_device


lowercase__					  =		False





@nightly
@require_torch_gpu
class     __SCREAMING_SNAKE_CASE       (   unittest.TestCase			):






     def 			a_       (      self		)							->     Union[str, Any]:
          # clean up the VRAM after each test
          super().tearDown()
          gc.collect()
          torch.cuda.empty_cache()






     def 			a_       (      self		)							->     Dict:
          _a            =		VersatileDiffusionDualGuidedPipeline.from_pretrained("shi-labs/versatile-diffusion"		)
          # remove text_unet
          pipe.remove_unused_weights()
          pipe.to(__UpperCamelCase		)
          pipe.set_progress_bar_config(disable=__UpperCamelCase		)

          _a            =		load_image(
              "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg"		)

          _a            =		torch.manual_seed(0		)
          _a            =		pipe(
              prompt="first prompt"  ,				image=__UpperCamelCase  ,				text_to_image_strength=0.75  ,				generator=__UpperCamelCase  ,				guidance_scale=7.5  ,				num_inference_steps=2  ,				output_type="numpy"  ,				).images

          with tempfile.TemporaryDirectory() as tmpdirname:
               pipe.save_pretrained(__UpperCamelCase		)
               _a            =		VersatileDiffusionDualGuidedPipeline.from_pretrained(__UpperCamelCase		)

          pipe.to(__UpperCamelCase		)
          pipe.set_progress_bar_config(disable=__UpperCamelCase		)

          _a            =		generator.manual_seed(0		)
          _a            =		pipe(
              prompt="first prompt"  ,				image=__UpperCamelCase  ,				text_to_image_strength=0.75  ,				generator=__UpperCamelCase  ,				guidance_scale=7.5  ,				num_inference_steps=2  ,				output_type="numpy"  ,				).images

          assert np.abs(image - new_image		).sum() < 1e-5, "Models don't have the same forward pass"






     def 			a_       (      self		)							->     int:
          _a            =		VersatileDiffusionDualGuidedPipeline.from_pretrained("shi-labs/versatile-diffusion"		)
          pipe.remove_unused_weights()
          pipe.to(__UpperCamelCase		)
          pipe.set_progress_bar_config(disable=__UpperCamelCase		)

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

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

          assert image.shape == (1, 512, 512, 3)
          _a            =		np.array([0.07_87, 0.08_49, 0.08_26, 0.08_12, 0.08_07, 0.07_95, 0.08_18, 0.07_98, 0.07_79]		)

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

