



"""simple docstring"""






import collections
import inspect
import unittest

from transformers import SwinvaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
	import torch
	from torch import nn

	from transformers import SwinvaForImageClassification, SwinvaForMaskedImageModeling, SwinvaModel
	from transformers.models.swinva.modeling_swinva import SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
	from PIL import Image

	from transformers import AutoImageProcessor



class     A__     :




	'''simple docstring'''





	def __init__(  self:	Optional[Any] ,    _SCREAMING_SNAKE_CASE:	Optional[int] ,    _SCREAMING_SNAKE_CASE:	Optional[int]=13 ,    _SCREAMING_SNAKE_CASE:	Optional[int]=32 ,    _SCREAMING_SNAKE_CASE:	List[str]=2 ,    _SCREAMING_SNAKE_CASE:	List[str]=3 ,    _SCREAMING_SNAKE_CASE:	Optional[int]=16 ,    _SCREAMING_SNAKE_CASE:	Union[str, Any]=[1, 2, 1] ,    _SCREAMING_SNAKE_CASE:	Union[str, Any]=[2, 2, 4] ,    _SCREAMING_SNAKE_CASE:	Any=2 ,    _SCREAMING_SNAKE_CASE:	Optional[Any]=2.0 ,    _SCREAMING_SNAKE_CASE:	Union[str, Any]=True ,    _SCREAMING_SNAKE_CASE:	Any=0.0 ,    _SCREAMING_SNAKE_CASE:	Optional[Any]=0.0 ,    _SCREAMING_SNAKE_CASE:	Tuple=0.1 ,    _SCREAMING_SNAKE_CASE:	Union[str, Any]="gelu" ,    _SCREAMING_SNAKE_CASE:	str=False ,    _SCREAMING_SNAKE_CASE:	Union[str, Any]=True ,    _SCREAMING_SNAKE_CASE:	Any=0.02 ,    _SCREAMING_SNAKE_CASE:	Any=1e-5 ,    _SCREAMING_SNAKE_CASE:	List[str]=True ,    _SCREAMING_SNAKE_CASE:	str=None ,    _SCREAMING_SNAKE_CASE:	str=True ,    _SCREAMING_SNAKE_CASE:	Dict=10 ,    _SCREAMING_SNAKE_CASE:	Optional[int]=8 ,    )       -> Dict:

				"""simple docstring"""

				__lowerCAmelCase   :						int				= parent
				__lowerCAmelCase   :						Any				= batch_size
				__lowerCAmelCase   :						List[Any]				= image_size
				__lowerCAmelCase   :						List[str]				= patch_size
				__lowerCAmelCase   :						int				= num_channels
				__lowerCAmelCase   :						List[str]				= embed_dim
				__lowerCAmelCase   :						List[str]				= depths
				__lowerCAmelCase   :						Optional[int]				= num_heads
				__lowerCAmelCase   :						List[Any]				= window_size
				__lowerCAmelCase   :						int				= mlp_ratio
				__lowerCAmelCase   :						Dict				= qkv_bias
				__lowerCAmelCase   :						Optional[Any]				= hidden_dropout_prob
				__lowerCAmelCase   :						Tuple				= attention_probs_dropout_prob
				__lowerCAmelCase   :						List[Any]				= drop_path_rate
				__lowerCAmelCase   :						Optional[Any]				= hidden_act
				__lowerCAmelCase   :						List[str]				= use_absolute_embeddings
				__lowerCAmelCase   :						Tuple				= patch_norm
				__lowerCAmelCase   :						str				= layer_norm_eps
				__lowerCAmelCase   :						Tuple				= initializer_range
				__lowerCAmelCase   :						List[str]				= is_training
				__lowerCAmelCase   :						int				= scope
				__lowerCAmelCase   :						Optional[int]				= use_labels
				__lowerCAmelCase   :						Any				= type_sequence_label_size
				__lowerCAmelCase   :						Dict				= encoder_stride

	def 							_SCREAMING_SNAKE_CASE     (  self:	Tuple)       -> Union[str, Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						Optional[Any]				= floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

				__lowerCAmelCase   :						Optional[Any]				= None
				if self.use_labels:
							__lowerCAmelCase   :						Optional[Any]				= ids_tensor([self.batch_size] ,    self.type_sequence_label_size)

				__lowerCAmelCase   :						str				= self.get_config()

				return config, pixel_values, labels

	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[Any])       -> Union[str, Any]:

				"""simple docstring"""

				return SwinvaConfig(
				    image_size=self.image_size ,    patch_size=self.patch_size ,    num_channels=self.num_channels ,    embed_dim=self.embed_dim ,    depths=self.depths ,    num_heads=self.num_heads ,    window_size=self.window_size ,    mlp_ratio=self.mlp_ratio ,    qkv_bias=self.qkv_bias ,    hidden_dropout_prob=self.hidden_dropout_prob ,    attention_probs_dropout_prob=self.attention_probs_dropout_prob ,    drop_path_rate=self.drop_path_rate ,    hidden_act=self.hidden_act ,    use_absolute_embeddings=self.use_absolute_embeddings ,    path_norm=self.patch_norm ,    layer_norm_eps=self.layer_norm_eps ,    initializer_range=self.initializer_range ,    encoder_stride=self.encoder_stride ,    )

	def 							_SCREAMING_SNAKE_CASE     (  self:	List[Any] ,    _SCREAMING_SNAKE_CASE:	int ,    _SCREAMING_SNAKE_CASE:	int ,    _SCREAMING_SNAKE_CASE:	Dict)       -> Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase   :						Tuple				= SwinvaModel(config=_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase   :						List[str]				= model(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase   :						List[str]				= ((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths) - 1))
				__lowerCAmelCase   :						str				= int(config.embed_dim * 2 ** (len(config.depths) - 1))

				self.parent.assertEqual(result.last_hidden_state.shape ,    (self.batch_size, expected_seq_len, expected_dim))

	def 							_SCREAMING_SNAKE_CASE     (  self:	str ,    _SCREAMING_SNAKE_CASE:	Any ,    _SCREAMING_SNAKE_CASE:	Tuple ,    _SCREAMING_SNAKE_CASE:	Optional[int])       -> List[str]:

				"""simple docstring"""

				__lowerCAmelCase   :						List[str]				= SwinvaForMaskedImageModeling(config=_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase   :						str				= model(_SCREAMING_SNAKE_CASE)
				self.parent.assertEqual(
				    result.logits.shape ,    (self.batch_size, self.num_channels, self.image_size, self.image_size))

				# test greyscale images
				__lowerCAmelCase   :						List[str]				= 1
				__lowerCAmelCase   :						Dict				= SwinvaForMaskedImageModeling(_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()

				__lowerCAmelCase   :						Optional[int]				= floats_tensor([self.batch_size, 1, self.image_size, self.image_size])
				__lowerCAmelCase   :						Optional[int]				= model(_SCREAMING_SNAKE_CASE)
				self.parent.assertEqual(result.logits.shape ,    (self.batch_size, 1, self.image_size, self.image_size))

	def 							_SCREAMING_SNAKE_CASE     (  self:	str ,    _SCREAMING_SNAKE_CASE:	List[str] ,    _SCREAMING_SNAKE_CASE:	Any ,    _SCREAMING_SNAKE_CASE:	Optional[Any])       -> Tuple:

				"""simple docstring"""

				__lowerCAmelCase   :						int				= self.type_sequence_label_size
				__lowerCAmelCase   :						str				= SwinvaForImageClassification(_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()
				__lowerCAmelCase   :						int				= model(_SCREAMING_SNAKE_CASE ,    labels=_SCREAMING_SNAKE_CASE)
				self.parent.assertEqual(result.logits.shape ,    (self.batch_size, self.type_sequence_label_size))







	def 							_SCREAMING_SNAKE_CASE     (  self:	Union[str, Any])       -> List[str]:

				"""simple docstring"""

				__lowerCAmelCase   :						int				= self.prepare_config_and_inputs()
				__lowerCAmelCase   :						Any				= config_and_inputs
				__lowerCAmelCase   :						List[str]				= {"pixel_values": pixel_values}
				return config, inputs_dict






@require_torch
class     A__     (						__SCREAMING_SNAKE_CASE						,	__SCREAMING_SNAKE_CASE						,	unittest.TestCase							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE					   =			(
	    (SwinvaModel, SwinvaForImageClassification, SwinvaForMaskedImageModeling) if is_torch_available() else ()
	)
	SCREAMING_SNAKE_CASE					   =			(
	    {'feature-extraction': SwinvaModel, 'image-classification': SwinvaForImageClassification}
	    if is_torch_available()
	    else {}
	)

	SCREAMING_SNAKE_CASE					   =			False
	SCREAMING_SNAKE_CASE					   =			False
	SCREAMING_SNAKE_CASE					   =			False
	SCREAMING_SNAKE_CASE					   =			False

	def 							_SCREAMING_SNAKE_CASE     (  self:	int)       -> Any:

				"""simple docstring"""

				__lowerCAmelCase   :						int				= SwinvaModelTester(self)
				__lowerCAmelCase   :						Tuple				= ConfigTester(self ,    config_class=_SCREAMING_SNAKE_CASE ,    embed_dim=37)

	def 							_SCREAMING_SNAKE_CASE     (  self:	List[str])       -> Dict:

				"""simple docstring"""

				self.config_tester.create_and_test_config_to_json_string()
				self.config_tester.create_and_test_config_to_json_file()
				self.config_tester.create_and_test_config_from_and_save_pretrained()
				self.config_tester.create_and_test_config_with_num_labels()
				self.config_tester.check_config_can_be_init_without_params()
				self.config_tester.check_config_arguments_init()

	def 							_SCREAMING_SNAKE_CASE     (  self:	Tuple)       -> int:

				"""simple docstring"""

				__lowerCAmelCase   :						Dict				= self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE)

	@unittest.skip(reason="Got `CUDA error: misaligned address` with PyTorch 2.0.0.")
	def 							_SCREAMING_SNAKE_CASE     (  self:	List[Any])       -> str:

				"""simple docstring"""

				pass

	@unittest.skip(reason="Swinv2 does not use inputs_embeds")
	def 							_SCREAMING_SNAKE_CASE     (  self:	Any)       -> List[Any]:

				"""simple docstring"""

				pass

	def 							_SCREAMING_SNAKE_CASE     (  self:	int)       -> Any:

				"""simple docstring"""

				__lowerCAmelCase   :						List[Any]				= self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
							__lowerCAmelCase   :						Optional[int]				= model_class(_SCREAMING_SNAKE_CASE)
							self.assertIsInstance(model.get_input_embeddings() ,    (nn.Module))
							__lowerCAmelCase   :						Dict				= model.get_output_embeddings()
							self.assertTrue(x is None or isinstance(_SCREAMING_SNAKE_CASE ,    nn.Linear))

	def 							_SCREAMING_SNAKE_CASE     (  self:	Any)       -> Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						List[str]				= self.model_tester.prepare_config_and_inputs_for_common()

				for model_class in self.all_model_classes:
							__lowerCAmelCase   :						str				= model_class(_SCREAMING_SNAKE_CASE)
							__lowerCAmelCase   :						Union[str, Any]				= inspect.signature(model.forward)
							# signature.parameters is an OrderedDict => so arg_names order is deterministic
							__lowerCAmelCase   :						Optional[Any]				= [*signature.parameters.keys()]

							__lowerCAmelCase   :						Optional[int]				= ["pixel_values"]
							self.assertListEqual(arg_names[:1] ,    _SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE     (  self:	int)       -> int:

				"""simple docstring"""

				__lowerCAmelCase   :						Tuple				= self.model_tester.prepare_config_and_inputs_for_common()
				__lowerCAmelCase   :						int				= True

				for model_class in self.all_model_classes:
							__lowerCAmelCase   :						str				= True
							__lowerCAmelCase   :						Optional[int]				= False
							__lowerCAmelCase   :						Union[str, Any]				= True
							__lowerCAmelCase   :						List[Any]				= model_class(_SCREAMING_SNAKE_CASE)
							model.to(_SCREAMING_SNAKE_CASE)
							model.eval()
							with torch.no_grad():
										__lowerCAmelCase   :						str				= model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE))
							__lowerCAmelCase   :						int				= outputs.attentions
							__lowerCAmelCase   :						Union[str, Any]				= len(self.model_tester.depths)
							self.assertEqual(len(_SCREAMING_SNAKE_CASE) ,    _SCREAMING_SNAKE_CASE)

							# check that output_attentions also work using config
							del inputs_dict["output_attentions"]
							__lowerCAmelCase   :						int				= True
							__lowerCAmelCase   :						List[Any]				= config.window_size**2
							__lowerCAmelCase   :						Optional[Any]				= model_class(_SCREAMING_SNAKE_CASE)
							model.to(_SCREAMING_SNAKE_CASE)
							model.eval()
							with torch.no_grad():
										__lowerCAmelCase   :						List[Any]				= model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE))
							__lowerCAmelCase   :						Union[str, Any]				= outputs.attentions
							self.assertEqual(len(_SCREAMING_SNAKE_CASE) ,    _SCREAMING_SNAKE_CASE)

							self.assertListEqual(
							    list(attentions[0].shape[-3:]) ,    [self.model_tester.num_heads[0], window_size_squared, window_size_squared] ,    )
							__lowerCAmelCase   :						int				= len(_SCREAMING_SNAKE_CASE)

							# Check attention is always last and order is fine
							__lowerCAmelCase   :						Tuple				= True
							__lowerCAmelCase   :						Optional[Any]				= True
							__lowerCAmelCase   :						Any				= model_class(_SCREAMING_SNAKE_CASE)
							model.to(_SCREAMING_SNAKE_CASE)
							model.eval()
							with torch.no_grad():
										__lowerCAmelCase   :						str				= model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE))

							if hasattr(self.model_tester ,    "num_hidden_states_types"):
										__lowerCAmelCase   :						List[str]				= self.model_tester.num_hidden_states_types
							else:
										# also another +1 for reshaped_hidden_states
										__lowerCAmelCase   :						List[str]				= 2
							self.assertEqual(out_len + added_hidden_states ,    len(_SCREAMING_SNAKE_CASE))

							__lowerCAmelCase   :						int				= outputs.attentions

							self.assertEqual(len(_SCREAMING_SNAKE_CASE) ,    _SCREAMING_SNAKE_CASE)

							self.assertListEqual(
							    list(self_attentions[0].shape[-3:]) ,    [self.model_tester.num_heads[0], window_size_squared, window_size_squared] ,    )

	def 							_SCREAMING_SNAKE_CASE     (  self:	Any ,    _SCREAMING_SNAKE_CASE:	Tuple ,    _SCREAMING_SNAKE_CASE:	List[str] ,    _SCREAMING_SNAKE_CASE:	int ,    _SCREAMING_SNAKE_CASE:	Any)       -> int:

				"""simple docstring"""

				__lowerCAmelCase   :						Dict				= model_class(_SCREAMING_SNAKE_CASE)
				model.to(_SCREAMING_SNAKE_CASE)
				model.eval()

				with torch.no_grad():
							__lowerCAmelCase   :						Union[str, Any]				= model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE))

				__lowerCAmelCase   :						Tuple				= outputs.hidden_states

				__lowerCAmelCase   :						List[Any]				= getattr(
				    self.model_tester ,    "expected_num_hidden_layers" ,    len(self.model_tester.depths) + 1)
				self.assertEqual(len(_SCREAMING_SNAKE_CASE) ,    _SCREAMING_SNAKE_CASE)

				# Swinv2 has a different seq_length
				__lowerCAmelCase   :						str				= (
				    config.patch_size
				    if isinstance(config.patch_size ,    collections.abc.Iterable)
				    else (config.patch_size, config.patch_size)
				)

				__lowerCAmelCase   :						Tuple				= (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

				self.assertListEqual(
				    list(hidden_states[0].shape[-2:]) ,    [num_patches, self.model_tester.embed_dim] ,    )

				__lowerCAmelCase   :						str				= outputs.reshaped_hidden_states
				self.assertEqual(len(_SCREAMING_SNAKE_CASE) ,    _SCREAMING_SNAKE_CASE)

				__lowerCAmelCase   :						Tuple				= reshaped_hidden_states[0].shape
				__lowerCAmelCase   :						List[str]				= (
				    reshaped_hidden_states[0].view(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    height * width).permute(0 ,    2 ,    1)
				)
				self.assertListEqual(
				    list(reshaped_hidden_states.shape[-2:]) ,    [num_patches, self.model_tester.embed_dim] ,    )

	def 							_SCREAMING_SNAKE_CASE     (  self:	Any)       -> Any:

				"""simple docstring"""

				__lowerCAmelCase   :						Any				= self.model_tester.prepare_config_and_inputs_for_common()

				__lowerCAmelCase   :						Optional[Any]				= (
				    self.model_tester.image_size
				    if isinstance(self.model_tester.image_size ,    collections.abc.Iterable)
				    else (self.model_tester.image_size, self.model_tester.image_size)
				)

				for model_class in self.all_model_classes:
							__lowerCAmelCase   :						Union[str, Any]				= True
							self.check_hidden_states_output(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE)

							# check that output_hidden_states also work using config
							del inputs_dict["output_hidden_states"]
							__lowerCAmelCase   :						Tuple				= True

							self.check_hidden_states_output(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE     (  self:	str)       -> Dict:

				"""simple docstring"""

				__lowerCAmelCase   :						int				= self.model_tester.prepare_config_and_inputs_for_common()
				__lowerCAmelCase   :						List[str]				= 3

				__lowerCAmelCase   :						Optional[Any]				= (
				    self.model_tester.image_size
				    if isinstance(self.model_tester.image_size ,    collections.abc.Iterable)
				    else (self.model_tester.image_size, self.model_tester.image_size)
				)
				__lowerCAmelCase   :						List[str]				= (
				    config.patch_size
				    if isinstance(config.patch_size ,    collections.abc.Iterable)
				    else (config.patch_size, config.patch_size)
				)

				__lowerCAmelCase   :						Optional[Any]				= image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
				__lowerCAmelCase   :						int				= image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

				for model_class in self.all_model_classes:
							__lowerCAmelCase   :						Any				= True
							self.check_hidden_states_output(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    (padded_height, padded_width))

							# check that output_hidden_states also work using config
							del inputs_dict["output_hidden_states"]
							__lowerCAmelCase   :						List[Any]				= True
							self.check_hidden_states_output(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    (padded_height, padded_width))

	def 							_SCREAMING_SNAKE_CASE     (  self:	Union[str, Any])       -> Tuple:

				"""simple docstring"""

				__lowerCAmelCase   :						str				= self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_masked_image_modeling(*_SCREAMING_SNAKE_CASE)

	def 							_SCREAMING_SNAKE_CASE     (  self:	Dict)       -> int:

				"""simple docstring"""

				__lowerCAmelCase   :						Tuple				= self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_image_classification(*_SCREAMING_SNAKE_CASE)

	@slow
	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[int])       -> Any:

				"""simple docstring"""

				for model_name in SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							__lowerCAmelCase   :						Tuple				= SwinvaModel.from_pretrained(_SCREAMING_SNAKE_CASE)
							self.assertIsNotNone(_SCREAMING_SNAKE_CASE)







	def 							_SCREAMING_SNAKE_CASE     (  self:	Union[str, Any])       -> Any:

				"""simple docstring"""

				__lowerCAmelCase   :						Union[str, Any]				= self.model_tester.prepare_config_and_inputs_for_common()

				__lowerCAmelCase   :						List[Any]				= _config_zero_init(_SCREAMING_SNAKE_CASE)
				for model_class in self.all_model_classes:
							__lowerCAmelCase   :						Optional[Any]				= model_class(config=_SCREAMING_SNAKE_CASE)
							for name, param in model.named_parameters():
										if "embeddings" not in name and "logit_scale" not in name and param.requires_grad:
													self.assertIn(
													    ((param.data.mean() * 1e9).round() / 1e9).item() ,    [0.0, 1.0] ,    msg=F"""Parameter {name} of model {model_class} seems not properly initialized""" ,    )






@require_vision
@require_torch
class     A__     (						unittest.TestCase							):




	'''simple docstring'''





	@cached_property
	def 							_SCREAMING_SNAKE_CASE     (  self:	Dict)       -> Any:

				"""simple docstring"""

				return (
				    AutoImageProcessor.from_pretrained("microsoft/swinv2-tiny-patch4-window8-256")
				    if is_vision_available()
				    else None
				)







	@slow
	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[Any])       -> Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						Dict				= SwinvaForImageClassification.from_pretrained("microsoft/swinv2-tiny-patch4-window8-256").to(
				    _SCREAMING_SNAKE_CASE)
				__lowerCAmelCase   :						Any				= self.default_image_processor

				__lowerCAmelCase   :						Union[str, Any]				= Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png")
				__lowerCAmelCase   :						Union[str, Any]				= image_processor(images=_SCREAMING_SNAKE_CASE ,    return_tensors="pt").to(_SCREAMING_SNAKE_CASE)

				# forward pass
				with torch.no_grad():
							__lowerCAmelCase   :						Union[str, Any]				= model(**_SCREAMING_SNAKE_CASE)

				# verify the logits
				__lowerCAmelCase   :						Union[str, Any]				= torch.Size((1, 1000))
				self.assertEqual(outputs.logits.shape ,    _SCREAMING_SNAKE_CASE)
				__lowerCAmelCase   :						Union[str, Any]				= torch.tensor([-0.3947, -0.4306, 0.0026]).to(_SCREAMING_SNAKE_CASE)
				self.assertTrue(torch.allclose(outputs.logits[0, :3] ,    _SCREAMING_SNAKE_CASE ,    atol=1e-4))




"""simple docstring"""






import math


def     _lowercase       (						__snake_case      ,__snake_case			)		->     float:
			return math.pow(__snake_case      ,2			) - a


def     _lowercase       (						__snake_case			)		->     float:
			return 2 * x


def     _lowercase       (						__snake_case			)		->     float:
			__lowerCAmelCase   :						List[str]				= 2.0

			while start <= a:
						__lowerCAmelCase   :						Union[str, Any]				= math.pow(__snake_case      ,2			)

			return start


def     _lowercase       (						__snake_case      ,__snake_case = 9_999      ,__snake_case = 0.00000000000001			)		->     float:

			if a < 0:
						raise ValueError("math domain error"			)

			__lowerCAmelCase   :						List[Any]				= get_initial_point(__snake_case			)

			for _ in range(__snake_case			):
						__lowerCAmelCase   :						Union[str, Any]				= value
						__lowerCAmelCase   :						List[str]				= value - fx(__snake_case      ,__snake_case			) / fx_derivative(__snake_case			)
						if abs(prev_value - value			) < tolerance:
									return value

			return value


if __name__ == "__main__":
	from doctest import testmod

	testmod()