"""simple docstring"""







from collections.abc import Generator
from math import sin
def   __UpperCAmelCase    (   UpperCAmelCase_   :    bytes  )							->      bytes:

	'''simple docstring'''





	if len(UpperCAmelCase_  ) != 32:
		raise ValueError('Input must be of length 32'  )

	__snake_case      :							Any						=			B''
	for i in [3, 2, 1, 0]:
		little_endian += string_aa[8 * i : 8 * i + 8]
	return little_endian
def   __UpperCAmelCase    (   UpperCAmelCase_   :    int  )							->      bytes:

	'''simple docstring'''





	if i < 0:
		raise ValueError('Input must be non-negative'  )

	__snake_case      :							Optional[int]						=			format(UpperCAmelCase_      ,							'08x'  )[-8:]
	__snake_case      :							List[Any]						=			B''
	for i in [3, 2, 1, 0]:
		little_endian_hex += hex_rep[2 * i : 2 * i + 2].encode('utf-8'  )
	return little_endian_hex
def   __UpperCAmelCase    (   UpperCAmelCase_   :    bytes  )							->      bytes:

	'''simple docstring'''





	__snake_case      :							Dict						=			B''
	for char in message:
		bit_string += format(UpperCAmelCase_      ,							'08b'  ).encode('utf-8'  )
	__snake_case      :							Dict						=			format(len(UpperCAmelCase_  )      ,							'064b'  ).encode('utf-8'  )

	# Pad bit_string to a multiple of 512 chars
	bit_string += b"1"
	while len(UpperCAmelCase_  ) % 5_12 != 4_48:
		bit_string += b"0"
	bit_string += to_little_endian(start_len[32:]  ) + to_little_endian(start_len[:32]  )

	return bit_string
def   __UpperCAmelCase    (   UpperCAmelCase_   :    bytes  )							->      Generator[list[int], None, None]:

	'''simple docstring'''





	if len(UpperCAmelCase_  ) % 5_12 != 0:
		raise ValueError('Input must have length that\'s a multiple of 512'  )

	for pos in range(0      ,							len(UpperCAmelCase_  )      ,							5_12  ):
		__snake_case      :							Tuple						=			bit_string[pos : pos + 5_12]
		__snake_case      :							int						=			[]
		for i in range(0      ,							5_12      ,							32  ):
			block_words.append(int(to_little_endian(block[i : i + 32]  )      ,							2  )  )
		yield block_words
def   __UpperCAmelCase    (   UpperCAmelCase_   :    int  )							->      int:

	'''simple docstring'''





	if i < 0:
		raise ValueError('Input must be non-negative'  )

	__snake_case      :							Dict						=			format(UpperCAmelCase_      ,							'032b'  )
	__snake_case      :							Tuple						=			''
	for c in i_str:
		new_str += "1" if c == "0" else "0"
	return int(UpperCAmelCase_      ,							2  )
def   __UpperCAmelCase    (   UpperCAmelCase_   :    int      ,							UpperCAmelCase_   :    int  )							->      int:

	'''simple docstring'''





	return (a + b) % 2**32
def   __UpperCAmelCase    (   UpperCAmelCase_   :    int      ,							UpperCAmelCase_   :    int  )							->      int:

	'''simple docstring'''





	if i < 0:
		raise ValueError('Input must be non-negative'  )
	if shift < 0:
		raise ValueError('Shift must be non-negative'  )
	return ((i << shift) ^ (i >> (32 - shift))) % 2**32
def   __UpperCAmelCase    (   UpperCAmelCase_   :    bytes  )							->      bytes:

	'''simple docstring'''





	__snake_case      :							Union[str, Any]						=			preprocess(UpperCAmelCase_  )

	__snake_case      :							Optional[int]						=			[int(2**32 * abs(sin(i + 1  )  )  ) for i in range(64  )]

	# Starting states
	__snake_case      :							Optional[int]						=			0x67452301
	__snake_case      :							List[str]						=			0xefcdab89
	__snake_case      :							Optional[Any]						=			0x98badcfe
	__snake_case      :							Dict						=			0x10325476

	__snake_case      :							Dict						=			[
	    7,
	    12,
	    17,
	    22,
	    7,
	    12,
	    17,
	    22,
	    7,
	    12,
	    17,
	    22,
	    7,
	    12,
	    17,
	    22,
	    5,
	    9,
	    14,
	    20,
	    5,
	    9,
	    14,
	    20,
	    5,
	    9,
	    14,
	    20,
	    5,
	    9,
	    14,
	    20,
	    4,
	    11,
	    16,
	    23,
	    4,
	    11,
	    16,
	    23,
	    4,
	    11,
	    16,
	    23,
	    4,
	    11,
	    16,
	    23,
	    6,
	    10,
	    15,
	    21,
	    6,
	    10,
	    15,
	    21,
	    6,
	    10,
	    15,
	    21,
	    6,
	    10,
	    15,
	    21,
	]

	# Process bit string in chunks, each with 16 32-char words
	for block_words in get_block_words(UpperCAmelCase_  ):
		__snake_case      :							Union[str, Any]						=			aa
		__snake_case      :							Any						=			ba
		__snake_case      :							List[Any]						=			ca
		__snake_case      :							Union[str, Any]						=			da

		# Hash current chunk
		for i in range(64  ):
			if i <= 15:
				# f = (b & c) | (not_32(b) & d)     # Alternate definition for f
				__snake_case      :							List[Any]						=			d ^ (b & (c ^ d))
				__snake_case      :							str						=			i
			elif i <= 31:
				# f = (d & b) | (not_32(d) & c)     # Alternate definition for f
				__snake_case      :							Optional[Any]						=			c ^ (d & (b ^ c))
				__snake_case      :							List[Any]						=			(5 * i + 1) % 16
			elif i <= 47:
				__snake_case      :							Dict						=			b ^ c ^ d
				__snake_case      :							List[str]						=			(3 * i + 5) % 16
			else:
				__snake_case      :							Tuple						=			c ^ (b | not_aa(UpperCAmelCase_  ))
				__snake_case      :							Optional[int]						=			(7 * i) % 16
			__snake_case      :							Union[str, Any]						=			(f + a + added_consts[i] + block_words[g]) % 2**32
			__snake_case      :							List[Any]						=			d
			__snake_case      :							Tuple						=			c
			__snake_case      :							List[str]						=			b
			__snake_case      :							Union[str, Any]						=			sum_aa(UpperCAmelCase_      ,							left_rotate_aa(UpperCAmelCase_      ,							shift_amounts[i]  )  )

		# Add hashed chunk to running total
		__snake_case      :							Any						=			sum_aa(UpperCAmelCase_      ,							UpperCAmelCase_  )
		__snake_case      :							List[Any]						=			sum_aa(UpperCAmelCase_      ,							UpperCAmelCase_  )
		__snake_case      :							Any						=			sum_aa(UpperCAmelCase_      ,							UpperCAmelCase_  )
		__snake_case      :							Tuple						=			sum_aa(UpperCAmelCase_      ,							UpperCAmelCase_  )

	__snake_case      :							Optional[int]						=			reformat_hex(UpperCAmelCase_  ) + reformat_hex(UpperCAmelCase_  ) + reformat_hex(UpperCAmelCase_  ) + reformat_hex(UpperCAmelCase_  )
	return digest


if __name__ == "__main__":
	import doctest

	doctest.testmod()






"""simple docstring"""







import gc
import tempfile
import unittest

import numpy as np
import torch

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


_a					:					int=			False

class 		UpperCamelCase      (   unittest.TestCase						):
				pass







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



				def  _lowercase					(self    :				Optional[Any])   ->     Tuple:
					# clean up the VRAM after each test
					super().tearDown()
					gc.collect()
					torch.cuda.empty_cache()



				def  _lowercase					(self    :				int)   ->     Tuple:
					__snake_case      :							str						=			VersatileDiffusionPipeline.from_pretrained('shi-labs/versatile-diffusion'     ,  torch_dtype=torch.floataa)
					pipe.to(_A)
					pipe.set_progress_bar_config(disable=_A)

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

					__snake_case      :							List[Any]						=			torch.manual_seed(0)
					__snake_case      :							Optional[int]						=			pipe.dual_guided(
					    prompt='first prompt'     ,  image=_A     ,  text_to_image_strength=0.75     ,  generator=_A     ,  guidance_scale=7.5     ,  num_inference_steps=2     ,  output_type='numpy'     ,  ).images

					with tempfile.TemporaryDirectory() as tmpdirname:
						pipe.save_pretrained(_A)
						__snake_case      :							Optional[Any]						=			VersatileDiffusionPipeline.from_pretrained(_A     ,  torch_dtype=torch.floataa)
					pipe.to(_A)
					pipe.set_progress_bar_config(disable=_A)

					__snake_case      :							Tuple						=			generator.manual_seed(0)
					__snake_case      :							int						=			pipe.dual_guided(
					    prompt='first prompt'     ,  image=_A     ,  text_to_image_strength=0.75     ,  generator=_A     ,  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  _lowercase					(self    :				Optional[Any])   ->     Optional[int]:
					__snake_case      :							Optional[Any]						=			VersatileDiffusionPipeline.from_pretrained('shi-labs/versatile-diffusion'     ,  torch_dtype=torch.floataa)
					pipe.to(_A)
					pipe.set_progress_bar_config(disable=_A)

					__snake_case      :							Tuple						=			'cyberpunk 2077'
					__snake_case      :							int						=			load_image(
					    'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg')
					__snake_case      :							str						=			torch.manual_seed(0)
					__snake_case      :							Union[str, Any]						=			pipe.dual_guided(
					    prompt=_A     ,  image=_A     ,  text_to_image_strength=0.75     ,  generator=_A     ,  guidance_scale=7.5     ,  num_inference_steps=50     ,  output_type='numpy'     ,  ).images

					__snake_case      :							Optional[Any]						=			image[0, 2_53:2_56, 2_53:2_56, -1]

					assert image.shape == (1, 5_12, 5_12, 3)
					__snake_case      :							Tuple						=			np.array([0.1_448, 0.1_619, 0.1_741, 0.1_086, 0.1_147, 0.1_128, 0.1_199, 0.1_165, 0.1_001])

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

					__snake_case      :							List[str]						=			'A painting of a squirrel eating a burger '
					__snake_case      :							str						=			torch.manual_seed(0)
					__snake_case      :							str						=			pipe.text_to_image(
					    prompt=_A     ,  generator=_A     ,  guidance_scale=7.5     ,  num_inference_steps=50     ,  output_type='numpy').images

					__snake_case      :							str						=			image[0, 2_53:2_56, 2_53:2_56, -1]

					assert image.shape == (1, 5_12, 5_12, 3)
					__snake_case      :							Any						=			np.array([0.3_367, 0.3_169, 0.2_656, 0.3_870, 0.4_790, 0.3_796, 0.4_009, 0.4_878, 0.4_778])

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

					__snake_case      :							List[str]						=			pipe.image_variation(_A     ,  generator=_A     ,  output_type='numpy').images

					__snake_case      :							Dict						=			image[0, 2_53:2_56, 2_53:2_56, -1]

					assert image.shape == (1, 5_12, 5_12, 3)
					__snake_case      :							List[Any]						=			np.array([0.3_076, 0.3_123, 0.3_284, 0.3_782, 0.3_770, 0.3_894, 0.4_297, 0.4_331, 0.4_456])

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





