




import unittest

from transformers import MPNetConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch

       from transformers import (
           MPNetForMaskedLM,
           MPNetForMultipleChoice,
           MPNetForQuestionAnswering,
           MPNetForSequenceClassification,
           MPNetForTokenClassification,
           MPNetModel,
       )





class     lowercase_	:



 '''simple docstring'''

 def __init__(			self	:	List[Any]   ,							_UpperCAmelCase	:	Optional[int]   ,							_UpperCAmelCase	:	List[str]=13   ,							_UpperCAmelCase	:	Tuple=7   ,							_UpperCAmelCase	:	str=True   ,							_UpperCAmelCase	:	List[str]=True   ,							_UpperCAmelCase	:	Union[str, Any]=False   ,							_UpperCAmelCase	:	int=True   ,							_UpperCAmelCase	:	Optional[Any]=99   ,							_UpperCAmelCase	:	Any=64   ,							_UpperCAmelCase	:	Dict=5   ,							_UpperCAmelCase	:	List[str]=4   ,							_UpperCAmelCase	:	Union[str, Any]=64   ,							_UpperCAmelCase	:	Union[str, Any]="gelu"   ,							_UpperCAmelCase	:	Any=0.1   ,							_UpperCAmelCase	:	Optional[Any]=0.1   ,							_UpperCAmelCase	:	Any=512   ,							_UpperCAmelCase	:	Tuple=16   ,							_UpperCAmelCase	:	Any=2   ,							_UpperCAmelCase	:	Optional[Any]=0.02   ,							_UpperCAmelCase	:	str=3   ,							_UpperCAmelCase	:	str=4   ,							_UpperCAmelCase	:	str=None   ,							):
       _A        =       parent
       _A        =       batch_size
       _A        =       seq_length
       _A        =       is_training
       _A        =       use_input_mask
       _A        =       use_token_type_ids
       _A        =       use_labels
       _A        =       vocab_size
       _A        =       hidden_size
       _A        =       num_hidden_layers
       _A        =       num_attention_heads
       _A        =       intermediate_size
       _A        =       hidden_act
       _A        =       hidden_dropout_prob
       _A        =       attention_probs_dropout_prob
       _A        =       max_position_embeddings
       _A        =       type_vocab_size
       _A        =       type_sequence_label_size
       _A        =       initializer_range
       _A        =       num_labels
       _A        =       num_choices
       _A        =       scope

 def       lowerCAmelCase_							(			self	:	Dict		):
       return MPNetConfig.from_pretrained('microsoft/mpnet-base'		)

 def       lowerCAmelCase_							(			self	:	Dict		):
       _A        =       ids_tensor([self.batch_size, self.seq_length]   ,							self.vocab_size		)

       _A        =       None
       if self.use_input_mask:
             _A        =       random_attention_mask([self.batch_size, self.seq_length]		)

       _A        =       None
       _A        =       None
       _A        =       None
       if self.use_labels:
             _A        =       ids_tensor([self.batch_size]   ,							self.type_sequence_label_size		)
             _A        =       ids_tensor([self.batch_size, self.seq_length]   ,							self.num_labels		)
             _A        =       ids_tensor([self.batch_size]   ,							self.num_choices		)

       _A        =       self.get_config()
       return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels

 def       lowerCAmelCase_							(			self	:	Dict		):
       return MPNetConfig(
           vocab_size=self.vocab_size   ,							hidden_size=self.hidden_size   ,							num_hidden_layers=self.num_hidden_layers   ,							num_attention_heads=self.num_attention_heads   ,							intermediate_size=self.intermediate_size   ,							hidden_act=self.hidden_act   ,							hidden_dropout_prob=self.hidden_dropout_prob   ,							attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,							max_position_embeddings=self.max_position_embeddings   ,							initializer_range=self.initializer_range   ,							)

 def       lowerCAmelCase_							(			self	:	Optional[Any]   ,							_UpperCAmelCase	:	int   ,							_UpperCAmelCase	:	Optional[Any]   ,							_UpperCAmelCase	:	Optional[int]   ,							_UpperCAmelCase	:	str   ,							_UpperCAmelCase	:	Tuple   ,							_UpperCAmelCase	:	Optional[Any]		):
       _A        =       MPNetModel(config=_UpperCAmelCase		)
       model.to(_UpperCAmelCase		)
       model.eval()
       _A        =       model(_UpperCAmelCase   ,							_UpperCAmelCase		)
       _A        =       model(_UpperCAmelCase		)
       self.parent.assertEqual(result.last_hidden_state.shape   ,							(self.batch_size, self.seq_length, self.hidden_size)		)
       self.parent.assertEqual(result.pooler_output.shape   ,							(self.batch_size, self.hidden_size)		)

 def       lowerCAmelCase_							(			self	:	Any   ,							_UpperCAmelCase	:	Dict   ,							_UpperCAmelCase	:	List[str]   ,							_UpperCAmelCase	:	Any   ,							_UpperCAmelCase	:	int   ,							_UpperCAmelCase	:	Dict   ,							_UpperCAmelCase	:	int		):
       _A        =       MPNetForQuestionAnswering(config=_UpperCAmelCase		)
       model.to(_UpperCAmelCase		)
       model.eval()
       _A        =       model(
           _UpperCAmelCase   ,							attention_mask=_UpperCAmelCase   ,							start_positions=_UpperCAmelCase   ,							end_positions=_UpperCAmelCase   ,							)
       self.parent.assertEqual(result.start_logits.shape   ,							(self.batch_size, self.seq_length)		)
       self.parent.assertEqual(result.end_logits.shape   ,							(self.batch_size, self.seq_length)		)

 def       lowerCAmelCase_							(			self	:	Tuple   ,							_UpperCAmelCase	:	List[str]   ,							_UpperCAmelCase	:	str   ,							_UpperCAmelCase	:	str   ,							_UpperCAmelCase	:	Union[str, Any]   ,							_UpperCAmelCase	:	List[Any]   ,							_UpperCAmelCase	:	Dict		):
       _A        =       self.num_labels
       _A        =       MPNetForSequenceClassification(_UpperCAmelCase		)
       model.to(_UpperCAmelCase		)
       model.eval()
       _A        =       model(_UpperCAmelCase   ,							attention_mask=_UpperCAmelCase   ,							labels=_UpperCAmelCase		)
       self.parent.assertEqual(result.logits.shape   ,							(self.batch_size, self.num_labels)		)

 def       lowerCAmelCase_							(			self	:	List[str]   ,							_UpperCAmelCase	:	str   ,							_UpperCAmelCase	:	Union[str, Any]   ,							_UpperCAmelCase	:	int   ,							_UpperCAmelCase	:	Optional[int]   ,							_UpperCAmelCase	:	int   ,							_UpperCAmelCase	:	int		):
       _A        =       self.num_choices
       _A        =       MPNetForMultipleChoice(config=_UpperCAmelCase		)
       model.to(_UpperCAmelCase		)
       model.eval()
       _A        =       input_ids.unsqueeze(1		).expand(-1   ,							self.num_choices   ,							-1		).contiguous()
       _A        =       input_mask.unsqueeze(1		).expand(-1   ,							self.num_choices   ,							-1		).contiguous()
       _A        =       model(
           _UpperCAmelCase   ,							attention_mask=_UpperCAmelCase   ,							labels=_UpperCAmelCase   ,							)
       self.parent.assertEqual(result.logits.shape   ,							(self.batch_size, self.num_choices)		)

 def       lowerCAmelCase_							(			self	:	str   ,							_UpperCAmelCase	:	Tuple   ,							_UpperCAmelCase	:	List[str]   ,							_UpperCAmelCase	:	Optional[Any]   ,							_UpperCAmelCase	:	List[str]   ,							_UpperCAmelCase	:	List[str]   ,							_UpperCAmelCase	:	List[str]		):
       _A        =       self.num_labels
       _A        =       MPNetForTokenClassification(config=_UpperCAmelCase		)
       model.to(_UpperCAmelCase		)
       model.eval()
       _A        =       model(_UpperCAmelCase   ,							attention_mask=_UpperCAmelCase   ,							labels=_UpperCAmelCase		)
       self.parent.assertEqual(result.logits.shape   ,							(self.batch_size, self.seq_length, self.num_labels)		)



 def       lowerCAmelCase_							(			self	:	Tuple		):
       _A        =       self.prepare_config_and_inputs()
       ((_A)       ,   (_A)       ,   (_A)       ,   (_A)       ,   (_A)       ,   (_A))        =       config_and_inputs
       _A        =       {'input_ids': input_ids, 'attention_mask': input_mask}
       return config, inputs_dict





@require_torch
class     lowercase_	(					__lowerCAmelCase      ,     __lowerCAmelCase      ,     unittest.TestCase							):



 '''simple docstring'''
 UpperCAmelCase   :					Tuple				  =     (
     (
         MPNetForMaskedLM,
         MPNetForMultipleChoice,
         MPNetForQuestionAnswering,
         MPNetForSequenceClassification,
         MPNetForTokenClassification,
         MPNetModel,
     )
     if is_torch_available()
     else ()
 )
 UpperCAmelCase   :					Union[str, Any]				  =     (
     {
         '''feature-extraction''': MPNetModel,
         '''fill-mask''': MPNetForMaskedLM,
         '''question-answering''': MPNetForQuestionAnswering,
         '''text-classification''': MPNetForSequenceClassification,
         '''token-classification''': MPNetForTokenClassification,
         '''zero-shot''': MPNetForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 UpperCAmelCase   :					Dict				  =     False
 UpperCAmelCase   :					List[str]				  =     True

 def       lowerCAmelCase_							(			self	:	List[Any]		):
       _A        =       MPNetModelTester(self		)
       _A        =       ConfigTester(self   ,							config_class=_UpperCAmelCase   ,							hidden_size=37		)

 def       lowerCAmelCase_							(			self	:	int		):
       self.config_tester.run_common_tests()

 def       lowerCAmelCase_							(			self	:	Union[str, Any]		):
       _A        =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_model(*_UpperCAmelCase		)

 def       lowerCAmelCase_							(			self	:	Optional[int]		):
       _A        =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_sequence_classification(*_UpperCAmelCase		)

 def       lowerCAmelCase_							(			self	:	Optional[Any]		):
       _A        =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_multiple_choice(*_UpperCAmelCase		)

 def       lowerCAmelCase_							(			self	:	List[Any]		):
       _A        =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_token_classification(*_UpperCAmelCase		)



 def       lowerCAmelCase_							(			self	:	List[str]		):
       _A        =       self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_mpnet_for_question_answering(*_UpperCAmelCase		)





@require_torch
class     lowercase_	(					unittest.TestCase							):



 '''simple docstring'''

 @slow
 def       lowerCAmelCase_							(			self	:	int		):
       _A        =       MPNetModel.from_pretrained('microsoft/mpnet-base'		)
       _A        =       torch.tensor([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]		)
       _A        =       model(_UpperCAmelCase		)[0]
       _A        =       torch.Size((1, 11, 768)		)
       self.assertEqual(output.shape   ,							_UpperCAmelCase		)
       _A        =       torch.tensor(
           [[[-0.0550, 0.1943, -0.0740], [-0.0562, 0.2211, -0.0579], [-0.0437, 0.3337, -0.0641]]]		)
       # compare the actual values for a slice.
       self.assertTrue(torch.allclose(output[:, :3, :3]   ,							_UpperCAmelCase   ,							atol=1E-4		)		)







"""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     lowercase_	(					__lowerCAmelCase							):



 '''simple docstring'''
 UpperCAmelCase   :					"DiagonalGaussianDistribution"





class     lowercase_	(					__lowerCAmelCase      ,     __lowerCAmelCase							):



 '''simple docstring'''
 UpperCAmelCase   :					List[Any]				  =     True

 @register_to_config
 def __init__(			self	:	List[str]   ,							_UpperCAmelCase	:	int = 3   ,							_UpperCAmelCase	:	int = 3   ,							_UpperCAmelCase	:	Tuple[str] = ("DownEncoderBlock2D",)   ,							_UpperCAmelCase	:	Tuple[str] = ("UpDecoderBlock2D",)   ,							_UpperCAmelCase	:	Tuple[int] = (64,)   ,							_UpperCAmelCase	:	int = 1   ,							_UpperCAmelCase	:	str = "silu"   ,							_UpperCAmelCase	:	int = 4   ,							_UpperCAmelCase	:	int = 32   ,							_UpperCAmelCase	:	int = 32   ,							_UpperCAmelCase	:	float = 0.1_8215   ,							):
       super().__init__()

       # pass init params to Encoder
       _A        =       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
       _A        =       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   ,							)

       _A        =       nn.Convad(2 * latent_channels   ,							2 * latent_channels   ,							1		)
       _A        =       nn.Convad(_UpperCAmelCase   ,							_UpperCAmelCase   ,							1		)

       _A        =       False
       _A        =       False

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

 def       lowerCAmelCase_							(			self	:	Union[str, Any]   ,							_UpperCAmelCase	:	int   ,							_UpperCAmelCase	:	Tuple=False		):
       if isinstance(_UpperCAmelCase   ,							(Encoder, Decoder)		):
             _A        =       value

 def       lowerCAmelCase_							(			self	:	List[str]   ,							_UpperCAmelCase	:	bool = True		):
       _A        =       use_tiling

 def       lowerCAmelCase_							(			self	:	Union[str, Any]		):
       self.enable_tiling(_UpperCAmelCase		)

 def       lowerCAmelCase_							(			self	:	Dict		):
       _A        =       True

 def       lowerCAmelCase_							(			self	:	str		):
       _A        =       False

 @property
 # Copied from diffusers.models.unet_2d_condition.UNet2DConditionModel.attn_processors
 def       lowerCAmelCase_							(			self	:	str		):
       _A        =       {}

       def fn_recursive_add_processors(_UpperCAmelCase	:	str   ,							_UpperCAmelCase	:	torch.nn.Module   ,							_UpperCAmelCase	:	Dict[str, AttentionProcessor]		):
             if hasattr(_UpperCAmelCase   ,							'set_processor'		):
                   _A        =       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       lowerCAmelCase_							(			self	:	str   ,							_UpperCAmelCase	:	Union[AttentionProcessor, Dict[str, AttentionProcessor]]		):
       _A        =       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	:	str   ,							_UpperCAmelCase	:	torch.nn.Module   ,							_UpperCAmelCase	:	int		):
             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       lowerCAmelCase_							(			self	:	List[str]		):
       self.set_attn_processor(AttnProcessor()		)

 @apply_forward_hook
 def       lowerCAmelCase_							(			self	:	int   ,							_UpperCAmelCase	:	torch.FloatTensor   ,							_UpperCAmelCase	:	bool = True		):
       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:
             _A        =       [self.encoder(_UpperCAmelCase		) for x_slice in x.split(1		)]
             _A        =       torch.cat(_UpperCAmelCase		)
       else:
             _A        =       self.encoder(_UpperCAmelCase		)

       _A        =       self.quant_conv(_UpperCAmelCase		)
       _A        =       DiagonalGaussianDistribution(_UpperCAmelCase		)

       if not return_dict:
             return (posterior,)

       return AutoencoderKLOutput(latent_dist=_UpperCAmelCase		)

 def       lowerCAmelCase_							(			self	:	Any   ,							_UpperCAmelCase	:	torch.FloatTensor   ,							_UpperCAmelCase	:	bool = True		):
       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		)

       _A        =       self.post_quant_conv(_UpperCAmelCase		)
       _A        =       self.decoder(_UpperCAmelCase		)

       if not return_dict:
             return (dec,)

       return DecoderOutput(sample=_UpperCAmelCase		)

 @apply_forward_hook
 def       lowerCAmelCase_							(			self	:	str   ,							_UpperCAmelCase	:	torch.FloatTensor   ,							_UpperCAmelCase	:	bool = True		):
       if self.use_slicing and z.shape[0] > 1:
             _A        =       [self._decode(_UpperCAmelCase		).sample for z_slice in z.split(1		)]
             _A        =       torch.cat(_UpperCAmelCase		)
       else:
             _A        =       self._decode(_UpperCAmelCase		).sample

       if not return_dict:
             return (decoded,)

       return DecoderOutput(sample=_UpperCAmelCase		)

 def       lowerCAmelCase_							(			self	:	str   ,							_UpperCAmelCase	:	int   ,							_UpperCAmelCase	:	Dict   ,							_UpperCAmelCase	:	Any		):
       _A        =       min(a.shape[2]   ,							b.shape[2]   ,							_UpperCAmelCase		)
       for y in range(_UpperCAmelCase		):
             _A        =       a[:, :, -blend_extent + y, :] * (1 - y / blend_extent) + b[:, :, y, :] * (y / blend_extent)
       return b

 def       lowerCAmelCase_							(			self	:	Optional[Any]   ,							_UpperCAmelCase	:	List[str]   ,							_UpperCAmelCase	:	List[Any]   ,							_UpperCAmelCase	:	List[Any]		):
       _A        =       min(a.shape[3]   ,							b.shape[3]   ,							_UpperCAmelCase		)
       for x in range(_UpperCAmelCase		):
             _A        =       a[:, :, :, -blend_extent + x] * (1 - x / blend_extent) + b[:, :, :, x] * (x / blend_extent)
       return b

 def       lowerCAmelCase_							(			self	:	str   ,							_UpperCAmelCase	:	torch.FloatTensor   ,							_UpperCAmelCase	:	bool = True		):
       _A        =       int(self.tile_sample_min_size * (1 - self.tile_overlap_factor)		)
       _A        =       int(self.tile_latent_min_size * self.tile_overlap_factor		)
       _A        =       self.tile_latent_min_size - blend_extent

       # Split the image into 512x512 tiles and encode them separately.
       _A        =       []
       for i in range(0   ,							x.shape[2]   ,							_UpperCAmelCase		):
             _A        =       []
             for j in range(0   ,							x.shape[3]   ,							_UpperCAmelCase		):
                   _A        =       x[:, :, i : i + self.tile_sample_min_size, j : j + self.tile_sample_min_size]
                   _A        =       self.encoder(_UpperCAmelCase		)
                   _A        =       self.quant_conv(_UpperCAmelCase		)
                   row.append(_UpperCAmelCase		)
             rows.append(_UpperCAmelCase		)
       _A        =       []
       for i, row in enumerate(_UpperCAmelCase		):
             _A        =       []
             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:
                         _A        =       self.blend_v(rows[i - 1][j]   ,							_UpperCAmelCase   ,							_UpperCAmelCase		)
                   if j > 0:
                         _A        =       self.blend_h(row[j - 1]   ,							_UpperCAmelCase   ,							_UpperCAmelCase		)
                   result_row.append(tile[:, :, :row_limit, :row_limit]		)
             result_rows.append(torch.cat(_UpperCAmelCase   ,							dim=3		)		)

       _A        =       torch.cat(_UpperCAmelCase   ,							dim=2		)
       _A        =       DiagonalGaussianDistribution(_UpperCAmelCase		)

       if not return_dict:
             return (posterior,)

       return AutoencoderKLOutput(latent_dist=_UpperCAmelCase		)

 def       lowerCAmelCase_							(			self	:	Tuple   ,							_UpperCAmelCase	:	torch.FloatTensor   ,							_UpperCAmelCase	:	bool = True		):
       _A        =       int(self.tile_latent_min_size * (1 - self.tile_overlap_factor)		)
       _A        =       int(self.tile_sample_min_size * self.tile_overlap_factor		)
       _A        =       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.
       _A        =       []
       for i in range(0   ,							z.shape[2]   ,							_UpperCAmelCase		):
             _A        =       []
             for j in range(0   ,							z.shape[3]   ,							_UpperCAmelCase		):
                   _A        =       z[:, :, i : i + self.tile_latent_min_size, j : j + self.tile_latent_min_size]
                   _A        =       self.post_quant_conv(_UpperCAmelCase		)
                   _A        =       self.decoder(_UpperCAmelCase		)
                   row.append(_UpperCAmelCase		)
             rows.append(_UpperCAmelCase		)
       _A        =       []
       for i, row in enumerate(_UpperCAmelCase		):
             _A        =       []
             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:
                         _A        =       self.blend_v(rows[i - 1][j]   ,							_UpperCAmelCase   ,							_UpperCAmelCase		)
                   if j > 0:
                         _A        =       self.blend_h(row[j - 1]   ,							_UpperCAmelCase   ,							_UpperCAmelCase		)
                   result_row.append(tile[:, :, :row_limit, :row_limit]		)
             result_rows.append(torch.cat(_UpperCAmelCase   ,							dim=3		)		)

       _A        =       torch.cat(_UpperCAmelCase   ,							dim=2		)
       if not return_dict:
             return (dec,)

       return DecoderOutput(sample=_UpperCAmelCase		)



 def       lowerCAmelCase_							(			self	:	List[str]   ,							_UpperCAmelCase	:	torch.FloatTensor   ,							_UpperCAmelCase	:	bool = False   ,							_UpperCAmelCase	:	bool = True   ,							_UpperCAmelCase	:	Optional[torch.Generator] = None   ,							):
       _A        =       sample
       _A        =       self.encode(_UpperCAmelCase		).latent_dist
       if sample_posterior:
             _A        =       posterior.sample(generator=_UpperCAmelCase		)
       else:
             _A        =       posterior.mode()
       _A        =       self.decode(_UpperCAmelCase		).sample

       if not return_dict:
             return (dec,)

       return DecoderOutput(sample=_UpperCAmelCase		)

