





'''simple docstring'''






import gc
import unittest

from diffusers import FlaxDPMSolverMultistepScheduler, FlaxStableDiffusionPipeline
from diffusers.utils import is_flax_available, slow
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
		import jax
		import jax.numpy as jnp
		from flax.jax_utils import replicate
		from flax.training.common_utils import shard







@slow
@require_flax
class 			lowerCamelCase					(						unittest.TestCase  ):


					def    SCREAMING_SNAKE_CASE_		(					self	:  Union[str, Any]       ):





											'''simple docstring'''





											super().tearDown()
											gc.collect()


					def    SCREAMING_SNAKE_CASE_		(					self	:  Tuple       ):





											'''simple docstring'''





											_snake_case					,						_snake_case:   Union[str, Any]  					=		FlaxStableDiffusionPipeline.from_pretrained(
											    'stabilityai/stable-diffusion-2'       ,     revision='bf16'       ,     dtype=jnp.bfloataa       ,     )

											_snake_case:   int  					=		'A painting of a squirrel eating a burger'
											_snake_case:   Optional[Any]  					=		jax.device_count()
											_snake_case:   Dict  					=		num_samples * [prompt]
											_snake_case:   int  					=		sd_pipe.prepare_inputs(__snake_case       )

											_snake_case:   Optional[Any]  					=		replicate(__snake_case       )
											_snake_case:   Dict  					=		shard(__snake_case       )

											_snake_case:   Any  					=		jax.random.PRNGKey(0       )
											_snake_case:   Any  					=		jax.random.split(__snake_case       ,     jax.device_count()       )

											_snake_case:   Optional[Any]  					=		sd_pipe(__snake_case       ,     __snake_case       ,     __snake_case       ,     num_inference_steps=25       ,     jit=__snake_case       )[0]
											assert images.shape == (jax.device_count(), 1, 7_68, 7_68, 3)

											_snake_case:   Any  					=		images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]       )
											_snake_case:   Dict  					=		images[0, 2_53:2_56, 2_53:2_56, -1]

											_snake_case:   List[Any]  					=		jnp.asarray(jax.device_get(image_slice.flatten()       )       )
											_snake_case:   List[str]  					=		jnp.array([0.4_238, 0.4_414, 0.4_395, 0.4_453, 0.4_629, 0.4_590, 0.4_531, 0.45_508, 0.4_512]       )
											print(f'''output_slice: {output_slice}'''       )
											assert jnp.abs(output_slice - expected_slice       ).max() < 1e-2




					def    SCREAMING_SNAKE_CASE_		(					self	:  int       ):





											'''simple docstring'''





											_snake_case:   Tuple  					=		'stabilityai/stable-diffusion-2'
											_snake_case					,						_snake_case:   Optional[int]  					=		FlaxDPMSolverMultistepScheduler.from_pretrained(__snake_case       ,     subfolder='scheduler'       )
											_snake_case					,						_snake_case:   int  					=		FlaxStableDiffusionPipeline.from_pretrained(
											    __snake_case       ,     scheduler=__snake_case       ,     revision='bf16'       ,     dtype=jnp.bfloataa       ,     )
											_snake_case:   Any  					=		scheduler_params

											_snake_case:   Dict  					=		'A painting of a squirrel eating a burger'
											_snake_case:   List[str]  					=		jax.device_count()
											_snake_case:   Optional[int]  					=		num_samples * [prompt]
											_snake_case:   str  					=		sd_pipe.prepare_inputs(__snake_case       )

											_snake_case:   List[Any]  					=		replicate(__snake_case       )
											_snake_case:   List[str]  					=		shard(__snake_case       )

											_snake_case:   Dict  					=		jax.random.PRNGKey(0       )
											_snake_case:   Any  					=		jax.random.split(__snake_case       ,     jax.device_count()       )

											_snake_case:   List[Any]  					=		sd_pipe(__snake_case       ,     __snake_case       ,     __snake_case       ,     num_inference_steps=25       ,     jit=__snake_case       )[0]
											assert images.shape == (jax.device_count(), 1, 7_68, 7_68, 3)

											_snake_case:   List[Any]  					=		images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]       )
											_snake_case:   List[str]  					=		images[0, 2_53:2_56, 2_53:2_56, -1]

											_snake_case:   Any  					=		jnp.asarray(jax.device_get(image_slice.flatten()       )       )
											_snake_case:   str  					=		jnp.array([0.4_336, 0.42_969, 0.4_453, 0.4_199, 0.4_297, 0.4_531, 0.4_434, 0.4_434, 0.4_297]       )
											print(f'''output_slice: {output_slice}'''       )
											assert jnp.abs(output_slice - expected_slice       ).max() < 1e-2












'''simple docstring'''






from typing import TYPE_CHECKING

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


A   : Dict             =			{'configuration_speech_encoder_decoder': ['SpeechEncoderDecoderConfig']}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		A   : int             =			['SpeechEncoderDecoderModel']

try:
		if not is_flax_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		A   : Union[str, Any]             =			['FlaxSpeechEncoderDecoderModel']

if TYPE_CHECKING:
		from .configuration_speech_encoder_decoder import SpeechEncoderDecoderConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_speech_encoder_decoder import SpeechEncoderDecoderModel

		try:
				if not is_flax_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_flax_speech_encoder_decoder import FlaxSpeechEncoderDecoderModel

else:
		import sys

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





