






"""simple docstring"""



import collections.abc
from typing import Optional, Tuple, Union

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

from ...activations import ACTaFN
from ...modeling_outputs import BaseModelOutputWithNoAttention, ImageClassifierOutputWithNoAttention
from ...modeling_utils import PreTrainedModel
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_poolformer import PoolFormerConfig


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

# General docstring
_UpperCamelCase		:  Dict						=		'PoolFormerConfig'

# Base docstring
_UpperCamelCase		:  List[Any]						=		'sail/poolformer_s12'
_UpperCamelCase		:  Any						=		[1, 5_1_2, 7, 7]

# Image classification docstring
_UpperCamelCase		:  Dict						=		'sail/poolformer_s12'
_UpperCamelCase		:  str						=		'tabby, tabby cat'

_UpperCamelCase		:  Dict						=		[
    'sail/poolformer_s12',
    # See all PoolFormer models at https://huggingface.co/models?filter=poolformer
]
def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  int		,					__snake_case			:  float = 0.0		,					__snake_case			:  bool = False    ):





  '''simple docstring'''





  if drop_prob == 0.0 or not training:
    return input
  lowercase							    =       1 - drop_prob
  lowercase							    =       (input.shape[0],) + (1,) * (input.ndim - 1)  # work with diff dim tensors, not just 2D ConvNets
  lowercase							    =       keep_prob + torch.rand(__snake_case		,					dtype=input.dtype		,					device=input.device    )
  random_tensor.floor_()  # binarize
  lowercase							    =       input.div(__snake_case    ) * random_tensor
  return output

class        a     (   nn.Module	):







    def __init__(			self							,		_lowerCamelCase = None       ):
      super().__init__()
      lowercase							    =       drop_prob







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase       ):
      return drop_path(_lowerCamelCase							,		self.drop_prob							,		self.training       )







    def 			UpperCamelCase_      (			self       ):
      return "p={}".format(self.drop_prob       )


class        a     (   nn.Module	):







    def __init__(			self							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase=None       ):
      super().__init__()
      lowercase							    =       patch_size if isinstance(_lowerCamelCase							,		collections.abc.Iterable       ) else (patch_size, patch_size)
      lowercase							    =       stride if isinstance(_lowerCamelCase							,		collections.abc.Iterable       ) else (stride, stride)
      lowercase							    =       padding if isinstance(_lowerCamelCase							,		collections.abc.Iterable       ) else (padding, padding)

      lowercase							    =       nn.Convad(_lowerCamelCase							,		_lowerCamelCase							,		kernel_size=_lowerCamelCase							,		stride=_lowerCamelCase							,		padding=_lowerCamelCase       )
      lowercase							    =       norm_layer(_lowerCamelCase       ) if norm_layer else nn.Identity()







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase       ):
      lowercase							    =       self.projection(_lowerCamelCase       )
      lowercase							    =       self.norm(_lowerCamelCase       )
      return embeddings


class        a     (   nn.GroupNorm	):







    def __init__(			self							,		_lowerCamelCase							,		**_lowerCamelCase       ):
      super().__init__(1							,		_lowerCamelCase							,		**_lowerCamelCase       )


class        a     (   nn.Module	):







    def __init__(			self							,		_lowerCamelCase       ):
      super().__init__()
      lowercase							    =       nn.AvgPoolad(_lowerCamelCase							,		stride=1							,		padding=pool_size // 2							,		count_include_pad=_lowerCamelCase       )







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase       ):
      return self.pool(_lowerCamelCase       ) - hidden_states


class        a     (   nn.Module	):







    def __init__(			self							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase       ):
      super().__init__()
      lowercase							    =       nn.Convad(_lowerCamelCase							,		_lowerCamelCase							,		1       )
      lowercase							    =       nn.Convad(_lowerCamelCase							,		_lowerCamelCase							,		1       )
      lowercase							    =       PoolFormerDropPath(_lowerCamelCase       )
      if isinstance(config.hidden_act							,		_lowerCamelCase       ):
        lowercase							    =       ACTaFN[config.hidden_act]
      else:
        lowercase							    =       config.hidden_act







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase       ):
      lowercase							    =       self.conva(_lowerCamelCase       )
      lowercase							    =       self.act_fn(_lowerCamelCase       )
      lowercase							    =       self.drop(_lowerCamelCase       )
      lowercase							    =       self.conva(_lowerCamelCase       )
      lowercase							    =       self.drop(_lowerCamelCase       )

      return hidden_states


class        a     (   nn.Module	):







    def __init__(			self							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase       ):
      super().__init__()
      lowercase							    =       PoolFormerPooling(_lowerCamelCase       )
      lowercase							    =       PoolFormerOutput(_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase							,		_lowerCamelCase       )
      lowercase							    =       PoolFormerGroupNorm(_lowerCamelCase       )
      lowercase							    =       PoolFormerGroupNorm(_lowerCamelCase       )

      # Useful for training neural nets
      lowercase							    =       PoolFormerDropPath(_lowerCamelCase       ) if drop_path > 0.0 else nn.Identity()
      lowercase							    =       config.use_layer_scale
      if config.use_layer_scale:
        lowercase							    =       nn.Parameter(
            config.layer_scale_init_value * torch.ones((_lowerCamelCase)       )							,		requires_grad=_lowerCamelCase       )
        lowercase							    =       nn.Parameter(
            config.layer_scale_init_value * torch.ones((_lowerCamelCase)       )							,		requires_grad=_lowerCamelCase       )







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase       ):
      if self.use_layer_scale:
        lowercase							    =       self.pooling(self.before_norm(_lowerCamelCase       )       )
        lowercase							    =       self.layer_scale_a.unsqueeze(-1       ).unsqueeze(-1       ) * pooling_output
        # First residual connection
        lowercase							    =       hidden_states + self.drop_path(_lowerCamelCase       )
        lowercase							    =       ()

        lowercase							    =       self.output(self.after_norm(_lowerCamelCase       )       )
        lowercase							    =       self.layer_scale_a.unsqueeze(-1       ).unsqueeze(-1       ) * layer_output
        # Second residual connection
        lowercase							    =       hidden_states + self.drop_path(_lowerCamelCase       )

        lowercase							    =       (output,) + outputs
        return outputs

      else:
        lowercase							    =       self.drop_path(self.pooling(self.before_norm(_lowerCamelCase       )       )       )
        # First residual connection
        lowercase							    =       pooling_output + hidden_states
        lowercase							    =       ()

        # Second residual connection inside the PoolFormerOutput block
        lowercase							    =       self.drop_path(self.output(self.after_norm(_lowerCamelCase       )       )       )
        lowercase							    =       hidden_states + layer_output

        lowercase							    =       (output,) + outputs
        return outputs


class        a     (   nn.Module	):







    def __init__(			self							,		_lowerCamelCase       ):
      super().__init__()
      lowercase							    =       config
      # stochastic depth decay rule
      lowercase							    =       [x.item() for x in torch.linspace(0							,		config.drop_path_rate							,		sum(config.depths       )       )]

      # patch embeddings
      lowercase							    =       []
      for i in range(config.num_encoder_blocks       ):
        embeddings.append(
            PoolFormerEmbeddings(
                patch_size=config.patch_sizes[i]							,		stride=config.strides[i]							,		padding=config.padding[i]							,		num_channels=config.num_channels if i == 0 else config.hidden_sizes[i - 1]							,		hidden_size=config.hidden_sizes[i]							,		)       )
      lowercase							    =       nn.ModuleList(_lowerCamelCase       )

      # Transformer blocks
      lowercase							    =       []
      lowercase							    =       0
      for i in range(config.num_encoder_blocks       ):
        # each block consists of layers
        lowercase							    =       []
        if i != 0:
          cur += config.depths[i - 1]
        for j in range(config.depths[i]       ):
          layers.append(
              PoolFormerLayer(
                  _lowerCamelCase							,		num_channels=config.hidden_sizes[i]							,		pool_size=config.pool_size							,		hidden_size=config.hidden_sizes[i]							,		intermediate_size=int(config.hidden_sizes[i] * config.mlp_ratio       )							,		drop_path=dpr[cur + j]							,		)       )
        blocks.append(nn.ModuleList(_lowerCamelCase       )       )

      lowercase							    =       nn.ModuleList(_lowerCamelCase       )







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase							,		_lowerCamelCase=False							,		_lowerCamelCase=True       ):
      lowercase							    =       () if output_hidden_states else None

      lowercase							    =       pixel_values
      for idx, layers in enumerate(zip(self.patch_embeddings							,		self.block       )       ):
        lowercase    ,     lowercase							    =       layers
        # Get patch embeddings from hidden_states
        lowercase							    =       embedding_layer(_lowerCamelCase       )
        # Send the embeddings through the blocks
        for _, blk in enumerate(_lowerCamelCase       ):
          lowercase							    =       blk(_lowerCamelCase       )
          lowercase							    =       layer_outputs[0]

        if output_hidden_states:
          lowercase							    =       all_hidden_states + (hidden_states,)

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

      return BaseModelOutputWithNoAttention(last_hidden_state=_lowerCamelCase							,		hidden_states=_lowerCamelCase       )


class        a     (   a_	):
    UpperCAmelCase_ :     Any	     =PoolFormerConfig
    UpperCAmelCase_ :     Union[str, Any]	     ="poolformer"
    UpperCAmelCase_ :     Optional[Any]	     ="pixel_values"
    UpperCAmelCase_ :     List[Any]	     =True







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase       ):
      if isinstance(_lowerCamelCase							,		(nn.Linear, nn.Convad)       ):
        module.weight.data.normal_(mean=0.0							,		std=self.config.initializer_range       )
        if module.bias is not None:
          module.bias.data.zero_()
      elif isinstance(_lowerCamelCase							,		nn.LayerNorm       ):
        module.bias.data.zero_()
        module.weight.data.fill_(1.0       )







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase							,		_lowerCamelCase=False       ):
      if isinstance(_lowerCamelCase							,		_lowerCamelCase       ):
        lowercase							    =       value


_UpperCamelCase		:  Tuple						=		R'\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) sub-class. Use\n    it 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 ([`PoolFormerConfig`]): 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'

_UpperCamelCase		:  Optional[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            [`PoolFormerImageProcessor.__call__`] for details.\n'

@add_start_docstrings(
    "The bare PoolFormer Model transformer outputting raw hidden-states without any specific head on top.",				a_,				)
class        a     (   a_	):







    def __init__(			self							,		_lowerCamelCase       ):
      super().__init__(_lowerCamelCase       )
      lowercase							    =       config

      lowercase							    =       PoolFormerEncoder(_lowerCamelCase       )

      # Initialize weights and apply final processing
      self.post_init()







    def 			UpperCamelCase_      (			self       ):
      return self.embeddings.patch_embeddings







    @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 			UpperCamelCase_      (			self							,		_lowerCamelCase = None							,		_lowerCamelCase = None							,		_lowerCamelCase = None							,		):
      lowercase							    =       (
          output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
      )
      lowercase							    =       return_dict if return_dict is not None else self.config.use_return_dict

      if pixel_values is None:
        raise ValueError('You have to specify pixel_values'       )

      lowercase							    =       self.encoder(
          _lowerCamelCase							,		output_hidden_states=_lowerCamelCase							,		return_dict=_lowerCamelCase							,		)
      lowercase							    =       encoder_outputs[0]

      if not return_dict:
        return (sequence_output, None) + encoder_outputs[1:]

      return BaseModelOutputWithNoAttention(
          last_hidden_state=_lowerCamelCase							,		hidden_states=encoder_outputs.hidden_states							,		)


class        a     (   nn.Module	):







    def __init__(			self							,		_lowerCamelCase       ):
      super().__init__()
      lowercase							    =       nn.Linear(config.hidden_size							,		config.hidden_size       )







    def 			UpperCamelCase_      (			self							,		_lowerCamelCase       ):
      lowercase							    =       self.dense(_lowerCamelCase       )
      return output


@add_start_docstrings(
    "\n    PoolFormer Model transformer with an image classification head on top\n    ",				a_,				)
class        a     (   a_	):







    def __init__(			self							,		_lowerCamelCase       ):
      super().__init__(_lowerCamelCase       )
      lowercase							    =       config.num_labels
      lowercase							    =       PoolFormerModel(_lowerCamelCase       )

      # Final norm
      lowercase							    =       PoolFormerGroupNorm(config.hidden_sizes[-1]       )
      # Classifier head
      lowercase							    =       (
          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(_lowerCamelCase       )
    @add_code_sample_docstrings(
        checkpoint=_IMAGE_CLASS_CHECKPOINT							,		output_type=_lowerCamelCase							,		config_class=_CONFIG_FOR_DOC							,		expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT							,		)
    def 			UpperCamelCase_      (			self							,		_lowerCamelCase = None							,		_lowerCamelCase = None							,		_lowerCamelCase = None							,		_lowerCamelCase = None							,		):
      lowercase							    =       return_dict if return_dict is not None else self.config.use_return_dict

      lowercase							    =       self.poolformer(
          _lowerCamelCase							,		output_hidden_states=_lowerCamelCase							,		return_dict=_lowerCamelCase							,		)

      lowercase							    =       outputs[0]

      lowercase							    =       self.classifier(self.norm(_lowerCamelCase       ).mean([-2, -1]       )       )

      lowercase							    =       None
      if labels is not None:
        if self.config.problem_type is None:
          if self.num_labels == 1:
            lowercase							    =       'regression'
          elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
            lowercase							    =       'single_label_classification'
          else:
            lowercase							    =       'multi_label_classification'

        if self.config.problem_type == "regression":
          lowercase							    =       MSELoss()
          if self.num_labels == 1:
            lowercase							    =       loss_fct(logits.squeeze()							,		labels.squeeze()       )
          else:
            lowercase							    =       loss_fct(_lowerCamelCase							,		_lowerCamelCase       )
        elif self.config.problem_type == "single_label_classification":
          lowercase							    =       CrossEntropyLoss()
          lowercase							    =       loss_fct(logits.view(-1							,		self.num_labels       )							,		labels.view(-1       )       )
        elif self.config.problem_type == "multi_label_classification":
          lowercase							    =       BCEWithLogitsLoss()
          lowercase							    =       loss_fct(_lowerCamelCase							,		_lowerCamelCase       )

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

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










"""simple docstring"""



def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  int = 4_00_00_00    ):





  '''simple docstring'''





  lowercase							    =       []
  lowercase    ,     lowercase							    =       0, 1
  while b <= n:
    if b % 2 == 0:
      even_fibs.append(__snake_case    )
    lowercase    ,     lowercase							    =       b, a + b
  return sum(__snake_case    )


if __name__ == "__main__":
    print(F'''{solution() = }''')


