"""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


_a  :  int=				logging.get_logger(__name__)

# General docstring
_a  :  List[str]=				"RegNetConfig"

# Base docstring
_a  :  Tuple=				"facebook/regnet-y-040"
_a  :  Union[str, Any]=				[1, 1_088, 7, 7]

# Image classification docstring
_a  :  Union[str, Any]=				"facebook/regnet-y-040"
_a  :  Optional[int]=				"tabby, tabby cat"

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

class 	UpperCamelCase    (					nn.Module		):



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






				def       _lowercase  (self       :   str			,						_A       :   Union[str, Any])					->			Dict:
					__snake_case    :							str   	=				self.convolution(_A)
					__snake_case    :							Dict   	=				self.normalization(_A)
					__snake_case    :							List[str]   	=				self.activation(_A)
					return hidden_state







class 	UpperCamelCase    (					nn.Module		):



				def __init__(self       :   int			,						_A       :   RegNetConfig)					->			Optional[Any]:
					super().__init__()
					__snake_case    :							Union[str, Any]   	=				RegNetConvLayer(
					    config.num_channels			,						config.embedding_size			,						kernel_size=3			,						stride=2			,						activation=config.hidden_act)
					__snake_case    :							Dict   	=				config.num_channels






				def       _lowercase  (self       :   Dict			,						_A       :   Tuple)					->			List[Any]:
					__snake_case    :							Optional[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.')
					__snake_case    :							Dict   	=				self.embedder(_A)
					return hidden_state







class 	UpperCamelCase    (					nn.Module		):



				def __init__(self       :   List[str]			,						_A       :   int			,						_A       :   int			,						_A       :   int = 2)					->			int:
					super().__init__()
					__snake_case    :							Optional[Any]   	=				nn.Convad(_A			,						_A			,						kernel_size=1			,						stride=_A			,						bias=_A)
					__snake_case    :							str   	=				nn.BatchNormad(_A)






				def       _lowercase  (self       :   int			,						_A       :   Tensor)					->			Tensor:
					__snake_case    :							Optional[Any]   	=				self.convolution(_A)
					__snake_case    :							Union[str, Any]   	=				self.normalization(_A)
					return hidden_state







class 	UpperCamelCase    (					nn.Module		):



				def __init__(self       :   str			,						_A       :   int			,						_A       :   int)					->			List[Any]:
					super().__init__()

					__snake_case    :							Optional[int]   	=				nn.AdaptiveAvgPoolad((1, 1))
					__snake_case    :							Dict   	=				nn.Sequential(
					    nn.Convad(_A			,						_A			,						kernel_size=1)			,						nn.ReLU()			,						nn.Convad(_A			,						_A			,						kernel_size=1)			,						nn.Sigmoid()			,						)






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







class 	UpperCamelCase    (					nn.Module		):



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






				def       _lowercase  (self       :   List[str]			,						_A       :   List[str])					->			List[Any]:
					__snake_case    :							str   	=				hidden_state
					__snake_case    :							Any   	=				self.layer(_A)
					__snake_case    :							Optional[Any]   	=				self.shortcut(_A)
					hidden_state += residual
					__snake_case    :							int   	=				self.activation(_A)
					return hidden_state







class 	UpperCamelCase    (					nn.Module		):



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






				def       _lowercase  (self       :   Any			,						_A       :   List[Any])					->			Optional[Any]:
					__snake_case    :							List[Any]   	=				hidden_state
					__snake_case    :							Tuple   	=				self.layer(_A)
					__snake_case    :							Tuple   	=				self.shortcut(_A)
					hidden_state += residual
					__snake_case    :							Optional[Any]   	=				self.activation(_A)
					return hidden_state







class 	UpperCamelCase    (					nn.Module		):



				def __init__(self       :   Tuple			,						_A       :   RegNetConfig			,						_A       :   int			,						_A       :   int			,						_A       :   int = 2			,						_A       :   int = 2			,						)					->			Optional[int]:
					super().__init__()

					__snake_case    :							Any   	=				RegNetXLayer if config.layer_type == 'x' else RegNetYLayer

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






				def       _lowercase  (self       :   Union[str, Any]			,						_A       :   Union[str, Any])					->			Tuple:
					__snake_case    :							str   	=				self.layers(_A)
					return hidden_state







class 	UpperCamelCase    (					nn.Module		):



				def __init__(self       :   str			,						_A       :   RegNetConfig)					->			Dict:
					super().__init__()
					__snake_case    :							List[Any]   	=				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(
					        _A			,						config.embedding_size			,						config.hidden_sizes[0]			,						stride=2 if config.downsample_in_first_stage else 1			,						depth=config.depths[0]			,						))
					__snake_case    :							str   	=				zip(config.hidden_sizes			,						config.hidden_sizes[1:])
					for (in_channels, out_channels), depth in zip(_A			,						config.depths[1:]):
						self.stages.append(RegNetStage(_A			,						_A			,						_A			,						depth=_A))






				def       _lowercase  (self       :   Optional[int]			,						_A       :   Tensor			,						_A       :   bool = False			,						_A       :   bool = True)					->			BaseModelOutputWithNoAttention:
					__snake_case    :							int   	=				() if output_hidden_states else None

					for stage_module in self.stages:
						if output_hidden_states:
							__snake_case    :							str   	=				hidden_states + (hidden_state,)

						__snake_case    :							List[str]   	=				stage_module(_A)

					if output_hidden_states:
						__snake_case    :							Optional[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=_A			,						hidden_states=_A)







class 	UpperCamelCase    (					lowercase		):
				UpperCAmelCase       :   int					=	RegNetConfig
				UpperCAmelCase       :   List[Any]					=	"""regnet"""
				UpperCAmelCase       :   Optional[Any]					=	"""pixel_values"""
				UpperCAmelCase       :   List[Any]					=	True



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






				def       _lowercase  (self       :   Union[str, Any]			,						_A       :   Optional[Any]			,						_A       :   List[Any]=False)					->			Any:
					if isinstance(_A			,						_A):
						__snake_case    :							Dict   	=				value







_a  :  Optional[int]=				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"

_a  :  str=				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."""   ,			lowercase   ,			)
# Copied from transformers.models.resnet.modeling_resnet.ResNetModel with RESNET->REGNET,ResNet->RegNet
class 	UpperCamelCase    (					lowercase		):



				def __init__(self       :   Tuple			,						_A       :   Tuple)					->			List[Any]:
					super().__init__(_A)
					__snake_case    :							Any   	=				config
					__snake_case    :							Dict   	=				RegNetEmbeddings(_A)
					__snake_case    :							Tuple   	=				RegNetEncoder(_A)
					__snake_case    :							Dict   	=				nn.AdaptiveAvgPoolad((1, 1))
					# Initialize weights and apply final processing
					self.post_init()






				@add_start_docstrings_to_model_forward(_A)
				@add_code_sample_docstrings(
				    checkpoint=_CHECKPOINT_FOR_DOC			,						output_type=_A			,						config_class=_CONFIG_FOR_DOC			,						modality='vision'			,						expected_output=_EXPECTED_OUTPUT_SHAPE			,						)
				def       _lowercase  (self       :   str			,						_A       :   Tensor			,						_A       :   Optional[bool] = None			,						_A       :   Optional[bool] = None)					->			BaseModelOutputWithPoolingAndNoAttention:
					__snake_case    :							Union[str, Any]   	=				(
					    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
					)
					__snake_case    :							Any   	=				return_dict if return_dict is not None else self.config.use_return_dict

					__snake_case    :							List[str]   	=				self.embedder(_A)

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

					__snake_case    :							int   	=				encoder_outputs[0]

					__snake_case    :							Any   	=				self.pooler(_A)

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

					return BaseModelOutputWithPoolingAndNoAttention(
					    last_hidden_state=_A			,						pooler_output=_A			,						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.
    """   ,			lowercase   ,			)
# Copied from transformers.models.resnet.modeling_resnet.ResNetForImageClassification with RESNET->REGNET,ResNet->RegNet,resnet->regnet
class 	UpperCamelCase    (					lowercase		):



				def __init__(self       :   Dict			,						_A       :   Optional[int])					->			Any:
					super().__init__(_A)
					__snake_case    :							Union[str, Any]   	=				config.num_labels
					__snake_case    :							List[str]   	=				RegNetModel(_A)
					# classification head
					__snake_case    :							Optional[int]   	=				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(_A)
				@add_code_sample_docstrings(
				    checkpoint=_IMAGE_CLASS_CHECKPOINT			,						output_type=_A			,						config_class=_CONFIG_FOR_DOC			,						expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT			,						)
				def       _lowercase  (self       :   Optional[Any]			,						_A       :   Optional[torch.FloatTensor] = None			,						_A       :   Optional[torch.LongTensor] = None			,						_A       :   Optional[bool] = None			,						_A       :   Optional[bool] = None			,						)					->			ImageClassifierOutputWithNoAttention:
					__snake_case    :							str   	=				return_dict if return_dict is not None else self.config.use_return_dict

					__snake_case    :							Any   	=				self.regnet(_A			,						output_hidden_states=_A			,						return_dict=_A)

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

					__snake_case    :							Optional[Any]   	=				self.classifier(_A)

					__snake_case    :							List[Any]   	=				None

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

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

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






"""simple docstring"""







from __future__ import annotations
def 						__UpperCAmelCase       (					UpperCAmelCase_					:       int						)							->    list[int]:

	'''simple docstring'''





	__snake_case    :							Union[str, Any]   	=				[True] * limit
	__snake_case    :							Tuple   	=				False
	__snake_case    :							Union[str, Any]   	=				False
	__snake_case    :							List[str]   	=				True

	for i in range(3    ,							int(limit**0.5 + 1						)    ,							2						):
		__snake_case    :							List[str]   	=				i * 2
		while index < limit:
			__snake_case    :							List[str]   	=				False
			__snake_case    :							Union[str, Any]   	=				index + i

	__snake_case    :							str   	=				[2]

	for i in range(3    ,							UpperCAmelCase_    ,							2						):
		if is_prime[i]:
			primes.append(UpperCAmelCase_						)

	return primes
def 						__UpperCAmelCase       (					UpperCAmelCase_					:       int = 1_00_00_00						)							->    int:

	'''simple docstring'''





	__snake_case    :							Tuple   	=				prime_sieve(UpperCAmelCase_						)
	__snake_case    :							int   	=				0
	__snake_case    :							str   	=				0

	for i in range(len(UpperCAmelCase_						)						):
		for j in range(i + length    ,							len(UpperCAmelCase_						)						):
			__snake_case    :							Union[str, Any]   	=				sum(primes[i:j]						)
			if sol >= ceiling:
				break

			if sol in primes:
				__snake_case    :							List[Any]   	=				j - i
				__snake_case    :							Optional[Any]   	=				sol

	return largest


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





