



'''simple docstring'''






import io
import os
import unicodedata
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


lowerCAmelCase: Union[str, Any]							=						logging.get_logger(__name__)

lowerCAmelCase: str							=						'▁'

lowerCAmelCase: Union[str, Any]							=						{'vocab_file': 'vocab.txt', 'sentencepiece_model_ckpt': 'sentencepiece.bpe.model'}

lowerCAmelCase: List[str]							=						{
    'sentencepiece_model_file': 'sentencepiece.bpe.model',
    'vocab_file': 'vocab.txt',
}

lowerCAmelCase: Union[str, Any]							=						{
    'vocab_file': {
        'ernie-m-base': 'https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt',
        'ernie-m-large': 'https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt',
    },
    'sentencepiece_model_file': {
        'ernie-m-base': 'https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model',
        'ernie-m-large': 'https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model',
    },
}

lowerCAmelCase: Tuple							=						{
    'ernie-m-base': 5_1_4,
    'ernie-m-large': 5_1_4,
}

lowerCAmelCase: Union[str, Any]							=						{
    'ernie-m-base': {'do_lower_case': False},
    'ernie-m-large': {'do_lower_case': False},
}

class 							a__( lowerCamelCase__     ):
    lowercase__			=   ["""input_ids"""]

    lowercase__			=   VOCAB_FILES_NAMES
    lowercase__			=   PRETRAINED_INIT_CONFIGURATION
    lowercase__			=   PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    lowercase__			=   PRETRAINED_VOCAB_FILES_MAP
    lowercase__			=   RESOURCE_FILES_NAMES







    def __init__(				self			:  Tuple						,      __snake_case			:  Optional[Any]						,      __snake_case			:  List[str]=None						,      __snake_case			:  str=False						,      __snake_case			:  str="utf8"						,      __snake_case			:  Optional[Any]="[UNK]"						,      __snake_case			:  Tuple="[SEP]"						,      __snake_case			:  Any="[PAD]"						,      __snake_case			:  Optional[int]="[CLS]"						,      __snake_case			:  Any="[MASK]"						,      __snake_case			:  Optional[Dict[str, Any]] = None						,      **__snake_case			:  List[Any]						,      ):
      # Mask token behave like a normal word, i.e. include the space before it and
      # is included in the raw text, there should be a match in a non-normalized sentence.

      a						: str					       =					{} if sp_model_kwargs is None else sp_model_kwargs
      super().__init__(
          do_lower_case=__snake_case						,      unk_token=__snake_case						,      sep_token=__snake_case						,      pad_token=__snake_case						,      cls_token=__snake_case						,      mask_token=__snake_case						,      vocab_file=__snake_case						,      encoding=__snake_case						,      sp_model_kwargs=self.sp_model_kwargs						,      **__snake_case						,      )
      a						: List[str]					       =					do_lower_case
      a						: Union[str, Any]					       =					sentencepiece_model_ckpt
      a						: Tuple					       =					spm.SentencePieceProcessor(**self.sp_model_kwargs     )
      self.sp_model.Load(__snake_case     )

      # to mimic paddlenlp.transformers.ernie_m.tokenizer.ErnieMTokenizer functioning
      if vocab_file is not None:
        a						: Union[str, Any]					       =					self.load_vocab(filepath=__snake_case     )
      else:
        a						: Tuple					       =					{self.sp_model.id_to_piece(__snake_case     ): id for id in range(self.sp_model.get_piece_size()     )}
      a						: Dict					       =					{v: k for k, v in self.vocab.items()}







    def       lowercase_	(				self			:  Optional[Any]						,      __snake_case			:  Tuple     ):
      if text is None:
        return None

      a						: List[Any]					       =					self.tokenize(__snake_case     )
      a						: Union[str, Any]					       =					'', []

      for i, ch in enumerate(__snake_case     ):
        if ch in self.SP_CHAR_MAPPING:
          a						: List[str]					       =					self.SP_CHAR_MAPPING.get(__snake_case     )
        else:
          a						: Tuple					       =					unicodedata.normalize('NFKC'						,      __snake_case     )
        if self.is_whitespace(__snake_case     ):
          continue
        normalized_text += ch
        char_mapping.extend([i] * len(__snake_case     )     )

      a						: Optional[Any]					       =					normalized_text, [], 0

      if self.do_lower_case:
        a						: List[Any]					       =					text.lower()

      for token in split_tokens:
        if token[:1] == "▁":
          a						: Tuple					       =					token[1:]
        a						: str					       =					text[offset:].index(__snake_case     ) + offset
        a						: str					       =					start + len(__snake_case     )

        token_mapping.append((char_mapping[start], char_mapping[end - 1] + 1)     )
        a						: Dict					       =					end
      return token_mapping







    @property
    def       lowercase_	(				self			:  int     ):
      return len(self.vocab     )







    def       lowercase_	(				self			:  Tuple     ):
      return dict(self.vocab						,      **self.added_tokens_encoder     )







    def __getstate__(				self			:  List[Any]     ):
      a						: Optional[Any]					       =					self.__dict__.copy()
      a						: Union[str, Any]					       =					None
      return state







    def __setstate__(				self			:  int						,      __snake_case			:  Dict     ):
      a						: Optional[int]					       =					d

      # for backward compatibility
      if not hasattr(self						,      'sp_model_kwargs'     ):
        a						: Optional[int]					       =					{}

      a						: Tuple					       =					spm.SentencePieceProcessor(**self.sp_model_kwargs     )
      self.sp_model.Load(self.sentencepiece_model_ckpt     )







    def       lowercase_	(				self			:  int						,      __snake_case			:  Any     ):
      return "".join((self.SP_CHAR_MAPPING.get(__snake_case						,      __snake_case     ) for c in text)     )







    def       lowercase_	(				self			:  Any						,      __snake_case			:  List[Any]						,      __snake_case			:  int=False						,      __snake_case			:  Optional[int]=64						,      __snake_case			:  List[Any]=0.1     ):

      if self.sp_model_kwargs.get('enable_sampling'     ) is True:
        a						: Dict					       =					True
      if self.sp_model_kwargs.get('alpha'     ) is not None:
        a						: Union[str, Any]					       =					self.sp_model_kwargs.get('alpha'     )
      if self.sp_model_kwargs.get('nbest_size'     ) is not None:
        a						: str					       =					self.sp_model_kwargs.get('nbest_size'     )

      if not enable_sampling:
        a						: Any					       =					self.sp_model.EncodeAsPieces(__snake_case     )
      else:
        a						: List[Any]					       =					self.sp_model.SampleEncodeAsPieces(__snake_case						,      __snake_case						,      __snake_case     )
      a						: str					       =					[]
      for pi, piece in enumerate(__snake_case     ):
        if piece == SPIECE_UNDERLINE:
          if not pieces[pi + 1].startswith(__snake_case     ) and pi != 0:
            new_pieces.append(__snake_case     )
            continue
          else:
            continue
        a						: Optional[Any]					       =					0
        for i, chunk in enumerate(__snake_case     ):
          if chunk == SPIECE_UNDERLINE:
            continue
          if self.is_ch_char(__snake_case     ) or self.is_punct(__snake_case     ):
            if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
              new_pieces.append(piece[lst_i:i]     )
            new_pieces.append(__snake_case     )
            a						: int					       =					i + 1
          elif chunk.isdigit() and i > 0 and not piece[i - 1].isdigit():
            if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
              new_pieces.append(piece[lst_i:i]     )
            a						: List[Any]					       =					i
          elif not chunk.isdigit() and i > 0 and piece[i - 1].isdigit():
            if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
              new_pieces.append(piece[lst_i:i]     )
            a						: int					       =					i
        if len(__snake_case     ) > lst_i:
          new_pieces.append(piece[lst_i:]     )
      return new_pieces







    def       lowercase_	(				self			:  List[Any]						,      __snake_case			:  Dict     ):
      a						: List[Any]					       =					''.join(__snake_case     ).replace(__snake_case						,      ' '     ).strip()
      return out_string







    def       lowercase_	(				self			:  Any						,      __snake_case			:  List[str]     ):
      a						: str					       =					self.convert_ids_to_tokens(__snake_case     )
      a						: Dict					       =					''.join(__snake_case     ).replace(__snake_case						,      ' '     ).strip()
      return out_string







    def       lowercase_	(				self			:  List[str]						,      __snake_case			:  Tuple     ):
      return self.vocab.get(__snake_case						,      self.vocab.get(self.unk_token     )     )







    def       lowercase_	(				self			:  Optional[int]						,      __snake_case			:  int     ):
      return self.reverse_vocab.get(__snake_case						,      self.unk_token     )







    def       lowercase_	(				self			:  str						,      __snake_case			:  List[str]						,      __snake_case			:  Union[str, Any]=None     ):
      if token_ids_a is None:
        return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
      a						: Tuple					       =					[self.cls_token_id]
      a						: Optional[Any]					       =					[self.sep_token_id]
      return _cls + token_ids_a + _sep + _sep + token_ids_a + _sep







    def       lowercase_	(				self			:  Union[str, Any]						,      __snake_case			:  List[Any]						,      __snake_case			:  Dict=None     ):
      if offset_mapping_a is None:
        return [(0, 0)] + offset_mapping_a + [(0, 0)]

      return [(0, 0)] + offset_mapping_a + [(0, 0), (0, 0)] + offset_mapping_a + [(0, 0)]







    def       lowercase_	(				self			:  Dict						,      __snake_case			:  List[Any]						,      __snake_case			:  int=None						,      __snake_case			:  Any=False     ):

      if already_has_special_tokens:
        if token_ids_a is not None:
          raise ValueError(
              'You should not supply a second sequence if the provided sequence of '
              'ids is already formatted with special tokens for the model.'     )
        return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_a]

      if token_ids_a is not None:
        return [1] + ([0] * len(__snake_case     )) + [1, 1] + ([0] * len(__snake_case     )) + [1]
      return [1] + ([0] * len(__snake_case     )) + [1]







    def       lowercase_	(				self			:  List[Any]						,      __snake_case			:  List[int]						,      __snake_case			:  Optional[List[int]] = None     ):
      # called when `add_special_tokens` is True, so align with `build_inputs_with_special_tokens` method
      if token_ids_a is None:
        # [CLS] X [SEP]
        return (len(__snake_case     ) + 2) * [0]

      # [CLS] A [SEP] [SEP] B [SEP]
      return [0] * (len(__snake_case     ) + 1) + [1] * (len(__snake_case     ) + 3)







    def       lowercase_	(				self			:  Dict						,      __snake_case			:  List[str]     ):
      if "\u4e00" <= char <= "\u9fff":
        return True
      return False







    def       lowercase_	(				self			:  Dict						,      __snake_case			:  Union[str, Any]     ):
      if ("a" <= char <= "z") or ("A" <= char <= "Z"):
        return True
      return False







    def       lowercase_	(				self			:  Any						,      __snake_case			:  List[Any]     ):
      if char in ",;:.?!~，；：。？！《》【】":
        return True
      return False







    def       lowercase_	(				self			:  Dict						,      __snake_case			:  str     ):
      if char == " " or char == "\t" or char == "\n" or char == "\r":
        return True
      if len(__snake_case     ) == 1:
        a						: Optional[Any]					       =					unicodedata.category(__snake_case     )
        if cat == "Zs":
          return True
      return False







    def       lowercase_	(				self			:  Union[str, Any]						,      __snake_case			:  Optional[Any]     ):
      a						: str					       =					{}
      with io.open(__snake_case						,      'r'						,      encoding='utf-8'     ) as f:
        for index, line in enumerate(__snake_case     ):
          a						: int					       =					line.rstrip('\n'     )
          a						: Optional[int]					       =					int(__snake_case     )

      return token_to_idx







    def       lowercase_	(				self			:  List[Any]						,      __snake_case			:  str						,      __snake_case			:  Optional[str] = None     ):
      a						: Optional[int]					       =					0
      if os.path.isdir(__snake_case     ):
        a						: Optional[int]					       =					os.path.join(
            __snake_case						,      (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']     )
      else:
        a						: Any					       =					(filename_prefix + '-' if filename_prefix else '') + save_directory
      with open(__snake_case						,      'w'						,      encoding='utf-8'     ) as writer:
        for token, token_index in sorted(self.vocab.items()						,      key=lambda __snake_case     : kv[1]     ):
          if index != token_index:
            logger.warning(
                F"""Saving vocabulary to {vocab_file}: vocabulary indices are not consecutive."""
                ' Please check that the vocabulary is not corrupted!'     )
            a						: Optional[int]					       =					token_index
          writer.write(token + '\n'     )
          index += 1

      a						: Any					       =					os.path.join(__snake_case						,      'sentencepiece.bpe.model'     )
      with open(__snake_case						,      'wb'     ) as fi:
        a						: List[Any]					       =					self.sp_model.serialized_model_proto()
        fi.write(__snake_case     )

      return (vocab_file,)




'''simple docstring'''






from typing import Optional

import torch
import torch.utils.checkpoint
from torch import Tensor, nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward
from ...modeling_outputs import (
    BaseModelOutputWithNoAttention,
    BaseModelOutputWithPoolingAndNoAttention,
    ImageClassifierOutputWithNoAttention,
)
from ...modeling_utils import PreTrainedModel
from ...utils import logging
from .configuration_regnet import RegNetConfig


lowerCAmelCase: List[Any]							=						logging.get_logger(__name__)

# General docstring
lowerCAmelCase: Optional[int]							=						'RegNetConfig'

# Base docstring
lowerCAmelCase: Tuple							=						'facebook/regnet-y-040'
lowerCAmelCase: str							=						[1, 1_0_8_8, 7, 7]

# Image classification docstring
lowerCAmelCase: Any							=						'facebook/regnet-y-040'
lowerCAmelCase: List[Any]							=						'tabby, tabby cat'

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

class 							a__( nn.Module     ):







    def __init__(				self			:  str						,      __snake_case			:  int						,      __snake_case			:  int						,      __snake_case			:  int = 3						,      __snake_case			:  int = 1						,      __snake_case			:  int = 1						,      __snake_case			:  Optional[str] = "relu"						,      ):
      super().__init__()
      a						: Tuple					       =					nn.Convad(
          __snake_case						,      __snake_case						,      kernel_size=__snake_case						,      stride=__snake_case						,      padding=kernel_size // 2						,      groups=__snake_case						,      bias=__snake_case						,      )
      a						: Dict					       =					nn.BatchNormad(__snake_case     )
      a						: Tuple					       =					ACTaFN[activation] if activation is not None else nn.Identity()







    def       lowercase_	(				self			:  Dict						,      __snake_case			:  int     ):
      a						: int					       =					self.convolution(__snake_case     )
      a						: int					       =					self.normalization(__snake_case     )
      a						: Any					       =					self.activation(__snake_case     )
      return hidden_state

class 							a__( nn.Module     ):







    def __init__(				self			:  List[str]						,      __snake_case			:  RegNetConfig     ):
      super().__init__()
      a						: Optional[int]					       =					RegNetConvLayer(
          config.num_channels						,      config.embedding_size						,      kernel_size=3						,      stride=2						,      activation=config.hidden_act     )
      a						: Optional[int]					       =					config.num_channels







    def       lowercase_	(				self			:  int						,      __snake_case			:  List[str]     ):
      a						: List[Any]					       =					pixel_values.shape[1]
      if 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.'     )
      a						: List[str]					       =					self.embedder(__snake_case     )
      return hidden_state

class 							a__( nn.Module     ):







    def __init__(				self			:  Tuple						,      __snake_case			:  int						,      __snake_case			:  int						,      __snake_case			:  int = 2     ):
      super().__init__()
      a						: Optional[int]					       =					nn.Convad(__snake_case						,      __snake_case						,      kernel_size=1						,      stride=__snake_case						,      bias=__snake_case     )
      a						: Optional[Any]					       =					nn.BatchNormad(__snake_case     )







    def       lowercase_	(				self			:  Union[str, Any]						,      __snake_case			:  Tensor     ):
      a						: Any					       =					self.convolution(__snake_case     )
      a						: Dict					       =					self.normalization(__snake_case     )
      return hidden_state

class 							a__( nn.Module     ):







    def __init__(				self			:  Union[str, Any]						,      __snake_case			:  int						,      __snake_case			:  int     ):
      super().__init__()

      a						: Any					       =					nn.AdaptiveAvgPoolad((1, 1)     )
      a						: Dict					       =					nn.Sequential(
          nn.Convad(__snake_case						,      __snake_case						,      kernel_size=1     )						,      nn.ReLU()						,      nn.Convad(__snake_case						,      __snake_case						,      kernel_size=1     )						,      nn.Sigmoid()						,      )







    def       lowercase_	(				self			:  List[str]						,      __snake_case			:  List[Any]     ):
      # b c h w -> b c 1 1
      a						: Any					       =					self.pooler(__snake_case     )
      a						: Optional[Any]					       =					self.attention(__snake_case     )
      a						: Tuple					       =					hidden_state * attention
      return hidden_state

class 							a__( nn.Module     ):







    def __init__(				self			:  List[str]						,      __snake_case			:  RegNetConfig						,      __snake_case			:  int						,      __snake_case			:  int						,      __snake_case			:  int = 1     ):
      super().__init__()
      a						: Union[str, Any]					       =					in_channels != out_channels or stride != 1
      a						: Dict					       =					max(1						,      out_channels // config.groups_width     )
      a						: List[str]					       =					(
          RegNetShortCut(__snake_case						,      __snake_case						,      stride=__snake_case     ) if should_apply_shortcut else nn.Identity()
      )
      a						: int					       =					nn.Sequential(
          RegNetConvLayer(__snake_case						,      __snake_case						,      kernel_size=1						,      activation=config.hidden_act     )						,      RegNetConvLayer(__snake_case						,      __snake_case						,      stride=__snake_case						,      groups=__snake_case						,      activation=config.hidden_act     )						,      RegNetConvLayer(__snake_case						,      __snake_case						,      kernel_size=1						,      activation=__snake_case     )						,      )
      a						: int					       =					ACTaFN[config.hidden_act]







    def       lowercase_	(				self			:  Union[str, Any]						,      __snake_case			:  Tuple     ):
      a						: List[str]					       =					hidden_state
      a						: Dict					       =					self.layer(__snake_case     )
      a						: Tuple					       =					self.shortcut(__snake_case     )
      hidden_state += residual
      a						: Optional[int]					       =					self.activation(__snake_case     )
      return hidden_state

class 							a__( nn.Module     ):







    def __init__(				self			:  List[str]						,      __snake_case			:  RegNetConfig						,      __snake_case			:  int						,      __snake_case			:  int						,      __snake_case			:  int = 1     ):
      super().__init__()
      a						: Union[str, Any]					       =					in_channels != out_channels or stride != 1
      a						: Dict					       =					max(1						,      out_channels // config.groups_width     )
      a						: Dict					       =					(
          RegNetShortCut(__snake_case						,      __snake_case						,      stride=__snake_case     ) if should_apply_shortcut else nn.Identity()
      )
      a						: List[str]					       =					nn.Sequential(
          RegNetConvLayer(__snake_case						,      __snake_case						,      kernel_size=1						,      activation=config.hidden_act     )						,      RegNetConvLayer(__snake_case						,      __snake_case						,      stride=__snake_case						,      groups=__snake_case						,      activation=config.hidden_act     )						,      RegNetSELayer(__snake_case						,      reduced_channels=int(round(in_channels / 4     )     )     )						,      RegNetConvLayer(__snake_case						,      __snake_case						,      kernel_size=1						,      activation=__snake_case     )						,      )
      a						: Union[str, Any]					       =					ACTaFN[config.hidden_act]







    def       lowercase_	(				self			:  Any						,      __snake_case			:  int     ):
      a						: Tuple					       =					hidden_state
      a						: Tuple					       =					self.layer(__snake_case     )
      a						: Optional[int]					       =					self.shortcut(__snake_case     )
      hidden_state += residual
      a						: Any					       =					self.activation(__snake_case     )
      return hidden_state

class 							a__( nn.Module     ):







    def __init__(				self			:  int						,      __snake_case			:  RegNetConfig						,      __snake_case			:  int						,      __snake_case			:  int						,      __snake_case			:  int = 2						,      __snake_case			:  int = 2						,      ):
      super().__init__()

      a						: int					       =					RegNetXLayer if config.layer_type == 'x' else RegNetYLayer

      a						: Any					       =					nn.Sequential(
          # downsampling is done in the first layer with stride of 2
          layer(
              __snake_case						,      __snake_case						,      __snake_case						,      stride=__snake_case						,      )						,      *[layer(__snake_case						,      __snake_case						,      __snake_case     ) for _ in range(depth - 1     )]						,      )







    def       lowercase_	(				self			:  Optional[Any]						,      __snake_case			:  str     ):
      a						: Dict					       =					self.layers(__snake_case     )
      return hidden_state

class 							a__( nn.Module     ):







    def __init__(				self			:  List[Any]						,      __snake_case			:  RegNetConfig     ):
      super().__init__()
      a						: Dict					       =					nn.ModuleList([]     )
      # based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
      self.stages.append(
          RegNetStage(
              __snake_case						,      config.embedding_size						,      config.hidden_sizes[0]						,      stride=2 if config.downsample_in_first_stage else 1						,      depth=config.depths[0]						,      )     )
      a						: str					       =					zip(config.hidden_sizes						,      config.hidden_sizes[1:]     )
      for (in_channels, out_channels), depth in zip(__snake_case						,      config.depths[1:]     ):
        self.stages.append(RegNetStage(__snake_case						,      __snake_case						,      __snake_case						,      depth=__snake_case     )     )







    def       lowercase_	(				self			:  Union[str, Any]						,      __snake_case			:  Tensor						,      __snake_case			:  bool = False						,      __snake_case			:  bool = True     ):
      a						: Union[str, Any]					       =					() if output_hidden_states else None

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

        a						: int					       =					stage_module(__snake_case     )

      if output_hidden_states:
        a						: Union[str, 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 BaseModelOutputWithNoAttention(last_hidden_state=__snake_case						,      hidden_states=__snake_case     )

class 							a__( lowerCamelCase__     ):
    lowercase__			=   RegNetConfig
    lowercase__			=   """regnet"""
    lowercase__			=   """pixel_values"""
    lowercase__			=   True







    def       lowercase_	(				self			:  Optional[Any]						,      __snake_case			:  Optional[int]     ):
      if isinstance(__snake_case						,      nn.Convad     ):
        nn.init.kaiming_normal_(module.weight						,      mode='fan_out'						,      nonlinearity='relu'     )
      elif isinstance(__snake_case						,      (nn.BatchNormad, nn.GroupNorm)     ):
        nn.init.constant_(module.weight						,      1     )
        nn.init.constant_(module.bias						,      0     )







    def       lowercase_	(				self			:  Dict						,      __snake_case			:  List[str]						,      __snake_case			:  Dict=False     ):
      if isinstance(__snake_case						,      __snake_case     ):
        a						: Optional[Any]					       =					value
lowerCAmelCase: Union[str, Any]							=						r'\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it\n    as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\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 [`~PreTrainedModel.from_pretrained`] method to load the model weights.\n'

lowerCAmelCase: int							=						r'\n    Args:\n        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConvNextImageProcessor.__call__`] for details.\n\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 [`~file_utils.ModelOutput`] instead of a plain tuple.\n'

@add_start_docstrings(
    """The bare RegNet model outputting raw features without any specific head on top."""		,			lowerCamelCase__		,			)
# Copied from transformers.models.resnet.modeling_resnet.ResNetModel with RESNET->REGNET,ResNet->RegNet
class 							a__( lowerCamelCase__     ):







    def __init__(				self			:  Dict						,      __snake_case			:  Dict     ):
      super().__init__(__snake_case     )
      a						: str					       =					config
      a						: str					       =					RegNetEmbeddings(__snake_case     )
      a						: Dict					       =					RegNetEncoder(__snake_case     )
      a						: int					       =					nn.AdaptiveAvgPoolad((1, 1)     )
      # Initialize weights and apply final processing
      self.post_init()







    @add_start_docstrings_to_model_forward(__snake_case     )
    @add_code_sample_docstrings(
        checkpoint=_CHECKPOINT_FOR_DOC						,      output_type=__snake_case						,      config_class=_CONFIG_FOR_DOC						,      modality='vision'						,      expected_output=_EXPECTED_OUTPUT_SHAPE						,      )
    def       lowercase_	(				self			:  Optional[Any]						,      __snake_case			:  Tensor						,      __snake_case			:  Optional[bool] = None						,      __snake_case			:  Optional[bool] = None     ):
      a						: Dict					       =					(
          output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
      )
      a						: List[Any]					       =					return_dict if return_dict is not None else self.config.use_return_dict

      a						: int					       =					self.embedder(__snake_case     )

      a						: Optional[int]					       =					self.encoder(
          __snake_case						,      output_hidden_states=__snake_case						,      return_dict=__snake_case     )

      a						: List[Any]					       =					encoder_outputs[0]

      a						: Any					       =					self.pooler(__snake_case     )

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

      return BaseModelOutputWithPoolingAndNoAttention(
          last_hidden_state=__snake_case						,      pooler_output=__snake_case						,      hidden_states=encoder_outputs.hidden_states						,      )

@add_start_docstrings(
    """
    RegNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    """		,			lowerCamelCase__		,			)
# Copied from transformers.models.resnet.modeling_resnet.ResNetForImageClassification with RESNET->REGNET,ResNet->RegNet,resnet->regnet
class 							a__( lowerCamelCase__     ):







    def __init__(				self			:  int						,      __snake_case			:  Optional[int]     ):
      super().__init__(__snake_case     )
      a						: Optional[Any]					       =					config.num_labels
      a						: Tuple					       =					RegNetModel(__snake_case     )
      # classification head
      a						: List[Any]					       =					nn.Sequential(
          nn.Flatten()						,      nn.Linear(config.hidden_sizes[-1]						,      config.num_labels     ) if config.num_labels > 0 else nn.Identity()						,      )
      # initialize weights and apply final processing
      self.post_init()







    @add_start_docstrings_to_model_forward(__snake_case     )
    @add_code_sample_docstrings(
        checkpoint=_IMAGE_CLASS_CHECKPOINT						,      output_type=__snake_case						,      config_class=_CONFIG_FOR_DOC						,      expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT						,      )
    def       lowercase_	(				self			:  Optional[Any]						,      __snake_case			:  Optional[torch.FloatTensor] = None						,      __snake_case			:  Optional[torch.LongTensor] = None						,      __snake_case			:  Optional[bool] = None						,      __snake_case			:  Optional[bool] = None						,      ):
      a						: str					       =					return_dict if return_dict is not None else self.config.use_return_dict

      a						: Optional[Any]					       =					self.regnet(__snake_case						,      output_hidden_states=__snake_case						,      return_dict=__snake_case     )

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

      a						: str					       =					self.classifier(__snake_case     )

      a						: Optional[int]					       =					None

      if labels is not None:
        if self.config.problem_type is None:
          if self.num_labels == 1:
            a						: List[str]					       =					'regression'
          elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
            a						: int					       =					'single_label_classification'
          else:
            a						: Dict					       =					'multi_label_classification'
        if self.config.problem_type == "regression":
          a						: Any					       =					MSELoss()
          if self.num_labels == 1:
            a						: int					       =					loss_fct(logits.squeeze()						,      labels.squeeze()     )
          else:
            a						: List[str]					       =					loss_fct(__snake_case						,      __snake_case     )
        elif self.config.problem_type == "single_label_classification":
          a						: Union[str, Any]					       =					CrossEntropyLoss()
          a						: Tuple					       =					loss_fct(logits.view(-1						,      self.num_labels     )						,      labels.view(-1     )     )
        elif self.config.problem_type == "multi_label_classification":
          a						: Any					       =					BCEWithLogitsLoss()
          a						: Tuple					       =					loss_fct(__snake_case						,      __snake_case     )

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

      return ImageClassifierOutputWithNoAttention(loss=__snake_case						,      logits=__snake_case						,      hidden_states=outputs.hidden_states     )