





import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import DetrConfig, MaskFormerConfig, SwinConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import MaskFormerForInstanceSegmentation, MaskFormerModel

				if is_vision_available():
								from transformers import MaskFormerImageProcessor

if is_vision_available():
				from PIL import Image



class    _a     :






							"""simple docstring"""

							def __init__(      self				:     List[Any]							,	a				:     List[str]							,	a				:     Optional[Any]=2							,	a				:     Optional[int]=True							,	a				:     Dict=False							,	a				:     List[Any]=10							,	a				:     str=3							,	a				:     Any=32 * 4							,	a				:     Dict=32 * 6							,	a				:     Tuple=4							,	a				:     List[Any]=32							,	)	->List[Any]:
													SCREAMING_SNAKE_CASE__     :				Any   =					parent
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					batch_size
													SCREAMING_SNAKE_CASE__     :				List[str]   =					is_training
													SCREAMING_SNAKE_CASE__     :				Dict   =					use_auxiliary_loss
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					num_queries
													SCREAMING_SNAKE_CASE__     :				int   =					num_channels
													SCREAMING_SNAKE_CASE__     :				Dict   =					min_size
													SCREAMING_SNAKE_CASE__     :				Tuple   =					max_size
													SCREAMING_SNAKE_CASE__     :				Any   =					num_labels
													SCREAMING_SNAKE_CASE__     :				Dict   =					mask_feature_size

							def      A_  (      self				:     Tuple    )	->Optional[int]:
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]    ).to(
													    a    )

													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					torch.ones([self.batch_size, self.min_size, self.max_size]							,	device=a    )

													SCREAMING_SNAKE_CASE__     :				int   =					(
													    torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]							,	device=a    ) > 0.5
													).float()
													SCREAMING_SNAKE_CASE__     :				List[str]   =					(torch.rand((self.batch_size, self.num_labels)							,	device=a    ) > 0.5).long()

													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					self.get_config()
													return config, pixel_values, pixel_mask, mask_labels, class_labels

							def      A_  (      self				:     Union[str, Any]    )	->List[str]:
													return MaskFormerConfig.from_backbone_and_decoder_configs(
													    backbone_config=SwinConfig(
													        depths=[1, 1, 1, 1]							,	)							,	decoder_config=DetrConfig(
													        decoder_ffn_dim=1_28							,	num_queries=self.num_queries							,	decoder_attention_heads=2							,	d_model=self.mask_feature_size							,	)							,	mask_feature_size=self.mask_feature_size							,	fpn_feature_size=self.mask_feature_size							,	num_channels=self.num_channels							,	num_labels=self.num_labels							,	)

							def      A_  (      self				:     Union[str, Any]    )	->List[str]:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Optional[int]   =					self.prepare_config_and_inputs()
													SCREAMING_SNAKE_CASE__     :				int   =					{"pixel_values": pixel_values, "pixel_mask": pixel_mask}
													return config, inputs_dict

							def      A_  (      self				:     List[Any]							,	a				:     List[str]							,	a				:     List[Any]    )	->Optional[Any]:
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					output.encoder_hidden_states
													SCREAMING_SNAKE_CASE__     :				Tuple   =					output.pixel_decoder_hidden_states
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					output.transformer_decoder_hidden_states

													self.parent.assertTrue(len(a    )							,	len(config.backbone_config.depths    )    )
													self.parent.assertTrue(len(a    )							,	len(config.backbone_config.depths    )    )
													self.parent.assertTrue(len(a    )							,	config.decoder_config.decoder_layers    )

							def      A_  (      self				:     str							,	a				:     Optional[Any]							,	a				:     Optional[int]							,	a				:     Any							,	a				:     int=False    )	->str:
													with torch.no_grad():
																			SCREAMING_SNAKE_CASE__     :				Optional[int]   =					MaskFormerModel(config=a    )
																			model.to(a    )
																			model.eval()

																			SCREAMING_SNAKE_CASE__     :				int   =					model(pixel_values=a							,	pixel_mask=a    )
																			SCREAMING_SNAKE_CASE__     :				List[Any]   =					model(a							,	output_hidden_states=a    )
													# the correct shape of output.transformer_decoder_hidden_states ensure the correcteness of the
													# encoder and pixel decoder
													self.parent.assertEqual(
													    output.transformer_decoder_last_hidden_state.shape							,	(self.batch_size, self.num_queries, self.mask_feature_size)							,	)
													# let's ensure the other two hidden state exists
													self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None    )
													self.parent.assertTrue(output.encoder_last_hidden_state is not None    )

													if output_hidden_states:
																			self.check_output_hidden_state(a							,	a    )






							def      A_  (      self				:     Dict							,	a				:     Tuple							,	a				:     str							,	a				:     Tuple							,	a				:     List[str]							,	a				:     Tuple    )	->Any:
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					MaskFormerForInstanceSegmentation(config=a    )
													model.to(a    )
													model.eval()

													def comm_check_on_output(a				:     Optional[Any]    ):
																			# let's still check that all the required stuff is there
																			self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None    )
																			self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None    )
																			self.parent.assertTrue(result.encoder_last_hidden_state is not None    )
																			# okay, now we need to check the logits shape
																			# due to the encoder compression, masks have a //4 spatial size
																			self.parent.assertEqual(
																			    result.masks_queries_logits.shape							,	(self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)							,	)
																			# + 1 for null class
																			self.parent.assertEqual(
																			    result.class_queries_logits.shape							,	(self.batch_size, self.num_queries, self.num_labels + 1)    )

													with torch.no_grad():
																			SCREAMING_SNAKE_CASE__     :				str   =					model(pixel_values=a							,	pixel_mask=a    )
																			SCREAMING_SNAKE_CASE__     :				Tuple   =					model(a    )

																			comm_check_on_output(a    )

																			SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					model(
																			    pixel_values=a							,	pixel_mask=a							,	mask_labels=a							,	class_labels=a    )

													comm_check_on_output(a    )

													self.parent.assertTrue(result.loss is not None    )
													self.parent.assertEqual(result.loss.shape							,	torch.Size([1]    )    )







@require_torch
class    _a     (				lowercase__					,							lowercase__					,							unittest.TestCase							):






							"""simple docstring"""

							snake_case_							 =						(MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
							snake_case_							 =						(
							    {"feature-extraction": MaskFormerModel, "image-segmentation": MaskFormerForInstanceSegmentation}
							    if is_torch_available()
							    else {}
							)

							snake_case_							 =						False
							snake_case_							 =						False
							snake_case_							 =						False
							snake_case_							 =						False

							def      A_  (      self				:     Any    )	->int:
													SCREAMING_SNAKE_CASE__     :				int   =					MaskFormerModelTester(self    )
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					ConfigTester(self							,	config_class=a							,	has_text_modality=a    )

							def      A_  (      self				:     Any    )	->Tuple:
													self.config_tester.run_common_tests()

							def      A_  (      self				:     Tuple    )	->str:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				List[Any]   =					self.model_tester.prepare_config_and_inputs_for_common()
													self.model_tester.create_and_check_maskformer_model(a							,	**a							,	output_hidden_states=a    )

							def      A_  (      self				:     Dict    )	->Tuple:
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_maskformer_instance_segmentation_head_model(*a    )

							@unittest.skip(reason="MaskFormer does not use inputs_embeds"    )
							def      A_  (      self				:     List[str]    )	->Optional[Any]:
													pass

							@unittest.skip(reason="MaskFormer does not have a get_input_embeddings method"    )
							def      A_  (      self				:     Any    )	->Any:
													pass

							@unittest.skip(reason="MaskFormer is not a generative model"    )
							def      A_  (      self				:     Optional[Any]    )	->Dict:
													pass

							@unittest.skip(reason="MaskFormer does not use token embeddings"    )
							def      A_  (      self				:     Dict    )	->int:
													pass

							@require_torch_multi_gpu
							@unittest.skip(
							    reason="MaskFormer has some layers using `add_module` which doesn't work well with `nn.DataParallel`"    )
							def      A_  (      self				:     Union[str, Any]    )	->Tuple:
													pass

							@unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."    )
							def      A_  (      self				:     int    )	->Dict:
													pass

							def      A_  (      self				:     Tuple    )	->Tuple:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				List[Any]   =					self.model_tester.prepare_config_and_inputs_for_common()

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

																			SCREAMING_SNAKE_CASE__     :				Tuple   =					["pixel_values"]
																			self.assertListEqual(arg_names[:1]							,	a    )

							@slow
							def      A_  (      self				:     Union[str, Any]    )	->List[str]:
													for model_name in ["facebook/maskformer-swin-small-coco"]:
																			SCREAMING_SNAKE_CASE__     :				str   =					MaskFormerModel.from_pretrained(a    )
																			self.assertIsNotNone(a    )

							def      A_  (      self				:     List[Any]    )	->Optional[int]:
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					(self.model_tester.min_size,) * 2
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					{
													    "pixel_values": torch.randn((2, 3, *size)							,	device=a    ),
													    "mask_labels": torch.randn((2, 10, *size)							,	device=a    ),
													    "class_labels": torch.zeros(2							,	10							,	device=a    ).long(),
													}

													SCREAMING_SNAKE_CASE__     :				Tuple   =					MaskFormerForInstanceSegmentation(MaskFormerConfig()    ).to(a    )
													SCREAMING_SNAKE_CASE__     :				Dict   =					model(**a    )
													self.assertTrue(outputs.loss is not None    )

							def      A_  (      self				:     Optional[int]    )	->int:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				int   =					self.model_tester.prepare_config_and_inputs_for_common()
													self.model_tester.create_and_check_maskformer_model(a							,	**a							,	output_hidden_states=a    )

							def      A_  (      self				:     Tuple    )	->str:
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				str   =					self.model_tester.prepare_config_and_inputs_for_common()

													for model_class in self.all_model_classes:
																			SCREAMING_SNAKE_CASE__     :				List[str]   =					model_class(a    ).to(a    )
																			SCREAMING_SNAKE_CASE__     :				str   =					model(**a							,	output_attentions=a    )
																			self.assertTrue(outputs.attentions is not None    )

							def      A_  (      self				:     Any    )	->List[str]:
													if not self.model_tester.is_training:
																			return
													# only MaskFormerForInstanceSegmentation has the loss
													SCREAMING_SNAKE_CASE__     :				Dict   =					self.all_model_classes[1]
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Any   =					self.model_tester.prepare_config_and_inputs()

													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					model_class(a    )
													model.to(a    )
													model.train()

													SCREAMING_SNAKE_CASE__     :				Tuple   =					model(a							,	mask_labels=a							,	class_labels=a    ).loss
													loss.backward()






							def      A_  (      self				:     Tuple    )	->Optional[Any]:
													# only MaskFormerForInstanceSegmentation has the loss
													SCREAMING_SNAKE_CASE__     :				List[str]   =					self.all_model_classes[1]
													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Dict   =					self.model_tester.prepare_config_and_inputs()
													SCREAMING_SNAKE_CASE__     :				int   =					True
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					True

													SCREAMING_SNAKE_CASE__     :				Any   =					model_class(a    )
													model.to(a    )
													model.train()

													SCREAMING_SNAKE_CASE__     :				Any   =					model(a							,	mask_labels=a							,	class_labels=a    )

													SCREAMING_SNAKE_CASE__     :				int   =					outputs.encoder_hidden_states[0]
													encoder_hidden_states.retain_grad()

													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					outputs.pixel_decoder_hidden_states[0]
													pixel_decoder_hidden_states.retain_grad()
													# we requires_grad=True in inputs_embeds (line 2152), the original implementation don't
													SCREAMING_SNAKE_CASE__     :				Any   =					outputs.transformer_decoder_hidden_states[0]
													transformer_decoder_hidden_states.retain_grad()

													SCREAMING_SNAKE_CASE__     :				List[Any]   =					outputs.attentions[0]
													attentions.retain_grad()

													outputs.loss.backward(retain_graph=a    )

													self.assertIsNotNone(encoder_hidden_states.grad    )
													self.assertIsNotNone(pixel_decoder_hidden_states.grad    )
													self.assertIsNotNone(transformer_decoder_hidden_states.grad    )
													self.assertIsNotNone(attentions.grad    )







__lowercase       :int       =  1e-4







def       UpperCAmelCase							(     ):





						'''simple docstring'''


						SCREAMING_SNAKE_CASE__     :				Dict   =					Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"     )
						return image



@require_vision
@slow
class    _a     (				unittest.TestCase							):






							"""simple docstring"""

							@cached_property
							def      A_  (      self				:     Tuple    )	->Optional[int]:
													return (
													    MaskFormerImageProcessor.from_pretrained("facebook/maskformer-swin-small-coco"    )
													    if is_vision_available()
													    else None
													)

							def      A_  (      self				:     List[Any]    )	->int:
													SCREAMING_SNAKE_CASE__     :				Tuple   =					MaskFormerModel.from_pretrained("facebook/maskformer-swin-small-coco"    ).to(a    )
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					self.default_image_processor
													SCREAMING_SNAKE_CASE__     :				Tuple   =					prepare_img()
													SCREAMING_SNAKE_CASE__     :				int   =					image_processor(a							,	return_tensors="pt"    ).to(a    )
													SCREAMING_SNAKE_CASE__     :				int   =					inputs["pixel_values"].shape
													# check size is divisible by 32
													self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0    )
													# check size
													self.assertEqual(a							,	(1, 3, 8_00, 10_88)    )

													with torch.no_grad():
																			SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					model(**a    )

													SCREAMING_SNAKE_CASE__     :				str   =					torch.tensor(
													    [[-0.0482, 0.9228, 0.4951], [-0.2547, 0.8017, 0.8527], [-0.0069, 0.3385, -0.0089]]    ).to(a    )
													self.assertTrue(
													    torch.allclose(
													        outputs.encoder_last_hidden_state[0, 0, :3, :3]							,	a							,	atol=a    )    )

													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					torch.tensor(
													    [[-0.8422, -0.8434, -0.9718], [-1.0144, -0.5565, -0.4195], [-1.0038, -0.4484, -0.1961]]    ).to(a    )
													self.assertTrue(
													    torch.allclose(
													        outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]							,	a							,	atol=a    )    )

													SCREAMING_SNAKE_CASE__     :				int   =					torch.tensor(
													    [[0.2852, -0.0159, 0.9735], [0.6254, 0.1858, 0.8529], [-0.0680, -0.4116, 1.8413]]    ).to(a    )
													self.assertTrue(
													    torch.allclose(
													        outputs.transformer_decoder_last_hidden_state[0, :3, :3]							,	a							,	atol=a    )    )

							def      A_  (      self				:     List[str]    )	->List[str]:
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					(
													    MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-small-coco"    )
													    .to(a    )
													    .eval()
													)
													SCREAMING_SNAKE_CASE__     :				int   =					self.default_image_processor
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					prepare_img()
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					image_processor(a							,	return_tensors="pt"    ).to(a    )
													SCREAMING_SNAKE_CASE__     :				Dict   =					inputs["pixel_values"].shape
													# check size is divisible by 32
													self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0    )
													# check size
													self.assertEqual(a							,	(1, 3, 8_00, 10_88)    )

													with torch.no_grad():
																			SCREAMING_SNAKE_CASE__     :				Dict   =					model(**a    )
													# masks_queries_logits
													SCREAMING_SNAKE_CASE__     :				Dict   =					outputs.masks_queries_logits
													self.assertEqual(
													    masks_queries_logits.shape							,	(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)							,	)
													SCREAMING_SNAKE_CASE__     :				int   =					[
													    [-1.373_7124, -1.772_4937, -1.936_4233],
													    [-1.597_7281, -1.986_7939, -2.152_3695],
													    [-1.579_5398, -1.926_9832, -2.09_3942],
													]
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					torch.tensor(a    ).to(a    )
													self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]							,	a							,	atol=a    )    )
													# class_queries_logits
													SCREAMING_SNAKE_CASE__     :				List[str]   =					outputs.class_queries_logits
													self.assertEqual(
													    class_queries_logits.shape							,	(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)    )
													SCREAMING_SNAKE_CASE__     :				Tuple   =					torch.tensor(
													    [
													        [1.6512E00, -5.2572E00, -3.3519E00],
													        [3.6169E-02, -5.9025E00, -2.9313E00],
													        [1.0766E-04, -7.7630E00, -5.1263E00],
													    ]    ).to(a    )
													self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]							,	a							,	atol=a    )    )

							def      A_  (      self				:     Tuple    )	->int:
													SCREAMING_SNAKE_CASE__     :				str   =					(
													    MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-resnet101-coco-stuff"    )
													    .to(a    )
													    .eval()
													)
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					self.default_image_processor
													SCREAMING_SNAKE_CASE__     :				Any   =					prepare_img()
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					image_processor(a							,	return_tensors="pt"    ).to(a    )
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					inputs["pixel_values"].shape
													# check size is divisible by 32
													self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0    )
													# check size
													self.assertEqual(a							,	(1, 3, 8_00, 10_88)    )

													with torch.no_grad():
																			SCREAMING_SNAKE_CASE__     :				int   =					model(**a    )
													# masks_queries_logits
													SCREAMING_SNAKE_CASE__     :				Dict   =					outputs.masks_queries_logits
													self.assertEqual(
													    masks_queries_logits.shape							,	(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)							,	)
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					[[-0.9046, -2.6366, -4.6062], [-3.4179, -5.7890, -8.8057], [-4.9179, -7.6560, -10.7711]]
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					torch.tensor(a    ).to(a    )
													self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]							,	a							,	atol=a    )    )
													# class_queries_logits
													SCREAMING_SNAKE_CASE__     :				str   =					outputs.class_queries_logits
													self.assertEqual(
													    class_queries_logits.shape							,	(1, model.config.decoder_config.num_queries, model.config.num_labels + 1)    )
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					torch.tensor(
													    [[4.7188, -3.2585, -2.8857], [6.6871, -2.9181, -1.2487], [7.2449, -2.2764, -2.1874]]    ).to(a    )
													self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]							,	a							,	atol=a    )    )






							def      A_  (      self				:     str    )	->Dict:
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					(
													    MaskFormerForInstanceSegmentation.from_pretrained("facebook/maskformer-swin-small-coco"    )
													    .to(a    )
													    .eval()
													)
													SCREAMING_SNAKE_CASE__     :				int   =					self.default_image_processor

													SCREAMING_SNAKE_CASE__     :				Dict   =					image_processor(
													    [np.zeros((3, 8_00, 13_33)    ), np.zeros((3, 8_00, 13_33)    )]							,	segmentation_maps=[np.zeros((3_84, 3_84)    ).astype(np.floataa    ), np.zeros((3_84, 3_84)    ).astype(np.floataa    )]							,	return_tensors="pt"							,	)

													SCREAMING_SNAKE_CASE__     :				List[str]   =					inputs["pixel_values"].to(a    )
													SCREAMING_SNAKE_CASE__     :				int   =					[el.to(a    ) for el in inputs["mask_labels"]]
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					[el.to(a    ) for el in inputs["class_labels"]]

													with torch.no_grad():
																			SCREAMING_SNAKE_CASE__     :				int   =					model(**a    )

													self.assertTrue(outputs.loss is not None    )






from __future__ import annotations







def       UpperCAmelCase							(     _lowerCamelCase      :  list[int]			,   _lowerCamelCase      :  int     ):





						'''simple docstring'''


						if len(_lowerCamelCase     ) < k or k < 0:
												raise ValueError("Invalid Input"     )
						SCREAMING_SNAKE_CASE__     :				int   =					sum(array[:k]     )
						for i in range(len(_lowerCamelCase     ) - k     ):
												SCREAMING_SNAKE_CASE__     :				str   =					current_sum - array[i] + array[i + k]
												SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					max(_lowerCamelCase			,   _lowerCamelCase     )
						return max_sum


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

				testmod()
				__lowercase       :List[str]       =  [randint(-1_000, 1_000) for i in range(100)]
				__lowercase       :Any       =  randint(0, 110)
				print(f"The maximum sum of {k} consecutive elements is {max_sum_in_array(array,k)}")