



'''simple docstring'''






import unittest

from transformers import DebertaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import (
						    DebertaForMaskedLM,
						    DebertaForQuestionAnswering,
						    DebertaForSequenceClassification,
						    DebertaForTokenClassification,
						    DebertaModel,
						)
						from transformers.models.deberta.modeling_deberta import DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST

class 				SCREAMING_SNAKE_CASE(							A__			):







	"""simple docstring"""






	def __init__(						self			:     Optional[Any]		,			__snake_case			:     List[str]		,			__snake_case			:     Tuple=13		,			__snake_case			:     Optional[Any]=7		,			__snake_case			:     Optional[int]=True		,			__snake_case			:     int=True		,			__snake_case			:     Optional[int]=True		,			__snake_case			:     str=True		,			__snake_case			:     str=99		,			__snake_case			:     Any=32		,			__snake_case			:     Union[str, Any]=5		,			__snake_case			:     Optional[int]=4		,			__snake_case			:     List[str]=37		,			__snake_case			:     Any="gelu"		,			__snake_case			:     Optional[int]=0.1		,			__snake_case			:     Dict=0.1		,			__snake_case			:     Dict=512		,			__snake_case			:     List[str]=16		,			__snake_case			:     Any=2		,			__snake_case			:     List[str]=0.02		,			__snake_case			:     str=False		,			__snake_case			:     str=True		,			__snake_case			:     List[str]="None"		,			__snake_case			:     List[Any]=3		,			__snake_case			:     Optional[Any]=4		,			__snake_case			:     Tuple=None		,			)			->		List[str]:
								UpperCAmelCase :       int 							=		parent
								UpperCAmelCase :       List[Any] 							=		batch_size
								UpperCAmelCase :       Tuple 							=		seq_length
								UpperCAmelCase :       int 							=		is_training
								UpperCAmelCase :       Union[str, Any] 							=		use_input_mask
								UpperCAmelCase :       List[str] 							=		use_token_type_ids
								UpperCAmelCase :       List[str] 							=		use_labels
								UpperCAmelCase :       Union[str, Any] 							=		vocab_size
								UpperCAmelCase :       int 							=		hidden_size
								UpperCAmelCase :       int 							=		num_hidden_layers
								UpperCAmelCase :       str 							=		num_attention_heads
								UpperCAmelCase :       Union[str, Any] 							=		intermediate_size
								UpperCAmelCase :       Optional[Any] 							=		hidden_act
								UpperCAmelCase :       Dict 							=		hidden_dropout_prob
								UpperCAmelCase :       int 							=		attention_probs_dropout_prob
								UpperCAmelCase :       Union[str, Any] 							=		max_position_embeddings
								UpperCAmelCase :       Union[str, Any] 							=		type_vocab_size
								UpperCAmelCase :       int 							=		type_sequence_label_size
								UpperCAmelCase :       List[Any] 							=		initializer_range
								UpperCAmelCase :       Optional[Any] 							=		num_labels
								UpperCAmelCase :       int 							=		num_choices
								UpperCAmelCase :       List[Any] 							=		relative_attention
								UpperCAmelCase :       Any 							=		position_biased_input
								UpperCAmelCase :       Any 							=		pos_att_type
								UpperCAmelCase :       Optional[int] 							=		scope







	def      A	(						self			:     Optional[int]		)			->		List[str]:
								UpperCAmelCase :       str 							=		ids_tensor([self.batch_size, self.seq_length]		,			self.vocab_size		)

								UpperCAmelCase :       Any 							=		None
								if self.use_input_mask:
															UpperCAmelCase :       Union[str, Any] 							=		ids_tensor([self.batch_size, self.seq_length]		,			vocab_size=2		)

								UpperCAmelCase :       Optional[Any] 							=		None
								if self.use_token_type_ids:
															UpperCAmelCase :       List[Any] 							=		ids_tensor([self.batch_size, self.seq_length]		,			self.type_vocab_size		)

								UpperCAmelCase :       Union[str, Any] 							=		None
								UpperCAmelCase :       Union[str, Any] 							=		None
								UpperCAmelCase :       Any 							=		None
								if self.use_labels:
															UpperCAmelCase :       int 							=		ids_tensor([self.batch_size]		,			self.type_sequence_label_size		)
															UpperCAmelCase :       Any 							=		ids_tensor([self.batch_size, self.seq_length]		,			self.num_labels		)
															UpperCAmelCase :       Optional[int] 							=		ids_tensor([self.batch_size]		,			self.num_choices		)

								UpperCAmelCase :       Optional[int] 							=		self.get_config()

								return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels







	def      A	(						self			:     List[Any]		)			->		Union[str, Any]:
								return DebertaConfig(
								    vocab_size=self.vocab_size		,			hidden_size=self.hidden_size		,			num_hidden_layers=self.num_hidden_layers		,			num_attention_heads=self.num_attention_heads		,			intermediate_size=self.intermediate_size		,			hidden_act=self.hidden_act		,			hidden_dropout_prob=self.hidden_dropout_prob		,			attention_probs_dropout_prob=self.attention_probs_dropout_prob		,			max_position_embeddings=self.max_position_embeddings		,			type_vocab_size=self.type_vocab_size		,			initializer_range=self.initializer_range		,			relative_attention=self.relative_attention		,			position_biased_input=self.position_biased_input		,			pos_att_type=self.pos_att_type		,			)







	def      A	(						self			:     int		)			->		List[str]:
								UpperCAmelCase :       Dict 							=		self.get_config()
								UpperCAmelCase :       int 							=		300
								return config







	def      A	(						self			:     Optional[int]		,			__snake_case			:     str		)			->		List[str]:
								self.parent.assertListEqual(list(result.loss.size()		)		,			[]		)







	def      A	(						self			:     Optional[int]		,			__snake_case			:     Dict		,			__snake_case			:     Tuple		,			__snake_case			:     Optional[Any]		,			__snake_case			:     int		,			__snake_case			:     List[str]		,			__snake_case			:     Dict		,			__snake_case			:     str		)			->		List[Any]:
								UpperCAmelCase :       Optional[int] 							=		DebertaModel(config=__snake_case		)
								model.to(__snake_case		)
								model.eval()
								UpperCAmelCase :       List[Any] 							=		model(__snake_case		,			attention_mask=__snake_case		,			token_type_ids=__snake_case		)[0]
								UpperCAmelCase :       Union[str, Any] 							=		model(__snake_case		,			token_type_ids=__snake_case		)[0]
								UpperCAmelCase :       List[Any] 							=		model(__snake_case		)[0]

								self.parent.assertListEqual(list(sequence_output.size()		)		,			[self.batch_size, self.seq_length, self.hidden_size]		)







	def      A	(						self			:     Dict		,			__snake_case			:     Dict		,			__snake_case			:     str		,			__snake_case			:     List[Any]		,			__snake_case			:     str		,			__snake_case			:     Optional[Any]		,			__snake_case			:     Tuple		,			__snake_case			:     List[Any]		)			->		str:
								UpperCAmelCase :       Tuple 							=		DebertaForMaskedLM(config=__snake_case		)
								model.to(__snake_case		)
								model.eval()
								UpperCAmelCase :       Dict 							=		model(__snake_case		,			attention_mask=__snake_case		,			token_type_ids=__snake_case		,			labels=__snake_case		)

								self.parent.assertEqual(result.logits.shape		,			(self.batch_size, self.seq_length, self.vocab_size)		)







	def      A	(						self			:     Tuple		,			__snake_case			:     Optional[int]		,			__snake_case			:     List[str]		,			__snake_case			:     Dict		,			__snake_case			:     Optional[int]		,			__snake_case			:     int		,			__snake_case			:     Tuple		,			__snake_case			:     Optional[int]		)			->		List[Any]:
								UpperCAmelCase :       Any 							=		self.num_labels
								UpperCAmelCase :       Optional[int] 							=		DebertaForSequenceClassification(__snake_case		)
								model.to(__snake_case		)
								model.eval()
								UpperCAmelCase :       Optional[Any] 							=		model(__snake_case		,			attention_mask=__snake_case		,			token_type_ids=__snake_case		,			labels=__snake_case		)
								self.parent.assertListEqual(list(result.logits.size()		)		,			[self.batch_size, self.num_labels]		)
								self.check_loss_output(__snake_case		)







	def      A	(						self			:     Tuple		,			__snake_case			:     Tuple		,			__snake_case			:     List[str]		,			__snake_case			:     int		,			__snake_case			:     int		,			__snake_case			:     Optional[int]		,			__snake_case			:     Optional[Any]		,			__snake_case			:     Any		)			->		Tuple:
								UpperCAmelCase :       int 							=		self.num_labels
								UpperCAmelCase :       Tuple 							=		DebertaForTokenClassification(config=__snake_case		)
								model.to(__snake_case		)
								model.eval()
								UpperCAmelCase :       Dict 							=		model(__snake_case		,			attention_mask=__snake_case		,			token_type_ids=__snake_case		,			labels=__snake_case		)
								self.parent.assertEqual(result.logits.shape		,			(self.batch_size, self.seq_length, self.num_labels)		)







	def      A	(						self			:     Union[str, Any]		,			__snake_case			:     Optional[int]		,			__snake_case			:     List[str]		,			__snake_case			:     List[str]		,			__snake_case			:     List[Any]		,			__snake_case			:     List[Any]		,			__snake_case			:     Union[str, Any]		,			__snake_case			:     Optional[int]		)			->		List[Any]:
								UpperCAmelCase :       int 							=		DebertaForQuestionAnswering(config=__snake_case		)
								model.to(__snake_case		)
								model.eval()
								UpperCAmelCase :       List[str] 							=		model(
								    __snake_case		,			attention_mask=__snake_case		,			token_type_ids=__snake_case		,			start_positions=__snake_case		,			end_positions=__snake_case		,			)
								self.parent.assertEqual(result.start_logits.shape		,			(self.batch_size, self.seq_length)		)
								self.parent.assertEqual(result.end_logits.shape		,			(self.batch_size, self.seq_length)		)







	def      A	(						self			:     Any		)			->		Union[str, Any]:
								UpperCAmelCase :       str 							=		self.prepare_config_and_inputs()
								(
								    (
								    UpperCAmelCase
								)							,		(
								    UpperCAmelCase
								)							,		(
								    UpperCAmelCase
								)							,		(
								    UpperCAmelCase
								)							,		(
								    UpperCAmelCase
								)							,		(
								    UpperCAmelCase
								)							,		(
								    UpperCAmelCase
								)							,		
								) :       Union[str, Any] 							=		config_and_inputs
								UpperCAmelCase :       Union[str, Any] 							=		{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
								return config, inputs_dict

@require_torch
class 				SCREAMING_SNAKE_CASE(							A__							,		A__							,		unittest.TestCase			):







	"""simple docstring"""






	lowerCamelCase__			 =       (
	    (
	        DebertaModel,
	        DebertaForMaskedLM,
	        DebertaForSequenceClassification,
	        DebertaForTokenClassification,
	        DebertaForQuestionAnswering,
	    )
	    if is_torch_available()
	    else ()
	)
	lowerCamelCase__			 =       (
	    {
	        """feature-extraction""": DebertaModel,
	        """fill-mask""": DebertaForMaskedLM,
	        """question-answering""": DebertaForQuestionAnswering,
	        """text-classification""": DebertaForSequenceClassification,
	        """token-classification""": DebertaForTokenClassification,
	        """zero-shot""": DebertaForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)

	lowerCamelCase__			 =       True
	lowerCamelCase__			 =       False
	lowerCamelCase__			 =       False
	lowerCamelCase__			 =       False
	lowerCamelCase__			 =       False







	def      A	(						self			:     Optional[int]		)			->		int:
								UpperCAmelCase :       Optional[Any] 							=		DebertaModelTester(self		)
								UpperCAmelCase :       Optional[Any] 							=		ConfigTester(self		,			config_class=__snake_case		,			hidden_size=37		)







	def      A	(						self			:     Dict		)			->		Any:
								self.config_tester.run_common_tests()







	def      A	(						self			:     Optional[int]		)			->		Tuple:
								UpperCAmelCase :       Optional[Any] 							=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_model(*__snake_case		)







	def      A	(						self			:     Union[str, Any]		)			->		Dict:
								UpperCAmelCase :       Union[str, Any] 							=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_sequence_classification(*__snake_case		)







	def      A	(						self			:     Tuple		)			->		int:
								UpperCAmelCase :       Any 							=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_masked_lm(*__snake_case		)







	def      A	(						self			:     List[Any]		)			->		Dict:
								UpperCAmelCase :       Tuple 							=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_question_answering(*__snake_case		)







	def      A	(						self			:     List[str]		)			->		List[str]:
								UpperCAmelCase :       List[str] 							=		self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_token_classification(*__snake_case		)







	@slow
	def      A	(						self			:     str		)			->		Optional[Any]:
								for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															UpperCAmelCase :       int 							=		DebertaModel.from_pretrained(__snake_case		)
															self.assertIsNotNone(__snake_case		)

@require_torch
@require_sentencepiece
@require_tokenizers
class 				SCREAMING_SNAKE_CASE(							unittest.TestCase			):







	"""simple docstring"""






	@unittest.skip(reason='''Model not available yet'''		)
	def      A	(						self			:     Tuple		)			->		str:
								pass







	@slow
	def      A	(						self			:     Any		)			->		str:
								UpperCAmelCase :       Tuple 							=		DebertaModel.from_pretrained('''microsoft/deberta-base'''		)

								UpperCAmelCase :       Optional[Any] 							=		torch.tensor([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]		)
								UpperCAmelCase :       Any 							=		torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
								with torch.no_grad():
															UpperCAmelCase :       Any 							=		model(__snake_case		,			attention_mask=__snake_case		)[0]
								# compare the actual values for a slice.
								UpperCAmelCase :       Optional[int] 							=		torch.tensor(
								    [[[-0.59_86, -0.80_55, -0.84_62], [1.44_84, -0.93_48, -0.80_59], [0.31_23, 0.00_32, -1.41_31]]]		)
								self.assertTrue(torch.allclose(output[:, 1:4, 1:4]		,			__snake_case		,			atol=1E-4		)		,			F"""{output[:, 1:4, 1:4]}"""		)










'''simple docstring'''






import os
import tempfile
import unittest

import numpy as np

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


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

						from diffusers import FlaxDDIMScheduler, FlaxDiffusionPipeline, FlaxStableDiffusionPipeline

@require_flax
class 				SCREAMING_SNAKE_CASE(							unittest.TestCase			):







	"""simple docstring"""






	def      A	(						self			:     str		)			->		int:
								with tempfile.TemporaryDirectory() as tmpdirname:
															# pipeline has Flax weights
															UpperCAmelCase :       Optional[Any] 							=		FlaxDiffusionPipeline.from_pretrained(
															    '''hf-internal-testing/tiny-stable-diffusion-pipe'''		,			safety_checker=__snake_case		,			cache_dir=__snake_case		)

															UpperCAmelCase :       str 							=		[t[-1] for t in os.walk(os.path.join(__snake_case		,			os.listdir(__snake_case		)[0]		,			'''snapshots'''		)		)]
															UpperCAmelCase :       str 							=		[item for sublist in all_root_files for item in sublist]

															# None of the downloaded files should be a PyTorch file even if we have some here:
															# https://huggingface.co/hf-internal-testing/tiny-stable-diffusion-pipe/blob/main/unet/diffusion_pytorch_model.bin
															assert not any(f.endswith('''.bin'''		) for f in files		)

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







	"""simple docstring"""






	def      A	(						self			:     List[str]		)			->		Dict:
								UpperCAmelCase							,		UpperCAmelCase :       str 							=		FlaxStableDiffusionPipeline.from_pretrained(
								    '''hf-internal-testing/tiny-stable-diffusion-pipe'''		,			safety_checker=__snake_case		)

								UpperCAmelCase :       List[Any] 							=		(
								    '''A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'''
								    ''' field, close up, split lighting, cinematic'''
								)

								UpperCAmelCase :       List[str] 							=		jax.random.PRNGKey(0		)
								UpperCAmelCase :       Optional[Any] 							=		4

								UpperCAmelCase :       Optional[Any] 							=		jax.device_count()
								UpperCAmelCase :       Tuple 							=		num_samples * [prompt]
								UpperCAmelCase :       int 							=		pipeline.prepare_inputs(__snake_case		)

								# shard inputs and rng
								UpperCAmelCase :       Tuple 							=		replicate(__snake_case		)
								UpperCAmelCase :       Any 							=		jax.random.split(__snake_case		,			__snake_case		)
								UpperCAmelCase :       Optional[Any] 							=		shard(__snake_case		)

								UpperCAmelCase :       Optional[int] 							=		pipeline(__snake_case		,			__snake_case		,			__snake_case		,			__snake_case		,			jit=__snake_case		).images

								assert images.shape == (num_samples, 1, 64, 64, 3)
								if jax.device_count() == 8:
															assert np.abs(np.abs(images[0, 0, :2, :2, -2:]		,			dtype=np.floataa		).sum() - 4.1_51_47_45		) < 1E-3
															assert np.abs(np.abs(__snake_case		,			dtype=np.floataa		).sum() - 4_99_47.8_75		) < 5E-1

								UpperCAmelCase :       Union[str, Any] 							=		pipeline.numpy_to_pil(np.asarray(images.reshape((num_samples,) + images.shape[-3:]		)		)		)
								assert len(__snake_case		) == num_samples







	def      A	(						self			:     List[Any]		)			->		List[str]:
								UpperCAmelCase							,		UpperCAmelCase :       Union[str, Any] 							=		FlaxStableDiffusionPipeline.from_pretrained(
								    '''CompVis/stable-diffusion-v1-4'''		,			revision='''flax'''		,			safety_checker=__snake_case		)

								UpperCAmelCase :       Dict 							=		(
								    '''A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'''
								    ''' field, close up, split lighting, cinematic'''
								)

								UpperCAmelCase :       Optional[Any] 							=		jax.random.PRNGKey(0		)
								UpperCAmelCase :       Any 							=		50

								UpperCAmelCase :       Union[str, Any] 							=		jax.device_count()
								UpperCAmelCase :       int 							=		num_samples * [prompt]
								UpperCAmelCase :       Union[str, Any] 							=		pipeline.prepare_inputs(__snake_case		)

								# shard inputs and rng
								UpperCAmelCase :       Dict 							=		replicate(__snake_case		)
								UpperCAmelCase :       int 							=		jax.random.split(__snake_case		,			__snake_case		)
								UpperCAmelCase :       Tuple 							=		shard(__snake_case		)

								UpperCAmelCase :       Tuple 							=		pipeline(__snake_case		,			__snake_case		,			__snake_case		,			__snake_case		,			jit=__snake_case		).images

								assert images.shape == (num_samples, 1, 512, 512, 3)
								if jax.device_count() == 8:
															assert np.abs((np.abs(images[0, 0, :2, :2, -2:]		,			dtype=np.floataa		).sum() - 0.05_65_24_01)		) < 1E-3
															assert np.abs((np.abs(__snake_case		,			dtype=np.floataa		).sum() - 2_38_38_08.2)		) < 5E-1







	def      A	(						self			:     int		)			->		Dict:
								UpperCAmelCase							,		UpperCAmelCase :       List[str] 							=		FlaxStableDiffusionPipeline.from_pretrained(
								    '''CompVis/stable-diffusion-v1-4'''		,			revision='''bf16'''		,			dtype=jnp.bfloataa		,			safety_checker=__snake_case		)

								UpperCAmelCase :       Dict 							=		(
								    '''A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'''
								    ''' field, close up, split lighting, cinematic'''
								)

								UpperCAmelCase :       Union[str, Any] 							=		jax.random.PRNGKey(0		)
								UpperCAmelCase :       List[str] 							=		50

								UpperCAmelCase :       Union[str, Any] 							=		jax.device_count()
								UpperCAmelCase :       List[Any] 							=		num_samples * [prompt]
								UpperCAmelCase :       int 							=		pipeline.prepare_inputs(__snake_case		)

								# shard inputs and rng
								UpperCAmelCase :       Tuple 							=		replicate(__snake_case		)
								UpperCAmelCase :       List[Any] 							=		jax.random.split(__snake_case		,			__snake_case		)
								UpperCAmelCase :       Optional[int] 							=		shard(__snake_case		)

								UpperCAmelCase :       Optional[Any] 							=		pipeline(__snake_case		,			__snake_case		,			__snake_case		,			__snake_case		,			jit=__snake_case		).images

								assert images.shape == (num_samples, 1, 512, 512, 3)
								if jax.device_count() == 8:
															assert np.abs((np.abs(images[0, 0, :2, :2, -2:]		,			dtype=np.floataa		).sum() - 0.04_00_39_06)		) < 1E-3
															assert np.abs((np.abs(__snake_case		,			dtype=np.floataa		).sum() - 2_37_35_16.75)		) < 5E-1







	def      A	(						self			:     int		)			->		Any:
								UpperCAmelCase							,		UpperCAmelCase :       Dict 							=		FlaxStableDiffusionPipeline.from_pretrained(
								    '''CompVis/stable-diffusion-v1-4'''		,			revision='''bf16'''		,			dtype=jnp.bfloataa		)

								UpperCAmelCase :       List[str] 							=		(
								    '''A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'''
								    ''' field, close up, split lighting, cinematic'''
								)

								UpperCAmelCase :       List[str] 							=		jax.random.PRNGKey(0		)
								UpperCAmelCase :       Union[str, Any] 							=		50

								UpperCAmelCase :       Optional[int] 							=		jax.device_count()
								UpperCAmelCase :       List[str] 							=		num_samples * [prompt]
								UpperCAmelCase :       Dict 							=		pipeline.prepare_inputs(__snake_case		)

								# shard inputs and rng
								UpperCAmelCase :       Tuple 							=		replicate(__snake_case		)
								UpperCAmelCase :       Any 							=		jax.random.split(__snake_case		,			__snake_case		)
								UpperCAmelCase :       str 							=		shard(__snake_case		)

								UpperCAmelCase :       Optional[int] 							=		pipeline(__snake_case		,			__snake_case		,			__snake_case		,			__snake_case		,			jit=__snake_case		).images

								assert images.shape == (num_samples, 1, 512, 512, 3)
								if jax.device_count() == 8:
															assert np.abs((np.abs(images[0, 0, :2, :2, -2:]		,			dtype=np.floataa		).sum() - 0.04_00_39_06)		) < 1E-3
															assert np.abs((np.abs(__snake_case		,			dtype=np.floataa		).sum() - 2_37_35_16.75)		) < 5E-1







	def      A	(						self			:     Tuple		)			->		Optional[Any]:
								UpperCAmelCase :       int 							=		FlaxDDIMScheduler(
								    beta_start=0.0_00_85		,			beta_end=0.0_12		,			beta_schedule='''scaled_linear'''		,			set_alpha_to_one=__snake_case		,			steps_offset=1		,			)

								UpperCAmelCase							,		UpperCAmelCase :       Tuple 							=		FlaxStableDiffusionPipeline.from_pretrained(
								    '''CompVis/stable-diffusion-v1-4'''		,			revision='''bf16'''		,			dtype=jnp.bfloataa		,			scheduler=__snake_case		,			safety_checker=__snake_case		,			)
								UpperCAmelCase :       Tuple 							=		scheduler.create_state()

								UpperCAmelCase :       Dict 							=		scheduler_state

								UpperCAmelCase :       str 							=		(
								    '''A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'''
								    ''' field, close up, split lighting, cinematic'''
								)

								UpperCAmelCase :       int 							=		jax.random.PRNGKey(0		)
								UpperCAmelCase :       Union[str, Any] 							=		50

								UpperCAmelCase :       Optional[Any] 							=		jax.device_count()
								UpperCAmelCase :       Any 							=		num_samples * [prompt]
								UpperCAmelCase :       Dict 							=		pipeline.prepare_inputs(__snake_case		)

								# shard inputs and rng
								UpperCAmelCase :       str 							=		replicate(__snake_case		)
								UpperCAmelCase :       List[str] 							=		jax.random.split(__snake_case		,			__snake_case		)
								UpperCAmelCase :       Optional[int] 							=		shard(__snake_case		)

								UpperCAmelCase :       Dict 							=		pipeline(__snake_case		,			__snake_case		,			__snake_case		,			__snake_case		,			jit=__snake_case		).images

								assert images.shape == (num_samples, 1, 512, 512, 3)
								if jax.device_count() == 8:
															assert np.abs((np.abs(images[0, 0, :2, :2, -2:]		,			dtype=np.floataa		).sum() - 0.0_45_04_39_45)		) < 1E-3
															assert np.abs((np.abs(__snake_case		,			dtype=np.floataa		).sum() - 2_34_76_93.5)		) < 5E-1







	def      A	(						self			:     Any		)			->		Tuple:
								UpperCAmelCase :       List[Any] 							=		(
								    '''A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'''
								    ''' field, close up, split lighting, cinematic'''
								)

								UpperCAmelCase :       Union[str, Any] 							=		jax.device_count()
								UpperCAmelCase :       List[Any] 							=		num_samples * [prompt]
								UpperCAmelCase :       str 							=		jax.random.split(jax.random.PRNGKey(0		)		,			__snake_case		)

								UpperCAmelCase							,		UpperCAmelCase :       Tuple 							=		FlaxStableDiffusionPipeline.from_pretrained(
								    '''CompVis/stable-diffusion-v1-4'''		,			revision='''bf16'''		,			dtype=jnp.bfloataa		,			safety_checker=__snake_case		,			)

								UpperCAmelCase :       Dict 							=		replicate(__snake_case		)
								UpperCAmelCase :       Optional[Any] 							=		pipeline.prepare_inputs(__snake_case		)
								UpperCAmelCase :       List[str] 							=		shard(__snake_case		)
								UpperCAmelCase :       Any 							=		pipeline(__snake_case		,			__snake_case		,			__snake_case		,			jit=__snake_case		).images
								assert images.shape == (num_samples, 1, 512, 512, 3)
								UpperCAmelCase :       Optional[int] 							=		images[2, 0, 256, 10:17, 1]

								# With memory efficient attention
								UpperCAmelCase							,		UpperCAmelCase :       Any 							=		FlaxStableDiffusionPipeline.from_pretrained(
								    '''CompVis/stable-diffusion-v1-4'''		,			revision='''bf16'''		,			dtype=jnp.bfloataa		,			safety_checker=__snake_case		,			use_memory_efficient_attention=__snake_case		,			)

								UpperCAmelCase :       int 							=		replicate(__snake_case		)
								UpperCAmelCase :       int 							=		pipeline.prepare_inputs(__snake_case		)
								UpperCAmelCase :       List[Any] 							=		shard(__snake_case		)
								UpperCAmelCase :       Optional[Any] 							=		pipeline(__snake_case		,			__snake_case		,			__snake_case		,			jit=__snake_case		).images
								assert images_eff.shape == (num_samples, 1, 512, 512, 3)
								UpperCAmelCase :       int 							=		images[2, 0, 256, 10:17, 1]

								# I checked the results visually and they are very similar. However, I saw that the max diff is `1` and the `sum`
								# over the 8 images is exactly `256`, which is very suspicious. Testing a random slice for now.
								assert abs(slice_eff - slice		).max() < 1E-2





