


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       lowerCamelCase__   (       lowerCAmelCase):
     SCREAMING_SNAKE_CASE__      			=			42







class       lowerCamelCase__   (       lowerCAmelCase   ,							lowerCAmelCase):





     @register_to_config
     def __init__(self		,     UpperCAmelCase = 3		,     UpperCAmelCase = 3		,     UpperCAmelCase = ("DownEncoderBlock2D",)		,     UpperCAmelCase = ("UpDecoderBlock2D",)		,     UpperCAmelCase = (6_4,)		,     UpperCAmelCase = 1		,     UpperCAmelCase = "silu"		,     UpperCAmelCase = 3		,     UpperCAmelCase = 3_2		,     UpperCAmelCase = 2_5_6		,     UpperCAmelCase = 3_2		,     UpperCAmelCase = None		,     UpperCAmelCase = 0.1_8215		,     UpperCAmelCase = "group"		,     )     ->   Any:
      super().__init__()

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

      _lowercase							      =vq_embed_dim if vq_embed_dim is not None else latent_channels

      _lowercase							      =nn.Convad(UpperCAmelCase		,     UpperCAmelCase		,     1       )
      _lowercase							      =VectorQuantizer(UpperCAmelCase		,     UpperCAmelCase		,     beta=0.25		,     remap=UpperCAmelCase		,     sane_index_shape=UpperCAmelCase       )
      _lowercase							      =nn.Convad(UpperCAmelCase		,     UpperCAmelCase		,     1       )

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





     @apply_forward_hook
     def      __A					(self		,     UpperCAmelCase		,     UpperCAmelCase = True       )     ->   VQEncoderOutput:
      _lowercase							      =self.encoder(UpperCAmelCase       )
      _lowercase							      =self.quant_conv(UpperCAmelCase       )

      if not return_dict:
       return (h,)

      return VQEncoderOutput(latents=UpperCAmelCase       )





     @apply_forward_hook
     def      __A					(self		,     UpperCAmelCase		,     UpperCAmelCase = False		,     UpperCAmelCase = True       )     ->   Union[DecoderOutput, torch.FloatTensor]:
      # also go through quantization layer
      if not force_not_quantize:
       _lowercase      ,    _lowercase      ,    _lowercase							      =self.quantize(UpperCAmelCase       )
      else:
       _lowercase							      =h
      _lowercase							      =self.post_quant_conv(UpperCAmelCase       )
      _lowercase							      =self.decoder(UpperCAmelCase		,     quant if self.config.norm_type == '''spatial''' else None       )

      if not return_dict:
       return (dec,)

      return DecoderOutput(sample=UpperCAmelCase       )





     def      __A					(self		,     UpperCAmelCase		,     UpperCAmelCase = True       )     ->   Union[DecoderOutput, torch.FloatTensor]:
      _lowercase							      =sample
      _lowercase							      =self.encode(UpperCAmelCase       ).latents
      _lowercase							      =self.decode(UpperCAmelCase       ).sample

      if not return_dict:
       return (dec,)

      return DecoderOutput(sample=UpperCAmelCase       )





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCAmelCase__   	=							{
    '''configuration_timesformer''': ['''TIMESFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''TimesformerConfig'''],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCAmelCase__   	=							[
      '''TIMESFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
      '''TimesformerModel''',
      '''TimesformerForVideoClassification''',
      '''TimesformerPreTrainedModel''',
  ]

if TYPE_CHECKING:
  from .configuration_timesformer import TIMESFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, TimesformerConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_timesformer import (
        TIMESFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
        TimesformerForVideoClassification,
        TimesformerModel,
        TimesformerPreTrainedModel,
    )

else:
  import sys

  UpperCAmelCase__   	=							_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

