






'''simple docstring'''







import collections
import inspect
import unittest

from transformers import DonutSwinConfig
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import is_torch_available

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


if is_torch_available():
  import torch
  from torch import nn

  from transformers import DonutSwinModel
  from transformers.models.donut.modeling_donut_swin import DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST




class 					__UpperCAmelCase :

      '''simple docstring'''





      def __init__(					self  ,		_UpperCAmelCase  ,		_UpperCAmelCase=13  ,		_UpperCAmelCase=32  ,		_UpperCAmelCase=2  ,		_UpperCAmelCase=3  ,		_UpperCAmelCase=16  ,		_UpperCAmelCase=[1, 2, 1]  ,		_UpperCAmelCase=[2, 2, 4]  ,		_UpperCAmelCase=2  ,		_UpperCAmelCase=2.0  ,		_UpperCAmelCase=True  ,		_UpperCAmelCase=0.0  ,		_UpperCAmelCase=0.0  ,		_UpperCAmelCase=0.1  ,		_UpperCAmelCase="gelu"  ,		_UpperCAmelCase=False  ,		_UpperCAmelCase=True  ,		_UpperCAmelCase=0.02  ,		_UpperCAmelCase=1E-5  ,		_UpperCAmelCase=True  ,		_UpperCAmelCase=None  ,		_UpperCAmelCase=True  ,		_UpperCAmelCase=10  ,		_UpperCAmelCase=8  ,		):
             UpperCAmelCase__	:   List[str]												=	parent
             UpperCAmelCase__	:   List[Any]												=	batch_size
             UpperCAmelCase__	:   int												=	image_size
             UpperCAmelCase__	:   Optional[Any]												=	patch_size
             UpperCAmelCase__	:   Optional[Any]												=	num_channels
             UpperCAmelCase__	:   str												=	embed_dim
             UpperCAmelCase__	:   Union[str, Any]												=	depths
             UpperCAmelCase__	:   str												=	num_heads
             UpperCAmelCase__	:   int												=	window_size
             UpperCAmelCase__	:   Optional[int]												=	mlp_ratio
             UpperCAmelCase__	:   Any												=	qkv_bias
             UpperCAmelCase__	:   Optional[int]												=	hidden_dropout_prob
             UpperCAmelCase__	:   Optional[Any]												=	attention_probs_dropout_prob
             UpperCAmelCase__	:   Optional[int]												=	drop_path_rate
             UpperCAmelCase__	:   Any												=	hidden_act
             UpperCAmelCase__	:   str												=	use_absolute_embeddings
             UpperCAmelCase__	:   Union[str, Any]												=	patch_norm
             UpperCAmelCase__	:   Optional[Any]												=	layer_norm_eps
             UpperCAmelCase__	:   int												=	initializer_range
             UpperCAmelCase__	:   Union[str, Any]												=	is_training
             UpperCAmelCase__	:   List[Any]												=	scope
             UpperCAmelCase__	:   Optional[int]												=	use_labels
             UpperCAmelCase__	:   Any												=	type_sequence_label_size
             UpperCAmelCase__	:   List[Any]												=	encoder_stride




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Tuple												=	floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

             UpperCAmelCase__	:   Any												=	None
             if self.use_labels:
                    UpperCAmelCase__	:   List[str]												=	ids_tensor([self.batch_size]  ,		self.type_sequence_label_size						)

             UpperCAmelCase__	:   List[Any]												=	self.get_config()

             return config, pixel_values, labels




      def 							lowerCamelCase     (					self						):
             return DonutSwinConfig(
                 image_size=self.image_size  ,		patch_size=self.patch_size  ,		num_channels=self.num_channels  ,		embed_dim=self.embed_dim  ,		depths=self.depths  ,		num_heads=self.num_heads  ,		window_size=self.window_size  ,		mlp_ratio=self.mlp_ratio  ,		qkv_bias=self.qkv_bias  ,		hidden_dropout_prob=self.hidden_dropout_prob  ,		attention_probs_dropout_prob=self.attention_probs_dropout_prob  ,		drop_path_rate=self.drop_path_rate  ,		hidden_act=self.hidden_act  ,		use_absolute_embeddings=self.use_absolute_embeddings  ,		path_norm=self.patch_norm  ,		layer_norm_eps=self.layer_norm_eps  ,		initializer_range=self.initializer_range  ,		encoder_stride=self.encoder_stride  ,		)




      def 							lowerCamelCase     (					self  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase						):
             UpperCAmelCase__	:   str												=	DonutSwinModel(config=_UpperCAmelCase						)
             model.to(_UpperCAmelCase						)
             model.eval()
             UpperCAmelCase__	:   List[str]												=	model(_UpperCAmelCase						)

             UpperCAmelCase__	:   Tuple												=	((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths						) - 1))
             UpperCAmelCase__	:   int												=	int(config.embed_dim * 2 ** (len(config.depths						) - 1)						)

             self.parent.assertEqual(result.last_hidden_state.shape  ,		(self.batch_size, expected_seq_len, expected_dim)						)




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Union[str, Any]												=	self.prepare_config_and_inputs()
             (
                 (
                 UpperCAmelCase__
             )							,							(
                 UpperCAmelCase__
             )							,							(
                 UpperCAmelCase__
             )							,							
             )	:   str												=	config_and_inputs
             UpperCAmelCase__	:   Optional[int]												=	{'''pixel_values''': pixel_values}
             return config, inputs_dict




@require_torch
class 					__UpperCAmelCase (		UpperCamelCase__      ,				UpperCamelCase__      ,				unittest.TestCase	):

      '''simple docstring'''





      SCREAMING_SNAKE_CASE				:    str				       =					(DonutSwinModel,) if is_torch_available() else ()
      SCREAMING_SNAKE_CASE				:    List[Any]				       =					{"feature-extraction": DonutSwinModel} if is_torch_available() else {}
      SCREAMING_SNAKE_CASE				:    Tuple				       =					True

      SCREAMING_SNAKE_CASE				:    List[Any]				       =					False
      SCREAMING_SNAKE_CASE				:    Tuple				       =					False
      SCREAMING_SNAKE_CASE				:    Optional[int]				       =					False




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   Optional[Any]												=	DonutSwinModelTester(self						)
             UpperCAmelCase__	:   Dict												=	ConfigTester(self  ,		config_class=_UpperCAmelCase  ,		embed_dim=37						)




      def 							lowerCamelCase     (					self						):
             self.create_and_test_config_common_properties()
             self.config_tester.create_and_test_config_to_json_string()
             self.config_tester.create_and_test_config_to_json_file()
             self.config_tester.create_and_test_config_from_and_save_pretrained()
             self.config_tester.create_and_test_config_with_num_labels()
             self.config_tester.check_config_can_be_init_without_params()
             self.config_tester.check_config_arguments_init()




      def 							lowerCamelCase     (					self						):
             return




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   int												=	self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*_UpperCAmelCase						)




      def 							lowerCamelCase     (					self						):
             # DonutSwin does not use inputs_embeds
             pass




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__							,							UpperCAmelCase__	:   List[Any]												=	self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                    UpperCAmelCase__	:   Union[str, Any]												=	model_class(_UpperCAmelCase						)
                    self.assertIsInstance(model.get_input_embeddings()  ,		(nn.Module)						)
                    UpperCAmelCase__	:   List[str]												=	model.get_output_embeddings()
                    self.assertTrue(x is None or isinstance(_UpperCAmelCase  ,		nn.Linear						)						)




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__							,							UpperCAmelCase__	:   Dict												=	self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                    UpperCAmelCase__	:   Optional[Any]												=	model_class(_UpperCAmelCase						)
                    UpperCAmelCase__	:   Union[str, Any]												=	inspect.signature(model.forward						)
                    # signature.parameters is an OrderedDict => so arg_names order is deterministic
                    UpperCAmelCase__	:   Tuple												=	[*signature.parameters.keys()]

                    UpperCAmelCase__	:   str												=	['''pixel_values''']
                    self.assertListEqual(arg_names[:1]  ,		_UpperCAmelCase						)




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__							,							UpperCAmelCase__	:   Optional[Any]												=	self.model_tester.prepare_config_and_inputs_for_common()
             UpperCAmelCase__	:   Any												=	True

             for model_class in self.all_model_classes:
                    UpperCAmelCase__	:   int												=	True
                    UpperCAmelCase__	:   Union[str, Any]												=	False
                    UpperCAmelCase__	:   Optional[int]												=	True
                    UpperCAmelCase__	:   List[Any]												=	model_class(_UpperCAmelCase						)
                    model.to(_UpperCAmelCase						)
                    model.eval()
                    with torch.no_grad():
                           UpperCAmelCase__	:   str												=	model(**self._prepare_for_class(_UpperCAmelCase  ,		_UpperCAmelCase						)						)
                    UpperCAmelCase__	:   List[Any]												=	outputs.attentions
                    UpperCAmelCase__	:   int												=	len(self.model_tester.depths						)
                    self.assertEqual(len(_UpperCAmelCase						)  ,		_UpperCAmelCase						)

                    # check that output_attentions also work using config
                    del inputs_dict["output_attentions"]
                    UpperCAmelCase__	:   List[Any]												=	True
                    UpperCAmelCase__	:   int												=	config.window_size**2
                    UpperCAmelCase__	:   Optional[Any]												=	model_class(_UpperCAmelCase						)
                    model.to(_UpperCAmelCase						)
                    model.eval()
                    with torch.no_grad():
                           UpperCAmelCase__	:   List[Any]												=	model(**self._prepare_for_class(_UpperCAmelCase  ,		_UpperCAmelCase						)						)
                    UpperCAmelCase__	:   Union[str, Any]												=	outputs.attentions
                    self.assertEqual(len(_UpperCAmelCase						)  ,		_UpperCAmelCase						)

                    self.assertListEqual(
                        list(attentions[0].shape[-3:]						)  ,		[self.model_tester.num_heads[0], window_size_squared, window_size_squared]  ,		)
                    UpperCAmelCase__	:   Union[str, Any]												=	len(_UpperCAmelCase						)

                    # Check attention is always last and order is fine
                    UpperCAmelCase__	:   Any												=	True
                    UpperCAmelCase__	:   Tuple												=	True
                    UpperCAmelCase__	:   Optional[Any]												=	model_class(_UpperCAmelCase						)
                    model.to(_UpperCAmelCase						)
                    model.eval()
                    with torch.no_grad():
                           UpperCAmelCase__	:   str												=	model(**self._prepare_for_class(_UpperCAmelCase  ,		_UpperCAmelCase						)						)

                    if hasattr(self.model_tester  ,		'''num_hidden_states_types'''						):
                           UpperCAmelCase__	:   Tuple												=	self.model_tester.num_hidden_states_types
                    else:
                           # also another +1 for reshaped_hidden_states
                           UpperCAmelCase__	:   int												=	2
                    self.assertEqual(out_len + added_hidden_states  ,		len(_UpperCAmelCase						)						)

                    UpperCAmelCase__	:   Optional[int]												=	outputs.attentions

                    self.assertEqual(len(_UpperCAmelCase						)  ,		_UpperCAmelCase						)

                    self.assertListEqual(
                        list(self_attentions[0].shape[-3:]						)  ,		[self.model_tester.num_heads[0], window_size_squared, window_size_squared]  ,		)




      def 							lowerCamelCase     (					self  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase						):
             UpperCAmelCase__	:   List[Any]												=	model_class(_UpperCAmelCase						)
             model.to(_UpperCAmelCase						)
             model.eval()

             with torch.no_grad():
                    UpperCAmelCase__	:   int												=	model(**self._prepare_for_class(_UpperCAmelCase  ,		_UpperCAmelCase						)						)

             UpperCAmelCase__	:   List[Any]												=	outputs.hidden_states

             UpperCAmelCase__	:   str												=	getattr(
                 self.model_tester  ,		'''expected_num_hidden_layers'''  ,		len(self.model_tester.depths						) + 1						)
             self.assertEqual(len(_UpperCAmelCase						)  ,		_UpperCAmelCase						)

             # DonutSwin has a different seq_length
             UpperCAmelCase__	:   Any												=	(
                 config.patch_size
                 if isinstance(config.patch_size  ,		collections.abc.Iterable						)
                 else (config.patch_size, config.patch_size)
             )

             UpperCAmelCase__	:   Optional[int]												=	(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

             self.assertListEqual(
                 list(hidden_states[0].shape[-2:]						)  ,		[num_patches, self.model_tester.embed_dim]  ,		)

             UpperCAmelCase__	:   Dict												=	outputs.reshaped_hidden_states
             self.assertEqual(len(_UpperCAmelCase						)  ,		_UpperCAmelCase						)

             UpperCAmelCase__							,							UpperCAmelCase__							,							UpperCAmelCase__							,							UpperCAmelCase__	:   int												=	reshaped_hidden_states[0].shape
             UpperCAmelCase__	:   int												=	(
                 reshaped_hidden_states[0].view(_UpperCAmelCase  ,		_UpperCAmelCase  ,		height * width						).permute(0  ,		2  ,		1						)
             )
             self.assertListEqual(
                 list(reshaped_hidden_states.shape[-2:]						)  ,		[num_patches, self.model_tester.embed_dim]  ,		)




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__							,							UpperCAmelCase__	:   List[Any]												=	self.model_tester.prepare_config_and_inputs_for_common()

             UpperCAmelCase__	:   int												=	(
                 self.model_tester.image_size
                 if isinstance(self.model_tester.image_size  ,		collections.abc.Iterable						)
                 else (self.model_tester.image_size, self.model_tester.image_size)
             )

             for model_class in self.all_model_classes:
                    UpperCAmelCase__	:   Any												=	True
                    self.check_hidden_states_output(_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase						)

                    # check that output_hidden_states also work using config
                    del inputs_dict["output_hidden_states"]
                    UpperCAmelCase__	:   List[Any]												=	True

                    self.check_hidden_states_output(_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase						)




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__							,							UpperCAmelCase__	:   List[str]												=	self.model_tester.prepare_config_and_inputs_for_common()
             UpperCAmelCase__	:   Tuple												=	3

             UpperCAmelCase__	:   int												=	(
                 self.model_tester.image_size
                 if isinstance(self.model_tester.image_size  ,		collections.abc.Iterable						)
                 else (self.model_tester.image_size, self.model_tester.image_size)
             )
             UpperCAmelCase__	:   Optional[int]												=	(
                 config.patch_size
                 if isinstance(config.patch_size  ,		collections.abc.Iterable						)
                 else (config.patch_size, config.patch_size)
             )

             UpperCAmelCase__	:   str												=	image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
             UpperCAmelCase__	:   Tuple												=	image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

             for model_class in self.all_model_classes:
                    UpperCAmelCase__	:   Any												=	True
                    self.check_hidden_states_output(_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		(padded_height, padded_width)						)

                    # check that output_hidden_states also work using config
                    del inputs_dict["output_hidden_states"]
                    UpperCAmelCase__	:   Union[str, Any]												=	True
                    self.check_hidden_states_output(_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		(padded_height, padded_width)						)




      @slow
      def 							lowerCamelCase     (					self						):
             for model_name in DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    UpperCAmelCase__	:   List[str]												=	DonutSwinModel.from_pretrained(_UpperCAmelCase						)
                    self.assertIsNotNone(_UpperCAmelCase						)




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__							,							UpperCAmelCase__	:   Tuple												=	self.model_tester.prepare_config_and_inputs_for_common()

             UpperCAmelCase__	:   Any												=	_config_zero_init(_UpperCAmelCase						)
             for model_class in self.all_model_classes:
                    UpperCAmelCase__	:   List[Any]												=	model_class(config=_UpperCAmelCase						)
                    for name, param in model.named_parameters():
                           if "embeddings" not in name and param.requires_grad:
                                  self.assertIn(
                                      ((param.data.mean() * 1E9).round() / 1E9).item()  ,		[0.0, 1.0]  ,		msg=F"""Parameter {name} of model {model_class} seems not properly initialized"""  ,		)







'''simple docstring'''







from typing import Union

import torch
from PIL import Image
from torchvision import transforms as tfms
from tqdm.auto import tqdm
from transformers import CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    UNetaDConditionModel,
)




class 					__UpperCAmelCase (		UpperCamelCase__	):

      '''simple docstring'''





      def __init__(					self  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		):
             super().__init__()

             self.register_modules(vae=_UpperCAmelCase  ,		text_encoder=_UpperCAmelCase  ,		tokenizer=_UpperCAmelCase  ,		unet=_UpperCAmelCase  ,		scheduler=_UpperCAmelCase						)




      def 							lowerCamelCase     (					self  ,		_UpperCAmelCase						):
             with torch.no_grad():
                    UpperCAmelCase__	:   Dict												=	self.vae.encode(tfms.ToTensor()(_UpperCAmelCase						).unsqueeze(0						).to(self.device						) * 2 - 1						)
                    UpperCAmelCase__	:   int												=	0.1_82_15 * latent.latent_dist.sample()
             return latent




      def 							lowerCamelCase     (					self  ,		_UpperCAmelCase						):
             UpperCAmelCase__	:   int												=	(1 / 0.1_82_15) * latent
             with torch.no_grad():
                    UpperCAmelCase__	:   Optional[Any]												=	self.vae.decode(_UpperCAmelCase						).sample
             UpperCAmelCase__	:   List[str]												=	(img / 2 + 0.5).clamp(0  ,		1						)
             UpperCAmelCase__	:   List[Any]												=	img.detach().cpu().permute(0  ,		2  ,		3  ,		1						).numpy()
             UpperCAmelCase__	:   Union[str, Any]												=	(img * 255).round().astype('''uint8'''						)
             return Image.fromarray(img[0]						)




      def 							lowerCamelCase     (					self  ,		_UpperCAmelCase						):
             UpperCAmelCase__	:   Dict												=	self.tokenizer(
                 _UpperCAmelCase  ,		padding='''max_length'''  ,		max_length=self.tokenizer.model_max_length  ,		truncation=_UpperCAmelCase  ,		return_tensors='''pt'''  ,		)

             UpperCAmelCase__	:   Tuple												=	self.text_encoder(text_input.input_ids.to(self.device						)						)[0]

             UpperCAmelCase__	:   Dict												=	self.tokenizer(
                 ''''''  ,		padding='''max_length'''  ,		max_length=self.tokenizer.model_max_length  ,		truncation=_UpperCAmelCase  ,		return_tensors='''pt'''  ,		)

             UpperCAmelCase__	:   List[Any]												=	self.text_encoder(uncond_input.input_ids.to(self.device						)						)[0]

             return torch.cat([uncond_embedding, text_embedding]						)




      def __call__(					self  ,		_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase = 0.3  ,		_UpperCAmelCase = 0.6  ,		_UpperCAmelCase = 0.5  ,		_UpperCAmelCase = 42  ,		_UpperCAmelCase = 50  ,		_UpperCAmelCase = 7.5  ,		):
             UpperCAmelCase__	:   Any												=	steps - int(kmin * steps						)
             UpperCAmelCase__	:   Any												=	steps - int(kmax * steps						)

             UpperCAmelCase__	:   List[str]												=	self.prep_text(_UpperCAmelCase						)

             self.scheduler.set_timesteps(_UpperCAmelCase						)

             UpperCAmelCase__							,							UpperCAmelCase__	:   List[str]												=	img.size
             UpperCAmelCase__	:   str												=	self.encode(_UpperCAmelCase						)

             torch.manual_seed(_UpperCAmelCase						)
             UpperCAmelCase__	:   Union[str, Any]												=	torch.randn(
                 (1, self.unet.config.in_channels, height // 8, width // 8)  ,		).to(self.device						)

             UpperCAmelCase__	:   Optional[int]												=	self.scheduler.add_noise(
                 _UpperCAmelCase  ,		_UpperCAmelCase  ,		timesteps=self.scheduler.timesteps[tmax]  ,		)

             UpperCAmelCase__	:   Any												=	torch.cat([latents] * 2						)

             UpperCAmelCase__	:   Dict												=	self.scheduler.scale_model_input(_UpperCAmelCase  ,		self.scheduler.timesteps[tmax]						)

             with torch.no_grad():
                    UpperCAmelCase__	:   Tuple												=	self.unet(
                        _UpperCAmelCase  ,		self.scheduler.timesteps[tmax]  ,		encoder_hidden_states=_UpperCAmelCase  ,		).sample

             UpperCAmelCase__							,							UpperCAmelCase__	:   List[Any]												=	pred.chunk(2						)
             UpperCAmelCase__	:   List[str]												=	pred_uncond + guidance_scale * (pred_text - pred_uncond)

             UpperCAmelCase__	:   Union[str, Any]												=	self.scheduler.step(_UpperCAmelCase  ,		self.scheduler.timesteps[tmax]  ,		_UpperCAmelCase						).prev_sample

             for i, t in enumerate(tqdm(self.scheduler.timesteps						)						):
                    if i > tmax:
                           if i < tmin:  # layout generation phase
                                  UpperCAmelCase__	:   Dict												=	self.scheduler.add_noise(
                                      _UpperCAmelCase  ,		_UpperCAmelCase  ,		timesteps=_UpperCAmelCase  ,		)

                                  UpperCAmelCase__	:   Union[str, Any]												=	(mix_factor * latents) + (
                                      1 - mix_factor
                                  ) * orig_latents  # interpolating between layout noise and conditionally generated noise to preserve layout sematics
                                  UpperCAmelCase__	:   Tuple												=	torch.cat([input] * 2						)

                           else:  # content generation phase
                                  UpperCAmelCase__	:   Any												=	torch.cat([latents] * 2						)

                           UpperCAmelCase__	:   str												=	self.scheduler.scale_model_input(_UpperCAmelCase  ,		_UpperCAmelCase						)

                           with torch.no_grad():
                                  UpperCAmelCase__	:   Any												=	self.unet(
                                      _UpperCAmelCase  ,		_UpperCAmelCase  ,		encoder_hidden_states=_UpperCAmelCase  ,		).sample

                           UpperCAmelCase__							,							UpperCAmelCase__	:   Tuple												=	pred.chunk(2						)
                           UpperCAmelCase__	:   str												=	pred_uncond + guidance_scale * (pred_text - pred_uncond)

                           UpperCAmelCase__	:   Union[str, Any]												=	self.scheduler.step(_UpperCAmelCase  ,		_UpperCAmelCase  ,		_UpperCAmelCase						).prev_sample

             return self.decode(_UpperCAmelCase						)