





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 					__lowerCAmelCase       :






			def __init__(self					,							__magic_name__					,							__magic_name__=13					,							__magic_name__=7					,							__magic_name__=True					,							__magic_name__=True					,							__magic_name__=False					,							__magic_name__=True					,							__magic_name__=99					,							__magic_name__=32					,							__magic_name__=5					,							__magic_name__=4					,							__magic_name__=37					,							__magic_name__="gelu"					,							__magic_name__=0.1					,							__magic_name__=0.1					,							__magic_name__=512					,							__magic_name__=16					,							__magic_name__=2					,							__magic_name__=0.02					,							__magic_name__=3					,							__magic_name__=4					,							__magic_name__=None					,							)     ->   str:


							'''simple docstring'''



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






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


							'''simple docstring'''



							snake_case_						:    List[str]				=  ids_tensor([self.batch_size, self.seq_length]					,							self.vocab_size    )

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

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

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

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

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






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


							'''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=__magic_name__					,							initializer_range=self.initializer_range					,							use_stable_embedding=__magic_name__					,							)






			def 			lowerCamelCase  (self					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__    )     ->   Any:


							'''simple docstring'''



							snake_case_						:    Any				=  OpenLlamaModel(config=__magic_name__    )
							model.to(__magic_name__    )
							model.eval()
							snake_case_						:    List[str]				=  model(__magic_name__					,							attention_mask=__magic_name__    )
							snake_case_						:    Any				=  model(__magic_name__    )
							self.parent.assertEqual(result.last_hidden_state.shape					,							(self.batch_size, self.seq_length, self.hidden_size)    )






			def 			lowerCamelCase  (self					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							)     ->   int:


							'''simple docstring'''



							snake_case_						:    Any				=  True
							snake_case_						:    Optional[int]				=  OpenLlamaModel(__magic_name__    )
							model.to(__magic_name__    )
							model.eval()
							snake_case_						:    Optional[int]				=  model(
							    __magic_name__					,							attention_mask=__magic_name__					,							encoder_hidden_states=__magic_name__					,							encoder_attention_mask=__magic_name__					,							)
							snake_case_						:    Optional[Any]				=  model(
							    __magic_name__					,							attention_mask=__magic_name__					,							encoder_hidden_states=__magic_name__					,							)
							snake_case_						:    Tuple				=  model(__magic_name__					,							attention_mask=__magic_name__    )
							self.parent.assertEqual(result.last_hidden_state.shape					,							(self.batch_size, self.seq_length, self.hidden_size)    )






			def 			lowerCamelCase  (self					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							)     ->   str:


							'''simple docstring'''



							snake_case_						:    List[Any]				=  OpenLlamaForCausalLM(config=__magic_name__    )
							model.to(__magic_name__    )
							model.eval()
							snake_case_						:    int				=  model(__magic_name__					,							attention_mask=__magic_name__					,							labels=__magic_name__    )
							self.parent.assertEqual(result.logits.shape					,							(self.batch_size, self.seq_length, self.vocab_size)    )






			def 			lowerCamelCase  (self					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							__magic_name__					,							)     ->   Any:


							'''simple docstring'''



							snake_case_						:    int				=  True
							snake_case_						:    str				=  True
							snake_case_						:    Tuple				=  OpenLlamaForCausalLM(config=__magic_name__    )
							model.to(__magic_name__    )
							model.eval()

							# first forward pass
							snake_case_						:    Tuple				=  model(
							    __magic_name__					,							attention_mask=__magic_name__					,							encoder_hidden_states=__magic_name__					,							encoder_attention_mask=__magic_name__					,							use_cache=__magic_name__					,							)
							snake_case_						:    Dict				=  outputs.past_key_values

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

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

							snake_case_						:    Tuple				=  model(
							    __magic_name__					,							attention_mask=__magic_name__					,							encoder_hidden_states=__magic_name__					,							encoder_attention_mask=__magic_name__					,							output_hidden_states=__magic_name__					,							)['''hidden_states'''][0]
							snake_case_						:    Any				=  model(
							    __magic_name__					,							attention_mask=__magic_name__					,							encoder_hidden_states=__magic_name__					,							encoder_attention_mask=__magic_name__					,							past_key_values=__magic_name__					,							output_hidden_states=__magic_name__					,							)['''hidden_states'''][0]

							# select random slice
							snake_case_						:    Optional[Any]				=  ids_tensor((1,)					,							output_from_past.shape[-1]    ).item()
							snake_case_						:    int				=  output_from_no_past[:, -3:, random_slice_idx].detach()
							snake_case_						:    Any				=  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(__magic_name__					,							__magic_name__					,							atol=1e-3    )    )






			def 			lowerCamelCase  (self    )     ->   Optional[int]:


							'''simple docstring'''



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




@require_torch
class 					__lowerCAmelCase       (			_a,     _a,     _a,     unittest.TestCase     ):
			lowerCamelCase_     :     str       			=      (
			    (OpenLlamaModel, OpenLlamaForCausalLM, OpenLlamaForSequenceClassification) if is_torch_available() else ()
			)
			lowerCamelCase_     :     Any       			=      (OpenLlamaForCausalLM,) if is_torch_available() else ()
			lowerCamelCase_     :     List[str]       			=      (
			    {
			        '''feature-extraction''': OpenLlamaModel,
			        '''text-classification''': OpenLlamaForSequenceClassification,
			        '''text-generation''': OpenLlamaForCausalLM,
			        '''zero-shot''': OpenLlamaForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			lowerCamelCase_     :     str       			=      False
			lowerCamelCase_     :     Dict       			=      False






			def 			lowerCamelCase  (self    )     ->   List[Any]:


							'''simple docstring'''



							snake_case_						:    List[Any]				=  OpenLlamaModelTester(self    )
							snake_case_						:    Tuple				=  ConfigTester(self					,							config_class=__magic_name__					,							hidden_size=37    )






			def 			lowerCamelCase  (self    )     ->   Optional[int]:


							'''simple docstring'''



							self.config_tester.run_common_tests()






			def 			lowerCamelCase  (self    )     ->   List[Any]:


							'''simple docstring'''



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






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


							'''simple docstring'''



							snake_case_						:    Optional[Any]				=  self.model_tester.prepare_config_and_inputs()
							for type in ["absolute", "relative_key", "relative_key_query"]:
											snake_case_						:    Dict				=  type
											self.model_tester.create_and_check_model(*__magic_name__    )






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


							'''simple docstring'''



							snake_case_			,							snake_case_						:    List[Any]				=  self.model_tester.prepare_config_and_inputs_for_common()
							snake_case_						:    Any				=  3
							snake_case_						:    Dict				=  input_dict['''input_ids''']
							snake_case_						:    List[str]				=  input_ids.ne(1    ).to(__magic_name__    )
							snake_case_						:    Dict				=  ids_tensor([self.model_tester.batch_size]					,							self.model_tester.type_sequence_label_size    )
							snake_case_						:    List[str]				=  OpenLlamaForSequenceClassification(__magic_name__    )
							model.to(__magic_name__    )
							model.eval()
							snake_case_						:    str				=  model(__magic_name__					,							attention_mask=__magic_name__					,							labels=__magic_name__    )
							self.assertEqual(result.logits.shape					,							(self.model_tester.batch_size, self.model_tester.num_labels)    )






			def 			lowerCamelCase  (self    )     ->   str:


							'''simple docstring'''



							snake_case_			,							snake_case_						:    int				=  self.model_tester.prepare_config_and_inputs_for_common()
							snake_case_						:    int				=  3
							snake_case_						:    Tuple				=  '''single_label_classification'''
							snake_case_						:    Optional[Any]				=  input_dict['''input_ids''']
							snake_case_						:    str				=  input_ids.ne(1    ).to(__magic_name__    )
							snake_case_						:    Dict				=  ids_tensor([self.model_tester.batch_size]					,							self.model_tester.type_sequence_label_size    )
							snake_case_						:    List[Any]				=  OpenLlamaForSequenceClassification(__magic_name__    )
							model.to(__magic_name__    )
							model.eval()
							snake_case_						:    List[Any]				=  model(__magic_name__					,							attention_mask=__magic_name__					,							labels=__magic_name__    )
							self.assertEqual(result.logits.shape					,							(self.model_tester.batch_size, self.model_tester.num_labels)    )






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


							'''simple docstring'''



							snake_case_			,							snake_case_						:    Tuple				=  self.model_tester.prepare_config_and_inputs_for_common()
							snake_case_						:    Optional[Any]				=  3
							snake_case_						:    Any				=  '''multi_label_classification'''
							snake_case_						:    Union[str, Any]				=  input_dict['''input_ids''']
							snake_case_						:    Tuple				=  input_ids.ne(1    ).to(__magic_name__    )
							snake_case_						:    Union[str, Any]				=  ids_tensor(
							    [self.model_tester.batch_size, config.num_labels]					,							self.model_tester.type_sequence_label_size    ).to(torch.float    )
							snake_case_						:    int				=  OpenLlamaForSequenceClassification(__magic_name__    )
							model.to(__magic_name__    )
							model.eval()
							snake_case_						:    List[str]				=  model(__magic_name__					,							attention_mask=__magic_name__					,							labels=__magic_name__    )
							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 			lowerCamelCase  (self    )     ->   Any:


							'''simple docstring'''



							pass






			@parameterized.expand([('''linear''',), ('''dynamic''',)]    )
			def 			lowerCamelCase  (self					,							__magic_name__    )     ->   Dict:


							'''simple docstring'''



							snake_case_			,							snake_case_						:    str				=  self.model_tester.prepare_config_and_inputs_for_common()
							snake_case_						:    Union[str, Any]				=  ids_tensor([1, 10]					,							config.vocab_size    )
							snake_case_						:    str				=  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
							snake_case_						:    Optional[Any]				=  OpenLlamaModel(__magic_name__    )
							original_model.to(__magic_name__    )
							original_model.eval()
							snake_case_						:    Any				=  original_model(__magic_name__    ).last_hidden_state
							snake_case_						:    List[Any]				=  original_model(__magic_name__    ).last_hidden_state

							set_seed(42    )  # Fixed seed at init time so the two models get the same random weights
							snake_case_						:    Any				=  {'''type''': scaling_type, '''factor''': 10.0}
							snake_case_						:    List[str]				=  OpenLlamaModel(__magic_name__    )
							scaled_model.to(__magic_name__    )
							scaled_model.eval()
							snake_case_						:    Dict				=  scaled_model(__magic_name__    ).last_hidden_state
							snake_case_						:    int				=  scaled_model(__magic_name__    ).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(__magic_name__					,							__magic_name__					,							atol=1e-5    )    )
							else:
											self.assertFalse(torch.allclose(__magic_name__					,							__magic_name__					,							atol=1e-5    )    )

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







def      lowerCamelCase_						(				_UpperCamelCase ,				_UpperCamelCase )		->						List[str]:






				"""simple docstring"""


				print('''\nThe shortest path matrix using Floyd Warshall algorithm\n''' )
				for i in range(_UpperCamelCase ):
								for j in range(_UpperCamelCase ):
												if dist[i][j] != float('''inf''' ):
																print(int(dist[i][j] ) ,				end='''\t''' )
												else:
																print('''INF''' ,				end='''\t''' )
								print()






def      lowerCamelCase_						(				_UpperCamelCase ,				_UpperCamelCase )		->						Union[str, Any]:






				"""simple docstring"""


				snake_case_						:    int				=  [[float('''inf''' ) for _ in range(_UpperCamelCase )] for _ in range(_UpperCamelCase )]

				for i in range(_UpperCamelCase ):
								for j in range(_UpperCamelCase ):
												snake_case_						:    Dict				=  graph[i][j]

												# check vertex k against all other vertices (i, j)
				for k in range(_UpperCamelCase ):
								# looping through rows of graph array
								for i in range(_UpperCamelCase ):
												# looping through columns of graph array
												for j in range(_UpperCamelCase ):
																if (
																    dist[i][k] != float('''inf''' )
																    and dist[k][j] != float('''inf''' )
																    and dist[i][k] + dist[k][j] < dist[i][j]
																):
																				snake_case_						:    List[Any]				=  dist[i][k] + dist[k][j]

				_print_dist(_UpperCamelCase ,				_UpperCamelCase )
				return dist, v


if __name__ == "__main__":
	lowerCAmelCase_    =				int(input('''Enter number of vertices: '''))
	lowerCAmelCase_    =				int(input('''Enter number of edges: '''))

	lowerCAmelCase_    =				[[float('''inf''') for i in range(v)] for j in range(v)]

	for i in range(v):
		lowerCAmelCase_    =				0.0

		# src and dst are indices that must be within the array size graph[e][v]
		# failure to follow this will result in an error
	for i in range(e):
		print('''\nEdge ''', i + 1)
		lowerCAmelCase_    =				int(input('''Enter source:'''))
		lowerCAmelCase_    =				int(input('''Enter destination:'''))
		lowerCAmelCase_    =				float(input('''Enter weight:'''))
		lowerCAmelCase_    =				weight

	floyd_warshall(graph, v)

	# Example Input
	# Enter number of vertices: 3
	# Enter number of edges: 2

	# # generated graph from vertex and edge inputs
	# [[inf, inf, inf], [inf, inf, inf], [inf, inf, inf]]
	# [[0.0, inf, inf], [inf, 0.0, inf], [inf, inf, 0.0]]

	# specify source, destination and weight for edge #1
	# Edge  1
	# Enter source:1
	# Enter destination:2
	# Enter weight:2

	# specify source, destination and weight for edge #2
	# Edge  2
	# Enter source:2
	# Enter destination:1
	# Enter weight:1

	# # Expected Output from the vertice, edge and src, dst, weight inputs!!
	# 0		INF	INF
	# INF	0	2
	# INF	1	0
