






"""simple docstring"""

import gc
import random
import unittest

import numpy as np
import torch
from transformers import XLMRobertaTokenizer

from diffusers import (
    AltDiffusionImgaImgPipeline,
    AutoencoderKL,
    PNDMScheduler,
    UNetaDConditionModel,
)
from diffusers.image_processor import VaeImageProcessor
from diffusers.pipelines.alt_diffusion.modeling_roberta_series import (
    RobertaSeriesConfig,
    RobertaSeriesModelWithTransformation,
)
from diffusers.utils import floats_tensor, load_image, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()

class 						A_							(      unittest.TestCase  ):







				def     _snake_case					(							self							:						Tuple	)				->					List[str]:
										# clean up the VRAM after each test
										super().tearDown()
										gc.collect()
										torch.cuda.empty_cache()







				@property
				def     _snake_case					(							self							:						Tuple	)				->					Optional[int]:
										__magic_name__            =     1
										__magic_name__            =     3
										__magic_name__            =     (3_2, 3_2)

										__magic_name__            =     floats_tensor((batch_size, num_channels) + sizes						,    rng=random.Random(0	)	).to(__lowerCamelCase	)
										return image







				@property
				def     _snake_case					(							self							:						Optional[Any]	)				->					str:
										torch.manual_seed(0	)
										__magic_name__            =     UNetaDConditionModel(
										    block_out_channels=(3_2, 6_4)						,    layers_per_block=2						,    sample_size=3_2						,    in_channels=4						,    out_channels=4						,    down_block_types=("DownBlock2D", "CrossAttnDownBlock2D")						,    up_block_types=("CrossAttnUpBlock2D", "UpBlock2D")						,    cross_attention_dim=3_2						,    )
										return model







				@property
				def     _snake_case					(							self							:						List[str]	)				->					Dict:
										torch.manual_seed(0	)
										__magic_name__            =     AutoencoderKL(
										    block_out_channels=[3_2, 6_4]						,    in_channels=3						,    out_channels=3						,    down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"]						,    up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"]						,    latent_channels=4						,    )
										return model







				@property
				def     _snake_case					(							self							:						Optional[Any]	)				->					str:
										torch.manual_seed(0	)
										__magic_name__            =     RobertaSeriesConfig(
										    hidden_size=3_2						,    project_dim=3_2						,    intermediate_size=3_7						,    layer_norm_eps=1e-05						,    num_attention_heads=4						,    num_hidden_layers=5						,    pad_token_id=1						,    vocab_size=5_0_0_6						,    )
										return RobertaSeriesModelWithTransformation(__lowerCamelCase	)







				@property
				def     _snake_case					(							self							:						Any	)				->					Any:
										def extract(*__lowerCamelCase							:						Optional[int]						,    **__lowerCamelCase							:						Optional[int]	):

																class 						A_							:







																				def __init__(							self							:						int	)				->					str:
																										__magic_name__            =     torch.ones([0]	)







																				def     _snake_case					(							self							:						Dict						,    __lowerCamelCase							:						Any	)				->					Optional[Any]:
																										self.pixel_values.to(__lowerCamelCase	)
																										return self





																return Out()

										return extract







				def     _snake_case					(							self							:						Any	)				->					int:
										__magic_name__            =     "cpu"  # ensure determinism for the device-dependent torch.Generator
										__magic_name__            =     self.dummy_cond_unet
										__magic_name__            =     PNDMScheduler(skip_prk_steps=__lowerCamelCase	)
										__magic_name__            =     self.dummy_vae
										__magic_name__            =     self.dummy_text_encoder
										__magic_name__            =     XLMRobertaTokenizer.from_pretrained("hf-internal-testing/tiny-xlm-roberta"	)
										__magic_name__            =     7_7

										__magic_name__            =     self.dummy_image.to(__lowerCamelCase	)
										__magic_name__            =     init_image / 2 + 0.5

										# make sure here that pndm scheduler skips prk
										__magic_name__            =     AltDiffusionImgaImgPipeline(
										    unet=__lowerCamelCase						,    scheduler=__lowerCamelCase						,    vae=__lowerCamelCase						,    text_encoder=__lowerCamelCase						,    tokenizer=__lowerCamelCase						,    safety_checker=__lowerCamelCase						,    feature_extractor=self.dummy_extractor						,    )
										__magic_name__            =     VaeImageProcessor(vae_scale_factor=alt_pipe.vae_scale_factor						,    do_normalize=__lowerCamelCase	)
										__magic_name__            =     alt_pipe.to(__lowerCamelCase	)
										alt_pipe.set_progress_bar_config(disable=__lowerCamelCase	)

										__magic_name__            =     "A painting of a squirrel eating a burger"
										__magic_name__            =     torch.Generator(device=__lowerCamelCase	).manual_seed(0	)
										__magic_name__            =     alt_pipe(
										    [prompt]						,    generator=__lowerCamelCase						,    guidance_scale=6.0						,    num_inference_steps=2						,    output_type="np"						,    image=__lowerCamelCase						,    )

										__magic_name__            =     output.images

										__magic_name__            =     torch.Generator(device=__lowerCamelCase	).manual_seed(0	)
										__magic_name__            =     alt_pipe(
										    [prompt]						,    generator=__lowerCamelCase						,    guidance_scale=6.0						,    num_inference_steps=2						,    output_type="np"						,    image=__lowerCamelCase						,    return_dict=__lowerCamelCase						,    )[0]

										__magic_name__            =     image[0, -3:, -3:, -1]
										__magic_name__            =     image_from_tuple[0, -3:, -3:, -1]

										assert image.shape == (1, 3_2, 3_2, 3)
										__magic_name__            =     np.array([0.4427, 0.3731, 0.4249, 0.4941, 0.4546, 0.4148, 0.4193, 0.4666, 0.4499]	)

										assert np.abs(image_slice.flatten() - expected_slice	).max() < 5e-3
										assert np.abs(image_from_tuple_slice.flatten() - expected_slice	).max() < 5e-3







				@unittest.skipIf(torch_device != "cuda"						,    "This test requires a GPU"	)
				def     _snake_case					(							self							:						Tuple	)				->					Optional[int]:
										__magic_name__            =     self.dummy_cond_unet
										__magic_name__            =     PNDMScheduler(skip_prk_steps=__lowerCamelCase	)
										__magic_name__            =     self.dummy_vae
										__magic_name__            =     self.dummy_text_encoder
										__magic_name__            =     XLMRobertaTokenizer.from_pretrained("hf-internal-testing/tiny-xlm-roberta"	)
										__magic_name__            =     7_7

										__magic_name__            =     self.dummy_image.to(__lowerCamelCase	)

										# put models in fp16
										__magic_name__            =     unet.half()
										__magic_name__            =     vae.half()
										__magic_name__            =     bert.half()

										# make sure here that pndm scheduler skips prk
										__magic_name__            =     AltDiffusionImgaImgPipeline(
										    unet=__lowerCamelCase						,    scheduler=__lowerCamelCase						,    vae=__lowerCamelCase						,    text_encoder=__lowerCamelCase						,    tokenizer=__lowerCamelCase						,    safety_checker=__lowerCamelCase						,    feature_extractor=self.dummy_extractor						,    )
										__magic_name__            =     VaeImageProcessor(vae_scale_factor=alt_pipe.vae_scale_factor						,    do_normalize=__lowerCamelCase	)
										__magic_name__            =     alt_pipe.to(__lowerCamelCase	)
										alt_pipe.set_progress_bar_config(disable=__lowerCamelCase	)

										__magic_name__            =     "A painting of a squirrel eating a burger"
										__magic_name__            =     torch.manual_seed(0	)
										__magic_name__            =     alt_pipe(
										    [prompt]						,    generator=__lowerCamelCase						,    num_inference_steps=2						,    output_type="np"						,    image=__lowerCamelCase						,    ).images

										assert image.shape == (1, 3_2, 3_2, 3)







				@unittest.skipIf(torch_device != "cuda"						,    "This test requires a GPU"	)
				def     _snake_case					(							self							:						Any	)				->					Tuple:
										__magic_name__            =     load_image(
										    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
										    "/img2img/sketch-mountains-input.jpg"	)
										# resize to resolution that is divisible by 8 but not 16 or 32
										__magic_name__            =     init_image.resize((7_6_0, 5_0_4)	)

										__magic_name__            =     "BAAI/AltDiffusion"
										__magic_name__            =     AltDiffusionImgaImgPipeline.from_pretrained(
										    __lowerCamelCase						,    safety_checker=__lowerCamelCase						,    )
										pipe.to(__lowerCamelCase	)
										pipe.set_progress_bar_config(disable=__lowerCamelCase	)
										pipe.enable_attention_slicing()

										__magic_name__            =     "A fantasy landscape, trending on artstation"

										__magic_name__            =     torch.manual_seed(0	)
										__magic_name__            =     pipe(
										    prompt=__lowerCamelCase						,    image=__lowerCamelCase						,    strength=0.75						,    guidance_scale=7.5						,    generator=__lowerCamelCase						,    output_type="np"						,    )
										__magic_name__            =     output.images[0]

										__magic_name__            =     image[2_5_5:2_5_8, 3_8_3:3_8_6, -1]

										assert image.shape == (5_0_4, 7_6_0, 3)
										__magic_name__            =     np.array([0.9358, 0.9397, 0.9599, 0.9901, 1.0000, 1.0000, 0.9882, 1.0000, 1.0000]	)

										assert np.abs(image_slice.flatten() - expected_slice	).max() < 1e-2





@slow
@require_torch_gpu
class 						A_							(      unittest.TestCase  ):







				def     _snake_case					(							self							:						Optional[Any]	)				->					Union[str, Any]:
										# clean up the VRAM after each test
										super().tearDown()
										gc.collect()
										torch.cuda.empty_cache()







				def     _snake_case					(							self							:						Optional[int]	)				->					List[Any]:
										__magic_name__            =     load_image(
										    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
										    "/img2img/sketch-mountains-input.jpg"	)
										__magic_name__            =     init_image.resize((7_6_8, 5_1_2)	)
										__magic_name__            =     load_numpy(
										    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/img2img/fantasy_landscape_alt.npy"	)

										__magic_name__            =     "BAAI/AltDiffusion"
										__magic_name__            =     AltDiffusionImgaImgPipeline.from_pretrained(
										    __lowerCamelCase						,    safety_checker=__lowerCamelCase						,    )
										pipe.to(__lowerCamelCase	)
										pipe.set_progress_bar_config(disable=__lowerCamelCase	)
										pipe.enable_attention_slicing()

										__magic_name__            =     "A fantasy landscape, trending on artstation"

										__magic_name__            =     torch.manual_seed(0	)
										__magic_name__            =     pipe(
										    prompt=__lowerCamelCase						,    image=__lowerCamelCase						,    strength=0.75						,    guidance_scale=7.5						,    generator=__lowerCamelCase						,    output_type="np"						,    )
										__magic_name__            =     output.images[0]

										assert image.shape == (5_1_2, 7_6_8, 3)
										# img2img is flaky across GPUs even in fp32, so using MAE here
										assert np.abs(expected_image - image	).max() < 1e-2











"""simple docstring"""

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 						A_							(      snake_case_  ):
				UpperCAmelCase__        =				42





class 						A_							(      snake_case_					,							snake_case_  ):
				UpperCAmelCase__        =				True







				@register_to_config
				def __init__(							self							:						Any						,    __lowerCamelCase							:						int = 3						,    __lowerCamelCase							:						int = 3						,    __lowerCamelCase							:						Tuple[str] = ("DownEncoderBlock2D",)						,    __lowerCamelCase							:						Tuple[str] = ("UpDecoderBlock2D",)						,    __lowerCamelCase							:						Tuple[int] = (6_4,)						,    __lowerCamelCase							:						int = 1						,    __lowerCamelCase							:						str = "silu"						,    __lowerCamelCase							:						int = 4						,    __lowerCamelCase							:						int = 3_2						,    __lowerCamelCase							:						int = 3_2						,    __lowerCamelCase							:						float = 0.1_8215						,    )				->					Any:
										super().__init__()

										# pass init params to Encoder
										__magic_name__            =     Encoder(
										    in_channels=__lowerCamelCase						,    out_channels=__lowerCamelCase						,    down_block_types=__lowerCamelCase						,    block_out_channels=__lowerCamelCase						,    layers_per_block=__lowerCamelCase						,    act_fn=__lowerCamelCase						,    norm_num_groups=__lowerCamelCase						,    double_z=__lowerCamelCase						,    )

										# pass init params to Decoder
										__magic_name__            =     Decoder(
										    in_channels=__lowerCamelCase						,    out_channels=__lowerCamelCase						,    up_block_types=__lowerCamelCase						,    block_out_channels=__lowerCamelCase						,    layers_per_block=__lowerCamelCase						,    norm_num_groups=__lowerCamelCase						,    act_fn=__lowerCamelCase						,    )

										__magic_name__            =     nn.Convad(2 * latent_channels						,    2 * latent_channels						,    1	)
										__magic_name__            =     nn.Convad(__lowerCamelCase						,    __lowerCamelCase						,    1	)

										__magic_name__            =     False
										__magic_name__            =     False

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







				def     _snake_case					(							self							:						List[str]						,    __lowerCamelCase							:						Tuple						,    __lowerCamelCase							:						Dict=False	)				->					Optional[int]:
										if isinstance(__lowerCamelCase						,    (Encoder, Decoder)	):
																__magic_name__            =     value







				def     _snake_case					(							self							:						Dict						,    __lowerCamelCase							:						bool = True	)				->					int:
										__magic_name__            =     use_tiling







				def     _snake_case					(							self							:						Dict	)				->					Optional[int]:
										self.enable_tiling(__lowerCamelCase	)







				def     _snake_case					(							self							:						int	)				->					str:
										__magic_name__            =     True







				def     _snake_case					(							self							:						Optional[Any]	)				->					Tuple:
										__magic_name__            =     False







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

										def fn_recursive_add_processors(__lowerCamelCase							:						str						,    __lowerCamelCase							:						torch.nn.Module						,    __lowerCamelCase							:						Dict[str, AttentionProcessor]	):
																if hasattr(__lowerCamelCase						,    "set_processor"	):
																						__magic_name__            =     module.processor

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

																return processors

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

										return processors







				def     _snake_case					(							self							:						Dict						,    __lowerCamelCase							:						Union[AttentionProcessor, Dict[str, AttentionProcessor]]	)				->					int:
										__magic_name__            =     len(self.attn_processors.keys()	)

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

										def fn_recursive_attn_processor(__lowerCamelCase							:						str						,    __lowerCamelCase							:						torch.nn.Module						,    __lowerCamelCase							:						List[str]	):
																if hasattr(__lowerCamelCase						,    "set_processor"	):
																						if not isinstance(__lowerCamelCase						,    __lowerCamelCase	):
																												module.set_processor(__lowerCamelCase	)
																						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}'''						,    __lowerCamelCase						,    __lowerCamelCase	)

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







				def     _snake_case					(							self							:						List[Any]	)				->					Optional[Any]:
										self.set_attn_processor(AttnProcessor()	)







				@apply_forward_hook
				def     _snake_case					(							self							:						str						,    __lowerCamelCase							:						torch.FloatTensor						,    __lowerCamelCase							:						bool = 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(__lowerCamelCase						,    return_dict=__lowerCamelCase	)

										if self.use_slicing and x.shape[0] > 1:
																__magic_name__            =     [self.encoder(__lowerCamelCase	) for x_slice in x.split(1	)]
																__magic_name__            =     torch.cat(__lowerCamelCase	)
										else:
																__magic_name__            =     self.encoder(__lowerCamelCase	)

										__magic_name__            =     self.quant_conv(__lowerCamelCase	)
										__magic_name__            =     DiagonalGaussianDistribution(__lowerCamelCase	)

										if not return_dict:
																return (posterior,)

										return AutoencoderKLOutput(latent_dist=__lowerCamelCase	)







				def     _snake_case					(							self							:						int						,    __lowerCamelCase							:						torch.FloatTensor						,    __lowerCamelCase							:						bool = 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(__lowerCamelCase						,    return_dict=__lowerCamelCase	)

										__magic_name__            =     self.post_quant_conv(__lowerCamelCase	)
										__magic_name__            =     self.decoder(__lowerCamelCase	)

										if not return_dict:
																return (dec,)

										return DecoderOutput(sample=__lowerCamelCase	)







				@apply_forward_hook
				def     _snake_case					(							self							:						Optional[Any]						,    __lowerCamelCase							:						torch.FloatTensor						,    __lowerCamelCase							:						bool = True	)				->					Union[DecoderOutput, torch.FloatTensor]:
										if self.use_slicing and z.shape[0] > 1:
																__magic_name__            =     [self._decode(__lowerCamelCase	).sample for z_slice in z.split(1	)]
																__magic_name__            =     torch.cat(__lowerCamelCase	)
										else:
																__magic_name__            =     self._decode(__lowerCamelCase	).sample

										if not return_dict:
																return (decoded,)

										return DecoderOutput(sample=__lowerCamelCase	)







				def     _snake_case					(							self							:						Optional[int]						,    __lowerCamelCase							:						str						,    __lowerCamelCase							:						List[str]						,    __lowerCamelCase							:						Dict	)				->					Optional[int]:
										__magic_name__            =     min(a.shape[2]						,    b.shape[2]						,    __lowerCamelCase	)
										for y in range(__lowerCamelCase	):
																__magic_name__            =     a[:, :, -blend_extent + y, :] * (1 - y / blend_extent) + b[:, :, y, :] * (y / blend_extent)
										return b







				def     _snake_case					(							self							:						List[str]						,    __lowerCamelCase							:						Any						,    __lowerCamelCase							:						Tuple						,    __lowerCamelCase							:						Tuple	)				->					Optional[int]:
										__magic_name__            =     min(a.shape[3]						,    b.shape[3]						,    __lowerCamelCase	)
										for x in range(__lowerCamelCase	):
																__magic_name__            =     a[:, :, :, -blend_extent + x] * (1 - x / blend_extent) + b[:, :, :, x] * (x / blend_extent)
										return b







				def     _snake_case					(							self							:						Optional[int]						,    __lowerCamelCase							:						torch.FloatTensor						,    __lowerCamelCase							:						bool = True	)				->					AutoencoderKLOutput:
										__magic_name__            =     int(self.tile_sample_min_size * (1 - self.tile_overlap_factor)	)
										__magic_name__            =     int(self.tile_latent_min_size * self.tile_overlap_factor	)
										__magic_name__            =     self.tile_latent_min_size - blend_extent

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

										__magic_name__            =     torch.cat(__lowerCamelCase						,    dim=2	)
										__magic_name__            =     DiagonalGaussianDistribution(__lowerCamelCase	)

										if not return_dict:
																return (posterior,)

										return AutoencoderKLOutput(latent_dist=__lowerCamelCase	)







				def     _snake_case					(							self							:						str						,    __lowerCamelCase							:						torch.FloatTensor						,    __lowerCamelCase							:						bool = True	)				->					Union[DecoderOutput, torch.FloatTensor]:
										__magic_name__            =     int(self.tile_latent_min_size * (1 - self.tile_overlap_factor)	)
										__magic_name__            =     int(self.tile_sample_min_size * self.tile_overlap_factor	)
										__magic_name__            =     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.
										__magic_name__            =     []
										for i in range(0						,    z.shape[2]						,    __lowerCamelCase	):
																__magic_name__            =     []
																for j in range(0						,    z.shape[3]						,    __lowerCamelCase	):
																						__magic_name__            =     z[:, :, i : i + self.tile_latent_min_size, j : j + self.tile_latent_min_size]
																						__magic_name__            =     self.post_quant_conv(__lowerCamelCase	)
																						__magic_name__            =     self.decoder(__lowerCamelCase	)
																						row.append(__lowerCamelCase	)
																rows.append(__lowerCamelCase	)
										__magic_name__            =     []
										for i, row in enumerate(__lowerCamelCase	):
																__magic_name__            =     []
																for j, tile in enumerate(__lowerCamelCase	):
																						# blend the above tile and the left tile
																						# to the current tile and add the current tile to the result row
																						if i > 0:
																												__magic_name__            =     self.blend_v(rows[i - 1][j]						,    __lowerCamelCase						,    __lowerCamelCase	)
																						if j > 0:
																												__magic_name__            =     self.blend_h(row[j - 1]						,    __lowerCamelCase						,    __lowerCamelCase	)
																						result_row.append(tile[:, :, :row_limit, :row_limit]	)
																result_rows.append(torch.cat(__lowerCamelCase						,    dim=3	)	)

										__magic_name__            =     torch.cat(__lowerCamelCase						,    dim=2	)
										if not return_dict:
																return (dec,)

										return DecoderOutput(sample=__lowerCamelCase	)







				def     _snake_case					(							self							:						List[str]						,    __lowerCamelCase							:						torch.FloatTensor						,    __lowerCamelCase							:						bool = False						,    __lowerCamelCase							:						bool = True						,    __lowerCamelCase							:						Optional[torch.Generator] = None						,    )				->					Union[DecoderOutput, torch.FloatTensor]:
										__magic_name__            =     sample
										__magic_name__            =     self.encode(__lowerCamelCase	).latent_dist
										if sample_posterior:
																__magic_name__            =     posterior.sample(generator=__lowerCamelCase	)
										else:
																__magic_name__            =     posterior.mode()
										__magic_name__            =     self.decode(__lowerCamelCase	).sample

										if not return_dict:
																return (dec,)

										return DecoderOutput(sample=__lowerCamelCase	)



