


"""simple docstring"""





from __future__ import annotations

import unittest

import numpy as np

from transformers import OPTConfig, is_tf_available
from transformers.testing_utils import require_sentencepiece, require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
				import tensorflow as tf

				from transformers import GPTaTokenizer, TFOPTForCausalLM, TFOPTModel



def 				lowerCamelCase__		(      __snake_case,					__snake_case,					__snake_case=None,					__snake_case=None     )							->		int:


					"""simple docstring"""





					if attention_mask is None:
										_UpperCamelCase										=  tf.cast(tf.math.not_equal(lowerCAmelCase_,					config.pad_token_id     ),					tf.inta     )
					return {"input_ids": input_ids, "attention_mask": attention_mask}






@require_tf
class    _UpperCAmelCase:
		lowercase__      =				OPTConfig
		lowercase__      =				{}
		lowercase__      =				'gelu'



		def __init__( self    ,		__a    ,		__a=13    ,		__a=7    ,		__a=True    ,		__a=False    ,		__a=99    ,		__a=16    ,		__a=2    ,		__a=4    ,		__a=4    ,		__a="gelu"    ,		__a=0.1    ,		__a=0.1    ,		__a=20    ,		__a=2    ,		__a=1    ,		__a=0    ,		__a=16    ,		__a=16    ,		)	->	Dict:






							'''simple docstring'''
							_UpperCamelCase										=  parent
							_UpperCamelCase										=  batch_size
							_UpperCamelCase										=  seq_length
							_UpperCamelCase										=  is_training
							_UpperCamelCase										=  use_labels
							_UpperCamelCase										=  vocab_size
							_UpperCamelCase										=  hidden_size
							_UpperCamelCase										=  num_hidden_layers
							_UpperCamelCase										=  num_attention_heads
							_UpperCamelCase										=  intermediate_size
							_UpperCamelCase										=  hidden_act
							_UpperCamelCase										=  hidden_dropout_prob
							_UpperCamelCase										=  attention_probs_dropout_prob
							_UpperCamelCase										=  max_position_embeddings
							_UpperCamelCase										=  eos_token_id
							_UpperCamelCase										=  pad_token_id
							_UpperCamelCase										=  bos_token_id
							_UpperCamelCase										=  embed_dim
							_UpperCamelCase										=  word_embed_proj_dim
							_UpperCamelCase										=  False



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






							'''simple docstring'''
							_UpperCamelCase										=  ids_tensor([self.batch_size, self.seq_length - 1]    ,		self.vocab_size)
							_UpperCamelCase										=  tf.expand_dims(tf.constant([self.eos_token_id] * self.batch_size)    ,		1)
							_UpperCamelCase										=  tf.concat([input_ids, eos_tensor]    ,		axis=1)

							_UpperCamelCase										=  self.config_cls(
							    vocab_size=self.vocab_size    ,		hidden_size=self.hidden_size    ,		num_hidden_layers=self.num_hidden_layers    ,		num_attention_heads=self.num_attention_heads    ,		ffn_dim=self.intermediate_size    ,		dropout=self.hidden_dropout_prob    ,		attention_dropout=self.attention_probs_dropout_prob    ,		max_position_embeddings=self.max_position_embeddings    ,		eos_token_id=self.eos_token_id    ,		bos_token_id=self.bos_token_id    ,		pad_token_id=self.pad_token_id    ,		embed_dim=self.embed_dim    ,		word_embed_proj_dim=self.word_embed_proj_dim    ,		is_encoder_decoder=_UpperCAmelCase    ,		**self.config_updates    ,		)
							_UpperCamelCase										=  prepare_opt_inputs_dict(_UpperCAmelCase    ,		_UpperCAmelCase)
							return config, inputs_dict




		def 						UpperCAmelCase							( self    ,		__a    ,		__a)	->	Union[str, Any]:






							'''simple docstring'''
							_UpperCamelCase										=  TFOPTModel(config=_UpperCAmelCase)
							_UpperCamelCase										=  inputs_dict['input_ids']

							_UpperCamelCase										=  input_ids[:1, :]
							_UpperCamelCase										=  inputs_dict['attention_mask'][:1, :]
							_UpperCamelCase										=  1

							# first forward pass
							_UpperCamelCase										=  model(_UpperCAmelCase    ,		attention_mask=_UpperCAmelCase    ,		use_cache=_UpperCAmelCase)

							_UpperCamelCase										=  outputs.to_tuple()

							# create hypothetical next token and extent to next_input_ids
							_UpperCamelCase										=  ids_tensor((self.batch_size, 3)    ,		config.vocab_size)
							_UpperCamelCase										=  tf.cast(ids_tensor((self.batch_size, 3)    ,		2)    ,		tf.inta)

							# append to next input_ids and
							_UpperCamelCase										=  tf.concat([input_ids, next_tokens]    ,		axis=-1)
							_UpperCamelCase										=  tf.concat([attention_mask, next_attn_mask]    ,		axis=-1)

							_UpperCamelCase										=  model(_UpperCAmelCase    ,		attention_mask=_UpperCAmelCase)[0]
							_UpperCamelCase										=  model(_UpperCAmelCase    ,		attention_mask=_UpperCAmelCase    ,		past_key_values=_UpperCAmelCase)[0]

							self.parent.assertEqual(next_tokens.shape[1]    ,		output_from_past.shape[1])

							# select random slice
							_UpperCamelCase										=  int(ids_tensor((1,)    ,		output_from_past.shape[-1]))
							_UpperCamelCase										=  output_from_no_past[:, -3:, random_slice_idx]
							_UpperCamelCase										=  output_from_past[:, :, random_slice_idx]

							# test that outputs are equal for slice
							tf.debugging.assert_near(_UpperCAmelCase    ,		_UpperCAmelCase    ,		rtol=1e-3)






@require_tf
class    _UpperCAmelCase(   _UpperCamelCase				,					_UpperCamelCase				,					unittest.TestCase     ):
		lowercase__      =				(TFOPTModel, TFOPTForCausalLM) if is_tf_available() else ()
		lowercase__      =				(TFOPTForCausalLM,) if is_tf_available() else ()
		lowercase__      =				(
		    {'feature-extraction': TFOPTModel, 'text-generation': TFOPTForCausalLM} if is_tf_available() else {}
		)
		lowercase__      =				False
		lowercase__      =				False
		lowercase__      =				False
		lowercase__      =				10



		def 						UpperCAmelCase							( self)	->	Optional[Any]:






							'''simple docstring'''
							_UpperCamelCase										=  TFOPTModelTester(self)
							_UpperCamelCase										=  ConfigTester(self    ,		config_class=_UpperCAmelCase)



		def 						UpperCAmelCase							( self)	->	Dict:






							'''simple docstring'''
							self.config_tester.run_common_tests()



		def 						UpperCAmelCase							( self)	->	Any:






							'''simple docstring'''
							_UpperCamelCase										=  self.model_tester.prepare_config_and_inputs_for_common()
							self.model_tester.check_decoder_model_past_large_inputs(*_UpperCAmelCase)




		def 						UpperCAmelCase							( self)	->	Union[str, Any]:






							'''simple docstring'''
							_UpperCamelCase										=  self.model_tester.prepare_config_and_inputs_for_common()

							def _get_word_embedding_weight(__a    ,		__a):
												if hasattr(_UpperCAmelCase    ,		'''weight'''):
																	return embedding_layer.weight
												else:
																	# Here we build the word embeddings weights if not exists.
																	# And then we retry to get the attribute once built.
																	model.build()
																	if hasattr(_UpperCAmelCase    ,		'''weight'''):
																						return embedding_layer.weight
																	else:
																						return None

							for model_class in self.all_model_classes:
												for size in [config.vocab_size - 10, config.vocab_size + 10]:
																	# build the embeddings
																	_UpperCamelCase										=  model_class(config=_UpperCAmelCase)
																	_UpperCamelCase										=  _get_word_embedding_weight(_UpperCAmelCase    ,		model.get_input_embeddings())
																	_UpperCamelCase										=  _get_word_embedding_weight(_UpperCAmelCase    ,		model.get_output_embeddings())

																	# reshape the embeddings
																	model.resize_token_embeddings(_UpperCAmelCase)
																	_UpperCamelCase										=  _get_word_embedding_weight(_UpperCAmelCase    ,		model.get_input_embeddings())
																	_UpperCamelCase										=  _get_word_embedding_weight(_UpperCAmelCase    ,		model.get_output_embeddings())

																	# check that the resized embeddings size matches the desired size.
																	_UpperCamelCase										=  size if size is not None else config.vocab_size

																	self.assertEqual(new_input_embeddings.shape[0]    ,		_UpperCAmelCase)

																	# check that weights remain the same after resizing
																	_UpperCamelCase										=  True
																	for pa, pa in zip(old_input_embeddings.value()    ,		new_input_embeddings.value()):
																						if tf.math.reduce_sum(tf.math.abs(pa - pa)) > 0:
																											_UpperCamelCase										=  False
																	self.assertTrue(_UpperCAmelCase)

																	if old_output_embeddings is not None and new_output_embeddings is not None:
																						self.assertEqual(new_output_embeddings.shape[0]    ,		_UpperCAmelCase)

																						_UpperCamelCase										=  True
																						for pa, pa in zip(old_output_embeddings.value()    ,		new_output_embeddings.value()):
																											if tf.math.reduce_sum(tf.math.abs(pa - pa)) > 0:
																																_UpperCamelCase										=  False
																						self.assertTrue(_UpperCAmelCase)





def 				lowerCamelCase__		(      __snake_case     )							->		Any:


					"""simple docstring"""





					return tf.constant(lowerCAmelCase_,					dtype=tf.intaa     )






@require_tf
class    _UpperCAmelCase(   unittest.TestCase     ):
		lowercase__      =				99



		def 						UpperCAmelCase							( self)	->	List[str]:






							'''simple docstring'''
							_UpperCamelCase										=  tf.ones((4, 1)    ,		dtype=tf.intaa) * 2
							_UpperCamelCase										=  tf.concat([ids_tensor((4, 6)    ,		self.vocab_size - 3) + 3, eos_column_vector]    ,		axis=1)
							_UpperCamelCase										=  input_ids.shape[0]
							_UpperCamelCase										=  OPTConfig(
							    vocab_size=self.vocab_size    ,		hidden_size=24    ,		num_hidden_layers=2    ,		num_attention_heads=2    ,		ffn_dim=32    ,		max_position_embeddings=48    ,		eos_token_id=2    ,		pad_token_id=1    ,		bos_token_id=0    ,		)
							return config, input_ids, batch_size






@require_sentencepiece
@require_tf
class    _UpperCAmelCase(   unittest.TestCase     ):



		@slow
		def 						UpperCAmelCase							( self)	->	int:






							'''simple docstring'''
							_UpperCamelCase										=  TFOPTModel.from_pretrained('''facebook/opt-350m''')
							_UpperCamelCase										=  _long_tensor([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]])
							_UpperCamelCase										=  tf.not_equal(_UpperCAmelCase    ,		model.config.pad_token_id)
							with tf.GradientTape():
												_UpperCamelCase										=  model(input_ids=_UpperCAmelCase    ,		attention_mask=_UpperCAmelCase).last_hidden_state
							_UpperCamelCase										=  (1, 11, 5_12)
							self.assertEqual(output.shape    ,		_UpperCAmelCase)
							_UpperCamelCase										=  tf.constant(
							    [[-0.2873, -1.9218, -0.3033], [-1.2710, -0.1338, -0.1902], [0.4095, 0.1214, -1.3121]])
							self.assertTrue(np.allclose(output[:, :3, :3]    ,		_UpperCAmelCase    ,		atol=4e-3))

							_UpperCamelCase										=  tf.function(_UpperCAmelCase    ,		jit_compile=_UpperCAmelCase)
							_UpperCamelCase										=  xla_generate(_UpperCAmelCase    ,		_UpperCAmelCase)[0]
							self.assertTrue(np.allclose(output[:, :3, :3]    ,		_UpperCAmelCase    ,		atol=4e-2))






@require_tf
@slow
class    _UpperCAmelCase(   unittest.TestCase     ):



		def 						UpperCAmelCase							( self)	->	List[str]:






							'''simple docstring'''
							super().setUp()
							_UpperCamelCase										=  'facebook/opt-350m'




		def 						UpperCAmelCase							( self)	->	Union[str, Any]:






							'''simple docstring'''
							_UpperCamelCase										=  TFOPTForCausalLM.from_pretrained(self.path_model)
							_UpperCamelCase										=  GPTaTokenizer.from_pretrained(self.path_model)

							_UpperCamelCase										=  [
							    'Today is a beautiful day and I want to',
							    'In the city of',
							    'Paris is the capital of France and',
							    'Computers and mobile phones have taken',
							]
							# verify that prompt without BOS token is identical to Metaseq -> add_special_tokens=False
							_UpperCamelCase										=  tokenizer(_UpperCAmelCase    ,		return_tensors='''tf'''    ,		padding=_UpperCAmelCase    ,		add_special_tokens=_UpperCAmelCase)
							_UpperCamelCase										=  tf.math.reduce_mean(model(inputs.input_ids    ,		attention_mask=inputs.attention_mask)[0]    ,		axis=-1)
							_UpperCamelCase										=  tf.constant(
							    [
							        [1.3851, -13.8923, -10.5229, -10.7533, -0.2309, -10.2384, -0.5365, -9.0947, -5.1670],
							        [-4.7073, -10.6276, -3.9415, -21.5242, -0.2822, -0.2822, -0.2822, -0.2822, -0.2822],
							        [0.6247, -3.4229, -8.9179, -1.4297, -14.1650, 1.4146, -9.0218, -0.2703, -0.2703],
							        [6.4783, -1.9913, -10.7926, -2.3336, 1.5092, -0.9974, -6.8213, 1.3477, 1.3477],
							    ])
							self.assertTrue(np.allclose(_UpperCAmelCase    ,		_UpperCAmelCase    ,		atol=1e-4))

							_UpperCamelCase										=  tf.function(_UpperCAmelCase    ,		jit_compile=_UpperCAmelCase)
							_UpperCamelCase										=  tf.math.reduce_mean(xla_generate(inputs.input_ids    ,		attention_mask=inputs.attention_mask)[0]    ,		axis=-1)
							self.assertTrue(np.allclose(_UpperCAmelCase    ,		_UpperCAmelCase    ,		atol=1e-4))






@require_tf
@slow
class    _UpperCAmelCase(   unittest.TestCase     ):



		@property
		def 						UpperCAmelCase							( self)	->	str:






							'''simple docstring'''
							return [
							    "Today is a beautiful day and I want",
							    "In the city of",
							    "Paris is the capital of France and",
							    "Computers and mobile phones have taken",
							]



		def 						UpperCAmelCase							( self)	->	Any:






							'''simple docstring'''
							_UpperCamelCase										=  'facebook/opt-125m'

							_UpperCamelCase										=  [
							    'Today is a beautiful day and I want to',
							    'In the city of New York, the city',
							    'Paris is the capital of France and the capital',
							    'Computers and mobile phones have taken over the',
							]

							_UpperCamelCase										=  []
							_UpperCamelCase										=  GPTaTokenizer.from_pretrained(_UpperCAmelCase)
							_UpperCamelCase										=  TFOPTForCausalLM.from_pretrained(_UpperCAmelCase)

							for prompt in self.prompts:
												_UpperCamelCase										=  tokenizer(_UpperCAmelCase    ,		return_tensors='''tf''').input_ids

												_UpperCamelCase										=  model.generate(_UpperCAmelCase    ,		max_length=10)

												_UpperCamelCase										=  tokenizer.batch_decode(_UpperCAmelCase    ,		skip_special_tokens=_UpperCAmelCase)
												predicted_outputs += generated_string

							self.assertListEqual(_UpperCAmelCase    ,		_UpperCAmelCase)



		def 						UpperCAmelCase							( self)	->	Dict:






							'''simple docstring'''
							_UpperCamelCase										=  'facebook/opt-350m'

							_UpperCamelCase										=  GPTaTokenizer.from_pretrained(_UpperCAmelCase)
							_UpperCamelCase										=  TFOPTForCausalLM.from_pretrained(_UpperCAmelCase)

							_UpperCamelCase										=  'left'

							# use different length sentences to test batching
							_UpperCamelCase										=  [
							    'Hello, my dog is a little',
							    'Today, I',
							]

							_UpperCamelCase										=  tokenizer(_UpperCAmelCase    ,		return_tensors='''tf'''    ,		padding=_UpperCAmelCase)
							_UpperCamelCase										=  inputs['input_ids']

							_UpperCamelCase										=  model.generate(input_ids=_UpperCAmelCase    ,		attention_mask=inputs['''attention_mask'''])

							_UpperCamelCase										=  tokenizer(sentences[0]    ,		return_tensors='''tf''').input_ids
							_UpperCamelCase										=  model.generate(input_ids=_UpperCAmelCase)

							_UpperCamelCase										=  inputs_non_padded.shape[-1] - tf.math.reduce_sum(
							    tf.cast(inputs['''attention_mask'''][-1]    ,		tf.intaa))
							_UpperCamelCase										=  tokenizer(sentences[1]    ,		return_tensors='''tf''').input_ids
							_UpperCamelCase										=  model.generate(input_ids=_UpperCAmelCase    ,		max_length=model.config.max_length - num_paddings)

							_UpperCamelCase										=  tokenizer.batch_decode(_UpperCAmelCase    ,		skip_special_tokens=_UpperCAmelCase)
							_UpperCamelCase										=  tokenizer.decode(output_non_padded[0]    ,		skip_special_tokens=_UpperCAmelCase)
							_UpperCamelCase										=  tokenizer.decode(output_padded[0]    ,		skip_special_tokens=_UpperCAmelCase)

							_UpperCamelCase										=  [
							    'Hello, my dog is a little bit of a dork.\nI\'m a little bit',
							    'Today, I was in the middle of a conversation with a friend about the',
							]
							self.assertListEqual(_UpperCAmelCase    ,		_UpperCAmelCase)
							self.assertListEqual(_UpperCAmelCase    ,		[non_padded_sentence, padded_sentence])




		def 						UpperCAmelCase							( self)	->	int:






							'''simple docstring'''
							_UpperCamelCase										=  'facebook/opt-350m'

							_UpperCamelCase										=  [
							    'Today is a beautiful day and I want to',
							    'In the city of San Francisco, the city',
							    'Paris is the capital of France and the capital',
							    'Computers and mobile phones have taken over the',
							]

							_UpperCamelCase										=  []
							_UpperCamelCase										=  GPTaTokenizer.from_pretrained(_UpperCAmelCase)
							_UpperCamelCase										=  TFOPTForCausalLM.from_pretrained(_UpperCAmelCase)

							for prompt in self.prompts:
												_UpperCamelCase										=  tokenizer(_UpperCAmelCase    ,		return_tensors='''tf''').input_ids

												_UpperCamelCase										=  model.generate(_UpperCAmelCase    ,		max_length=10)

												_UpperCamelCase										=  tokenizer.batch_decode(_UpperCAmelCase    ,		skip_special_tokens=_UpperCAmelCase)
												predicted_outputs += generated_string

							self.assertListEqual(_UpperCAmelCase    ,		_UpperCAmelCase)








"""simple docstring"""





from typing import Dict, List, Optional, Tuple, Union

import torch

from ...models import AutoencoderKL, TransformeraDModel
from ...schedulers import KarrasDiffusionSchedulers
from ...utils import randn_tensor
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput






class    _UpperCAmelCase(   lowerCamelCase     ):



		def __init__( self    ,		__a    ,		__a    ,		__a    ,		__a = None    ,		)	->	List[str]:






							'''simple docstring'''
							super().__init__()
							self.register_modules(transformer=__a    ,		vae=__a    ,		scheduler=__a)

							# create a imagenet -> id dictionary for easier use
							_UpperCamelCase										=  {}
							if idalabel is not None:
												for key, value in idalabel.items():
																	for label in value.split(''','''):
																						_UpperCamelCase										=  int(__a)
												_UpperCamelCase										=  dict(sorted(self.labels.items()))



		def 						UpperCAmelCase							( self    ,		__a)	->	List[int]:






							'''simple docstring'''

							if not isinstance(__a    ,		__a):
												_UpperCamelCase										=  list(__a)

							for l in label:
												if l not in self.labels:
																	raise ValueError(
																	    F'''{l} does not exist. Please make sure to select one of the following labels: \n {self.labels}.''')

							return [self.labels[l] for l in label]




		@torch.no_grad()
		def __call__( self    ,		__a    ,		__a = 4.0    ,		__a = None    ,		__a = 50    ,		__a = "pil"    ,		__a = True    ,		)	->	Union[ImagePipelineOutput, Tuple]:






							'''simple docstring'''
							_UpperCamelCase										=  len(__a)
							_UpperCamelCase										=  self.transformer.config.sample_size
							_UpperCamelCase										=  self.transformer.config.in_channels

							_UpperCamelCase										=  randn_tensor(
							    shape=(batch_size, latent_channels, latent_size, latent_size)    ,		generator=__a    ,		device=self.device    ,		dtype=self.transformer.dtype    ,		)
							_UpperCamelCase										=  torch.cat([latents] * 2) if guidance_scale > 1 else latents

							_UpperCamelCase										=  torch.tensor(__a    ,		device=self.device).reshape(-1)
							_UpperCamelCase										=  torch.tensor([10_00] * batch_size    ,		device=self.device)
							_UpperCamelCase										=  torch.cat([class_labels, class_null]    ,		0) if guidance_scale > 1 else class_labels

							# set step values
							self.scheduler.set_timesteps(__a)

							for t in self.progress_bar(self.scheduler.timesteps):
												if guidance_scale > 1:
																	_UpperCamelCase										=  latent_model_input[: len(__a) // 2]
																	_UpperCamelCase										=  torch.cat([half, half]    ,		dim=0)
												_UpperCamelCase										=  self.scheduler.scale_model_input(__a    ,		__a)

												_UpperCamelCase										=  t
												if not torch.is_tensor(__a):
																	# TODO: this requires sync between CPU and GPU. So try to pass timesteps as tensors if you can
																	# This would be a good case for the `match` statement (Python 3.10+)
																	_UpperCamelCase										=  latent_model_input.device.type == '''mps'''
																	if isinstance(__a    ,		__a):
																						_UpperCamelCase										=  torch.floataa if is_mps else torch.floataa
																	else:
																						_UpperCamelCase										=  torch.intaa if is_mps else torch.intaa
																	_UpperCamelCase										=  torch.tensor([timesteps]    ,		dtype=__a    ,		device=latent_model_input.device)
												elif len(timesteps.shape) == 0:
																	_UpperCamelCase										=  timesteps[None].to(latent_model_input.device)
												# broadcast to batch dimension in a way that's compatible with ONNX/Core ML
												_UpperCamelCase										=  timesteps.expand(latent_model_input.shape[0])
												# predict noise model_output
												_UpperCamelCase										=  self.transformer(
												    __a    ,		timestep=__a    ,		class_labels=__a).sample

												# perform guidance
												if guidance_scale > 1:
																	_UpperCamelCase			,  _UpperCamelCase										=  noise_pred[:, :latent_channels], noise_pred[:, latent_channels:]
																	_UpperCamelCase			,  _UpperCamelCase										=  torch.split(__a    ,		len(__a) // 2    ,		dim=0)

																	_UpperCamelCase										=  uncond_eps + guidance_scale * (cond_eps - uncond_eps)
																	_UpperCamelCase										=  torch.cat([half_eps, half_eps]    ,		dim=0)

																	_UpperCamelCase										=  torch.cat([eps, rest]    ,		dim=1)

												# learned sigma
												if self.transformer.config.out_channels // 2 == latent_channels:
																	_UpperCamelCase			,  _UpperCamelCase										=  torch.split(__a    ,		__a    ,		dim=1)
												else:
																	_UpperCamelCase										=  noise_pred

												# compute previous image: x_t -> x_t-1
												_UpperCamelCase										=  self.scheduler.step(__a    ,		__a    ,		__a).prev_sample

							if guidance_scale > 1:
												_UpperCamelCase			,  _UpperCamelCase										=  latent_model_input.chunk(2    ,		dim=0)
							else:
												_UpperCamelCase										=  latent_model_input

							_UpperCamelCase										=  1 / self.vae.config.scaling_factor * latents
							_UpperCamelCase										=  self.vae.decode(__a).sample

							_UpperCamelCase										=  (samples / 2 + 0.5).clamp(0    ,		1)

							# we always cast to float32 as this does not cause significant overhead and is compatible with bfloat16
							_UpperCamelCase										=  samples.cpu().permute(0    ,		2    ,		3    ,		1).float().numpy()

							if output_type == "pil":
												_UpperCamelCase										=  self.numpy_to_pil(__a)

							if not return_dict:
												return (samples,)

							return ImagePipelineOutput(images=__a)






