






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


lowerCamelCase	:							Optional[Any]				=logging.get_logger(__name__)

# General docstring
lowerCamelCase	:							Optional[Any]				='''RegNetConfig'''

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

# Image classification docstring
lowerCamelCase	:							Dict				='''facebook/regnet-y-040'''
lowerCamelCase	:							Union[str, Any]				='''tabby, tabby cat'''

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





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







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


      '''simple docstring'''






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







 def 					__lowercase					(		self					:   Tuple							,   SCREAMING_SNAKE_CASE					:   str						):


      '''simple docstring'''






      UpperCamelCase__			:   Optional[Any]       				=  self.convolution(self.padding(UpperCamelCase_						)						)
      UpperCamelCase__			:   int       				=  self.normalization(UpperCamelCase_						)
      UpperCamelCase__			:   Tuple       				=  self.activation(UpperCamelCase_						)
      return hidden_state







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







 def __init__(		self					:   Dict							,   SCREAMING_SNAKE_CASE					:   Any							,   **SCREAMING_SNAKE_CASE					:   Optional[int]						):


      '''simple docstring'''






      super().__init__(**UpperCamelCase_						)
      UpperCamelCase__			:   Dict       				=  config.num_channels
      UpperCamelCase__			:   Union[str, Any]       				=  TFRegNetConvLayer(
          out_channels=config.embedding_size							,   kernel_size=3							,   stride=2							,   activation=config.hidden_act							,   name="embedder"							,   )







 def 					__lowercase					(		self					:   Tuple							,   SCREAMING_SNAKE_CASE					:   Any						):


      '''simple docstring'''






      UpperCamelCase__			:   Optional[Any]       				=  shape_list(UpperCamelCase_						)[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)
      UpperCamelCase__			:   int       				=  tf.transpose(UpperCamelCase_							,   perm=(0, 2, 3, 1)						)
      UpperCamelCase__			:   Dict       				=  self.embedder(UpperCamelCase_						)
      return hidden_state







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







 def __init__(		self					:   List[Any]							,   SCREAMING_SNAKE_CASE					:   str							,   SCREAMING_SNAKE_CASE					:   Any = 2							,   **SCREAMING_SNAKE_CASE					:   Optional[Any]						):


      '''simple docstring'''






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







 def 					__lowercase					(		self					:   str							,   SCREAMING_SNAKE_CASE					:   Optional[Any]							,   SCREAMING_SNAKE_CASE					:   Optional[int] = False						):


      '''simple docstring'''






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







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







 def __init__(		self					:   Union[str, Any]							,   SCREAMING_SNAKE_CASE					:   int							,   SCREAMING_SNAKE_CASE					:   int							,   **SCREAMING_SNAKE_CASE					:   Any						):


      '''simple docstring'''






      super().__init__(**UpperCamelCase_						)
      UpperCamelCase__			:   Tuple       				=  tf.keras.layers.GlobalAveragePoolingaD(keepdims=UpperCamelCase_							,   name="pooler"						)
      UpperCamelCase__			:   str       				=  [
          tf.keras.layers.ConvaD(filters=UpperCamelCase_							,   kernel_size=1							,   activation="relu"							,   name="attention.0"						),
          tf.keras.layers.ConvaD(filters=UpperCamelCase_							,   kernel_size=1							,   activation="sigmoid"							,   name="attention.2"						),
      ]







 def 					__lowercase					(		self					:   int							,   SCREAMING_SNAKE_CASE					:   List[str]						):


      '''simple docstring'''






      UpperCamelCase__			:   Any       				=  self.pooler(UpperCamelCase_						)
      for layer_module in self.attention:
           UpperCamelCase__			:   Tuple       				=  layer_module(UpperCamelCase_						)
      UpperCamelCase__			:   Tuple       				=  hidden_state * pooled
      return hidden_state







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







 def __init__(		self					:   int							,   SCREAMING_SNAKE_CASE					:   Optional[Any]							,   SCREAMING_SNAKE_CASE					:   Optional[Any]							,   SCREAMING_SNAKE_CASE					:   str							,   SCREAMING_SNAKE_CASE					:   Optional[Any] = 1							,   **SCREAMING_SNAKE_CASE					:   int						):


      '''simple docstring'''






      super().__init__(**UpperCamelCase_						)
      UpperCamelCase__			:   Union[str, Any]       				=  in_channels != out_channels or stride != 1
      UpperCamelCase__			:   Any       				=  max(1							,   out_channels // config.groups_width						)
      UpperCamelCase__			:   Optional[Any]       				=  (
          TFRegNetShortCut(UpperCamelCase_							,   stride=UpperCamelCase_							,   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.
      UpperCamelCase__			:   Optional[Any]       				=  [
          TFRegNetConvLayer(UpperCamelCase_							,   kernel_size=1							,   activation=config.hidden_act							,   name="layer.0"						),
          TFRegNetConvLayer(
              UpperCamelCase_							,   stride=UpperCamelCase_							,   groups=UpperCamelCase_							,   activation=config.hidden_act							,   name="layer.1"						),
          TFRegNetConvLayer(UpperCamelCase_							,   kernel_size=1							,   activation=UpperCamelCase_							,   name="layer.2"						),
      ]
      UpperCamelCase__			:   List[Any]       				=  ACTaFN[config.hidden_act]







 def 					__lowercase					(		self					:   Optional[Any]							,   SCREAMING_SNAKE_CASE					:   int						):


      '''simple docstring'''






      UpperCamelCase__			:   Any       				=  hidden_state
      for layer_module in self.layers:
           UpperCamelCase__			:   int       				=  layer_module(UpperCamelCase_						)
      UpperCamelCase__			:   Union[str, Any]       				=  self.shortcut(UpperCamelCase_						)
      hidden_state += residual
      UpperCamelCase__			:   str       				=  self.activation(UpperCamelCase_						)
      return hidden_state







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







 def __init__(		self					:   List[Any]							,   SCREAMING_SNAKE_CASE					:   Any							,   SCREAMING_SNAKE_CASE					:   Any							,   SCREAMING_SNAKE_CASE					:   Optional[int]							,   SCREAMING_SNAKE_CASE					:   int = 1							,   **SCREAMING_SNAKE_CASE					:   Union[str, Any]						):


      '''simple docstring'''






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







 def 					__lowercase					(		self					:   Optional[int]							,   SCREAMING_SNAKE_CASE					:   Optional[int]						):


      '''simple docstring'''






      UpperCamelCase__			:   List[Any]       				=  hidden_state
      for layer_module in self.layers:
           UpperCamelCase__			:   Optional[Any]       				=  layer_module(UpperCamelCase_						)
      UpperCamelCase__			:   Optional[Any]       				=  self.shortcut(UpperCamelCase_						)
      hidden_state += residual
      UpperCamelCase__			:   Dict       				=  self.activation(UpperCamelCase_						)
      return hidden_state







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







 def __init__(		self					:   List[str]							,   SCREAMING_SNAKE_CASE					:   Dict							,   SCREAMING_SNAKE_CASE					:   List[Any]							,   SCREAMING_SNAKE_CASE					:   int							,   SCREAMING_SNAKE_CASE					:   Any = 2							,   SCREAMING_SNAKE_CASE					:   Dict = 2							,   **SCREAMING_SNAKE_CASE					:   List[str]						):


      '''simple docstring'''






      super().__init__(**UpperCamelCase_						)

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







 def 					__lowercase					(		self					:   Any							,   SCREAMING_SNAKE_CASE					:   str						):


      '''simple docstring'''






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







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







 def __init__(		self					:   Union[str, Any]							,   SCREAMING_SNAKE_CASE					:   List[str]							,   **SCREAMING_SNAKE_CASE					:   int						):


      '''simple docstring'''






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







 def 					__lowercase					(		self					:   Any							,   SCREAMING_SNAKE_CASE					:   Tuple							,   SCREAMING_SNAKE_CASE					:   Tuple = False							,   SCREAMING_SNAKE_CASE					:   Union[str, Any] = True						):


      '''simple docstring'''






      UpperCamelCase__			:   Any       				=  () if output_hidden_states else None

      for stage_module in self.stages:
           if output_hidden_states:
                UpperCamelCase__			:   List[Any]       				=  hidden_states + (hidden_state,)

           UpperCamelCase__			:   Optional[Any]       				=  stage_module(UpperCamelCase_						)

      if output_hidden_states:
           UpperCamelCase__			:   Dict       				=  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=UpperCamelCase_							,   hidden_states=UpperCamelCase_						)







@keras_serializable
class 			__a  (    tf.keras.layers.Layer       ):
 _lowerCAmelCase       :       Union[str, Any]        = RegNetConfig







 def __init__(		self					:   Optional[Any]							,   SCREAMING_SNAKE_CASE					:   Dict							,   **SCREAMING_SNAKE_CASE					:   Optional[Any]						):


      '''simple docstring'''






      super().__init__(**UpperCamelCase_						)
      UpperCamelCase__			:   Any       				=  config
      UpperCamelCase__			:   Dict       				=  TFRegNetEmbeddings(UpperCamelCase_							,   name="embedder"						)
      UpperCamelCase__			:   Any       				=  TFRegNetEncoder(UpperCamelCase_							,   name="encoder"						)
      UpperCamelCase__			:   Union[str, Any]       				=  tf.keras.layers.GlobalAveragePoolingaD(keepdims=UpperCamelCase_							,   name="pooler"						)







 @unpack_inputs
 def 					__lowercase					(		self					:   Tuple							,   SCREAMING_SNAKE_CASE					:   Optional[Any]							,   SCREAMING_SNAKE_CASE					:   Dict = None							,   SCREAMING_SNAKE_CASE					:   Optional[Any] = None							,   SCREAMING_SNAKE_CASE					:   List[Any] = False							,   ):


      '''simple docstring'''






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

      UpperCamelCase__			:   List[str]       				=  self.embedder(UpperCamelCase_							,   training=UpperCamelCase_						)

      UpperCamelCase__			:   Optional[int]       				=  self.encoder(
          UpperCamelCase_							,   output_hidden_states=UpperCamelCase_							,   return_dict=UpperCamelCase_							,   training=UpperCamelCase_						)

      UpperCamelCase__			:   Union[str, Any]       				=  encoder_outputs[0]
      UpperCamelCase__			:   str       				=  self.pooler(UpperCamelCase_						)

      # Change to NCHW output format have uniformity in the modules
      UpperCamelCase__			:   Tuple       				=  tf.transpose(UpperCamelCase_							,   perm=(0, 3, 1, 2)						)
      UpperCamelCase__			:   List[str]       				=  tf.transpose(UpperCamelCase_							,   perm=(0, 3, 1, 2)						)

      # Change the other hidden state outputs to NCHW as well
      if output_hidden_states:
           UpperCamelCase__			:   Union[str, Any]       				=  tuple([tf.transpose(UpperCamelCase_							,   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=UpperCamelCase_							,   pooler_output=UpperCamelCase_							,   hidden_states=hidden_states if output_hidden_states else encoder_outputs.hidden_states							,   )







class 			__a  (    A__       ):
 _lowerCAmelCase       :       str        = RegNetConfig
 _lowerCAmelCase       :       List[Any]        = '''regnet'''
 _lowerCAmelCase       :       int        = '''pixel_values'''







 @property
 def 					__lowercase					(		self					:   Union[str, Any]						):


      '''simple docstring'''






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







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

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





@add_start_docstrings(
    '''The bare RegNet model outputting raw features without any specific head on top.'''       ,   A__       ,   )
class 			__a  (    A__       ):







 def __init__(		self					:   Union[str, Any]							,   SCREAMING_SNAKE_CASE					:   Any							,   *SCREAMING_SNAKE_CASE					:   Optional[int]							,   **SCREAMING_SNAKE_CASE					:   str						):


      '''simple docstring'''






      super().__init__(UpperCamelCase_							,   *UpperCamelCase_							,   **UpperCamelCase_						)
      UpperCamelCase__			:   str       				=  TFRegNetMainLayer(UpperCamelCase_							,   name="regnet"						)







 @unpack_inputs
 @add_start_docstrings_to_model_forward(UpperCamelCase_						)
 @add_code_sample_docstrings(
     checkpoint=_CHECKPOINT_FOR_DOC							,   output_type=UpperCamelCase_							,   config_class=_CONFIG_FOR_DOC							,   modality="vision"							,   expected_output=_EXPECTED_OUTPUT_SHAPE							,   )
 def 					__lowercase					(		self					:   List[str]							,   SCREAMING_SNAKE_CASE					:   Optional[int]							,   SCREAMING_SNAKE_CASE					:   Optional[Any] = None							,   SCREAMING_SNAKE_CASE					:   Dict = None							,   SCREAMING_SNAKE_CASE					:   Tuple=False							,   ):


      '''simple docstring'''






      UpperCamelCase__			:   str       				=  (
          output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
      )
      UpperCamelCase__			:   Optional[int]       				=  return_dict if return_dict is not None else self.config.use_return_dict

      UpperCamelCase__			:   Tuple       				=  self.regnet(
          pixel_values=UpperCamelCase_							,   output_hidden_states=UpperCamelCase_							,   return_dict=UpperCamelCase_							,   training=UpperCamelCase_							,   )
      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 			__a  (    A__       ,   A__       ):







 def __init__(		self					:   str							,   SCREAMING_SNAKE_CASE					:   List[Any]							,   *SCREAMING_SNAKE_CASE					:   Union[str, Any]							,   **SCREAMING_SNAKE_CASE					:   Union[str, Any]						):


      '''simple docstring'''






      super().__init__(UpperCamelCase_							,   *UpperCamelCase_							,   **UpperCamelCase_						)
      UpperCamelCase__			:   List[str]       				=  config.num_labels
      UpperCamelCase__			:   Dict       				=  TFRegNetMainLayer(UpperCamelCase_							,   name="regnet"						)
      # classification head
      UpperCamelCase__			:   str       				=  [
          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(UpperCamelCase_						)
 @add_code_sample_docstrings(
     checkpoint=_IMAGE_CLASS_CHECKPOINT							,   output_type=UpperCamelCase_							,   config_class=_CONFIG_FOR_DOC							,   expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT							,   )
 def 					__lowercase					(		self					:   int							,   SCREAMING_SNAKE_CASE					:   Dict = None							,   SCREAMING_SNAKE_CASE					:   List[Any] = None							,   SCREAMING_SNAKE_CASE					:   Optional[Any] = None							,   SCREAMING_SNAKE_CASE					:   List[str] = None							,   SCREAMING_SNAKE_CASE					:   Tuple=False							,   ):


      '''simple docstring'''






      UpperCamelCase__			:   Optional[Any]       				=  (
          output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
      )
      UpperCamelCase__			:   List[Any]       				=  return_dict if return_dict is not None else self.config.use_return_dict

      UpperCamelCase__			:   List[str]       				=  self.regnet(
          UpperCamelCase_							,   output_hidden_states=UpperCamelCase_							,   return_dict=UpperCamelCase_							,   training=UpperCamelCase_						)

      UpperCamelCase__			:   str       				=  outputs.pooler_output if return_dict else outputs[1]

      UpperCamelCase__			:   Tuple       				=  self.classifier[0](UpperCamelCase_						)
      UpperCamelCase__			:   Optional[int]       				=  self.classifier[1](UpperCamelCase_						)

      UpperCamelCase__			:   Dict       				=  None if labels is None else self.hf_compute_loss(labels=UpperCamelCase_							,   logits=UpperCamelCase_						)

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

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



'''simple docstring'''
def 			a      (			__a   )  ->	"list[int]":



					'''simple docstring'''






					if upper_limit < 0:
										raise ValueError('''Limit for the Catalan sequence must be ≥ 0'''   )

					UpperCamelCase__   :Optional[Any]												= [0] * (upper_limit + 1)

					# Base case: C(0) = C(1) = 1
					UpperCamelCase__   :int												= 1
					if upper_limit > 0:
										UpperCamelCase__   :int												= 1

					# Recurrence relation: C(i) = sum(C(j).C(i-j-1)), from j = 0 to i
					for i in range(2 ,					upper_limit + 1   ):
										for j in range(__a   ):
															catalan_list[i] += catalan_list[j] * catalan_list[i - j - 1]

					return catalan_list


if __name__ == "__main__":
		print('''\n********* Catalan Numbers Using Dynamic Programming ************\n''')
		print('''\n*** Enter -1 at any time to quit ***''')
		print('''\nEnter the upper limit (≥ 0) for the Catalan number sequence: ''', end='''''')
		try:
				while True:
						__snake_case							      =     int(input().strip())
						if N < 0:
								print('''\n********* Goodbye!! ************''')
								break
						else:
								print(F"""The Catalan numbers from 0 through {N} are:""")
								print(catalan_numbers(N))
								print('''Try another upper limit for the sequence: ''', end='''''')
		except (NameError, ValueError):
				print('''\n********* Invalid input, goodbye! ************\n''')

		import doctest

		doctest.testmod()