

'''simple docstring'''



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__  ( a   ):



 """simple docstring"""



 lowerCAmelCase__       = 42







class 		lowerCAmelCase__  ( a					,   a   ):



 """simple docstring"""



 @register_to_config
 def __init__(						self   :			Dict   ,				__SCREAMING_SNAKE_CASE   :			str = 3   ,				__SCREAMING_SNAKE_CASE   :			Union[str, Any] = 3   ,				__SCREAMING_SNAKE_CASE   :			Optional[Any] = ("DownEncoderBlock2D",)   ,				__SCREAMING_SNAKE_CASE   :			List[str] = ("UpDecoderBlock2D",)   ,				__SCREAMING_SNAKE_CASE   :			List[str] = (64,)   ,				__SCREAMING_SNAKE_CASE   :			Optional[Any] = 1   ,				__SCREAMING_SNAKE_CASE   :			Optional[Any] = "silu"   ,				__SCREAMING_SNAKE_CASE   :			Optional[int] = 3   ,				__SCREAMING_SNAKE_CASE   :			Optional[Any] = 32   ,				__SCREAMING_SNAKE_CASE   :			Optional[Any] = 256   ,				__SCREAMING_SNAKE_CASE   :			int = 32   ,				__SCREAMING_SNAKE_CASE   :			str = None   ,				__SCREAMING_SNAKE_CASE   :			str = 0.18215   ,				__SCREAMING_SNAKE_CASE   :			List[Any] = "group"   ,				)    ->					List[str]:


      """simple docstring"""




      super().__init__()

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

      __SCREAMING_SNAKE_CASE      = vq_embed_dim if vq_embed_dim is not None else latent_channels

      __SCREAMING_SNAKE_CASE      = nn.Convad(__UpperCAmelCase   ,				__UpperCAmelCase   ,				1     )
      __SCREAMING_SNAKE_CASE      = VectorQuantizer(__UpperCAmelCase   ,				__UpperCAmelCase   ,				beta=0.25   ,				remap=__UpperCAmelCase   ,				sane_index_shape=__UpperCAmelCase     )
      __SCREAMING_SNAKE_CASE      = nn.Convad(__UpperCAmelCase   ,				__UpperCAmelCase   ,				1     )

      # pass init params to Decoder
      __SCREAMING_SNAKE_CASE      = 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  UpperCAmelCase__						(						self   :			List[str]   ,				__SCREAMING_SNAKE_CASE   :			Any   ,				__SCREAMING_SNAKE_CASE   :			Union[str, Any] = True     )    ->					Union[str, Any]:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE      = self.encoder(__UpperCAmelCase     )
      __SCREAMING_SNAKE_CASE      = self.quant_conv(__UpperCAmelCase     )

      if not return_dict:
           return (h,)

      return VQEncoderOutput(latents=__UpperCAmelCase     )
 @apply_forward_hook
 def  UpperCAmelCase__						(						self   :			List[str]   ,				__SCREAMING_SNAKE_CASE   :			Optional[int]   ,				__SCREAMING_SNAKE_CASE   :			str = False   ,				__SCREAMING_SNAKE_CASE   :			Tuple = True     )    ->					Union[str, Any]:


      """simple docstring"""




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

      if not return_dict:
           return (dec,)

      return DecoderOutput(sample=__UpperCAmelCase     )


 def  UpperCAmelCase__						(						self   :			Any   ,				__SCREAMING_SNAKE_CASE   :			Union[str, Any]   ,				__SCREAMING_SNAKE_CASE   :			List[str] = True     )    ->					int:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE      = sample
      __SCREAMING_SNAKE_CASE      = self.encode(__UpperCAmelCase     ).latents
      __SCREAMING_SNAKE_CASE      = self.decode(__UpperCAmelCase     ).sample

      if not return_dict:
           return (dec,)

      return DecoderOutput(sample=__UpperCAmelCase     )













"""simple docstring"""





# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__A											=						{
    """configuration_mgp_str""": ["""MGP_STR_PRETRAINED_CONFIG_ARCHIVE_MAP""", """MgpstrConfig"""],
    """processing_mgp_str""": ["""MgpstrProcessor"""],
    """tokenization_mgp_str""": ["""MgpstrTokenizer"""],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __A											=						[
      """MGP_STR_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """MgpstrModel""",
      """MgpstrPreTrainedModel""",
      """MgpstrForSceneTextRecognition""",
  ]

if TYPE_CHECKING:
  from .configuration_mgp_str import MGP_STR_PRETRAINED_CONFIG_ARCHIVE_MAP, MgpstrConfig
  from .processing_mgp_str import MgpstrProcessor
  from .tokenization_mgp_str import MgpstrTokenizer

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_mgp_str import (
        MGP_STR_PRETRAINED_MODEL_ARCHIVE_LIST,
        MgpstrForSceneTextRecognition,
        MgpstrModel,
        MgpstrPreTrainedModel,
    )
else:
  import sys

  __A											=						_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)
