





import unittest

from transformers import AlbertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import (
						    MODEL_FOR_PRETRAINING_MAPPING,
						    AlbertForMaskedLM,
						    AlbertForMultipleChoice,
						    AlbertForPreTraining,
						    AlbertForQuestionAnswering,
						    AlbertForSequenceClassification,
						    AlbertForTokenClassification,
						    AlbertModel,
						)
						from transformers.models.albert.modeling_albert import ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST
class SCREAMING_SNAKE_CASE_  :






						def __init__( self : Optional[Any]						,				_A : List[Any]						,				_A : Union[str, Any]=13						,				_A : List[str]=7						,				_A : Union[str, Any]=True						,				_A : Optional[Any]=True						,				_A : int=True						,				_A : Dict=True						,				_A : List[str]=99						,				_A : Tuple=16						,				_A : int=36						,				_A : Dict=6						,				_A : Tuple=6						,				_A : str=6						,				_A : Optional[Any]=37						,				_A : Optional[int]="gelu"						,				_A : Any=0.1						,				_A : Optional[int]=0.1						,				_A : Any=512						,				_A : Optional[int]=16						,				_A : int=2						,				_A : Tuple=0.0_2						,				_A : str=3						,				_A : Any=4						,				_A : Optional[int]=None						,				)							->      Optional[Any]:







							"""simple docstring"""


							snake_case_						:     Tuple     =		parent
							snake_case_						:     List[str]     =		batch_size
							snake_case_						:     Union[str, Any]     =		seq_length
							snake_case_						:     List[Any]     =		is_training
							snake_case_						:     int     =		use_input_mask
							snake_case_						:     List[str]     =		use_token_type_ids
							snake_case_						:     str     =		use_labels
							snake_case_						:     Any     =		vocab_size
							snake_case_						:     Any     =		embedding_size
							snake_case_						:     Optional[Any]     =		hidden_size
							snake_case_						:     Dict     =		num_hidden_layers
							snake_case_						:     str     =		num_hidden_groups
							snake_case_						:     List[Any]     =		num_attention_heads
							snake_case_						:     int     =		intermediate_size
							snake_case_						:     int     =		hidden_act
							snake_case_						:     Optional[int]     =		hidden_dropout_prob
							snake_case_						:     List[str]     =		attention_probs_dropout_prob
							snake_case_						:     Union[str, Any]     =		max_position_embeddings
							snake_case_						:     str     =		type_vocab_size
							snake_case_						:     List[str]     =		type_sequence_label_size
							snake_case_						:     int     =		initializer_range
							snake_case_						:     Union[str, Any]     =		num_labels
							snake_case_						:     Union[str, Any]     =		num_choices
							snake_case_						:     str     =		scope






						def UpperCAmelCase_			( self : List[str]		)							->      str:







							"""simple docstring"""


							snake_case_						:     Optional[Any]     =		ids_tensor([self.batch_size, self.seq_length]						,				self.vocab_size		)

							snake_case_						:     Optional[Any]     =		None
							if self.use_input_mask:
								snake_case_						:     Optional[int]     =		random_attention_mask([self.batch_size, self.seq_length]		)

							snake_case_						:     Optional[int]     =		None
							if self.use_token_type_ids:
								snake_case_						:     int     =		ids_tensor([self.batch_size, self.seq_length]						,				self.type_vocab_size		)

							snake_case_						:     Tuple     =		None
							snake_case_						:     Dict     =		None
							snake_case_						:     Dict     =		None
							if self.use_labels:
								snake_case_						:     List[Any]     =		ids_tensor([self.batch_size]						,				self.type_sequence_label_size		)
								snake_case_						:     Union[str, Any]     =		ids_tensor([self.batch_size, self.seq_length]						,				self.num_labels		)
								snake_case_						:     int     =		ids_tensor([self.batch_size]						,				self.num_choices		)

							snake_case_						:     Optional[Any]     =		self.get_config()

							return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






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







							"""simple docstring"""


							return AlbertConfig(
							    vocab_size=self.vocab_size						,				hidden_size=self.hidden_size						,				num_hidden_layers=self.num_hidden_layers						,				num_attention_heads=self.num_attention_heads						,				intermediate_size=self.intermediate_size						,				hidden_act=self.hidden_act						,				hidden_dropout_prob=self.hidden_dropout_prob						,				attention_probs_dropout_prob=self.attention_probs_dropout_prob						,				max_position_embeddings=self.max_position_embeddings						,				type_vocab_size=self.type_vocab_size						,				initializer_range=self.initializer_range						,				num_hidden_groups=self.num_hidden_groups						,				)






						def UpperCAmelCase_			( self : Dict						,				_A : int						,				_A : Dict						,				_A : Optional[int]						,				_A : Dict						,				_A : Union[str, Any]						,				_A : str						,				_A : Optional[Any]		)							->      List[str]:







							"""simple docstring"""


							snake_case_						:     Dict     =		AlbertModel(config=_A		)
							model.to(_A		)
							model.eval()
							snake_case_						:     Union[str, Any]     =		model(_A						,				attention_mask=_A						,				token_type_ids=_A		)
							snake_case_						:     str     =		model(_A						,				token_type_ids=_A		)
							snake_case_						:     Optional[int]     =		model(_A		)
							self.parent.assertEqual(result.last_hidden_state.shape						,				(self.batch_size, self.seq_length, self.hidden_size)		)
							self.parent.assertEqual(result.pooler_output.shape						,				(self.batch_size, self.hidden_size)		)






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







							"""simple docstring"""


							snake_case_						:     str     =		AlbertForPreTraining(config=_A		)
							model.to(_A		)
							model.eval()
							snake_case_						:     Tuple     =		model(
							    _A						,				attention_mask=_A						,				token_type_ids=_A						,				labels=_A						,				sentence_order_label=_A						,				)
							self.parent.assertEqual(result.prediction_logits.shape						,				(self.batch_size, self.seq_length, self.vocab_size)		)
							self.parent.assertEqual(result.sop_logits.shape						,				(self.batch_size, config.num_labels)		)






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







							"""simple docstring"""


							snake_case_						:     List[Any]     =		AlbertForMaskedLM(config=_A		)
							model.to(_A		)
							model.eval()
							snake_case_						:     Dict     =		model(_A						,				attention_mask=_A						,				token_type_ids=_A						,				labels=_A		)
							self.parent.assertEqual(result.logits.shape						,				(self.batch_size, self.seq_length, self.vocab_size)		)






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







							"""simple docstring"""


							snake_case_						:     List[str]     =		AlbertForQuestionAnswering(config=_A		)
							model.to(_A		)
							model.eval()
							snake_case_						:     Any     =		model(
							    _A						,				attention_mask=_A						,				token_type_ids=_A						,				start_positions=_A						,				end_positions=_A						,				)
							self.parent.assertEqual(result.start_logits.shape						,				(self.batch_size, self.seq_length)		)
							self.parent.assertEqual(result.end_logits.shape						,				(self.batch_size, self.seq_length)		)






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







							"""simple docstring"""


							snake_case_						:     Union[str, Any]     =		self.num_labels
							snake_case_						:     Tuple     =		AlbertForSequenceClassification(_A		)
							model.to(_A		)
							model.eval()
							snake_case_						:     int     =		model(_A						,				attention_mask=_A						,				token_type_ids=_A						,				labels=_A		)
							self.parent.assertEqual(result.logits.shape						,				(self.batch_size, self.num_labels)		)






						def UpperCAmelCase_			( self : Optional[Any]						,				_A : Optional[Any]						,				_A : Optional[int]						,				_A : Optional[Any]						,				_A : List[str]						,				_A : Union[str, Any]						,				_A : int						,				_A : Dict		)							->      Union[str, Any]:







							"""simple docstring"""


							snake_case_						:     Optional[int]     =		self.num_labels
							snake_case_						:     Any     =		AlbertForTokenClassification(config=_A		)
							model.to(_A		)
							model.eval()
							snake_case_						:     Tuple     =		model(_A						,				attention_mask=_A						,				token_type_ids=_A						,				labels=_A		)
							self.parent.assertEqual(result.logits.shape						,				(self.batch_size, self.seq_length, self.num_labels)		)






						def UpperCAmelCase_			( self : Union[str, Any]						,				_A : List[str]						,				_A : Union[str, Any]						,				_A : int						,				_A : Dict						,				_A : int						,				_A : Tuple						,				_A : List[Any]		)							->      Optional[Any]:







							"""simple docstring"""


							snake_case_						:     Optional[Any]     =		self.num_choices
							snake_case_						:     Dict     =		AlbertForMultipleChoice(config=_A		)
							model.to(_A		)
							model.eval()
							snake_case_						:     Optional[int]     =		input_ids.unsqueeze(1		).expand(-1						,				self.num_choices						,				-1		).contiguous()
							snake_case_						:     Tuple     =		token_type_ids.unsqueeze(1		).expand(-1						,				self.num_choices						,				-1		).contiguous()
							snake_case_						:     Dict     =		input_mask.unsqueeze(1		).expand(-1						,				self.num_choices						,				-1		).contiguous()
							snake_case_						:     Union[str, Any]     =		model(
							    _A						,				attention_mask=_A						,				token_type_ids=_A						,				labels=_A						,				)
							self.parent.assertEqual(result.logits.shape						,				(self.batch_size, self.num_choices)		)






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







							"""simple docstring"""


							snake_case_						:     List[Any]     =		self.prepare_config_and_inputs()
							(
							    (
							    snake_case_
							)  ,(
							    snake_case_
							)  ,(
							    snake_case_
							)  ,(
							    snake_case_
							)  ,(
							    snake_case_
							)  ,(
							    snake_case_
							)  ,(
							    snake_case_
							)  ,
							)						:     int     =		config_and_inputs
							snake_case_						:     Tuple     =		{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
							return config, inputs_dict
@require_torch
class SCREAMING_SNAKE_CASE_  (   snake_case_    ,			snake_case_    ,			unittest.TestCase   ):
						__magic_name__:     str	 =    (
						    (
						        AlbertModel,
						        AlbertForPreTraining,
						        AlbertForMaskedLM,
						        AlbertForMultipleChoice,
						        AlbertForSequenceClassification,
						        AlbertForTokenClassification,
						        AlbertForQuestionAnswering,
						    )
						    if is_torch_available()
						    else ()
						)
						__magic_name__:     Union[str, Any]	 =    (
						    {
						        "feature-extraction": AlbertModel,
						        "fill-mask": AlbertForMaskedLM,
						        "question-answering": AlbertForQuestionAnswering,
						        "text-classification": AlbertForSequenceClassification,
						        "token-classification": AlbertForTokenClassification,
						        "zero-shot": AlbertForSequenceClassification,
						    }
						    if is_torch_available()
						    else {}
						)
						__magic_name__:     List[str]	 =    True






						def UpperCAmelCase_			( self : int						,				_A : Dict						,				_A : Tuple						,				_A : Any=False		)							->      List[Any]:







							"""simple docstring"""


							snake_case_						:     Dict     =		super()._prepare_for_class(_A						,				_A						,				return_labels=_A		)

							if return_labels:
								if model_class in get_values(_A		):
									snake_case_						:     Optional[Any]     =		torch.zeros(
									    (self.model_tester.batch_size, self.model_tester.seq_length)						,				dtype=torch.long						,				device=_A		)
									snake_case_						:     Optional[Any]     =		torch.zeros(
									    self.model_tester.batch_size						,				dtype=torch.long						,				device=_A		)
							return inputs_dict






						def UpperCAmelCase_			( self : Any		)							->      List[str]:







							"""simple docstring"""


							snake_case_						:     List[Any]     =		AlbertModelTester(self		)
							snake_case_						:     List[str]     =		ConfigTester(self						,				config_class=_A						,				hidden_size=37		)






						def UpperCAmelCase_			( self : Optional[int]		)							->      Dict:







							"""simple docstring"""


							self.config_tester.run_common_tests()






						def UpperCAmelCase_			( self : List[Any]		)							->      Optional[Any]:







							"""simple docstring"""


							snake_case_						:     Any     =		self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*_A		)






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







							"""simple docstring"""


							snake_case_						:     List[Any]     =		self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_pretraining(*_A		)






						def UpperCAmelCase_			( self : Dict		)							->      Any:







							"""simple docstring"""


							snake_case_						:     Any     =		self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*_A		)






						def UpperCAmelCase_			( self : Tuple		)							->      Any:







							"""simple docstring"""


							snake_case_						:     List[str]     =		self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_multiple_choice(*_A		)






						def UpperCAmelCase_			( self : str		)							->      Optional[Any]:







							"""simple docstring"""


							snake_case_						:     List[str]     =		self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*_A		)






						def UpperCAmelCase_			( self : Dict		)							->      int:







							"""simple docstring"""


							snake_case_						:     int     =		self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*_A		)






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







							"""simple docstring"""


							snake_case_						:     Tuple     =		self.model_tester.prepare_config_and_inputs()
							for type in ["absolute", "relative_key", "relative_key_query"]:
								snake_case_						:     Union[str, Any]     =		type
								self.model_tester.create_and_check_model(*_A		)






						@slow
						def UpperCAmelCase_			( self : List[Any]		)							->      Dict:







							"""simple docstring"""


							for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								snake_case_						:     Optional[Any]     =		AlbertModel.from_pretrained(_A		)
								self.assertIsNotNone(_A		)
@require_torch
class SCREAMING_SNAKE_CASE_  (   unittest.TestCase   ):






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







							"""simple docstring"""


							snake_case_						:     List[str]     =		AlbertModel.from_pretrained('albert-base-v2'		)
							snake_case_						:     Dict     =		torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]		)
							snake_case_						:     Tuple     =		torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
							with torch.no_grad():
								snake_case_						:     Tuple     =		model(_A						,				attention_mask=_A		)[0]
							snake_case_						:     Dict     =		torch.Size((1, 11, 768)		)
							self.assertEqual(output.shape						,				_A		)
							snake_case_						:     int     =		torch.tensor(
							    [[[-0.6_5_1_3, 1.5_0_3_5, -0.2_7_6_6], [-0.6_5_1_5, 1.5_0_4_6, -0.2_7_8_0], [-0.6_5_1_2, 1.5_0_4_9, -0.2_7_8_4]]]		)

							self.assertTrue(torch.allclose(output[:, 1:4, 1:4]						,				_A						,				atol=1E-4		)		)








from __future__ import annotations

import pandas as pd


def 							SCREAMING_SNAKE_CASE__  (      __a				,	__a				,	__a				):
	snake_case_						:     Optional[Any]     =		[0] * no_of_processes
	snake_case_						:     Tuple     =		[0] * no_of_processes
	# Copy the burst time into remaining_time[]
	for i in range(__a				):
		snake_case_						:     Union[str, Any]     =		burst_time[i]

	snake_case_						:     Optional[Any]     =		0
	snake_case_						:     Dict     =		0
	snake_case_						:     Any     =		9_99_99_99_99
	snake_case_						:     Tuple     =		0
	snake_case_						:     List[Any]     =		False

	# Process until all processes are completed
	while complete != no_of_processes:
		for j in range(__a				):
			if arrival_time[j] <= increment_time and remaining_time[j] > 0:
				if remaining_time[j] < minm:
					snake_case_						:     str     =		remaining_time[j]
					snake_case_						:     Any     =		j
					snake_case_						:     List[str]     =		True

		if not check:
			increment_time += 1
			continue
		remaining_time[short] -= 1

		snake_case_						:     Any     =		remaining_time[short]
		if minm == 0:
			snake_case_						:     Dict     =		9_99_99_99_99

		if remaining_time[short] == 0:
			complete += 1
			snake_case_						:     List[str]     =		False

			# Find finish time of current process
			snake_case_						:     List[str]     =		increment_time + 1

			# Calculate waiting time
			snake_case_						:     Any     =		finish_time - arrival_time[short]
			snake_case_						:     Any     =		finar - burst_time[short]

			if waiting_time[short] < 0:
				snake_case_						:     Optional[int]     =		0

        # Increment time
		increment_time += 1
	return waiting_time


def 							SCREAMING_SNAKE_CASE__  (      __a				,	__a				,	__a				):
	snake_case_						:     Tuple     =		[0] * no_of_processes
	for i in range(__a				):
		snake_case_						:     str     =		burst_time[i] + waiting_time[i]
	return turn_around_time


def 							SCREAMING_SNAKE_CASE__  (      __a				,	__a				,	__a				):
	snake_case_						:     int     =		0
	snake_case_						:     Optional[Any]     =		0
	for i in range(__a				):
		snake_case_						:     int     =		total_waiting_time + waiting_time[i]
		snake_case_						:     Optional[Any]     =		total_turn_around_time + turn_around_time[i]
	print(f"""Average waiting time = {total_waiting_time / no_of_processes:.5f}"""				)
	print('Average turn around time ='				,	total_turn_around_time / no_of_processes				)


if __name__ == "__main__":
						print("""Enter how many process you want to analyze""")
						_SCREAMING_SNAKE_CASE 		=						int(input())
						_SCREAMING_SNAKE_CASE 		=						[0] * no_of_processes
						_SCREAMING_SNAKE_CASE 		=						[0] * no_of_processes
						_SCREAMING_SNAKE_CASE 		=						list(range(1, no_of_processes + 1))

						for i in range(no_of_processes):
												print("""Enter the arrival time and burst time for process:--""" + str(i + 1))
												_SCREAMING_SNAKE_CASE		,							_SCREAMING_SNAKE_CASE 		=						map(int, input().split())

						_SCREAMING_SNAKE_CASE 		=						calculate_waitingtime(arrival_time, burst_time, no_of_processes)

						_SCREAMING_SNAKE_CASE 		=						burst_time
						_SCREAMING_SNAKE_CASE 		=						no_of_processes
						_SCREAMING_SNAKE_CASE 		=						waiting_time
						_SCREAMING_SNAKE_CASE 		=						calculate_turnaroundtime(bt, n, wt)

						calculate_average_times(waiting_time, turn_around_time, no_of_processes)

						_SCREAMING_SNAKE_CASE 		=						pd.DataFrame(
						    list(zip(processes, burst_time, arrival_time, waiting_time, turn_around_time)),
						    columns=[
						        """Process""",
						        """BurstTime""",
						        """ArrivalTime""",
						        """WaitingTime""",
						        """TurnAroundTime""",
						    ],
						)

						# Printing the dataFrame
						pd.set_option("""display.max_rows""", fcfs.shape[0] + 1)
						print(fcfs)

