
import unittest

from transformers import YosoConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
      import torch

      from transformers import (
          YosoForMaskedLM,
          YosoForMultipleChoice,
          YosoForQuestionAnswering,
          YosoForSequenceClassification,
          YosoForTokenClassification,
          YosoModel,
      )
      from transformers.models.yoso.modeling_yoso import YOSO_PRETRAINED_MODEL_ARCHIVE_LIST






class     a_       :



       """simple docstring"""






       def __init__(		self				,       _lowerCamelCase				,       _lowerCamelCase=13				,       _lowerCamelCase=7				,       _lowerCamelCase=True				,       _lowerCamelCase=True				,       _lowerCamelCase=True				,       _lowerCamelCase=True				,       _lowerCamelCase=99				,       _lowerCamelCase=32				,       _lowerCamelCase=5				,       _lowerCamelCase=4				,       _lowerCamelCase=37				,       _lowerCamelCase="gelu"				,       _lowerCamelCase=0.1				,       _lowerCamelCase=0.1				,       _lowerCamelCase=512				,       _lowerCamelCase=16				,       _lowerCamelCase=2				,       _lowerCamelCase=0.0_2				,       _lowerCamelCase=3				,       _lowerCamelCase=4				,       _lowerCamelCase=None				,       )					->Any:
           SCREAMING_SNAKE_CASE				:				Tuple				      = parent
           SCREAMING_SNAKE_CASE				:				Optional[int]				      = batch_size
           SCREAMING_SNAKE_CASE				:				Optional[int]				      = seq_length
           SCREAMING_SNAKE_CASE				:				Dict				      = is_training
           SCREAMING_SNAKE_CASE				:				int				      = use_input_mask
           SCREAMING_SNAKE_CASE				:				str				      = use_token_type_ids
           SCREAMING_SNAKE_CASE				:				Optional[Any]				      = use_labels
           SCREAMING_SNAKE_CASE				:				int				      = vocab_size
           SCREAMING_SNAKE_CASE				:				Optional[Any]				      = hidden_size
           SCREAMING_SNAKE_CASE				:				List[Any]				      = num_hidden_layers
           SCREAMING_SNAKE_CASE				:				int				      = num_attention_heads
           SCREAMING_SNAKE_CASE				:				str				      = intermediate_size
           SCREAMING_SNAKE_CASE				:				Optional[Any]				      = hidden_act
           SCREAMING_SNAKE_CASE				:				List[str]				      = hidden_dropout_prob
           SCREAMING_SNAKE_CASE				:				int				      = attention_probs_dropout_prob
           SCREAMING_SNAKE_CASE				:				str				      = max_position_embeddings
           SCREAMING_SNAKE_CASE				:				str				      = type_vocab_size
           SCREAMING_SNAKE_CASE				:				int				      = type_sequence_label_size
           SCREAMING_SNAKE_CASE				:				List[str]				      = initializer_range
           SCREAMING_SNAKE_CASE				:				Dict				      = num_labels
           SCREAMING_SNAKE_CASE				:				Tuple				      = num_choices
           SCREAMING_SNAKE_CASE				:				Optional[Any]				      = scope






       def 	__lowerCAmelCase     (		self   )					->str:
           SCREAMING_SNAKE_CASE				:				Tuple				      = ids_tensor([self.batch_size, self.seq_length]				,       self.vocab_size   )

           SCREAMING_SNAKE_CASE				:				List[str]				      = None
           if self.use_input_mask:
               SCREAMING_SNAKE_CASE				:				List[Any]				      = random_attention_mask([self.batch_size, self.seq_length]   )

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

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

           SCREAMING_SNAKE_CASE				:				Optional[int]				      = self.get_config()

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






       def 	__lowerCAmelCase     (		self   )					->List[str]:
           return YosoConfig(
               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				,       is_decoder=snake_case_				,       initializer_range=self.initializer_range				,       )






       def 	__lowerCAmelCase     (		self   )					->Union[str, Any]:
           SCREAMING_SNAKE_CASE				:				str				      = self.get_config()
           SCREAMING_SNAKE_CASE				:				Optional[int]				      = 300
           return config






       def 	__lowerCAmelCase     (		self   )					->Dict:
           (
               SCREAMING_SNAKE_CASE       
           )				:				List[Any]				      = self.prepare_config_and_inputs()

           SCREAMING_SNAKE_CASE				:				Optional[Any]				      = True
           SCREAMING_SNAKE_CASE				:				Optional[int]				      = floats_tensor([self.batch_size, self.seq_length, self.hidden_size]   )
           SCREAMING_SNAKE_CASE				:				str				      = ids_tensor([self.batch_size, self.seq_length]				,       vocab_size=2   )

           return (
               config,
               input_ids,
               token_type_ids,
               input_mask,
               sequence_labels,
               token_labels,
               choice_labels,
               encoder_hidden_states,
               encoder_attention_mask,
           )






       def 	__lowerCAmelCase     (		self				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase   )					->Optional[int]:
           SCREAMING_SNAKE_CASE				:				int				      = YosoModel(config=snake_case_   )
           model.to(snake_case_   )
           model.eval()
           SCREAMING_SNAKE_CASE				:				Dict				      = model(snake_case_				,       attention_mask=snake_case_				,       token_type_ids=snake_case_   )
           SCREAMING_SNAKE_CASE				:				List[Any]				      = model(snake_case_				,       token_type_ids=snake_case_   )
           SCREAMING_SNAKE_CASE				:				int				      = model(snake_case_   )
           self.parent.assertEqual(result.last_hidden_state.shape				,       (self.batch_size, self.seq_length, self.hidden_size)   )






       def 	__lowerCAmelCase     (		self				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       )					->List[Any]:
           SCREAMING_SNAKE_CASE				:				Any				      = True
           SCREAMING_SNAKE_CASE				:				Any				      = YosoModel(snake_case_   )
           model.to(snake_case_   )
           model.eval()
           SCREAMING_SNAKE_CASE				:				str				      = model(
               snake_case_				,       attention_mask=snake_case_				,       token_type_ids=snake_case_				,       encoder_hidden_states=snake_case_				,       encoder_attention_mask=snake_case_				,       )
           SCREAMING_SNAKE_CASE				:				Any				      = model(
               snake_case_				,       attention_mask=snake_case_				,       token_type_ids=snake_case_				,       encoder_hidden_states=snake_case_				,       )
           SCREAMING_SNAKE_CASE				:				Tuple				      = model(snake_case_				,       attention_mask=snake_case_				,       token_type_ids=snake_case_   )
           self.parent.assertEqual(result.last_hidden_state.shape				,       (self.batch_size, self.seq_length, self.hidden_size)   )






       def 	__lowerCAmelCase     (		self				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase   )					->Union[str, Any]:
           SCREAMING_SNAKE_CASE				:				Any				      = YosoForMaskedLM(config=snake_case_   )
           model.to(snake_case_   )
           model.eval()
           SCREAMING_SNAKE_CASE				:				Any				      = model(snake_case_				,       attention_mask=snake_case_				,       token_type_ids=snake_case_				,       labels=snake_case_   )
           self.parent.assertEqual(result.logits.shape				,       (self.batch_size, self.seq_length, self.vocab_size)   )






       def 	__lowerCAmelCase     (		self				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase   )					->Union[str, Any]:
           SCREAMING_SNAKE_CASE				:				Any				      = YosoForQuestionAnswering(config=snake_case_   )
           model.to(snake_case_   )
           model.eval()
           SCREAMING_SNAKE_CASE				:				Union[str, Any]				      = model(
               snake_case_				,       attention_mask=snake_case_				,       token_type_ids=snake_case_				,       start_positions=snake_case_				,       end_positions=snake_case_				,       )
           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 	__lowerCAmelCase     (		self				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase   )					->Optional[Any]:
           SCREAMING_SNAKE_CASE				:				Optional[int]				      = self.num_labels
           SCREAMING_SNAKE_CASE				:				List[Any]				      = YosoForSequenceClassification(snake_case_   )
           model.to(snake_case_   )
           model.eval()
           SCREAMING_SNAKE_CASE				:				Any				      = model(snake_case_				,       attention_mask=snake_case_				,       token_type_ids=snake_case_				,       labels=snake_case_   )
           self.parent.assertEqual(result.logits.shape				,       (self.batch_size, self.num_labels)   )






       def 	__lowerCAmelCase     (		self				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase   )					->List[str]:
           SCREAMING_SNAKE_CASE				:				Tuple				      = self.num_labels
           SCREAMING_SNAKE_CASE				:				str				      = YosoForTokenClassification(config=snake_case_   )
           model.to(snake_case_   )
           model.eval()
           SCREAMING_SNAKE_CASE				:				Optional[int]				      = model(snake_case_				,       attention_mask=snake_case_				,       token_type_ids=snake_case_				,       labels=snake_case_   )
           self.parent.assertEqual(result.logits.shape				,       (self.batch_size, self.seq_length, self.num_labels)   )






       def 	__lowerCAmelCase     (		self				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase				,       _lowerCamelCase   )					->Union[str, Any]:
           SCREAMING_SNAKE_CASE				:				str				      = self.num_choices
           SCREAMING_SNAKE_CASE				:				List[str]				      = YosoForMultipleChoice(config=snake_case_   )
           model.to(snake_case_   )
           model.eval()
           SCREAMING_SNAKE_CASE				:				Union[str, Any]				      = input_ids.unsqueeze(1   ).expand(-1				,       self.num_choices				,       -1   ).contiguous()
           SCREAMING_SNAKE_CASE				:				Optional[Any]				      = token_type_ids.unsqueeze(1   ).expand(-1				,       self.num_choices				,       -1   ).contiguous()
           SCREAMING_SNAKE_CASE				:				Any				      = input_mask.unsqueeze(1   ).expand(-1				,       self.num_choices				,       -1   ).contiguous()
           SCREAMING_SNAKE_CASE				:				Any				      = model(
               snake_case_				,       attention_mask=snake_case_				,       token_type_ids=snake_case_				,       labels=snake_case_				,       )
           self.parent.assertEqual(result.logits.shape				,       (self.batch_size, self.num_choices)   )






       def 	__lowerCAmelCase     (		self   )					->int:
           SCREAMING_SNAKE_CASE				:				Optional[Any]				      = self.prepare_config_and_inputs()
           (
               SCREAMING_SNAKE_CASE       
           )				:				Optional[int]				      = config_and_inputs
           SCREAMING_SNAKE_CASE				:				Dict				      = {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
           return config, inputs_dict






@require_torch
class     a_       (			_snake_case				,    _snake_case				,    unittest.TestCase							):



       """simple docstring"""
       __SCREAMING_SNAKE_CASE       :					Any						=  (
           (
               YosoModel,
               YosoForMaskedLM,
               YosoForMultipleChoice,
               YosoForQuestionAnswering,
               YosoForSequenceClassification,
               YosoForTokenClassification,
           )
           if is_torch_available()
           else ()
       )
       __SCREAMING_SNAKE_CASE       :					List[str]						=  False
       __SCREAMING_SNAKE_CASE       :					Any						=  False
       __SCREAMING_SNAKE_CASE       :					List[str]						=  False

       __SCREAMING_SNAKE_CASE       :					Optional[Any]						=  ()
       __SCREAMING_SNAKE_CASE       :					Dict						=  (
           {
               """feature-extraction""": YosoModel,
               """fill-mask""": YosoForMaskedLM,
               """question-answering""": YosoForQuestionAnswering,
               """text-classification""": YosoForSequenceClassification,
               """token-classification""": YosoForTokenClassification,
               """zero-shot""": YosoForSequenceClassification,
           }
           if is_torch_available()
           else {}
       )






       def 	__lowerCAmelCase     (		self   )					->Optional[Any]:
           SCREAMING_SNAKE_CASE				:				Optional[int]				      = YosoModelTester(self   )
           SCREAMING_SNAKE_CASE				:				List[Any]				      = ConfigTester(self				,       config_class=snake_case_				,       hidden_size=37   )






       def 	__lowerCAmelCase     (		self   )					->List[str]:
           self.config_tester.run_common_tests()






       def 	__lowerCAmelCase     (		self   )					->List[str]:
           SCREAMING_SNAKE_CASE				:				int				      = self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*snake_case_   )






       def 	__lowerCAmelCase     (		self   )					->Optional[Any]:
           SCREAMING_SNAKE_CASE				:				Tuple				      = self.model_tester.prepare_config_and_inputs()
           for type in ["absolute", "relative_key", "relative_key_query"]:
               SCREAMING_SNAKE_CASE				:				Dict				      = type
               self.model_tester.create_and_check_model(*snake_case_   )






       def 	__lowerCAmelCase     (		self   )					->int:
           SCREAMING_SNAKE_CASE				:				List[Any]				      = self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*snake_case_   )






       def 	__lowerCAmelCase     (		self   )					->Tuple:
           SCREAMING_SNAKE_CASE				:				str				      = self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_multiple_choice(*snake_case_   )






       def 	__lowerCAmelCase     (		self   )					->int:
           SCREAMING_SNAKE_CASE				:				Dict				      = self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*snake_case_   )






       def 	__lowerCAmelCase     (		self   )					->Optional[int]:
           SCREAMING_SNAKE_CASE				:				List[Any]				      = self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*snake_case_   )






       def 	__lowerCAmelCase     (		self   )					->Optional[int]:
           SCREAMING_SNAKE_CASE				:				Optional[Any]				      = self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*snake_case_   )






       @slow
       def 	__lowerCAmelCase     (		self   )					->Dict:
           for model_name in YOSO_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               SCREAMING_SNAKE_CASE				:				Optional[int]				      = YosoModel.from_pretrained(snake_case_   )
               self.assertIsNotNone(snake_case_   )






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






@require_torch
class     a_       (			unittest.TestCase							):



       """simple docstring"""






       @slow
       def 	__lowerCAmelCase     (		self   )					->Union[str, Any]:
           SCREAMING_SNAKE_CASE				:				List[str]				      = YosoModel.from_pretrained('''uw-madison/yoso-4096'''   )
           SCREAMING_SNAKE_CASE				:				Tuple				      = torch.tensor([[0, 1, 2, 3, 4, 5]]   )

           with torch.no_grad():
               SCREAMING_SNAKE_CASE				:				str				      = model(snake_case_   )[0]

           SCREAMING_SNAKE_CASE				:				Any				      = torch.Size((1, 6, 768)   )
           self.assertEqual(output.shape				,       snake_case_   )

           SCREAMING_SNAKE_CASE				:				str				      = torch.tensor(
               [[[-0.0_6_1_1, 0.1_2_4_2, 0.0_8_4_0], [0.0_2_8_0, -0.0_0_4_8, 0.1_1_2_5], [0.0_1_0_6, 0.0_2_2_6, 0.0_7_5_1]]]   )

           self.assertTrue(torch.allclose(output[:, :3, :3]				,       snake_case_				,       atol=1e-4   )   )






       @slow
       def 	__lowerCAmelCase     (		self   )					->Dict:
           SCREAMING_SNAKE_CASE				:				Optional[int]				      = YosoForMaskedLM.from_pretrained('''uw-madison/yoso-4096'''   )
           SCREAMING_SNAKE_CASE				:				Tuple				      = torch.tensor([[0, 1, 2, 3, 4, 5]]   )

           with torch.no_grad():
               SCREAMING_SNAKE_CASE				:				Tuple				      = model(snake_case_   )[0]

           SCREAMING_SNAKE_CASE				:				Union[str, Any]				      = 5_0265

           SCREAMING_SNAKE_CASE				:				Optional[Any]				      = torch.Size((1, 6, vocab_size)   )
           self.assertEqual(output.shape				,       snake_case_   )

           SCREAMING_SNAKE_CASE				:				List[Any]				      = torch.tensor(
               [[[-2.1_3_1_3, -3.7_2_8_5, -2.2_4_0_7], [-2.7_0_4_7, -3.3_3_1_4, -2.6_4_0_8], [0.0_6_2_9, -2.5_1_6_6, -0.3_3_5_6]]]   )

           self.assertTrue(torch.allclose(output[:, :3, :3]				,       snake_case_				,       atol=1e-4   )   )






       @slow
       def 	__lowerCAmelCase     (		self   )					->Dict:
           SCREAMING_SNAKE_CASE				:				Dict				      = YosoForMaskedLM.from_pretrained('''uw-madison/yoso-4096'''   )
           SCREAMING_SNAKE_CASE				:				str				      = torch.arange(4096   ).unsqueeze(0   )

           with torch.no_grad():
               SCREAMING_SNAKE_CASE				:				Any				      = model(snake_case_   )[0]

           SCREAMING_SNAKE_CASE				:				Optional[Any]				      = 5_0265

           SCREAMING_SNAKE_CASE				:				Tuple				      = torch.Size((1, 4096, vocab_size)   )
           self.assertEqual(output.shape				,       snake_case_   )

           SCREAMING_SNAKE_CASE				:				Optional[int]				      = torch.tensor(
               [[[-2.3_9_1_4, -4.3_7_4_2, -5.0_9_5_6], [-4.0_9_8_8, -4.2_3_8_4, -7.0_4_0_6], [-3.1_4_2_7, -3.7_1_9_2, -6.6_8_0_0]]]   )

           self.assertTrue(torch.allclose(output[:, :3, :3]				,       snake_case_				,       atol=1e-4   )   )


"""simple docstring"""
from __future__ import annotations

from statistics import mean
def 					a__ ( a :					list[int]		):

  """simple docstring"""







  _snake_case  :    List[str]            = 2
  _snake_case  :    Union[str, Any]            = list(a		)
  _snake_case  :    Any            = [0] * len(a		)
  _snake_case  :    Any            = 0
  while True:
    _snake_case  :    str            = True
    for i, burst_time in enumerate(a		):
      if rem_burst_times[i] > 0:
        _snake_case  :    str            = False
        if rem_burst_times[i] > quantum:
          t += quantum
          rem_burst_times[i] -= quantum
        else:
          t += rem_burst_times[i]
          _snake_case  :    int            = t - burst_time
          _snake_case  :    Dict            = 0
    if done is True:
      return waiting_times
def 					a__ ( a :					list[int]							,  a :					list[int]		):

  """simple docstring"""







  return [burst + waiting for burst, waiting in zip(a							,  a		)]


if __name__ == "__main__":
    _a   :      Dict       =				[3, 5, 7]
    _a   :      Dict       =				calculate_waiting_times(burst_times)
    _a   :      Tuple       =				calculate_turn_around_times(burst_times, waiting_times)
    print("""Process ID \tBurst Time \tWaiting Time \tTurnaround Time""")
    for i, burst_time in enumerate(burst_times):
        print(
            f'  {i + 1}\t\t  {burst_time}\t\t  {waiting_times[i]}\t\t  '
            f'{turn_around_times[i]}'
        )
    print(f'\nAverage waiting time = {mean(waiting_times):.5f}')
    print(f'Average turn around time = {mean(turn_around_times):.5f}')

