import unittest

from parameterized import parameterized

from transformers import OpenLlamaConfig, is_torch_available, set_seed
from transformers.testing_utils import require_torch, torch_device

from ...generation.test_utils import GenerationTesterMixin
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 OpenLlamaForCausalLM, OpenLlamaForSequenceClassification, OpenLlamaModel







class 	__snake_case      :
 def __init__(     self						,      snake_case__						,      snake_case__=13						,      snake_case__=7						,      snake_case__=True						,      snake_case__=True						,      snake_case__=False						,      snake_case__=True						,      snake_case__=99						,      snake_case__=32						,      snake_case__=5						,      snake_case__=4						,      snake_case__=37						,      snake_case__="gelu"						,      snake_case__=0.1						,      snake_case__=0.1						,      snake_case__=512						,      snake_case__=16						,      snake_case__=2						,      snake_case__=0.02						,      snake_case__=3						,      snake_case__=4						,      snake_case__=None						,      )		->							Any:
       '''simple docstring'''





       UpperCAmelCase			:       Tuple			     =parent
       UpperCAmelCase			:       Dict			     =batch_size
       UpperCAmelCase			:       Optional[int]			     =seq_length
       UpperCAmelCase			:       Union[str, Any]			     =is_training
       UpperCAmelCase			:       Tuple			     =use_input_mask
       UpperCAmelCase			:       int			     =use_token_type_ids
       UpperCAmelCase			:       List[str]			     =use_labels
       UpperCAmelCase			:       Optional[Any]			     =vocab_size
       UpperCAmelCase			:       Union[str, Any]			     =hidden_size
       UpperCAmelCase			:       Any			     =num_hidden_layers
       UpperCAmelCase			:       List[Any]			     =num_attention_heads
       UpperCAmelCase			:       Optional[Any]			     =intermediate_size
       UpperCAmelCase			:       List[str]			     =hidden_act
       UpperCAmelCase			:       Tuple			     =hidden_dropout_prob
       UpperCAmelCase			:       str			     =attention_probs_dropout_prob
       UpperCAmelCase			:       Optional[Any]			     =max_position_embeddings
       UpperCAmelCase			:       List[str]			     =type_vocab_size
       UpperCAmelCase			:       Optional[int]			     =type_sequence_label_size
       UpperCAmelCase			:       Optional[Any]			     =initializer_range
       UpperCAmelCase			:       Union[str, Any]			     =num_labels
       UpperCAmelCase			:       str			     =num_choices
       UpperCAmelCase			:       Union[str, Any]			     =scope
 def 		UpperCAmelCase__				(     self  )		->							Optional[int]:
       '''simple docstring'''





       UpperCAmelCase			:       List[Any]			     =ids_tensor([self.batch_size, self.seq_length]						,      self.vocab_size  )

       UpperCAmelCase			:       Tuple			     =None
       if self.use_input_mask:
             UpperCAmelCase			:       int			     =random_attention_mask([self.batch_size, self.seq_length]  )

       UpperCAmelCase			:       str			     =None
       if self.use_token_type_ids:
             UpperCAmelCase			:       List[str]			     =ids_tensor([self.batch_size, self.seq_length]						,      self.type_vocab_size  )

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

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

       return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
 def 		UpperCAmelCase__				(     self  )		->							List[str]:
       '''simple docstring'''





       return OpenLlamaConfig(
           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						,      use_stable_embedding=snake_case__						,      )
 def 		UpperCAmelCase__				(     self						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__  )		->							Optional[Any]:
       '''simple docstring'''





       UpperCAmelCase			:       Optional[int]			     =OpenLlamaModel(config=snake_case__  )
       model.to(snake_case__  )
       model.eval()
       UpperCAmelCase			:       List[str]			     =model(snake_case__						,      attention_mask=snake_case__  )
       UpperCAmelCase			:       Dict			     =model(snake_case__  )
       self.parent.assertEqual(result.last_hidden_state.shape						,      (self.batch_size, self.seq_length, self.hidden_size)  )
 def 		UpperCAmelCase__				(     self						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      )		->							List[Any]:
       '''simple docstring'''





       UpperCAmelCase			:       Optional[Any]			     =True
       UpperCAmelCase			:       str			     =OpenLlamaModel(snake_case__  )
       model.to(snake_case__  )
       model.eval()
       UpperCAmelCase			:       List[str]			     =model(
           snake_case__						,      attention_mask=snake_case__						,      encoder_hidden_states=snake_case__						,      encoder_attention_mask=snake_case__						,      )
       UpperCAmelCase			:       List[Any]			     =model(
           snake_case__						,      attention_mask=snake_case__						,      encoder_hidden_states=snake_case__						,      )
       UpperCAmelCase			:       Tuple			     =model(snake_case__						,      attention_mask=snake_case__  )
       self.parent.assertEqual(result.last_hidden_state.shape						,      (self.batch_size, self.seq_length, self.hidden_size)  )
 def 		UpperCAmelCase__				(     self						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      )		->							Optional[int]:
       '''simple docstring'''





       UpperCAmelCase			:       Dict			     =OpenLlamaForCausalLM(config=snake_case__  )
       model.to(snake_case__  )
       model.eval()
       UpperCAmelCase			:       int			     =model(snake_case__						,      attention_mask=snake_case__						,      labels=snake_case__  )
       self.parent.assertEqual(result.logits.shape						,      (self.batch_size, self.seq_length, self.vocab_size)  )
 def 		UpperCAmelCase__				(     self						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      snake_case__						,      )		->							Any:
       '''simple docstring'''





       UpperCAmelCase			:       List[Any]			     =True
       UpperCAmelCase			:       Optional[int]			     =True
       UpperCAmelCase			:       Optional[int]			     =OpenLlamaForCausalLM(config=snake_case__  )
       model.to(snake_case__  )
       model.eval()

       # first forward pass
       UpperCAmelCase			:       List[str]			     =model(
           snake_case__						,      attention_mask=snake_case__						,      encoder_hidden_states=snake_case__						,      encoder_attention_mask=snake_case__						,      use_cache=snake_case__						,      )
       UpperCAmelCase			:       str			     =outputs.past_key_values

       # create hypothetical multiple next token and extent to next_input_ids
       UpperCAmelCase			:       Optional[int]			     =ids_tensor((self.batch_size, 3)						,      config.vocab_size  )
       UpperCAmelCase			:       str			     =ids_tensor((self.batch_size, 3)						,      vocab_size=2  )

       # append to next input_ids and
       UpperCAmelCase			:       str			     =torch.cat([input_ids, next_tokens]						,      dim=-1  )
       UpperCAmelCase			:       List[str]			     =torch.cat([input_mask, next_mask]						,      dim=-1  )

       UpperCAmelCase			:       List[Any]			     =model(
           snake_case__						,      attention_mask=snake_case__						,      encoder_hidden_states=snake_case__						,      encoder_attention_mask=snake_case__						,      output_hidden_states=snake_case__						,      )['''hidden_states'''][0]
       UpperCAmelCase			:       Tuple			     =model(
           snake_case__						,      attention_mask=snake_case__						,      encoder_hidden_states=snake_case__						,      encoder_attention_mask=snake_case__						,      past_key_values=snake_case__						,      output_hidden_states=snake_case__						,      )['''hidden_states'''][0]

       # select random slice
       UpperCAmelCase			:       Optional[Any]			     =ids_tensor((1,)						,      output_from_past.shape[-1]  ).item()
       UpperCAmelCase			:       List[str]			     =output_from_no_past[:, -3:, random_slice_idx].detach()
       UpperCAmelCase			:       Optional[int]			     =output_from_past[:, :, random_slice_idx].detach()

       self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]  )

       # test that outputs are equal for slice
       self.parent.assertTrue(torch.allclose(snake_case__						,      snake_case__						,      atol=1e-3  )  )






 def 		UpperCAmelCase__				(     self  )		->							Tuple:
       '''simple docstring'''





       UpperCAmelCase			:       List[Any]			     =self.prepare_config_and_inputs()
       (
           (
           UpperCAmelCase       
       )     ,  (
           UpperCAmelCase       
       )     ,  (
           UpperCAmelCase       
       )     ,  (
           UpperCAmelCase       
       )     ,  (
           UpperCAmelCase       
       )     ,  (
           UpperCAmelCase       
       )     ,  (
           UpperCAmelCase       
       )     ,         
       )			:       Tuple			     =config_and_inputs
       UpperCAmelCase			:       Any			     ={'''input_ids''': input_ids, '''attention_mask''': input_mask}
       return config, inputs_dict







@require_torch
class 	__snake_case      (   lowerCamelCase__    ,      lowerCamelCase__    ,      lowerCamelCase__    ,      unittest.TestCase      ):
 __lowerCamelCase			:      Any           =					(
     (OpenLlamaModel, OpenLlamaForCausalLM, OpenLlamaForSequenceClassification) if is_torch_available() else ()
 )
 __lowerCamelCase			:      Optional[Any]           =					(OpenLlamaForCausalLM,) if is_torch_available() else ()
 __lowerCamelCase			:      Union[str, Any]           =					(
     {
         """feature-extraction""": OpenLlamaModel,
         """text-classification""": OpenLlamaForSequenceClassification,
         """text-generation""": OpenLlamaForCausalLM,
         """zero-shot""": OpenLlamaForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 __lowerCamelCase			:      int           =					False
 __lowerCamelCase			:      Dict           =					False
 def 		UpperCAmelCase__				(     self  )		->							str:
       '''simple docstring'''





       UpperCAmelCase			:       Union[str, Any]			     =OpenLlamaModelTester(self  )
       UpperCAmelCase			:       List[Any]			     =ConfigTester(self						,      config_class=snake_case__						,      hidden_size=37  )
 def 		UpperCAmelCase__				(     self  )		->							Any:
       '''simple docstring'''





       self.config_tester.run_common_tests()
 def 		UpperCAmelCase__				(     self  )		->							List[str]:
       '''simple docstring'''





       UpperCAmelCase			:       List[str]			     =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*snake_case__  )
 def 		UpperCAmelCase__				(     self  )		->							Union[str, Any]:
       '''simple docstring'''





       UpperCAmelCase			:       str			     =self.model_tester.prepare_config_and_inputs()
       for type in ["absolute", "relative_key", "relative_key_query"]:
             UpperCAmelCase			:       Dict			     =type
             self.model_tester.create_and_check_model(*snake_case__  )
 def 		UpperCAmelCase__				(     self  )		->							List[str]:
       '''simple docstring'''





       UpperCAmelCase     ,  UpperCAmelCase			:       Optional[Any]			     =self.model_tester.prepare_config_and_inputs_for_common()
       UpperCAmelCase			:       Optional[int]			     =3
       UpperCAmelCase			:       Any			     =input_dict['''input_ids''']
       UpperCAmelCase			:       Any			     =input_ids.ne(1  ).to(snake_case__  )
       UpperCAmelCase			:       str			     =ids_tensor([self.model_tester.batch_size]						,      self.model_tester.type_sequence_label_size  )
       UpperCAmelCase			:       Union[str, Any]			     =OpenLlamaForSequenceClassification(snake_case__  )
       model.to(snake_case__  )
       model.eval()
       UpperCAmelCase			:       Union[str, Any]			     =model(snake_case__						,      attention_mask=snake_case__						,      labels=snake_case__  )
       self.assertEqual(result.logits.shape						,      (self.model_tester.batch_size, self.model_tester.num_labels)  )
 def 		UpperCAmelCase__				(     self  )		->							List[Any]:
       '''simple docstring'''





       UpperCAmelCase     ,  UpperCAmelCase			:       Optional[int]			     =self.model_tester.prepare_config_and_inputs_for_common()
       UpperCAmelCase			:       Union[str, Any]			     =3
       UpperCAmelCase			:       Union[str, Any]			     ='''single_label_classification'''
       UpperCAmelCase			:       int			     =input_dict['''input_ids''']
       UpperCAmelCase			:       List[str]			     =input_ids.ne(1  ).to(snake_case__  )
       UpperCAmelCase			:       Dict			     =ids_tensor([self.model_tester.batch_size]						,      self.model_tester.type_sequence_label_size  )
       UpperCAmelCase			:       Tuple			     =OpenLlamaForSequenceClassification(snake_case__  )
       model.to(snake_case__  )
       model.eval()
       UpperCAmelCase			:       Dict			     =model(snake_case__						,      attention_mask=snake_case__						,      labels=snake_case__  )
       self.assertEqual(result.logits.shape						,      (self.model_tester.batch_size, self.model_tester.num_labels)  )
 def 		UpperCAmelCase__				(     self  )		->							Dict:
       '''simple docstring'''





       UpperCAmelCase     ,  UpperCAmelCase			:       List[Any]			     =self.model_tester.prepare_config_and_inputs_for_common()
       UpperCAmelCase			:       int			     =3
       UpperCAmelCase			:       Optional[int]			     ='''multi_label_classification'''
       UpperCAmelCase			:       Union[str, Any]			     =input_dict['''input_ids''']
       UpperCAmelCase			:       Union[str, Any]			     =input_ids.ne(1  ).to(snake_case__  )
       UpperCAmelCase			:       str			     =ids_tensor(
           [self.model_tester.batch_size, config.num_labels]						,      self.model_tester.type_sequence_label_size  ).to(torch.float  )
       UpperCAmelCase			:       Dict			     =OpenLlamaForSequenceClassification(snake_case__  )
       model.to(snake_case__  )
       model.eval()
       UpperCAmelCase			:       Any			     =model(snake_case__						,      attention_mask=snake_case__						,      labels=snake_case__  )
       self.assertEqual(result.logits.shape						,      (self.model_tester.batch_size, self.model_tester.num_labels)  )
 @unittest.skip('''Open-Llama buffers include complex numbers, which breaks this test'''  )
 def 		UpperCAmelCase__				(     self  )		->							Dict:
       '''simple docstring'''





       pass






 @parameterized.expand([('''linear''',), ('''dynamic''',)]  )
 def 		UpperCAmelCase__				(     self						,      snake_case__  )		->							List[str]:
       '''simple docstring'''





       UpperCAmelCase     ,  UpperCAmelCase			:       Optional[Any]			     =self.model_tester.prepare_config_and_inputs_for_common()
       UpperCAmelCase			:       List[str]			     =ids_tensor([1, 10]						,      config.vocab_size  )
       UpperCAmelCase			:       Tuple			     =ids_tensor([1, int(config.max_position_embeddings * 1.5  )]						,      config.vocab_size  )

       set_seed(42  )  # Fixed seed at init time so the two models get the same random weights
       UpperCAmelCase			:       Tuple			     =OpenLlamaModel(snake_case__  )
       original_model.to(snake_case__  )
       original_model.eval()
       UpperCAmelCase			:       str			     =original_model(snake_case__  ).last_hidden_state
       UpperCAmelCase			:       str			     =original_model(snake_case__  ).last_hidden_state

       set_seed(42  )  # Fixed seed at init time so the two models get the same random weights
       UpperCAmelCase			:       Optional[Any]			     ={'''type''': scaling_type, '''factor''': 10.0}
       UpperCAmelCase			:       Optional[Any]			     =OpenLlamaModel(snake_case__  )
       scaled_model.to(snake_case__  )
       scaled_model.eval()
       UpperCAmelCase			:       Optional[Any]			     =scaled_model(snake_case__  ).last_hidden_state
       UpperCAmelCase			:       Optional[int]			     =scaled_model(snake_case__  ).last_hidden_state

       # Dynamic scaling does not change the RoPE embeddings until it receives an input longer than the original
       # maximum sequence length, so the outputs for the short input should match.
       if scaling_type == "dynamic":
             self.assertTrue(torch.allclose(snake_case__						,      snake_case__						,      atol=1e-5  )  )
       else:
             self.assertFalse(torch.allclose(snake_case__						,      snake_case__						,      atol=1e-5  )  )

       # The output should be different for long inputs
       self.assertFalse(torch.allclose(snake_case__						,      snake_case__						,      atol=1e-5  )  )



import argparse
import math
import traceback

import dateutil.parser as date_parser
import requests
def      a      (			A__	:   Dict     )    ->      str:





      """simple docstring"""



      _lowercase	       ={}

      _lowercase	       =job['started_at']
      _lowercase	       =job['completed_at']

      _lowercase	       =date_parser.parse(A__     )
      _lowercase	       =date_parser.parse(A__     )

      _lowercase	       =round((end_datetime - start_datetime).total_seconds() / 60.0     )

      _lowercase	       =start
      _lowercase	       =end
      _lowercase	       =duration_in_min

      return job_info
def      a      (			A__	:   Dict      ,   A__	:   str=None     )    ->      Tuple:





      """simple docstring"""



      _lowercase	       =None
      if token is not None:
            _lowercase	       ={'Accept': 'application/vnd.github+json', 'Authorization': F'''Bearer {token}'''}

      _lowercase	       =F'''https://api.github.com/repos/huggingface/transformers/actions/runs/{workflow_run_id}/jobs?per_page=100'''
      _lowercase	       =requests.get(A__      ,   headers=A__     ).json()
      _lowercase	       ={}

      try:
            job_time.update({job['name']: extract_time_from_single_job(A__     ) for job in result['jobs']}     )
            _lowercase	       =math.ceil((result['total_count'] - 100) / 100     )

            for i in range(A__     ):
                  _lowercase	       =requests.get(url + F'''&page={i + 2}'''      ,   headers=A__     ).json()
                  job_time.update({job['name']: extract_time_from_single_job(A__     ) for job in result['jobs']}     )

            return job_time
      except Exception:
            print(F'''Unknown error, could not fetch links:\n{traceback.format_exc()}'''     )

      return {}


if __name__ == "__main__":
  lowercase_									=   argparse.ArgumentParser()
  # Required parameters
  parser.add_argument('--workflow_run_id', type=str, required=True, help='A GitHub Actions workflow run id.')
  lowercase_									=   parser.parse_args()

  lowercase_									=   get_job_time(args.workflow_run_id)
  lowercase_									=   dict(sorted(job_time.items(), key=lambda item: item[1]["duration"], reverse=True))

  for k, v in job_time.items():
    print(f"{k}: {v['duration']}")


