





"""simple docstring"""





def 					__A  (_SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE     )   ->int:





  """simple docstring"""


  return number | (1 << position)
def 					__A  (_SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE     )   ->int:





  """simple docstring"""


  return number & ~(1 << position)
def 					__A  (_SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE     )   ->int:





  """simple docstring"""


  return number ^ (1 << position)
def 					__A  (_SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE     )   ->bool:





  """simple docstring"""


  return ((number >> position) & 1) == 1
def 					__A  (_SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE     )   ->int:





  """simple docstring"""


  return int((number & (1 << position)) != 0     )


if __name__ == "__main__":
  import doctest

  doctest.testmod()







from dataclasses import dataclass
from typing import 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 .modeling_utils import ModelMixin
from .vae import Decoder, DecoderOutput, Encoder, VectorQuantizer




@dataclass
class 	UpperCamelCase_							(  UpperCamelCase__     ):
							lowerCamelCase_							     =       42




class 	UpperCamelCase_							(  UpperCamelCase__					,	UpperCamelCase__     ):


							@register_to_config
							def __init__(				self     :Union[str, Any]				,					__A     :int = 3				,					__A     :int = 3				,					__A     :Tuple[str] = ("DownEncoderBlock2D",)				,					__A     :Tuple[str] = ("UpDecoderBlock2D",)				,					__A     :Tuple[int] = (64,)				,					__A     :int = 1				,					__A     :str = "silu"				,					__A     :int = 3				,					__A     :int = 32				,					__A     :int = 256				,					__A     :int = 32				,					__A     :Optional[int] = None				,					__A     :float = 0.1_8_2_1_5				,					__A     :str = "group"				,					) -> Any:



									"""simple docstring"""



									super().__init__()

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

									SCREAMING_SNAKE_CASE__								=   vq_embed_dim if vq_embed_dim is not None else latent_channels

									SCREAMING_SNAKE_CASE__								=   nn.Convad(__A				,					__A				,					1		)
									SCREAMING_SNAKE_CASE__								=   VectorQuantizer(__A				,					__A				,					beta=0.2_5				,					remap=__A				,					sane_index_shape=__A		)
									SCREAMING_SNAKE_CASE__								=   nn.Convad(__A				,					__A				,					1		)

									# pass init params to Decoder
									SCREAMING_SNAKE_CASE__								=   Decoder(
									    in_channels=__A				,					out_channels=__A				,					up_block_types=__A				,					block_out_channels=__A				,					layers_per_block=__A				,					act_fn=__A				,					norm_num_groups=__A				,					norm_type=__A				,					)


							@apply_forward_hook
							def   _snake_case	(				self     :Union[str, Any]				,					__A     :torch.FloatTensor				,					__A     :bool = True		) -> VQEncoderOutput:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   self.encoder(__A		)
									SCREAMING_SNAKE_CASE__								=   self.quant_conv(__A		)

									if not return_dict:
											return (h,)

									return VQEncoderOutput(latents=__A		)


							@apply_forward_hook
							def   _snake_case	(				self     :Tuple				,					__A     :torch.FloatTensor				,					__A     :bool = False				,					__A     :bool = True		) -> Union[DecoderOutput, torch.FloatTensor]:



									"""simple docstring"""



									if not force_not_quantize:
											SCREAMING_SNAKE_CASE__						,    SCREAMING_SNAKE_CASE__						,    SCREAMING_SNAKE_CASE__								=   self.quantize(__A		)
									else:
											SCREAMING_SNAKE_CASE__								=   h
									SCREAMING_SNAKE_CASE__								=   self.post_quant_conv(__A		)
									SCREAMING_SNAKE_CASE__								=   self.decoder(__A				,					quant if self.config.norm_type == """spatial""" else None		)

									if not return_dict:
											return (dec,)

									return DecoderOutput(sample=__A		)


							def   _snake_case	(				self     :int				,					__A     :torch.FloatTensor				,					__A     :bool = True		) -> Union[DecoderOutput, torch.FloatTensor]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=   sample
									SCREAMING_SNAKE_CASE__								=   self.encode(__A		).latents
									SCREAMING_SNAKE_CASE__								=   self.decode(__A		).sample

									if not return_dict:
											return (dec,)

									return DecoderOutput(sample=__A		)