





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 ...modeling_outputs import (
    BackboneOutput,
    BaseModelOutputWithNoAttention,
    BaseModelOutputWithPoolingAndNoAttention,
    ImageClassifierOutputWithNoAttention,
)
from ...modeling_utils import PreTrainedModel
from ...utils import (
    add_code_sample_docstrings,
    add_start_docstrings,
    add_start_docstrings_to_model_forward,
    logging,
    replace_return_docstrings,
)
from ...utils.backbone_utils import BackboneMixin
from .configuration_resnet import ResNetConfig


UpperCamelCase__           =			logging.get_logger(__name__)

# General docstring
UpperCamelCase__           =			"ResNetConfig"

# Base docstring
UpperCamelCase__           =			"microsoft/resnet-50"
UpperCamelCase__           =			[1, 2_048, 7, 7]

# Image classification docstring
UpperCamelCase__           =			"microsoft/resnet-50"
UpperCamelCase__           =			"tiger cat"

UpperCamelCase__           =			[
    "microsoft/resnet-50",
    # See all resnet models at https://huggingface.co/models?filter=resnet
]

class 							__SCREAMING_SNAKE_CASE       (  nn.Module							):






							def __init__(    self	,			__lowerCAmelCase	,			__lowerCAmelCase	,			__lowerCAmelCase = 3	,			__lowerCAmelCase = 1	,			__lowerCAmelCase = "relu"	):
														super().__init__()
														UpperCamelCase__					  =      nn.Convad(
														    UpperCamelCase_	,			UpperCamelCase_	,			kernel_size=UpperCamelCase_	,			stride=UpperCamelCase_	,			padding=kernel_size // 2	,			bias=UpperCamelCase_	)
														UpperCamelCase__					  =      nn.BatchNormad(UpperCamelCase_	)
														UpperCamelCase__					  =      ACTaFN[activation] if activation is not None else nn.Identity()







							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	):
														UpperCamelCase__					  =      self.convolution(UpperCamelCase_	)
														UpperCamelCase__					  =      self.normalization(UpperCamelCase_	)
														UpperCamelCase__					  =      self.activation(UpperCamelCase_	)
														return hidden_state






class 							__SCREAMING_SNAKE_CASE       (  nn.Module							):






							def __init__(    self	,			__lowerCAmelCase	):
														super().__init__()
														UpperCamelCase__					  =      ResNetConvLayer(
														    config.num_channels	,			config.embedding_size	,			kernel_size=7	,			stride=2	,			activation=config.hidden_act	)
														UpperCamelCase__					  =      nn.MaxPoolad(kernel_size=3	,			stride=2	,			padding=1	)
														UpperCamelCase__					  =      config.num_channels







							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	):
														UpperCamelCase__					  =      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."""	)
														UpperCamelCase__					  =      self.embedder(UpperCamelCase_	)
														UpperCamelCase__					  =      self.pooler(UpperCamelCase_	)
														return embedding






class 							__SCREAMING_SNAKE_CASE       (  nn.Module							):






							def __init__(    self	,			__lowerCAmelCase	,			__lowerCAmelCase	,			__lowerCAmelCase = 2	):
														super().__init__()
														UpperCamelCase__					  =      nn.Convad(UpperCamelCase_	,			UpperCamelCase_	,			kernel_size=1	,			stride=UpperCamelCase_	,			bias=UpperCamelCase_	)
														UpperCamelCase__					  =      nn.BatchNormad(UpperCamelCase_	)







							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	):
														UpperCamelCase__					  =      self.convolution(UpperCamelCase_	)
														UpperCamelCase__					  =      self.normalization(UpperCamelCase_	)
														return hidden_state






class 							__SCREAMING_SNAKE_CASE       (  nn.Module							):






							def __init__(    self	,			__lowerCAmelCase	,			__lowerCAmelCase	,			__lowerCAmelCase = 1	,			__lowerCAmelCase = "relu"	):
														super().__init__()
														UpperCamelCase__					  =      in_channels != out_channels or stride != 1
														UpperCamelCase__					  =      (
														    ResNetShortCut(UpperCamelCase_	,			UpperCamelCase_	,			stride=UpperCamelCase_	) if should_apply_shortcut else nn.Identity()
														)
														UpperCamelCase__					  =      nn.Sequential(
														    ResNetConvLayer(UpperCamelCase_	,			UpperCamelCase_	,			stride=UpperCamelCase_	)	,			ResNetConvLayer(UpperCamelCase_	,			UpperCamelCase_	,			activation=UpperCamelCase_	)	,			)
														UpperCamelCase__					  =      ACTaFN[activation]







							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	):
														UpperCamelCase__					  =      hidden_state
														UpperCamelCase__					  =      self.layer(UpperCamelCase_	)
														UpperCamelCase__					  =      self.shortcut(UpperCamelCase_	)
														hidden_state += residual
														UpperCamelCase__					  =      self.activation(UpperCamelCase_	)
														return hidden_state






class 							__SCREAMING_SNAKE_CASE       (  nn.Module							):






							def __init__(    self	,			__lowerCAmelCase	,			__lowerCAmelCase	,			__lowerCAmelCase = 1	,			__lowerCAmelCase = "relu"	,			__lowerCAmelCase = 4	):
														super().__init__()
														UpperCamelCase__					  =      in_channels != out_channels or stride != 1
														UpperCamelCase__					  =      out_channels // reduction
														UpperCamelCase__					  =      (
														    ResNetShortCut(UpperCamelCase_	,			UpperCamelCase_	,			stride=UpperCamelCase_	) if should_apply_shortcut else nn.Identity()
														)
														UpperCamelCase__					  =      nn.Sequential(
														    ResNetConvLayer(UpperCamelCase_	,			UpperCamelCase_	,			kernel_size=1	)	,			ResNetConvLayer(UpperCamelCase_	,			UpperCamelCase_	,			stride=UpperCamelCase_	)	,			ResNetConvLayer(UpperCamelCase_	,			UpperCamelCase_	,			kernel_size=1	,			activation=UpperCamelCase_	)	,			)
														UpperCamelCase__					  =      ACTaFN[activation]







							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	):
														UpperCamelCase__					  =      hidden_state
														UpperCamelCase__					  =      self.layer(UpperCamelCase_	)
														UpperCamelCase__					  =      self.shortcut(UpperCamelCase_	)
														hidden_state += residual
														UpperCamelCase__					  =      self.activation(UpperCamelCase_	)
														return hidden_state






class 							__SCREAMING_SNAKE_CASE       (  nn.Module							):






							def __init__(    self	,			__lowerCAmelCase	,			__lowerCAmelCase	,			__lowerCAmelCase	,			__lowerCAmelCase = 2	,			__lowerCAmelCase = 2	,			):
														super().__init__()

														UpperCamelCase__					  =      ResNetBottleNeckLayer if config.layer_type == '''bottleneck''' else ResNetBasicLayer

														UpperCamelCase__					  =      nn.Sequential(
														    # downsampling is done in the first layer with stride of 2
														    layer(UpperCamelCase_	,			UpperCamelCase_	,			stride=UpperCamelCase_	,			activation=config.hidden_act	)	,			*[layer(UpperCamelCase_	,			UpperCamelCase_	,			activation=config.hidden_act	) for _ in range(depth - 1	)]	,			)







							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	):
														UpperCamelCase__					  =      input
														for layer in self.layers:
																					UpperCamelCase__					  =      layer(UpperCamelCase_	)
														return hidden_state






class 							__SCREAMING_SNAKE_CASE       (  nn.Module							):






							def __init__(    self	,			__lowerCAmelCase	):
														super().__init__()
														UpperCamelCase__					  =      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(
														    ResNetStage(
														        UpperCamelCase_	,			config.embedding_size	,			config.hidden_sizes[0]	,			stride=2 if config.downsample_in_first_stage else 1	,			depth=config.depths[0]	,			)	)
														UpperCamelCase__					  =      zip(config.hidden_sizes	,			config.hidden_sizes[1:]	)
														for (in_channels, out_channels), depth in zip(UpperCamelCase_	,			config.depths[1:]	):
																					self.stages.append(ResNetStage(UpperCamelCase_	,			UpperCamelCase_	,			UpperCamelCase_	,			depth=UpperCamelCase_	)	)







							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			__lowerCAmelCase = False	,			__lowerCAmelCase = True	):
														UpperCamelCase__					  =      () if output_hidden_states else None

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

																					UpperCamelCase__					  =      stage_module(UpperCamelCase_	)

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






class 							__SCREAMING_SNAKE_CASE       (  A__							):
							snake_case  :   Any      =							ResNetConfig
							snake_case  :   List[str]      =							"""resnet"""
							snake_case  :   str      =							"""pixel_values"""
							snake_case  :   Tuple      =							True






							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	):


														if isinstance(UpperCamelCase_	,			nn.Convad	):
																					nn.init.kaiming_normal_(module.weight	,			mode="""fan_out"""	,			nonlinearity="""relu"""	)
														elif isinstance(UpperCamelCase_	,			(nn.BatchNormad, nn.GroupNorm)	):
																					nn.init.constant_(module.weight	,			1	)
																					nn.init.constant_(module.bias	,			0	)







							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			__lowerCAmelCase=False	):


														if isinstance(UpperCamelCase_	,			UpperCamelCase_	):
																					UpperCamelCase__					  =      value






UpperCamelCase__           =			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 ([`ResNetConfig`]): 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__           =			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 [`~utils.ModelOutput`] instead of a plain tuple.\n"

@add_start_docstrings(
    """The bare ResNet model outputting raw features without any specific head on top.""" ,		A__ ,		)
class 							__SCREAMING_SNAKE_CASE       (  A__							):






							def __init__(    self	,			__lowerCAmelCase	):
														super().__init__(UpperCamelCase_	)
														UpperCamelCase__					  =      config
														UpperCamelCase__					  =      ResNetEmbeddings(UpperCamelCase_	)
														UpperCamelCase__					  =      ResNetEncoder(UpperCamelCase_	)
														UpperCamelCase__					  =      nn.AdaptiveAvgPoolad((1, 1)	)
														# Initialize weights and apply final processing
														self.post_init()







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

														UpperCamelCase__					  =      self.embedder(UpperCamelCase_	)

														UpperCamelCase__					  =      self.encoder(
														    UpperCamelCase_	,			output_hidden_states=UpperCamelCase_	,			return_dict=UpperCamelCase_	)

														UpperCamelCase__					  =      encoder_outputs[0]

														UpperCamelCase__					  =      self.pooler(UpperCamelCase_	)

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

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






@add_start_docstrings(
    """\n    ResNet 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 							__SCREAMING_SNAKE_CASE       (  A__							):






							def __init__(    self	,			__lowerCAmelCase	):
														super().__init__(UpperCamelCase_	)
														UpperCamelCase__					  =      config.num_labels
														UpperCamelCase__					  =      ResNetModel(UpperCamelCase_	)
														# classification head
														UpperCamelCase__					  =      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(UpperCamelCase_	)
							@add_code_sample_docstrings(
							    checkpoint=_IMAGE_CLASS_CHECKPOINT	,			output_type=UpperCamelCase_	,			config_class=_CONFIG_FOR_DOC	,			expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT	,			)
							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase = None	,			__lowerCAmelCase = None	,			__lowerCAmelCase = None	,			__lowerCAmelCase = None	,			):
														UpperCamelCase__					  =      return_dict if return_dict is not None else self.config.use_return_dict

														UpperCamelCase__					  =      self.resnet(UpperCamelCase_	,			output_hidden_states=UpperCamelCase_	,			return_dict=UpperCamelCase_	)

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

														UpperCamelCase__					  =      self.classifier(UpperCamelCase_	)

														UpperCamelCase__					  =      None

														if labels is not None:
																					if self.config.problem_type is None:
																												if self.num_labels == 1:
																																			UpperCamelCase__					  =      '''regression'''
																												elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
																																			UpperCamelCase__					  =      '''single_label_classification'''
																												else:
																																			UpperCamelCase__					  =      '''multi_label_classification'''
																					if self.config.problem_type == "regression":
																												UpperCamelCase__					  =      MSELoss()
																												if self.num_labels == 1:
																																			UpperCamelCase__					  =      loss_fct(logits.squeeze()	,			labels.squeeze()	)
																												else:
																																			UpperCamelCase__					  =      loss_fct(UpperCamelCase_	,			UpperCamelCase_	)
																					elif self.config.problem_type == "single_label_classification":
																												UpperCamelCase__					  =      CrossEntropyLoss()
																												UpperCamelCase__					  =      loss_fct(logits.view(-1	,			self.num_labels	)	,			labels.view(-1	)	)
																					elif self.config.problem_type == "multi_label_classification":
																												UpperCamelCase__					  =      BCEWithLogitsLoss()
																												UpperCamelCase__					  =      loss_fct(UpperCamelCase_	,			UpperCamelCase_	)

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

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






@add_start_docstrings(
    """\n    ResNet backbone, to be used with frameworks like DETR and MaskFormer.\n    """ ,		A__ ,		)
class 							__SCREAMING_SNAKE_CASE       (  A__ ,		A__							):






							def __init__(    self	,			__lowerCAmelCase	):
														super().__init__(UpperCamelCase_	)
														super()._init_backbone(UpperCamelCase_	)

														UpperCamelCase__					  =      [config.embedding_size] + config.hidden_sizes
														UpperCamelCase__					  =      ResNetEmbeddings(UpperCamelCase_	)
														UpperCamelCase__					  =      ResNetEncoder(UpperCamelCase_	)

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







							@add_start_docstrings_to_model_forward(UpperCamelCase_	)
							@replace_return_docstrings(output_type=UpperCamelCase_	,			config_class=_CONFIG_FOR_DOC	)
							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			__lowerCAmelCase = None	,			__lowerCAmelCase = None	):
														UpperCamelCase__					  =      return_dict if return_dict is not None else self.config.use_return_dict
														UpperCamelCase__					  =      (
														    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
														)

														UpperCamelCase__					  =      self.embedder(UpperCamelCase_	)

														UpperCamelCase__					  =      self.encoder(UpperCamelCase_	,			output_hidden_states=UpperCamelCase_	,			return_dict=UpperCamelCase_	)

														UpperCamelCase__					  =      outputs.hidden_states

														UpperCamelCase__					  =      ()
														for idx, stage in enumerate(self.stage_names	):
																					if stage in self.out_features:
																												feature_maps += (hidden_states[idx],)

														if not return_dict:
																					UpperCamelCase__					  =      (feature_maps,)
																					if output_hidden_states:
																												output += (outputs.hidden_states,)
																					return output

														return BackboneOutput(
														    feature_maps=UpperCamelCase_	,			hidden_states=outputs.hidden_states if output_hidden_states else None	,			attentions=UpperCamelCase_	,			)








'''simple docstring'''
import requests
from bsa import BeautifulSoup


def      a (     __a = "AAPL"  )    ->      str:



					'''simple docstring'''






					UpperCamelCase__  :str				   =					f'''https://in.finance.yahoo.com/quote/{symbol}?s={symbol}'''
					UpperCamelCase__  :Tuple				   =					BeautifulSoup(requests.get(__a  ).text					,   '''html.parser'''  )
					UpperCamelCase__  :Tuple				   =					'''My(6px) Pos(r) smartphone_Mt(6px)'''
					return soup.find('''div'''					,   class_=class_  ).find('''span'''  ).text


if __name__ == "__main__":
		for symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split():
				print(F"""Current {symbol:<4} stock price is {stock_price(symbol):>8}""")