




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 						__lowercase		(UpperCAmelCase__							):




      """simple docstring"""





      _snake_case							     =						42




class 						__lowercase		(UpperCAmelCase__     ,		UpperCAmelCase__							):




      """simple docstring"""





      @register_to_config
      def __init__(      self				,      A = 3				,      A = 3				,      A = ("DownEncoderBlock2D",)				,      A = ("UpDecoderBlock2D",)				,      A = (6_4,)				,      A = 1				,      A = "silu"				,      A = 3				,      A = 3_2				,      A = 2_5_6				,      A = 3_2				,      A = None				,      A = 0.1_82_15				,      A = "group"				,      )		->				Optional[int]:
         super().__init__()

         # pass init params to Encoder
         snake_case      :				Union[str, Any]				=       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				,      )

         snake_case      :				Optional[int]				=       vq_embed_dim if vq_embed_dim is not None else latent_channels

         snake_case      :				Optional[int]				=       nn.Convad(A				,      A				,      1	)
         snake_case      :				str				=       VectorQuantizer(A				,      A				,      beta=0.25				,      remap=A				,      sane_index_shape=A	)
         snake_case      :				List[str]				=       nn.Convad(A				,      A				,      1	)

         # pass init params to Decoder
         snake_case      :				List[str]				=       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 	UpperCAmelCase      (      self				,      A				,      A = True	)		->				VQEncoderOutput:
         snake_case      :				Optional[int]				=       self.encoder(A	)
         snake_case      :				int				=       self.quant_conv(A	)

         if not return_dict:
            return (h,)

         return VQEncoderOutput(latents=A	)

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

         if not return_dict:
            return (dec,)

         return DecoderOutput(sample=A	)

      def 	UpperCAmelCase      (      self				,      A				,      A = True	)		->				Union[DecoderOutput, torch.FloatTensor]:
         snake_case      :				Tuple				=       sample
         snake_case      :				int				=       self.encode(A	).latents
         snake_case      :				List[Any]				=       self.decode(A	).sample

         if not return_dict:
            return (dec,)

         return DecoderOutput(sample=A	)









'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


A__:    List[str]					    =       {
    '''configuration_chinese_clip''': [
        '''CHINESE_CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''ChineseCLIPConfig''',
        '''ChineseCLIPOnnxConfig''',
        '''ChineseCLIPTextConfig''',
        '''ChineseCLIPVisionConfig''',
    ],
    '''processing_chinese_clip''': ['''ChineseCLIPProcessor'''],
}

try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A__:    Optional[int]					    =       ['''ChineseCLIPFeatureExtractor''']
   A__:    Any					    =       ['''ChineseCLIPImageProcessor''']

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A__:    Dict					    =       [
       '''CHINESE_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''ChineseCLIPModel''',
       '''ChineseCLIPPreTrainedModel''',
       '''ChineseCLIPTextModel''',
       '''ChineseCLIPVisionModel''',
   ]

if TYPE_CHECKING:
   from .configuration_chinese_clip import (
       CHINESE_CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
       ChineseCLIPConfig,
       ChineseCLIPOnnxConfig,
       ChineseCLIPTextConfig,
       ChineseCLIPVisionConfig,
   )
   from .processing_chinese_clip import ChineseCLIPProcessor

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .feature_extraction_chinese_clip import ChineseCLIPFeatureExtractor, ChineseCLIPImageProcessor

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_chinese_clip import (
          CHINESE_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
          ChineseCLIPModel,
          ChineseCLIPPreTrainedModel,
          ChineseCLIPTextModel,
          ChineseCLIPVisionModel,
      )

else:
   import sys

   A__:    str					    =       _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


