
"""simple docstring"""




from typing import List

from packaging import version
from sklearn.metrics import fa_score

import datasets
from datasets.config import PY_VERSION


if PY_VERSION < version.parse('3.8'):
	import importlib_metadata
else:
	import importlib.metadata as importlib_metadata


# TODO(Patrick/Anton)
snake_case			       =		'\\n'

snake_case			       =		'\\n    XTREME-S is a benchmark to evaluate universal cross-lingual speech representations in many languages.\n    XTREME-S covers four task families: speech recognition, classification, speech-to-text translation and retrieval.\n'

snake_case			       =		'\nCompute XTREME-S evaluation metric associated to each XTREME-S dataset.\nArgs:\n    predictions: list of predictions to score.\n        Each translation should be tokenized into a list of tokens.\n    references: list of lists of references for each translation.\n        Each reference should be tokenized into a list of tokens.\n    bleu_kwargs: optional dict of keywords to be passed when computing \'bleu\'.\n        Keywords include Dict can be one of \'smooth_method\', \'smooth_value\', \'force\', \'lowercase\',\n        \'tokenize\', \'use_effective_order\'.\n    wer_kwargs: optional dict of keywords to be passed when computing \'wer\' and \'cer\'.\n        Keywords include \'concatenate_texts\'.\nReturns: depending on the XTREME-S task, one or several of:\n    "accuracy": Accuracy - for \'fleurs-lang_id\', \'minds14\'\n    "f1": F1 score - for \'minds14\'\n    "wer": Word error rate - for \'mls\', \'fleurs-asr\', \'voxpopuli\', \'babel\'\n    "cer": Character error rate - for \'mls\', \'fleurs-asr\', \'voxpopuli\', \'babel\'\n    "bleu": BLEU score according to the `sacrebleu` metric - for \'covost2\'\nExamples:\n\n    >>> xtreme_s_metric = datasets.load_metric(\'xtreme_s\', \'mls\')  # \'mls\', \'voxpopuli\', \'fleurs-asr\' or \'babel\'\n    >>> references = ["it is sunny here", "paper and pen are essentials"]\n    >>> predictions = ["it\'s sunny", "paper pen are essential"]\n    >>> results = xtreme_s_metric.compute(predictions=predictions, references=references)\n    >>> print({k: round(v, 2) for k, v in results.items()})\n    {\'wer\': 0.56, \'cer\': 0.27}\n\n    >>> xtreme_s_metric = datasets.load_metric(\'xtreme_s\', \'covost2\')\n    >>> references = ["bonjour paris", "il est necessaire de faire du sport de temps en temp"]\n    >>> predictions = ["bonjour paris", "il est important de faire du sport souvent"]\n    >>> results = xtreme_s_metric.compute(predictions=predictions, references=references)\n    >>> print({k: round(v, 2) for k, v in results.items()})\n    {\'bleu\': 31.65}\n\n    >>> xtreme_s_metric = datasets.load_metric(\'xtreme_s\', \'fleurs-lang_id\')\n    >>> references = [0, 1, 0, 0, 1]\n    >>> predictions = [0, 1, 1, 0, 0]\n    >>> results = xtreme_s_metric.compute(predictions=predictions, references=references)\n    >>> print({k: round(v, 2) for k, v in results.items()})\n    {\'accuracy\': 0.6}\n\n    >>> xtreme_s_metric = datasets.load_metric(\'xtreme_s\', \'minds14\')\n    >>> references = [0, 1, 0, 0, 1]\n    >>> predictions = [0, 1, 1, 0, 0]\n    >>> results = xtreme_s_metric.compute(predictions=predictions, references=references)\n    >>> print({k: round(v, 2) for k, v in results.items()})\n    {\'f1\': 0.58, \'accuracy\': 0.6}\n'

snake_case			       =		['fleurs-asr', 'mls', 'voxpopuli', 'babel', 'covost2', 'fleurs-lang_id', 'minds14']
snake_case			       =		''

try:
	from jiwer import transforms as tr

	snake_case			       =		True
except ImportError:
	snake_case			       =		False

if _jiwer_available and version.parse(importlib_metadata.version('jiwer')) < version.parse('2.3.0'):




	class 					UpperCamelCase     (	tr.AbstractTransform				):

					"""simple docstring"""



					def __init__(    self		,     lowercase__ = " "      )   ->   Dict:
										"""simple docstring"""







										SCREAMING_SNAKE_CASE           =     sentence_delimiter


					def 							A (    self		,     lowercase__      )   ->   Any:
										"""simple docstring"""







										return list(lowercase__      )




					def 							A (    self		,     lowercase__      )   ->   List[Any]:
										"""simple docstring"""







										SCREAMING_SNAKE_CASE           =     []
										for sent_idx, sentence in enumerate(lowercase__      ):
															chars.extend(self.process_string(lowercase__      )      )
															if self.sentence_delimiter is not None and self.sentence_delimiter != "" and sent_idx < len(lowercase__      ) - 1:
																				chars.append(self.sentence_delimiter      )
										return chars






	snake_case			       =		tr.Compose(
	    [tr.RemoveMultipleSpaces(), tr.Strip(), SentencesToListOfCharacters(SENTENCE_DELIMITER)]
	)
elif _jiwer_available:
	snake_case			       =		tr.Compose(
	    [
	        tr.RemoveMultipleSpaces(),
	        tr.Strip(),
	        tr.ReduceToSingleSentence(SENTENCE_DELIMITER),
	        tr.ReduceToListOfListOfChars(),
	    ]
	)
else:
	snake_case			       =		None

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_      ):
					return float((preds == labels).mean()      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_      ):
					return {
					    "f1": float(fa_score(y_true=SCREAMING_SNAKE_CASE_,					y_pred=SCREAMING_SNAKE_CASE_,					average='macro'      )      ),
					    "accuracy": simple_accuracy(SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_      ),
					}

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_="exp",					SCREAMING_SNAKE_CASE_=None,					SCREAMING_SNAKE_CASE_=False,					SCREAMING_SNAKE_CASE_=False,					SCREAMING_SNAKE_CASE_=None,					SCREAMING_SNAKE_CASE_=False,					):
					# xtreme-s can only have one label
					SCREAMING_SNAKE_CASE           =     [[label] for label in labels]
					SCREAMING_SNAKE_CASE           =     list(SCREAMING_SNAKE_CASE_      )
					try:
										import sacrebleu as scb
					except ImportError:
										raise ValueError(
										    'sacrebleu has to be installed in order to apply the bleu metric for covost2.'
										    'You can install it via `pip install sacrebleu`.'      )

					if version.parse(scb.__version__      ) < version.parse('1.4.12'      ):
										raise ImportWarning(
										    'To use `sacrebleu`, the module `sacrebleu>=1.4.12` is required, and the current version of `sacrebleu` doesn\'t match this condition.\n'
										    'You can install it with `pip install "sacrebleu>=1.4.12"`.'      )

					SCREAMING_SNAKE_CASE           =     len(labels[0]      )
					if any(len(SCREAMING_SNAKE_CASE_      ) != references_per_prediction for refs in labels      ):
										raise ValueError('Sacrebleu requires the same number of references for each prediction'      )
					SCREAMING_SNAKE_CASE           =     [[refs[i] for refs in labels] for i in range(SCREAMING_SNAKE_CASE_      )]
					SCREAMING_SNAKE_CASE           =     scb.corpus_bleu(
					    SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_,					smooth_method=SCREAMING_SNAKE_CASE_,					smooth_value=SCREAMING_SNAKE_CASE_,					force=SCREAMING_SNAKE_CASE_,					lowercase=SCREAMING_SNAKE_CASE_,					use_effective_order=SCREAMING_SNAKE_CASE_,					**({'tokenize': tokenize} if tokenize else {}),					)
					return {"bleu": output.score}

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_      ):
					try:
										from jiwer import compute_measures
					except ImportError:
										raise ValueError(
										    f'''jiwer has to be installed in order to apply the wer metric for {config_name}.'''
										    'You can install it via `pip install jiwer`.'      )

					if concatenate_texts:
										SCREAMING_SNAKE_CASE           =     compute_measures(SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_      )['wer']

										SCREAMING_SNAKE_CASE           =     compute_measures(SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_,					truth_transform=SCREAMING_SNAKE_CASE_,					hypothesis_transform=SCREAMING_SNAKE_CASE_      )['wer']
										return {"wer": wer, "cer": cer}
					else:

										def compute_score(SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_="wer"      ):
															SCREAMING_SNAKE_CASE           =     0
															SCREAMING_SNAKE_CASE           =     0
															for prediction, reference in zip(SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_      ):
																				if score_type == "wer":
																									SCREAMING_SNAKE_CASE           =     compute_measures(SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_      )
																				elif score_type == "cer":
																									SCREAMING_SNAKE_CASE           =     compute_measures(
																									    SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_,					truth_transform=SCREAMING_SNAKE_CASE_,					hypothesis_transform=SCREAMING_SNAKE_CASE_      )
																				incorrect += measures["substitutions"] + measures["deletions"] + measures["insertions"]
																				total += measures["substitutions"] + measures["deletions"] + measures["hits"]
															return incorrect / total

										return {"wer": compute_score(SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_,					'wer'      ), "cer": compute_score(SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_,					'cer'      )}




@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION  ,				_KWARGS_DESCRIPTION				)
class 					UpperCamelCase     (	datasets.Metric				):

				"""simple docstring"""



				def 							A (    self      )   ->   Any:
									"""simple docstring"""







									if self.config_name not in _CONFIG_NAMES:
														raise KeyError(f'''You should supply a configuration name selected in {_CONFIG_NAMES}'''      )

									SCREAMING_SNAKE_CASE           =     'int64' if self.config_name in ['fleurs-lang_id', 'minds14'] else 'string'

									return datasets.MetricInfo(
									    description=_DESCRIPTION		,     citation=_CITATION		,     inputs_description=_KWARGS_DESCRIPTION		,     features=datasets.Features(
									        {'predictions': datasets.Value(lowercase__      ), 'references': datasets.Value(lowercase__      )}      )		,     codebase_urls=[]		,     reference_urls=[]		,     format='numpy'		,     )




				def 							A (    self		,     lowercase__		,     lowercase__		,     lowercase__=None		,     lowercase__=None      )   ->   Union[str, Any]:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =     bleu_kwargs if bleu_kwargs is not None else {}
									SCREAMING_SNAKE_CASE           =     wer_kwargs if wer_kwargs is not None else {}

									if self.config_name == "fleurs-lang_id":
														return {"accuracy": simple_accuracy(lowercase__		,     lowercase__      )}
									elif self.config_name == "minds14":
														return fa_and_simple_accuracy(lowercase__		,     lowercase__      )
									elif self.config_name == "covost2":
														SCREAMING_SNAKE_CASE           =     bleu_kwargs.pop('smooth_method'		,     'exp'      )
														SCREAMING_SNAKE_CASE           =     bleu_kwargs.pop('smooth_value'		,     lowercase__      )
														SCREAMING_SNAKE_CASE           =     bleu_kwargs.pop('force'		,     lowercase__      )
														SCREAMING_SNAKE_CASE           =     bleu_kwargs.pop('lowercase'		,     lowercase__      )
														SCREAMING_SNAKE_CASE           =     bleu_kwargs.pop('tokenize'		,     lowercase__      )
														SCREAMING_SNAKE_CASE           =     bleu_kwargs.pop('use_effective_order'		,     lowercase__      )
														return bleu(
														    preds=lowercase__		,     labels=lowercase__		,     smooth_method=lowercase__		,     smooth_value=lowercase__		,     force=lowercase__		,     lowercase=lowercase__		,     tokenize=lowercase__		,     use_effective_order=lowercase__		,     )
									elif self.config_name in ["fleurs-asr", "mls", "voxpopuli", "babel"]:
														SCREAMING_SNAKE_CASE           =     wer_kwargs.pop('concatenate_texts'		,     lowercase__      )
														return wer_and_cer(lowercase__		,     lowercase__		,     lowercase__		,     self.config_name      )
									else:
														raise KeyError(f'''You should supply a configuration name selected in {_CONFIG_NAMES}'''      )


"""simple docstring"""




from dataclasses import dataclass
from typing import Any, Dict, Optional

import torch
import torch.nn.functional as F
from torch import nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..models.embeddings import ImagePositionalEmbeddings
from ..utils import BaseOutput, deprecate
from .attention import BasicTransformerBlock
from .embeddings import PatchEmbed
from .modeling_utils import ModelMixin




@dataclass
class 					UpperCamelCase     (	__magic_name__				):

				"""simple docstring"""



				UpperCAmelCase_    :				torch.FloatTensor






class 					UpperCamelCase     (	__magic_name__  ,				__magic_name__				):

				"""simple docstring"""



				@register_to_config
				def __init__(    self		,     lowercase__ = 16		,     lowercase__ = 88		,     lowercase__ = None		,     lowercase__ = None		,     lowercase__ = 1		,     lowercase__ = 0.0		,     lowercase__ = 32		,     lowercase__ = None		,     lowercase__ = False		,     lowercase__ = None		,     lowercase__ = None		,     lowercase__ = None		,     lowercase__ = "geglu"		,     lowercase__ = None		,     lowercase__ = False		,     lowercase__ = False		,     lowercase__ = False		,     lowercase__ = "layer_norm"		,     lowercase__ = True		,     )   ->   List[Any]:
									"""simple docstring"""







									super().__init__()
									SCREAMING_SNAKE_CASE           =     use_linear_projection
									SCREAMING_SNAKE_CASE           =     num_attention_heads
									SCREAMING_SNAKE_CASE           =     attention_head_dim
									SCREAMING_SNAKE_CASE           =     num_attention_heads * attention_head_dim

									# 1. Transformer2DModel can process both standard continuous images of shape `(batch_size, num_channels, width, height)` as well as quantized image embeddings of shape `(batch_size, num_image_vectors)`
									# Define whether input is continuous or discrete depending on configuration
									SCREAMING_SNAKE_CASE           =     (in_channels is not None) and (patch_size is None)
									SCREAMING_SNAKE_CASE           =     num_vector_embeds is not None
									SCREAMING_SNAKE_CASE           =     in_channels is not None and patch_size is not None

									if norm_type == "layer_norm" and num_embeds_ada_norm is not None:
														SCREAMING_SNAKE_CASE           =     (
														    f'''The configuration file of this model: {self.__class__} is outdated. `norm_type` is either not set or'''
														    ' incorrectly set to `\'layer_norm\'`.Make sure to set `norm_type` to `\'ada_norm\'` in the config.'
														    ' Please make sure to update the config accordingly as leaving `norm_type` might led to incorrect'
														    ' results in future versions. If you have downloaded this checkpoint from the Hugging Face Hub, it'
														    ' would be very nice if you could open a Pull request for the `transformer/config.json` file'
														)
														deprecate('norm_type!=num_embeds_ada_norm'		,     '1.0.0'		,     lowercase__		,     standard_warn=lowercase__      )
														SCREAMING_SNAKE_CASE           =     'ada_norm'

									if self.is_input_continuous and self.is_input_vectorized:
														raise ValueError(
														    f'''Cannot define both `in_channels`: {in_channels} and `num_vector_embeds`: {num_vector_embeds}. Make'''
														    ' sure that either `in_channels` or `num_vector_embeds` is None.'      )
									elif self.is_input_vectorized and self.is_input_patches:
														raise ValueError(
														    f'''Cannot define both `num_vector_embeds`: {num_vector_embeds} and `patch_size`: {patch_size}. Make'''
														    ' sure that either `num_vector_embeds` or `num_patches` is None.'      )
									elif not self.is_input_continuous and not self.is_input_vectorized and not self.is_input_patches:
														raise ValueError(
														    f'''Has to define `in_channels`: {in_channels}, `num_vector_embeds`: {num_vector_embeds}, or patch_size:'''
														    f''' {patch_size}. Make sure that `in_channels`, `num_vector_embeds` or `num_patches` is not None.'''      )

									# 2. Define input layers
									if self.is_input_continuous:
														SCREAMING_SNAKE_CASE           =     in_channels

														SCREAMING_SNAKE_CASE           =     torch.nn.GroupNorm(num_groups=lowercase__		,     num_channels=lowercase__		,     eps=1E-6		,     affine=lowercase__      )
														if use_linear_projection:
																			SCREAMING_SNAKE_CASE           =     nn.Linear(lowercase__		,     lowercase__      )
														else:
																			SCREAMING_SNAKE_CASE           =     nn.Convad(lowercase__		,     lowercase__		,     kernel_size=1		,     stride=1		,     padding=0      )
									elif self.is_input_vectorized:
														assert sample_size is not None, "Transformer2DModel over discrete input must provide sample_size"
														assert num_vector_embeds is not None, "Transformer2DModel over discrete input must provide num_embed"

														SCREAMING_SNAKE_CASE           =     sample_size
														SCREAMING_SNAKE_CASE           =     sample_size
														SCREAMING_SNAKE_CASE           =     num_vector_embeds
														SCREAMING_SNAKE_CASE           =     self.height * self.width

														SCREAMING_SNAKE_CASE           =     ImagePositionalEmbeddings(
														    num_embed=lowercase__		,     embed_dim=lowercase__		,     height=self.height		,     width=self.width      )
									elif self.is_input_patches:
														assert sample_size is not None, "Transformer2DModel over patched input must provide sample_size"

														SCREAMING_SNAKE_CASE           =     sample_size
														SCREAMING_SNAKE_CASE           =     sample_size

														SCREAMING_SNAKE_CASE           =     patch_size
														SCREAMING_SNAKE_CASE           =     PatchEmbed(
														    height=lowercase__		,     width=lowercase__		,     patch_size=lowercase__		,     in_channels=lowercase__		,     embed_dim=lowercase__		,     )

									# 3. Define transformers blocks
									SCREAMING_SNAKE_CASE           =     nn.ModuleList(
									    [
									        BasicTransformerBlock(
									            lowercase__		,     lowercase__		,     lowercase__		,     dropout=lowercase__		,     cross_attention_dim=lowercase__		,     activation_fn=lowercase__		,     num_embeds_ada_norm=lowercase__		,     attention_bias=lowercase__		,     only_cross_attention=lowercase__		,     upcast_attention=lowercase__		,     norm_type=lowercase__		,     norm_elementwise_affine=lowercase__		,     )
									        for d in range(lowercase__      )
									    ]      )

									# 4. Define output layers
									SCREAMING_SNAKE_CASE           =     in_channels if out_channels is None else out_channels
									if self.is_input_continuous:
														# TODO: should use out_channels for continuous projections
														if use_linear_projection:
																			SCREAMING_SNAKE_CASE           =     nn.Linear(lowercase__		,     lowercase__      )
														else:
																			SCREAMING_SNAKE_CASE           =     nn.Convad(lowercase__		,     lowercase__		,     kernel_size=1		,     stride=1		,     padding=0      )
									elif self.is_input_vectorized:
														SCREAMING_SNAKE_CASE           =     nn.LayerNorm(lowercase__      )
														SCREAMING_SNAKE_CASE           =     nn.Linear(lowercase__		,     self.num_vector_embeds - 1      )
									elif self.is_input_patches:
														SCREAMING_SNAKE_CASE           =     nn.LayerNorm(lowercase__		,     elementwise_affine=lowercase__		,     eps=1E-6      )
														SCREAMING_SNAKE_CASE           =     nn.Linear(lowercase__		,     2 * inner_dim      )
														SCREAMING_SNAKE_CASE           =     nn.Linear(lowercase__		,     patch_size * patch_size * self.out_channels      )




				def 							A (    self		,     lowercase__		,     lowercase__ = None		,     lowercase__ = None		,     lowercase__ = None		,     lowercase__ = None		,     lowercase__ = None		,     lowercase__ = None		,     lowercase__ = True		,     )   ->   List[Any]:
									"""simple docstring"""







									if attention_mask is not None and attention_mask.ndim == 2:
														# assume that mask is expressed as:
														#   (1 = keep,      0 = discard)
														# convert mask into a bias that can be added to attention scores:
														#       (keep = +0,     discard = -10000.0)
														SCREAMING_SNAKE_CASE           =     (1 - attention_mask.to(hidden_states.dtype      )) * -10_000.0
														SCREAMING_SNAKE_CASE           =     attention_mask.unsqueeze(1      )

									# convert encoder_attention_mask to a bias the same way we do for attention_mask
									if encoder_attention_mask is not None and encoder_attention_mask.ndim == 2:
														SCREAMING_SNAKE_CASE           =     (1 - encoder_attention_mask.to(hidden_states.dtype      )) * -10_000.0
														SCREAMING_SNAKE_CASE           =     encoder_attention_mask.unsqueeze(1      )

									# 1. Input
									if self.is_input_continuous:
														SCREAMING_SNAKE_CASE     ,   SCREAMING_SNAKE_CASE     ,   SCREAMING_SNAKE_CASE     ,   SCREAMING_SNAKE_CASE           =     hidden_states.shape
														SCREAMING_SNAKE_CASE           =     hidden_states

														SCREAMING_SNAKE_CASE           =     self.norm(lowercase__      )
														if not self.use_linear_projection:
																			SCREAMING_SNAKE_CASE           =     self.proj_in(lowercase__      )
																			SCREAMING_SNAKE_CASE           =     hidden_states.shape[1]
																			SCREAMING_SNAKE_CASE           =     hidden_states.permute(0		,     2		,     3		,     1      ).reshape(lowercase__		,     height * width		,     lowercase__      )
														else:
																			SCREAMING_SNAKE_CASE           =     hidden_states.shape[1]
																			SCREAMING_SNAKE_CASE           =     hidden_states.permute(0		,     2		,     3		,     1      ).reshape(lowercase__		,     height * width		,     lowercase__      )
																			SCREAMING_SNAKE_CASE           =     self.proj_in(lowercase__      )
									elif self.is_input_vectorized:
														SCREAMING_SNAKE_CASE           =     self.latent_image_embedding(lowercase__      )
									elif self.is_input_patches:
														SCREAMING_SNAKE_CASE           =     self.pos_embed(lowercase__      )

									# 2. Blocks
									for block in self.transformer_blocks:
														SCREAMING_SNAKE_CASE           =     block(
														    lowercase__		,     attention_mask=lowercase__		,     encoder_hidden_states=lowercase__		,     encoder_attention_mask=lowercase__		,     timestep=lowercase__		,     cross_attention_kwargs=lowercase__		,     class_labels=lowercase__		,     )

									# 3. Output
									if self.is_input_continuous:
														if not self.use_linear_projection:
																			SCREAMING_SNAKE_CASE           =     hidden_states.reshape(lowercase__		,     lowercase__		,     lowercase__		,     lowercase__      ).permute(0		,     3		,     1		,     2      ).contiguous()
																			SCREAMING_SNAKE_CASE           =     self.proj_out(lowercase__      )
														else:
																			SCREAMING_SNAKE_CASE           =     self.proj_out(lowercase__      )
																			SCREAMING_SNAKE_CASE           =     hidden_states.reshape(lowercase__		,     lowercase__		,     lowercase__		,     lowercase__      ).permute(0		,     3		,     1		,     2      ).contiguous()

														SCREAMING_SNAKE_CASE           =     hidden_states + residual
									elif self.is_input_vectorized:
														SCREAMING_SNAKE_CASE           =     self.norm_out(lowercase__      )
														SCREAMING_SNAKE_CASE           =     self.out(lowercase__      )
														# (batch, self.num_vector_embeds - 1, self.num_latent_pixels)
														SCREAMING_SNAKE_CASE           =     logits.permute(0		,     2		,     1      )

														# log(p(x_0))
														SCREAMING_SNAKE_CASE           =     F.log_softmax(logits.double()		,     dim=1      ).float()
									elif self.is_input_patches:
														# TODO: cleanup!
														SCREAMING_SNAKE_CASE           =     self.transformer_blocks[0].norma.emb(
														    lowercase__		,     lowercase__		,     hidden_dtype=hidden_states.dtype      )
														SCREAMING_SNAKE_CASE     ,   SCREAMING_SNAKE_CASE           =     self.proj_out_a(F.silu(lowercase__      )      ).chunk(2		,     dim=1      )
														SCREAMING_SNAKE_CASE           =     self.norm_out(lowercase__      ) * (1 + scale[:, None]) + shift[:, None]
														SCREAMING_SNAKE_CASE           =     self.proj_out_a(lowercase__      )

														# unpatchify
														SCREAMING_SNAKE_CASE           =     SCREAMING_SNAKE_CASE           =     int(hidden_states.shape[1] ** 0.5      )
														SCREAMING_SNAKE_CASE           =     hidden_states.reshape(
														    shape=(-1, height, width, self.patch_size, self.patch_size, self.out_channels)      )
														SCREAMING_SNAKE_CASE           =     torch.einsum('nhwpqc->nchpwq'		,     lowercase__      )
														SCREAMING_SNAKE_CASE           =     hidden_states.reshape(
														    shape=(-1, self.out_channels, height * self.patch_size, width * self.patch_size)      )

									if not return_dict:
														return (output,)

									return TransformeraDModelOutput(sample=lowercase__      )
