






import logging
import os
from dataclasses import dataclass
from typing import List, Optional, Union

import tqdm
from filelock import FileLock

from transformers import (
    BartTokenizer,
    BartTokenizerFast,
    DataProcessor,
    PreTrainedTokenizer,
    RobertaTokenizer,
    RobertaTokenizerFast,
    XLMRobertaTokenizer,
    is_tf_available,
    is_torch_available,
)


__UpperCAmelCase								=						logging.getLogger(__name__)



@dataclass(frozen=_snake_case			)
class   lowerCamelCase      :







		'''simple docstring'''



		_snake_case    :    str
		_snake_case    :    str
		_snake_case    :    Optional[str]       						=  None
		_snake_case    :    Optional[str]       						=  None
		_snake_case    :    Optional[str]       						=  None





@dataclass(frozen=_snake_case			)
class   lowerCamelCase      :







		'''simple docstring'''



		_snake_case    :    List[int]
		_snake_case    :    Optional[List[int]]       						=  None
		_snake_case    :    Optional[List[int]]       						=  None
		_snake_case    :    Optional[Union[int, float]]       						=  None
		_snake_case    :    Optional[int]       						=  None


if is_torch_available():
		import torch
		from torch.utils.data import Dataset



		class   lowerCamelCase      (_snake_case			):







				'''simple docstring'''



				_snake_case    :    List[InputFeatures]



				def __init__(							self				,		_UpperCamelCase				,		_UpperCamelCase				,		_UpperCamelCase				,		_UpperCamelCase = None				,		_UpperCamelCase=False				,		_UpperCamelCase = False				,		)	->							Tuple:
									UpperCAmelCase_    :      List[Any]            =						hans_processors[task]()

									UpperCAmelCase_    :      Tuple            =						os.path.join(
									    _UpperCamelCase				,		'cached_{}_{}_{}_{}'.format(
									        'dev' if evaluate else 'train'				,		tokenizer.__class__.__name__				,		str(_UpperCamelCase   )				,		_UpperCamelCase				,		)				,		)
									UpperCAmelCase_    :      Optional[Any]            =						processor.get_labels()
									if tokenizer.__class__ in (
									    RobertaTokenizer,
									    RobertaTokenizerFast,
									    XLMRobertaTokenizer,
									    BartTokenizer,
									    BartTokenizerFast,
									):
														# HACK(label indices are swapped in RoBERTa pretrained model)
														UpperCAmelCase_       ,  UpperCAmelCase_    :      Union[str, Any]            =						label_list[2], label_list[1]
									UpperCAmelCase_    :      str            =						label_list

									# Make sure only the first process in distributed training processes the dataset,
									# and the others will use the cache.
									UpperCAmelCase_    :      Any            =						cached_features_file + '.lock'
									with FileLock(_UpperCamelCase   ):
														if os.path.exists(_UpperCamelCase   ) and not overwrite_cache:
																			logger.info(f"Loading features from cached file {cached_features_file}"   )
																			UpperCAmelCase_    :      Union[str, Any]            =						torch.load(_UpperCamelCase   )
														else:
																			logger.info(f"Creating features from dataset file at {data_dir}"   )

																			UpperCAmelCase_    :      List[Any]            =						(
																			    processor.get_dev_examples(_UpperCamelCase   ) if evaluate else processor.get_train_examples(_UpperCamelCase   )
																			)

																			logger.info('Training examples: %s'				,		len(_UpperCamelCase   )   )
																			UpperCAmelCase_    :      Any            =						hans_convert_examples_to_features(_UpperCamelCase				,		_UpperCamelCase				,		_UpperCamelCase				,		_UpperCamelCase   )
																			logger.info('Saving features into cached file %s'				,		_UpperCamelCase   )
																			torch.save(self.features				,		_UpperCamelCase   )



				def __len__(							self   )	->							int:
									return len(self.features   )



				def __getitem__(							self				,		_UpperCamelCase   )	->							InputFeatures:
									return self.features[i]



				def 					__UpperCAmelCase			(							self   )	->							Optional[Any]:
									return self.label_list


if is_tf_available():
		import tensorflow as tf



		class   lowerCamelCase      :







				'''simple docstring'''



				_snake_case    :    List[InputFeatures]



				def __init__(							self				,		_UpperCamelCase				,		_UpperCamelCase				,		_UpperCamelCase				,		_UpperCamelCase = 1_2_8				,		_UpperCamelCase=False				,		_UpperCamelCase = False				,		)	->							Optional[int]:
									UpperCAmelCase_    :      Dict            =						hans_processors[task]()
									UpperCAmelCase_    :      Dict            =						processor.get_labels()
									if tokenizer.__class__ in (
									    RobertaTokenizer,
									    RobertaTokenizerFast,
									    XLMRobertaTokenizer,
									    BartTokenizer,
									    BartTokenizerFast,
									):
														# HACK(label indices are swapped in RoBERTa pretrained model)
														UpperCAmelCase_       ,  UpperCAmelCase_    :      Union[str, Any]            =						label_list[2], label_list[1]
									UpperCAmelCase_    :      str            =						label_list

									UpperCAmelCase_    :      List[str]            =						processor.get_dev_examples(_UpperCamelCase   ) if evaluate else processor.get_train_examples(_UpperCamelCase   )
									UpperCAmelCase_    :      Union[str, Any]            =						hans_convert_examples_to_features(_UpperCamelCase				,		_UpperCamelCase				,		_UpperCamelCase				,		_UpperCamelCase   )

									def gen():
														for ex_index, ex in tqdm.tqdm(enumerate(self.features   )				,		desc='convert examples to features'   ):
																			if ex_index % 1_0_0_0_0 == 0:
																								logger.info('Writing example %d of %d' % (ex_index, len(_UpperCamelCase   ))   )

																			yield (
																			    {
																			        "example_id": 0,
																			        "input_ids": ex.input_ids,
																			        "attention_mask": ex.attention_mask,
																			        "token_type_ids": ex.token_type_ids,
																			    },
																			    ex.label,
																			)

									UpperCAmelCase_    :      Tuple            =						tf.data.Dataset.from_generator(
									    _UpperCamelCase				,		(
									        {
									            'example_id': tf.intaa,
									            'input_ids': tf.intaa,
									            'attention_mask': tf.intaa,
									            'token_type_ids': tf.intaa,
									        },
									        tf.intaa,
									    )				,		(
									        {
									            'example_id': tf.TensorShape([]   ),
									            'input_ids': tf.TensorShape([None, None]   ),
									            'attention_mask': tf.TensorShape([None, None]   ),
									            'token_type_ids': tf.TensorShape([None, None]   ),
									        },
									        tf.TensorShape([]   ),
									    )				,		)



				def 					__UpperCAmelCase			(							self   )	->							Optional[int]:
									return self.dataset



				def __len__(							self   )	->							int:
									return len(self.features   )



				def __getitem__(							self				,		_UpperCamelCase   )	->							InputFeatures:
									return self.features[i]



				def 					__UpperCAmelCase			(							self   )	->							List[str]:
									return self.label_list



class   lowerCamelCase      (_snake_case			):







		'''simple docstring'''



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase   )	->							Optional[int]:
							return self._create_examples(self._read_tsv(os.path.join(_UpperCamelCase				,		'heuristics_train_set.txt'   )   )				,		'train'   )



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase   )	->							Any:
							return self._create_examples(self._read_tsv(os.path.join(_UpperCamelCase				,		'heuristics_evaluation_set.txt'   )   )				,		'dev'   )



		def 					__UpperCAmelCase			(							self   )	->							Tuple:
							return ["contradiction", "entailment", "neutral"]



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase				,		_UpperCamelCase   )	->							Dict:
							UpperCAmelCase_    :      List[str]            =						[]
							for i, line in enumerate(_UpperCamelCase   ):
												if i == 0:
																	continue
												UpperCAmelCase_    :      Dict            =						'%s-%s' % (set_type, line[0])
												UpperCAmelCase_    :      Tuple            =						line[5]
												UpperCAmelCase_    :      Tuple            =						line[6]
												UpperCAmelCase_    :      Dict            =						line[7][2:] if line[7].startswith('ex'   ) else line[7]
												UpperCAmelCase_    :      Tuple            =						line[0]
												examples.append(InputExample(guid=_UpperCamelCase				,		text_a=_UpperCamelCase				,		text_b=_UpperCamelCase				,		label=_UpperCamelCase				,		pairID=_UpperCamelCase   )   )
							return examples





def      lowercase__      (     __snake_case    :							List[InputExample]     ,       __snake_case    :							List[str]     ,       __snake_case    :							int     ,       __snake_case    :							PreTrainedTokenizer     ,       ):


					'''simple docstring'''


					UpperCAmelCase_    :      List[str]            =						{label: i for i, label in enumerate(__snake_case  )}

					UpperCAmelCase_    :      Optional[int]            =						[]
					for ex_index, example in tqdm.tqdm(enumerate(__snake_case  )     ,       desc='convert examples to features'  ):
										if ex_index % 10_000 == 0:
															logger.info('Writing example %d' % (ex_index)  )

										UpperCAmelCase_    :      List[Any]            =						tokenizer(
										    example.text_a     ,       example.text_b     ,       add_special_tokens=__snake_case     ,       max_length=__snake_case     ,       padding='max_length'     ,       truncation=__snake_case     ,       return_overflowing_tokens=__snake_case     ,       )

										UpperCAmelCase_    :      str            =						label_map[example.label] if example.label in label_map else 0

										UpperCAmelCase_    :      List[str]            =						int(example.pairID  )

										features.append(InputFeatures(**__snake_case     ,       label=__snake_case     ,       pairID=__snake_case  )  )

					for i, example in enumerate(examples[:5]  ):
										logger.info('*** Example ***'  )
										logger.info(F"guid: {example}"  )
										logger.info(F"features: {features[i]}"  )

					return features


__UpperCAmelCase								=						{
    'hans': 3,
}






__UpperCAmelCase								=						{
    'hans': HansProcessor,
}














from dataclasses import dataclass
from typing import Dict, Optional, Tuple, Union

import torch
import torch.nn as nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, apply_forward_hook
from .attention_processor import AttentionProcessor, AttnProcessor
from .modeling_utils import ModelMixin
from .vae import Decoder, DecoderOutput, DiagonalGaussianDistribution, Encoder



@dataclass
class   lowerCamelCase      (_snake_case			):







		'''simple docstring'''



		_snake_case    :    "DiagonalGaussianDistribution"





class   lowerCamelCase      (_snake_case ,  _snake_case			):







		'''simple docstring'''



		_snake_case    :    Optional[int]       						=  True



		@register_to_config
		def __init__(							self				,		_UpperCamelCase = 3				,		_UpperCamelCase = 3				,		_UpperCamelCase = ("DownEncoderBlock2D",)				,		_UpperCamelCase = ("UpDecoderBlock2D",)				,		_UpperCamelCase = (6_4,)				,		_UpperCamelCase = 1				,		_UpperCamelCase = "silu"				,		_UpperCamelCase = 4				,		_UpperCamelCase = 3_2				,		_UpperCamelCase = 3_2				,		_UpperCamelCase = 0.1_82_15				,		)	->							List[Any]:
							super().__init__()

							# pass init params to Encoder
							UpperCAmelCase_    :      List[str]            =						Encoder(
							    in_channels=_UpperCamelCase				,		out_channels=_UpperCamelCase				,		down_block_types=_UpperCamelCase				,		block_out_channels=_UpperCamelCase				,		layers_per_block=_UpperCamelCase				,		act_fn=_UpperCamelCase				,		norm_num_groups=_UpperCamelCase				,		double_z=_UpperCamelCase				,		)

							# pass init params to Decoder
							UpperCAmelCase_    :      Dict            =						Decoder(
							    in_channels=_UpperCamelCase				,		out_channels=_UpperCamelCase				,		up_block_types=_UpperCamelCase				,		block_out_channels=_UpperCamelCase				,		layers_per_block=_UpperCamelCase				,		norm_num_groups=_UpperCamelCase				,		act_fn=_UpperCamelCase				,		)

							UpperCAmelCase_    :      Any            =						nn.Convad(2 * latent_channels				,		2 * latent_channels				,		1   )
							UpperCAmelCase_    :      List[Any]            =						nn.Convad(_UpperCamelCase				,		_UpperCamelCase				,		1   )

							UpperCAmelCase_    :      Any            =						False
							UpperCAmelCase_    :      int            =						False

							# only relevant if vae tiling is enabled
							UpperCAmelCase_    :      Optional[int]            =						self.config.sample_size
							UpperCAmelCase_    :      int            =						(
							    self.config.sample_size[0]
							    if isinstance(self.config.sample_size				,		(list, tuple)   )
							    else self.config.sample_size
							)
							UpperCAmelCase_    :      Union[str, Any]            =						int(sample_size / (2 ** (len(self.config.block_out_channels   ) - 1))   )
							UpperCAmelCase_    :      Optional[Any]            =						0.25



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase				,		_UpperCamelCase=False   )	->							List[str]:
							if isinstance(_UpperCamelCase				,		(Encoder, Decoder)   ):
												UpperCAmelCase_    :      Union[str, Any]            =						value



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase = True   )	->							int:
							UpperCAmelCase_    :      Tuple            =						use_tiling



		def 					__UpperCAmelCase			(							self   )	->							Dict:
							self.enable_tiling(_UpperCamelCase   )



		def 					__UpperCAmelCase			(							self   )	->							Optional[Any]:
							UpperCAmelCase_    :      str            =						True



		def 					__UpperCAmelCase			(							self   )	->							List[Any]:
							UpperCAmelCase_    :      Optional[int]            =						False



		@property
		# Copied from diffusers.models.unet_2d_condition.UNet2DConditionModel.attn_processors
		def 					__UpperCAmelCase			(							self   )	->							Dict[str, AttentionProcessor]:
							UpperCAmelCase_    :      Optional[int]            =						{}

							def fn_recursive_add_processors(_UpperCamelCase				,		_UpperCamelCase				,		_UpperCamelCase   ):
												if hasattr(_UpperCamelCase				,		'set_processor'   ):
																	UpperCAmelCase_    :      Optional[int]            =						module.processor

												for sub_name, child in module.named_children():
																	fn_recursive_add_processors(f"{name}.{sub_name}"				,		_UpperCamelCase				,		_UpperCamelCase   )

												return processors

							for name, module in self.named_children():
												fn_recursive_add_processors(_UpperCamelCase				,		_UpperCamelCase				,		_UpperCamelCase   )

							return processors



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase   )	->							List[Any]:
							UpperCAmelCase_    :      Union[str, Any]            =						len(self.attn_processors.keys()   )

							if isinstance(_UpperCamelCase				,		_UpperCamelCase   ) and len(_UpperCamelCase   ) != count:
												raise ValueError(
												    f"A dict of processors was passed, but the number of processors {len(_UpperCamelCase   )} does not match the"
												    f" number of attention layers: {count}. Please make sure to pass {count} processor classes."   )

							def fn_recursive_attn_processor(_UpperCamelCase				,		_UpperCamelCase				,		_UpperCamelCase   ):
												if hasattr(_UpperCamelCase				,		'set_processor'   ):
																	if not isinstance(_UpperCamelCase				,		_UpperCamelCase   ):
																						module.set_processor(_UpperCamelCase   )
																	else:
																						module.set_processor(processor.pop(f"{name}.processor"   )   )

												for sub_name, child in module.named_children():
																	fn_recursive_attn_processor(f"{name}.{sub_name}"				,		_UpperCamelCase				,		_UpperCamelCase   )

							for name, module in self.named_children():
												fn_recursive_attn_processor(_UpperCamelCase				,		_UpperCamelCase				,		_UpperCamelCase   )



		def 					__UpperCAmelCase			(							self   )	->							Union[str, Any]:
							self.set_attn_processor(AttnProcessor()   )



		@apply_forward_hook
		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase				,		_UpperCamelCase = True   )	->							AutoencoderKLOutput:
							if self.use_tiling and (x.shape[-1] > self.tile_sample_min_size or x.shape[-2] > self.tile_sample_min_size):
												return self.tiled_encode(_UpperCamelCase				,		return_dict=_UpperCamelCase   )

							if self.use_slicing and x.shape[0] > 1:
												UpperCAmelCase_    :      Union[str, Any]            =						[self.encoder(_UpperCamelCase   ) for x_slice in x.split(1   )]
												UpperCAmelCase_    :      Tuple            =						torch.cat(_UpperCamelCase   )
							else:
												UpperCAmelCase_    :      List[Any]            =						self.encoder(_UpperCamelCase   )

							UpperCAmelCase_    :      Optional[Any]            =						self.quant_conv(_UpperCamelCase   )
							UpperCAmelCase_    :      Tuple            =						DiagonalGaussianDistribution(_UpperCamelCase   )

							if not return_dict:
												return (posterior,)

							return AutoencoderKLOutput(latent_dist=_UpperCamelCase   )



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase				,		_UpperCamelCase = True   )	->							Union[DecoderOutput, torch.FloatTensor]:
							if self.use_tiling and (z.shape[-1] > self.tile_latent_min_size or z.shape[-2] > self.tile_latent_min_size):
												return self.tiled_decode(_UpperCamelCase				,		return_dict=_UpperCamelCase   )

							UpperCAmelCase_    :      str            =						self.post_quant_conv(_UpperCamelCase   )
							UpperCAmelCase_    :      List[str]            =						self.decoder(_UpperCamelCase   )

							if not return_dict:
												return (dec,)

							return DecoderOutput(sample=_UpperCamelCase   )



		@apply_forward_hook
		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase				,		_UpperCamelCase = True   )	->							Union[DecoderOutput, torch.FloatTensor]:
							if self.use_slicing and z.shape[0] > 1:
												UpperCAmelCase_    :      List[str]            =						[self._decode(_UpperCamelCase   ).sample for z_slice in z.split(1   )]
												UpperCAmelCase_    :      Dict            =						torch.cat(_UpperCamelCase   )
							else:
												UpperCAmelCase_    :      Any            =						self._decode(_UpperCamelCase   ).sample

							if not return_dict:
												return (decoded,)

							return DecoderOutput(sample=_UpperCamelCase   )



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase				,		_UpperCamelCase				,		_UpperCamelCase   )	->							Any:
							UpperCAmelCase_    :      Tuple            =						min(a.shape[2]				,		b.shape[2]				,		_UpperCamelCase   )
							for y in range(_UpperCamelCase   ):
												UpperCAmelCase_    :      str            =						a[:, :, -blend_extent + y, :] * (1 - y / blend_extent) + b[:, :, y, :] * (y / blend_extent)
							return b



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase				,		_UpperCamelCase				,		_UpperCamelCase   )	->							Dict:
							UpperCAmelCase_    :      Tuple            =						min(a.shape[3]				,		b.shape[3]				,		_UpperCamelCase   )
							for x in range(_UpperCamelCase   ):
												UpperCAmelCase_    :      int            =						a[:, :, :, -blend_extent + x] * (1 - x / blend_extent) + b[:, :, :, x] * (x / blend_extent)
							return b



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase				,		_UpperCamelCase = True   )	->							AutoencoderKLOutput:
							UpperCAmelCase_    :      Any            =						int(self.tile_sample_min_size * (1 - self.tile_overlap_factor)   )
							UpperCAmelCase_    :      Tuple            =						int(self.tile_latent_min_size * self.tile_overlap_factor   )
							UpperCAmelCase_    :      Optional[int]            =						self.tile_latent_min_size - blend_extent

							# Split the image into 512x512 tiles and encode them separately.
							UpperCAmelCase_    :      List[str]            =						[]
							for i in range(0				,		x.shape[2]				,		_UpperCamelCase   ):
												UpperCAmelCase_    :      Any            =						[]
												for j in range(0				,		x.shape[3]				,		_UpperCamelCase   ):
																	UpperCAmelCase_    :      Any            =						x[:, :, i : i + self.tile_sample_min_size, j : j + self.tile_sample_min_size]
																	UpperCAmelCase_    :      Dict            =						self.encoder(_UpperCamelCase   )
																	UpperCAmelCase_    :      List[str]            =						self.quant_conv(_UpperCamelCase   )
																	row.append(_UpperCamelCase   )
												rows.append(_UpperCamelCase   )
							UpperCAmelCase_    :      str            =						[]
							for i, row in enumerate(_UpperCamelCase   ):
												UpperCAmelCase_    :      List[Any]            =						[]
												for j, tile in enumerate(_UpperCamelCase   ):
																	# blend the above tile and the left tile
																	# to the current tile and add the current tile to the result row
																	if i > 0:
																						UpperCAmelCase_    :      Dict            =						self.blend_v(rows[i - 1][j]				,		_UpperCamelCase				,		_UpperCamelCase   )
																	if j > 0:
																						UpperCAmelCase_    :      List[str]            =						self.blend_h(row[j - 1]				,		_UpperCamelCase				,		_UpperCamelCase   )
																	result_row.append(tile[:, :, :row_limit, :row_limit]   )
												result_rows.append(torch.cat(_UpperCamelCase				,		dim=3   )   )

							UpperCAmelCase_    :      Union[str, Any]            =						torch.cat(_UpperCamelCase				,		dim=2   )
							UpperCAmelCase_    :      List[Any]            =						DiagonalGaussianDistribution(_UpperCamelCase   )

							if not return_dict:
												return (posterior,)

							return AutoencoderKLOutput(latent_dist=_UpperCamelCase   )



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase				,		_UpperCamelCase = True   )	->							Union[DecoderOutput, torch.FloatTensor]:
							UpperCAmelCase_    :      str            =						int(self.tile_latent_min_size * (1 - self.tile_overlap_factor)   )
							UpperCAmelCase_    :      Dict            =						int(self.tile_sample_min_size * self.tile_overlap_factor   )
							UpperCAmelCase_    :      Dict            =						self.tile_sample_min_size - blend_extent

							# Split z into overlapping 64x64 tiles and decode them separately.
							# The tiles have an overlap to avoid seams between tiles.
							UpperCAmelCase_    :      Union[str, Any]            =						[]
							for i in range(0				,		z.shape[2]				,		_UpperCamelCase   ):
												UpperCAmelCase_    :      List[str]            =						[]
												for j in range(0				,		z.shape[3]				,		_UpperCamelCase   ):
																	UpperCAmelCase_    :      List[str]            =						z[:, :, i : i + self.tile_latent_min_size, j : j + self.tile_latent_min_size]
																	UpperCAmelCase_    :      Optional[Any]            =						self.post_quant_conv(_UpperCamelCase   )
																	UpperCAmelCase_    :      Tuple            =						self.decoder(_UpperCamelCase   )
																	row.append(_UpperCamelCase   )
												rows.append(_UpperCamelCase   )
							UpperCAmelCase_    :      Optional[Any]            =						[]
							for i, row in enumerate(_UpperCamelCase   ):
												UpperCAmelCase_    :      List[Any]            =						[]
												for j, tile in enumerate(_UpperCamelCase   ):
																	# blend the above tile and the left tile
																	# to the current tile and add the current tile to the result row
																	if i > 0:
																						UpperCAmelCase_    :      Union[str, Any]            =						self.blend_v(rows[i - 1][j]				,		_UpperCamelCase				,		_UpperCamelCase   )
																	if j > 0:
																						UpperCAmelCase_    :      Optional[Any]            =						self.blend_h(row[j - 1]				,		_UpperCamelCase				,		_UpperCamelCase   )
																	result_row.append(tile[:, :, :row_limit, :row_limit]   )
												result_rows.append(torch.cat(_UpperCamelCase				,		dim=3   )   )

							UpperCAmelCase_    :      Dict            =						torch.cat(_UpperCamelCase				,		dim=2   )
							if not return_dict:
												return (dec,)

							return DecoderOutput(sample=_UpperCamelCase   )



		def 					__UpperCAmelCase			(							self				,		_UpperCamelCase				,		_UpperCamelCase = False				,		_UpperCamelCase = True				,		_UpperCamelCase = None				,		)	->							Union[DecoderOutput, torch.FloatTensor]:
							UpperCAmelCase_    :      Optional[Any]            =						sample
							UpperCAmelCase_    :      Union[str, Any]            =						self.encode(_UpperCamelCase   ).latent_dist
							if sample_posterior:
												UpperCAmelCase_    :      str            =						posterior.sample(generator=_UpperCamelCase   )
							else:
												UpperCAmelCase_    :      int            =						posterior.mode()
							UpperCAmelCase_    :      Dict            =						self.decode(_UpperCamelCase   ).sample

							if not return_dict:
												return (dec,)

							return DecoderOutput(sample=_UpperCamelCase   )






