


from typing import Optional, Tuple, Union

import tensorflow as tf

from ...activations_tf import ACTaFN
from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward
from ...modeling_tf_outputs import (
    TFBaseModelOutputWithNoAttention,
    TFBaseModelOutputWithPoolingAndNoAttention,
    TFSequenceClassifierOutput,
)
from ...modeling_tf_utils import TFPreTrainedModel, TFSequenceClassificationLoss, keras_serializable, unpack_inputs
from ...tf_utils import shape_list
from ...utils import logging
from .configuration_regnet import RegNetConfig


__UpperCamelCase    :						Dict     =							logging.get_logger(__name__)

# General docstring
__UpperCamelCase    :						int     =							'RegNetConfig'

# Base docstring
__UpperCamelCase    :						str     =							'facebook/regnet-y-040'
__UpperCamelCase    :						Any     =							[1, 1088, 7, 7]

# Image classification docstring
__UpperCamelCase    :						Optional[int]     =							'facebook/regnet-y-040'
__UpperCamelCase    :						Any     =							'tabby, tabby cat'

__UpperCamelCase    :						Any     =							[
    'facebook/regnet-y-040',
    # See all regnet models at https://huggingface.co/models?filter=regnet
]



class 							_UpperCamelCase (						tf.keras.layers.Layer						):

   '''simple docstring'''







   def __init__(  self  : Union[str, Any]       ,  _lowerCamelCase  : int       ,  _lowerCamelCase  : int = 3       ,  _lowerCamelCase  : int = 1       ,  _lowerCamelCase  : int = 1       ,  _lowerCamelCase  : Optional[str] = "relu"       ,  **_lowerCamelCase  : Optional[int]       ,  ):






         '''simple docstring'''



         super().__init__(**_lowerCamelCase							)
         # The padding and conv has been verified in
         # https://colab.research.google.com/gist/sayakpaul/854bc10eeaf21c9ee2119e0b9f3841a7/scratchpad.ipynb
         __lowerCamelCase     :      Any       						=						tf.keras.layers.ZeroPaddingaD(padding=kernel_size // 2							)
         __lowerCamelCase     :      Dict       						=						tf.keras.layers.ConvaD(
             filters=_lowerCamelCase       ,  kernel_size=_lowerCamelCase       ,  strides=_lowerCamelCase       ,  padding="""VALID"""       ,  groups=_lowerCamelCase       ,  use_bias=_lowerCamelCase       ,  name="""convolution"""       ,  )
         __lowerCamelCase     :      List[Any]       						=						tf.keras.layers.BatchNormalization(epsilon=1E-5       ,  momentum=0.9       ,  name="""normalization"""							)
         __lowerCamelCase     :      Tuple       						=						ACTaFN[activation] if activation is not None else tf.identity


   def   _snake_case    (  self  : Tuple       ,  _lowerCamelCase  : Optional[int]							):






         '''simple docstring'''



         __lowerCamelCase     :      Dict       						=						self.convolution(self.padding(_lowerCamelCase							)							)
         __lowerCamelCase     :      Union[str, Any]       						=						self.normalization(_lowerCamelCase							)
         __lowerCamelCase     :      int       						=						self.activation(_lowerCamelCase							)
         return hidden_state



class 							_UpperCamelCase (						tf.keras.layers.Layer						):

   '''simple docstring'''







   def __init__(  self  : List[Any]       ,  _lowerCamelCase  : RegNetConfig       ,  **_lowerCamelCase  : Optional[Any]							):






         '''simple docstring'''



         super().__init__(**_lowerCamelCase							)
         __lowerCamelCase     :      List[Any]       						=						config.num_channels
         __lowerCamelCase     :      Any       						=						TFRegNetConvLayer(
             out_channels=config.embedding_size       ,  kernel_size=3       ,  stride=2       ,  activation=config.hidden_act       ,  name="""embedder"""       ,  )


   def   _snake_case    (  self  : Optional[Any]       ,  _lowerCamelCase  : Optional[int]							):






         '''simple docstring'''



         __lowerCamelCase     :      Union[str, Any]       						=						shape_list(_lowerCamelCase							)[1]
         if tf.executing_eagerly() and num_channels != self.num_channels:
               raise ValueError(
                   """Make sure that the channel dimension of the pixel values match with the one set in the configuration."""							)

         # When running on CPU, `tf.keras.layers.Conv2D` doesn't support `NCHW` format.
         # So change the input format from `NCHW` to `NHWC`.
         # shape = (batch_size, in_height, in_width, in_channels=num_channels)
         __lowerCamelCase     :      List[Any]       						=						tf.transpose(_lowerCamelCase       ,  perm=(0, 2, 3, 1)							)
         __lowerCamelCase     :      Dict       						=						self.embedder(_lowerCamelCase							)
         return hidden_state



class 							_UpperCamelCase (						tf.keras.layers.Layer						):

   '''simple docstring'''







   def __init__(  self  : Dict       ,  _lowerCamelCase  : int       ,  _lowerCamelCase  : int = 2       ,  **_lowerCamelCase  : str							):






         '''simple docstring'''



         super().__init__(**_lowerCamelCase							)
         __lowerCamelCase     :      List[Any]       						=						tf.keras.layers.ConvaD(
             filters=_lowerCamelCase       ,  kernel_size=1       ,  strides=_lowerCamelCase       ,  use_bias=_lowerCamelCase       ,  name="""convolution"""							)
         __lowerCamelCase     :      int       						=						tf.keras.layers.BatchNormalization(epsilon=1E-5       ,  momentum=0.9       ,  name="""normalization"""							)


   def   _snake_case    (  self  : int       ,  _lowerCamelCase  : tf.Tensor       ,  _lowerCamelCase  : bool = False							):






         '''simple docstring'''



         return self.normalization(self.convolution(_lowerCamelCase							)       ,  training=_lowerCamelCase							)



class 							_UpperCamelCase (						tf.keras.layers.Layer						):

   '''simple docstring'''







   def __init__(  self  : Dict       ,  _lowerCamelCase  : int       ,  _lowerCamelCase  : int       ,  **_lowerCamelCase  : int							):






         '''simple docstring'''



         super().__init__(**_lowerCamelCase							)
         __lowerCamelCase     :      List[Any]       						=						tf.keras.layers.GlobalAveragePoolingaD(keepdims=_lowerCamelCase       ,  name="""pooler"""							)
         __lowerCamelCase     :      int       						=						[
             tf.keras.layers.ConvaD(filters=_lowerCamelCase       ,  kernel_size=1       ,  activation="""relu"""       ,  name="""attention.0"""							),
             tf.keras.layers.ConvaD(filters=_lowerCamelCase       ,  kernel_size=1       ,  activation="""sigmoid"""       ,  name="""attention.2"""							),
         ]


   def   _snake_case    (  self  : int       ,  _lowerCamelCase  : List[Any]							):






         '''simple docstring'''



         __lowerCamelCase     :      str       						=						self.pooler(_lowerCamelCase							)
         for layer_module in self.attention:
               __lowerCamelCase     :      List[Any]       						=						layer_module(_lowerCamelCase							)
         __lowerCamelCase     :      Dict       						=						hidden_state * pooled
         return hidden_state



class 							_UpperCamelCase (						tf.keras.layers.Layer						):

   '''simple docstring'''







   def __init__(  self  : str       ,  _lowerCamelCase  : RegNetConfig       ,  _lowerCamelCase  : int       ,  _lowerCamelCase  : int       ,  _lowerCamelCase  : int = 1       ,  **_lowerCamelCase  : Optional[int]							):






         '''simple docstring'''



         super().__init__(**_lowerCamelCase							)
         __lowerCamelCase     :      Optional[int]       						=						in_channels != out_channels or stride != 1
         __lowerCamelCase     :      List[str]       						=						max(1       ,  out_channels // config.groups_width							)
         __lowerCamelCase     :      List[Any]       						=						(
             TFRegNetShortCut(_lowerCamelCase       ,  stride=_lowerCamelCase       ,  name="""shortcut"""							)
             if should_apply_shortcut
             else tf.keras.layers.Activation("""linear"""       ,  name="""shortcut"""							)
         )
         # `self.layers` instead of `self.layer` because that is a reserved argument.
         __lowerCamelCase     :      Tuple       						=						[
             TFRegNetConvLayer(_lowerCamelCase       ,  kernel_size=1       ,  activation=config.hidden_act       ,  name="""layer.0"""							),
             TFRegNetConvLayer(
                 _lowerCamelCase       ,  stride=_lowerCamelCase       ,  groups=_lowerCamelCase       ,  activation=config.hidden_act       ,  name="""layer.1"""							),
             TFRegNetConvLayer(_lowerCamelCase       ,  kernel_size=1       ,  activation=_lowerCamelCase       ,  name="""layer.2"""							),
         ]
         __lowerCamelCase     :      Optional[Any]       						=						ACTaFN[config.hidden_act]


   def   _snake_case    (  self  : str       ,  _lowerCamelCase  : Dict							):






         '''simple docstring'''



         __lowerCamelCase     :      int       						=						hidden_state
         for layer_module in self.layers:
               __lowerCamelCase     :      Tuple       						=						layer_module(_lowerCamelCase							)
         __lowerCamelCase     :      Optional[int]       						=						self.shortcut(_lowerCamelCase							)
         hidden_state += residual
         __lowerCamelCase     :      int       						=						self.activation(_lowerCamelCase							)
         return hidden_state



class 							_UpperCamelCase (						tf.keras.layers.Layer						):

   '''simple docstring'''







   def __init__(  self  : Any       ,  _lowerCamelCase  : RegNetConfig       ,  _lowerCamelCase  : int       ,  _lowerCamelCase  : int       ,  _lowerCamelCase  : int = 1       ,  **_lowerCamelCase  : Tuple							):






         '''simple docstring'''



         super().__init__(**_lowerCamelCase							)
         __lowerCamelCase     :      str       						=						in_channels != out_channels or stride != 1
         __lowerCamelCase     :      int       						=						max(1       ,  out_channels // config.groups_width							)
         __lowerCamelCase     :      Dict       						=						(
             TFRegNetShortCut(_lowerCamelCase       ,  stride=_lowerCamelCase       ,  name="""shortcut"""							)
             if should_apply_shortcut
             else tf.keras.layers.Activation("""linear"""       ,  name="""shortcut"""							)
         )
         __lowerCamelCase     :      Optional[int]       						=						[
             TFRegNetConvLayer(_lowerCamelCase       ,  kernel_size=1       ,  activation=config.hidden_act       ,  name="""layer.0"""							),
             TFRegNetConvLayer(
                 _lowerCamelCase       ,  stride=_lowerCamelCase       ,  groups=_lowerCamelCase       ,  activation=config.hidden_act       ,  name="""layer.1"""							),
             TFRegNetSELayer(_lowerCamelCase       ,  reduced_channels=int(round(in_channels / 4							)							)       ,  name="""layer.2"""							),
             TFRegNetConvLayer(_lowerCamelCase       ,  kernel_size=1       ,  activation=_lowerCamelCase       ,  name="""layer.3"""							),
         ]
         __lowerCamelCase     :      str       						=						ACTaFN[config.hidden_act]


   def   _snake_case    (  self  : str       ,  _lowerCamelCase  : Dict							):






         '''simple docstring'''



         __lowerCamelCase     :      str       						=						hidden_state
         for layer_module in self.layers:
               __lowerCamelCase     :      int       						=						layer_module(_lowerCamelCase							)
         __lowerCamelCase     :      Optional[Any]       						=						self.shortcut(_lowerCamelCase							)
         hidden_state += residual
         __lowerCamelCase     :      List[str]       						=						self.activation(_lowerCamelCase							)
         return hidden_state



class 							_UpperCamelCase (						tf.keras.layers.Layer						):

   '''simple docstring'''







   def __init__(  self  : str       ,  _lowerCamelCase  : RegNetConfig       ,  _lowerCamelCase  : int       ,  _lowerCamelCase  : int       ,  _lowerCamelCase  : int = 2       ,  _lowerCamelCase  : int = 2       ,  **_lowerCamelCase  : List[str]							):






         '''simple docstring'''



         super().__init__(**_lowerCamelCase							)

         __lowerCamelCase     :      Optional[int]       						=						TFRegNetXLayer if config.layer_type == """x""" else TFRegNetYLayer
         __lowerCamelCase     :      int       						=						[
             # downsampling is done in the first layer with stride of 2
             layer(_lowerCamelCase       ,  _lowerCamelCase       ,  _lowerCamelCase       ,  stride=_lowerCamelCase       ,  name="""layers.0"""							),
             *[layer(_lowerCamelCase       ,  _lowerCamelCase       ,  _lowerCamelCase       ,  name=F"""layers.{i+1}"""							) for i in range(depth - 1							)],
         ]


   def   _snake_case    (  self  : Union[str, Any]       ,  _lowerCamelCase  : Dict							):






         '''simple docstring'''



         for layer_module in self.layers:
               __lowerCamelCase     :      List[str]       						=						layer_module(_lowerCamelCase							)
         return hidden_state



class 							_UpperCamelCase (						tf.keras.layers.Layer						):

   '''simple docstring'''







   def __init__(  self  : Dict       ,  _lowerCamelCase  : RegNetConfig       ,  **_lowerCamelCase  : Tuple							):






         '''simple docstring'''



         super().__init__(**_lowerCamelCase							)
         __lowerCamelCase     :      str       						=						[]
         # based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
         self.stages.append(
             TFRegNetStage(
                 _lowerCamelCase       ,  config.embedding_size       ,  config.hidden_sizes[0]       ,  stride=2 if config.downsample_in_first_stage else 1       ,  depth=config.depths[0]       ,  name="""stages.0"""       ,  )							)
         __lowerCamelCase     :      str       						=						zip(config.hidden_sizes       ,  config.hidden_sizes[1:]							)
         for i, ((in_channels, out_channels), depth) in enumerate(zip(_lowerCamelCase       ,  config.depths[1:]							)							):
               self.stages.append(TFRegNetStage(_lowerCamelCase       ,  _lowerCamelCase       ,  _lowerCamelCase       ,  depth=_lowerCamelCase       ,  name=F"""stages.{i+1}"""							)							)


   def   _snake_case    (  self  : str       ,  _lowerCamelCase  : tf.Tensor       ,  _lowerCamelCase  : bool = False       ,  _lowerCamelCase  : bool = True							):






         '''simple docstring'''



         __lowerCamelCase     :      Any       						=						() if output_hidden_states else None

         for stage_module in self.stages:
               if output_hidden_states:
                     __lowerCamelCase     :      Union[str, Any]       						=						hidden_states + (hidden_state,)

               __lowerCamelCase     :      str       						=						stage_module(_lowerCamelCase							)

         if output_hidden_states:
               __lowerCamelCase     :      Any       						=						hidden_states + (hidden_state,)

         if not return_dict:
               return tuple(v for v in [hidden_state, hidden_states] if v is not None							)

         return TFBaseModelOutputWithNoAttention(last_hidden_state=_lowerCamelCase       ,  hidden_states=_lowerCamelCase							)



@keras_serializable
class 							_UpperCamelCase (						tf.keras.layers.Layer						):

   '''simple docstring'''







   a_				:							List[Any]    = RegNetConfig

   def __init__(  self  : Optional[int]       ,  _lowerCamelCase  : List[str]       ,  **_lowerCamelCase  : Dict							):






         '''simple docstring'''



         super().__init__(**_lowerCamelCase							)
         __lowerCamelCase     :      Optional[Any]       						=						config
         __lowerCamelCase     :      Optional[Any]       						=						TFRegNetEmbeddings(_lowerCamelCase       ,  name="""embedder"""							)
         __lowerCamelCase     :      Optional[Any]       						=						TFRegNetEncoder(_lowerCamelCase       ,  name="""encoder"""							)
         __lowerCamelCase     :      Any       						=						tf.keras.layers.GlobalAveragePoolingaD(keepdims=_lowerCamelCase       ,  name="""pooler"""							)


   @unpack_inputs
   def   _snake_case    (  self  : Optional[Any]       ,  _lowerCamelCase  : tf.Tensor       ,  _lowerCamelCase  : Optional[bool] = None       ,  _lowerCamelCase  : Optional[bool] = None       ,  _lowerCamelCase  : bool = False       ,  ):






         '''simple docstring'''



         __lowerCamelCase     :      Union[str, Any]       						=						(
             output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
         )
         __lowerCamelCase     :      Tuple       						=						return_dict if return_dict is not None else self.config.use_return_dict

         __lowerCamelCase     :      str       						=						self.embedder(_lowerCamelCase       ,  training=_lowerCamelCase							)

         __lowerCamelCase     :      Optional[Any]       						=						self.encoder(
             _lowerCamelCase       ,  output_hidden_states=_lowerCamelCase       ,  return_dict=_lowerCamelCase       ,  training=_lowerCamelCase							)

         __lowerCamelCase     :      List[str]       						=						encoder_outputs[0]
         __lowerCamelCase     :      int       						=						self.pooler(_lowerCamelCase							)

         # Change to NCHW output format have uniformity in the modules
         __lowerCamelCase     :      Tuple       						=						tf.transpose(_lowerCamelCase       ,  perm=(0, 3, 1, 2)							)
         __lowerCamelCase     :      str       						=						tf.transpose(_lowerCamelCase       ,  perm=(0, 3, 1, 2)							)

         # Change the other hidden state outputs to NCHW as well
         if output_hidden_states:
               __lowerCamelCase     :      List[str]       						=						tuple([tf.transpose(_lowerCamelCase       ,  perm=(0, 3, 1, 2)							) for h in encoder_outputs[1]]							)

         if not return_dict:
               return (last_hidden_state, pooled_output) + encoder_outputs[1:]

         return TFBaseModelOutputWithPoolingAndNoAttention(
             last_hidden_state=_lowerCamelCase       ,  pooler_output=_lowerCamelCase       ,  hidden_states=hidden_states if output_hidden_states else encoder_outputs.hidden_states       ,  )



class 							_UpperCamelCase (						A						):

   '''simple docstring'''







   a_				:							int    = RegNetConfig
   a_				:							List[Any]    = "regnet"
   a_				:							Optional[Any]    = "pixel_values"

   @property
   def   _snake_case    (  self  : str							):






         '''simple docstring'''



         return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 2_2_4, 2_2_4)       ,  dtype=tf.floataa							)}

__UpperCamelCase    :						Optional[int]     =							R'\n    Parameters:\n    This model is a Tensorflow\n    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a\n    regular Tensorflow Module and refer to the Tensorflow documentation for all matter related to general usage and\n    behavior.\n        config ([`RegNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.\n'

__UpperCamelCase    :						int     =							R'\n    Args:\n        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConveNextImageProcessor.__call__`] for details.\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n'



@add_start_docstrings(
    "The bare RegNet model outputting raw features without any specific head on top.",A,)
class 							_UpperCamelCase (						A						):

   '''simple docstring'''







   def __init__(  self  : Optional[int]       ,  _lowerCamelCase  : RegNetConfig       ,  *_lowerCamelCase  : str       ,  **_lowerCamelCase  : Optional[Any]							):






         '''simple docstring'''



         super().__init__(_lowerCamelCase       ,  *_lowerCamelCase       ,  **_lowerCamelCase							)
         __lowerCamelCase     :      Any       						=						TFRegNetMainLayer(_lowerCamelCase       ,  name="""regnet"""							)


   @unpack_inputs
   @add_start_docstrings_to_model_forward(_lowerCamelCase							)
   @add_code_sample_docstrings(
       checkpoint=_CHECKPOINT_FOR_DOC       ,  output_type=_lowerCamelCase       ,  config_class=_CONFIG_FOR_DOC       ,  modality="""vision"""       ,  expected_output=_EXPECTED_OUTPUT_SHAPE       ,  )
   def   _snake_case    (  self  : List[str]       ,  _lowerCamelCase  : tf.Tensor       ,  _lowerCamelCase  : Optional[bool] = None       ,  _lowerCamelCase  : Optional[bool] = None       ,  _lowerCamelCase  : Optional[int]=False       ,  ):






         '''simple docstring'''



         __lowerCamelCase     :      str       						=						(
             output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
         )
         __lowerCamelCase     :      Tuple       						=						return_dict if return_dict is not None else self.config.use_return_dict

         __lowerCamelCase     :      Optional[Any]       						=						self.regnet(
             pixel_values=_lowerCamelCase       ,  output_hidden_states=_lowerCamelCase       ,  return_dict=_lowerCamelCase       ,  training=_lowerCamelCase       ,  )
         if not return_dict:
               return (outputs[0],) + outputs[1:]

         return TFBaseModelOutputWithPoolingAndNoAttention(
             last_hidden_state=outputs.last_hidden_state       ,  pooler_output=outputs.pooler_output       ,  hidden_states=outputs.hidden_states       ,  )



@add_start_docstrings(
    "\n    RegNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for\n    ImageNet.\n    ",A,)
class 							_UpperCamelCase (						A,A						):

   '''simple docstring'''







   def __init__(  self  : Any       ,  _lowerCamelCase  : RegNetConfig       ,  *_lowerCamelCase  : Union[str, Any]       ,  **_lowerCamelCase  : Any							):






         '''simple docstring'''



         super().__init__(_lowerCamelCase       ,  *_lowerCamelCase       ,  **_lowerCamelCase							)
         __lowerCamelCase     :      Optional[int]       						=						config.num_labels
         __lowerCamelCase     :      str       						=						TFRegNetMainLayer(_lowerCamelCase       ,  name="""regnet"""							)
         # classification head
         __lowerCamelCase     :      Tuple       						=						[
             tf.keras.layers.Flatten(),
             tf.keras.layers.Dense(config.num_labels       ,  name="""classifier.1"""							) if config.num_labels > 0 else tf.identity,
         ]


   @unpack_inputs
   @add_start_docstrings_to_model_forward(_lowerCamelCase							)
   @add_code_sample_docstrings(
       checkpoint=_IMAGE_CLASS_CHECKPOINT       ,  output_type=_lowerCamelCase       ,  config_class=_CONFIG_FOR_DOC       ,  expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT       ,  )
   def   _snake_case    (  self  : str       ,  _lowerCamelCase  : tf.Tensor = None       ,  _lowerCamelCase  : tf.Tensor = None       ,  _lowerCamelCase  : bool = None       ,  _lowerCamelCase  : bool = None       ,  _lowerCamelCase  : Optional[int]=False       ,  ):






         '''simple docstring'''



         __lowerCamelCase     :      int       						=						(
             output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
         )
         __lowerCamelCase     :      Any       						=						return_dict if return_dict is not None else self.config.use_return_dict

         __lowerCamelCase     :      Dict       						=						self.regnet(
             _lowerCamelCase       ,  output_hidden_states=_lowerCamelCase       ,  return_dict=_lowerCamelCase       ,  training=_lowerCamelCase							)

         __lowerCamelCase     :      Any       						=						outputs.pooler_output if return_dict else outputs[1]

         __lowerCamelCase     :      Dict       						=						self.classifier[0](_lowerCamelCase							)
         __lowerCamelCase     :      Optional[Any]       						=						self.classifier[1](_lowerCamelCase							)

         __lowerCamelCase     :      List[Any]       						=						None if labels is None else self.hf_compute_loss(labels=_lowerCamelCase       ,  logits=_lowerCamelCase							)

         if not return_dict:
               __lowerCamelCase     :      Optional[Any]       						=						(logits,) + outputs[2:]
               return ((loss,) + output) if loss is not None else output

         return TFSequenceClassifierOutput(loss=_lowerCamelCase       ,  logits=_lowerCamelCase       ,  hidden_states=outputs.hidden_states							)







# 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


__UpperCamelCase    :						Any     =							{
    '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:
    __UpperCamelCase    :						Tuple     =							[
        '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

    __UpperCamelCase    :						Optional[Any]     =							_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



