


import os
from itertools import chain
from random import randrange, shuffle

import pytest

from .sola import PokerHand

a					  =     (
    '4S 3H 2C 7S 5H',
    '9D 8H 2C 6S 7H',
    '2D 6D 9D TH 7D',
    'TC 8C 2S JH 6C',
    'JH 8S TH AH QH',
    'TS KS 5S 9S AC',
    'KD 6S 9D TH AD',
    'KS 8D 4D 9S 4S',  # pair
    '8C 4S KH JS 4D',  # pair
    'QH 8H KD JH 8S',  # pair
    'KC 4H KS 2H 8D',  # pair
    'KD 4S KC 3H 8S',  # pair
    'AH 8S AS KC JH',  # pair
    '3H 4C 4H 3S 2H',  # 2 pairs
    '5S 5D 2C KH KH',  # 2 pairs
    '3C KH 5D 5S KH',  # 2 pairs
    'AS 3C KH AD KH',  # 2 pairs
    '7C 7S 3S 7H 5S',  # 3 of a kind
    '7C 7S KH 2H 7H',  # 3 of a kind
    'AC KH QH AH AS',  # 3 of a kind
    '2H 4D 3C AS 5S',  # straight (low ace)
    '3C 5C 4C 2C 6H',  # straight
    '6S 8S 7S 5H 9H',  # straight
    'JS QS 9H TS KH',  # straight
    'QC KH TS JS AH',  # straight (high ace)
    '8C 9C 5C 3C TC',  # flush
    '3S 8S 9S 5S KS',  # flush
    '4C 5C 9C 8C KC',  # flush
    'JH 8H AH KH QH',  # flush
    '3D 2H 3H 2C 2D',  # full house
    '2H 2C 3S 3H 3D',  # full house
    'KH KC 3S 3H 3D',  # full house
    'JC 6H JS JD JH',  # 4 of a kind
    'JC 7H JS JD JH',  # 4 of a kind
    'JC KH JS JD JH',  # 4 of a kind
    '2S AS 4S 5S 3S',  # straight flush (low ace)
    '2D 6D 3D 4D 5D',  # straight flush
    '5C 6C 3C 7C 4C',  # straight flush
    'JH 9H TH KH QH',  # straight flush
    'JH AH TH KH QH',  # royal flush (high ace straight flush)
)

a					  =     (
    ('2H 3H 4H 5H 6H', 'KS AS TS QS JS', 'Loss'),
    ('2H 3H 4H 5H 6H', 'AS AD AC AH JD', 'Win'),
    ('AS AH 2H AD AC', 'JS JD JC JH 3D', 'Win'),
    ('2S AH 2H AS AC', 'JS JD JC JH AD', 'Loss'),
    ('2S AH 2H AS AC', '2H 3H 5H 6H 7H', 'Win'),
    ('AS 3S 4S 8S 2S', '2H 3H 5H 6H 7H', 'Win'),
    ('2H 3H 5H 6H 7H', '2S 3H 4H 5S 6C', 'Win'),
    ('2S 3H 4H 5S 6C', '3D 4C 5H 6H 2S', 'Tie'),
    ('2S 3H 4H 5S 6C', 'AH AC 5H 6H AS', 'Win'),
    ('2S 2H 4H 5S 4C', 'AH AC 5H 6H AS', 'Loss'),
    ('2S 2H 4H 5S 4C', 'AH AC 5H 6H 7S', 'Win'),
    ('6S AD 7H 4S AS', 'AH AC 5H 6H 7S', 'Loss'),
    ('2S AH 4H 5S KC', 'AH AC 5H 6H 7S', 'Loss'),
    ('2S 3H 6H 7S 9C', '7H 3C TH 6H 9S', 'Loss'),
    ('4S 5H 6H TS AC', '3S 5H 6H TS AC', 'Win'),
    ('2S AH 4H 5S 6C', 'AD 4C 5H 6H 2C', 'Tie'),
    ('AS AH 3H AD AC', 'AS AH 2H AD AC', 'Win'),
    ('AH AC 5H 5C QS', 'AH AC 5H 5C KS', 'Loss'),
    ('AH AC 5H 5C QS', 'KH KC 5H 5C QS', 'Win'),
    ('7C 7S KH 2H 7H', '3C 3S AH 2H 3H', 'Win'),
    ('3C 3S AH 2H 3H', '7C 7S KH 2H 7H', 'Loss'),
    ('6H 5H 4H 3H 2H', '5H 4H 3H 2H AH', 'Win'),
    ('5H 4H 3H 2H AH', '5H 4H 3H 2H AH', 'Tie'),
    ('5H 4H 3H 2H AH', '6H 5H 4H 3H 2H', 'Loss'),
    ('AH AD KS KC AC', 'AH KD KH AC KC', 'Win'),
    ('2H 4D 3C AS 5S', '2H 4D 3C 6S 5S', 'Loss'),
    ('2H 3S 3C 3H 2S', '3S 3C 2S 2H 2D', 'Win'),
    ('4D 6D 5D 2D JH', '3S 8S 3H TC KH', 'Loss'),
    ('4S 6C 8S 3S 7S', 'AD KS 2D 7D 7C', 'Loss'),
    ('6S 4C 7H 8C 3H', '5H JC AH 9D 9C', 'Loss'),
    ('9D 9H JH TC QH', '3C 2S JS 5C 7H', 'Win'),
    ('2H TC 8S AD 9S', '4H TS 7H 2C 5C', 'Win'),
    ('9D 3S 2C 7S 7C', 'JC TD 3C TC 9H', 'Loss'),
)

a					  =     (
    ('2H 3H 4H 5H 6H', True),
    ('AS AH 2H AD AC', False),
    ('2H 3H 5H 6H 7H', True),
    ('KS AS TS QS JS', True),
    ('8H 9H QS JS TH', False),
    ('AS 3S 4S 8S 2S', True),
)

a					  =     (
    ('2H 3H 4H 5H 6H', True),
    ('AS AH 2H AD AC', False),
    ('2H 3H 5H 6H 7H', False),
    ('KS AS TS QS JS', True),
    ('8H 9H QS JS TH', True),
)

a					  =     (
    ('2H 4D 3C AS 5S', True, [5, 4, 3, 2, 1_4]),
    ('2H 5D 3C AS 5S', False, [1_4, 5, 5, 3, 2]),
    ('JH QD KC AS TS', False, [1_4, 1_3, 1_2, 1_1, 1_0]),
    ('9D 3S 2C 7S 7C', False, [9, 7, 7, 3, 2]),
)

a					  =     (
    ('JH AH TH KH QH', 0),
    ('JH 9H TH KH QH', 0),
    ('JC KH JS JD JH', 7),
    ('KH KC 3S 3H 3D', 6),
    ('8C 9C 5C 3C TC', 0),
    ('JS QS 9H TS KH', 0),
    ('7C 7S KH 2H 7H', 3),
    ('3C KH 5D 5S KH', 2),
    ('QH 8H KD JH 8S', 1),
    ('2D 6D 9D TH 7D', 0),
)

a					  =     (
    ('JH AH TH KH QH', 2_3),
    ('JH 9H TH KH QH', 2_2),
    ('JC KH JS JD JH', 2_1),
    ('KH KC 3S 3H 3D', 2_0),
    ('8C 9C 5C 3C TC', 1_9),
    ('JS QS 9H TS KH', 1_8),
    ('7C 7S KH 2H 7H', 1_7),
    ('3C KH 5D 5S KH', 1_6),
    ('QH 8H KD JH 8S', 1_5),
    ('2D 6D 9D TH 7D', 1_4),
)


def 			UpperCAmelCase_				(      ):
					lowercase_							,					lowercase_  							=			randrange(len(UpperCAmelCase__  )  ), randrange(len(UpperCAmelCase__  )  )
					lowercase_  							=			["""Loss""", """Tie""", """Win"""][(play >= oppo) + (play > oppo)]
					lowercase_							,					lowercase_  							=			SORTED_HANDS[play], SORTED_HANDS[oppo]
					return hand, other, expected


def 			UpperCAmelCase_				(      UpperCAmelCase__ = 1_0_0  ):
					return (generate_random_hand() for _ in range(UpperCAmelCase__  ))


@pytest.mark.parametrize("""hand, expected"""						,							UpperCAmelCase__  )
def 			UpperCAmelCase_				(      UpperCAmelCase__						,							UpperCAmelCase__  ):
					assert PokerHand(UpperCAmelCase__  )._is_flush() == expected


@pytest.mark.parametrize("""hand, expected"""						,							UpperCAmelCase__  )
def 			UpperCAmelCase_				(      UpperCAmelCase__						,							UpperCAmelCase__  ):
					assert PokerHand(UpperCAmelCase__  )._is_straight() == expected


@pytest.mark.parametrize("""hand, expected, card_values"""						,							UpperCAmelCase__  )
def 			UpperCAmelCase_				(      UpperCAmelCase__						,							UpperCAmelCase__						,							UpperCAmelCase__  ):
					lowercase_  							=			PokerHand(UpperCAmelCase__  )
					assert player._is_five_high_straight() == expected
					assert player._card_values == card_values


@pytest.mark.parametrize("""hand, expected"""						,							UpperCAmelCase__  )
def 			UpperCAmelCase_				(      UpperCAmelCase__						,							UpperCAmelCase__  ):
					assert PokerHand(UpperCAmelCase__  )._is_same_kind() == expected


@pytest.mark.parametrize("""hand, expected"""						,							UpperCAmelCase__  )
def 			UpperCAmelCase_				(      UpperCAmelCase__						,							UpperCAmelCase__  ):
					assert PokerHand(UpperCAmelCase__  )._hand_type == expected


@pytest.mark.parametrize("""hand, other, expected"""						,							UpperCAmelCase__  )
def 			UpperCAmelCase_				(      UpperCAmelCase__						,							UpperCAmelCase__						,							UpperCAmelCase__  ):
					assert PokerHand(UpperCAmelCase__  ).compare_with(PokerHand(UpperCAmelCase__  )  ) == expected


@pytest.mark.parametrize("""hand, other, expected"""						,							generate_random_hands()  )
def 			UpperCAmelCase_				(      UpperCAmelCase__						,							UpperCAmelCase__						,							UpperCAmelCase__  ):
					assert PokerHand(UpperCAmelCase__  ).compare_with(PokerHand(UpperCAmelCase__  )  ) == expected


def 			UpperCAmelCase_				(      ):
					lowercase_  							=			[PokerHand(UpperCAmelCase__  ) for hand in SORTED_HANDS]
					lowercase_  							=			poker_hands.copy()
					shuffle(UpperCAmelCase__  )
					lowercase_  							=			chain(sorted(UpperCAmelCase__  )  )
					for index, hand in enumerate(UpperCAmelCase__  ):
										assert hand == poker_hands[index]


def 			UpperCAmelCase_				(      ):
					# Test that five high straights are compared correctly.
					lowercase_  							=			[PokerHand("""2D AC 3H 4H 5S"""  ), PokerHand("""2S 3H 4H 5S 6C"""  )]
					pokerhands.sort(reverse=UpperCAmelCase__  )
					assert pokerhands[0].__str__() == "2S 3H 4H 5S 6C"


def 			UpperCAmelCase_				(      ):
					# Multiple calls to five_high_straight function should still return True
					# and shouldn't mutate the list in every call other than the first.
					lowercase_  							=			PokerHand("""2C 4S AS 3D 5C"""  )
					lowercase_  							=			True
					lowercase_  							=			[5, 4, 3, 2, 1_4]
					for _ in range(1_0  ):
										assert pokerhand._is_five_high_straight() == expected
										assert pokerhand._card_values == expected_card_values



def 			UpperCAmelCase_				(      ):
					# Problem number 54 from Project Euler
					# Testing from poker_hands.txt file
					lowercase_  							=			0
					lowercase_  							=			os.path.abspath(os.path.dirname(UpperCAmelCase__  )  )
					lowercase_  							=			os.path.join(UpperCAmelCase__						,							"""poker_hands.txt"""  )
					with open(UpperCAmelCase__  ) as file_hand:
										for line in file_hand:
															lowercase_  							=			line[:1_4].strip()
															lowercase_  							=			line[1_5:].strip()
															lowercase_							,					lowercase_  							=			PokerHand(UpperCAmelCase__  ), PokerHand(UpperCAmelCase__  )
															lowercase_  							=			player.compare_with(UpperCAmelCase__  )
															if output == "Win":
																				answer += 1
					assert answer == 3_7_6






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

					def __init__(     self       :   List[str]							,					UpperCamelCase__       :   Tuple							,					UpperCamelCase__       :   List[str]=13							,					UpperCamelCase__       :   str=7							,					UpperCamelCase__       :   List[str]=True							,					UpperCamelCase__       :   List[str]=True							,					UpperCamelCase__       :   str=False							,					UpperCamelCase__       :   str=True							,					UpperCamelCase__       :   Union[str, Any]=99							,					UpperCamelCase__       :   Dict=32							,					UpperCamelCase__       :   Union[str, Any]=5							,					UpperCamelCase__       :   Tuple=4							,					UpperCamelCase__       :   Dict=37							,					UpperCamelCase__       :   Any="gelu"							,					UpperCamelCase__       :   Dict=0.1							,					UpperCamelCase__       :   Tuple=0.1							,					UpperCamelCase__       :   Tuple=512							,					UpperCamelCase__       :   Union[str, Any]=16							,					UpperCamelCase__       :   List[str]=2							,					UpperCamelCase__       :   int=0.02							,					UpperCamelCase__       :   int=3							,					UpperCamelCase__       :   Optional[Any]=4							,					UpperCamelCase__       :   int=None							,					):






										'''simple docstring'''






										lowercase_  							=			parent
										lowercase_  							=			batch_size
										lowercase_  							=			seq_length
										lowercase_  							=			is_training
										lowercase_  							=			use_input_mask
										lowercase_  							=			use_token_type_ids
										lowercase_  							=			use_labels
										lowercase_  							=			vocab_size
										lowercase_  							=			hidden_size
										lowercase_  							=			num_hidden_layers
										lowercase_  							=			num_attention_heads
										lowercase_  							=			intermediate_size
										lowercase_  							=			hidden_act
										lowercase_  							=			hidden_dropout_prob
										lowercase_  							=			attention_probs_dropout_prob
										lowercase_  							=			max_position_embeddings
										lowercase_  							=			type_vocab_size
										lowercase_  							=			type_sequence_label_size
										lowercase_  							=			initializer_range
										lowercase_  							=			num_labels
										lowercase_  							=			num_choices
										lowercase_  							=			scope

					def   UpperCAmelCase__       (     self       :   Optional[Any]       ):






										'''simple docstring'''






										lowercase_  							=			ids_tensor([self.batch_size, self.seq_length]							,					self.vocab_size       )

										lowercase_  							=			None
										if self.use_input_mask:
															lowercase_  							=			random_attention_mask([self.batch_size, self.seq_length]       )

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

										lowercase_  							=			None
										lowercase_  							=			None
										lowercase_  							=			None
										if self.use_labels:
															lowercase_  							=			ids_tensor([self.batch_size]							,					self.type_sequence_label_size       )
															lowercase_  							=			ids_tensor([self.batch_size, self.seq_length]							,					self.num_labels       )
															lowercase_  							=			ids_tensor([self.batch_size]							,					self.num_choices       )

										lowercase_  							=			self.get_config()

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

					def   UpperCAmelCase__       (     self       :   Dict       ):






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

					def   UpperCAmelCase__       (     self       :   str							,					UpperCamelCase__       :   Optional[Any]							,					UpperCamelCase__       :   Tuple							,					UpperCamelCase__       :   Dict							,					UpperCamelCase__       :   List[str]							,					UpperCamelCase__       :   Dict							,					UpperCamelCase__       :   str							,					UpperCamelCase__       :   Optional[Any]       ):






										'''simple docstring'''






										lowercase_  							=			OpenLlamaModel(config=UpperCamelCase__       )
										model.to(UpperCamelCase__       )
										model.eval()
										lowercase_  							=			model(UpperCamelCase__							,					attention_mask=UpperCamelCase__       )
										lowercase_  							=			model(UpperCamelCase__       )
										self.parent.assertEqual(result.last_hidden_state.shape							,					(self.batch_size, self.seq_length, self.hidden_size)       )

					def   UpperCAmelCase__       (     self       :   Union[str, Any]							,					UpperCamelCase__       :   Tuple							,					UpperCamelCase__       :   str							,					UpperCamelCase__       :   Tuple							,					UpperCamelCase__       :   str							,					UpperCamelCase__       :   int							,					UpperCamelCase__       :   str							,					UpperCamelCase__       :   Optional[int]							,					UpperCamelCase__       :   Optional[Any]							,					UpperCamelCase__       :   Optional[Any]							,					):






										'''simple docstring'''






										lowercase_  							=			True
										lowercase_  							=			OpenLlamaModel(UpperCamelCase__       )
										model.to(UpperCamelCase__       )
										model.eval()
										lowercase_  							=			model(
										    UpperCamelCase__							,					attention_mask=UpperCamelCase__							,					encoder_hidden_states=UpperCamelCase__							,					encoder_attention_mask=UpperCamelCase__							,					)
										lowercase_  							=			model(
										    UpperCamelCase__							,					attention_mask=UpperCamelCase__							,					encoder_hidden_states=UpperCamelCase__							,					)
										lowercase_  							=			model(UpperCamelCase__							,					attention_mask=UpperCamelCase__       )
										self.parent.assertEqual(result.last_hidden_state.shape							,					(self.batch_size, self.seq_length, self.hidden_size)       )

					def   UpperCAmelCase__       (     self       :   Any							,					UpperCamelCase__       :   List[str]							,					UpperCamelCase__       :   List[Any]							,					UpperCamelCase__       :   Optional[int]							,					UpperCamelCase__       :   str							,					UpperCamelCase__       :   Any							,					UpperCamelCase__       :   Union[str, Any]							,					UpperCamelCase__       :   Tuple							,					UpperCamelCase__       :   Any							,					UpperCamelCase__       :   List[Any]							,					):






										'''simple docstring'''






										lowercase_  							=			OpenLlamaForCausalLM(config=UpperCamelCase__       )
										model.to(UpperCamelCase__       )
										model.eval()
										lowercase_  							=			model(UpperCamelCase__							,					attention_mask=UpperCamelCase__							,					labels=UpperCamelCase__       )
										self.parent.assertEqual(result.logits.shape							,					(self.batch_size, self.seq_length, self.vocab_size)       )

					def   UpperCAmelCase__       (     self       :   int							,					UpperCamelCase__       :   Optional[int]							,					UpperCamelCase__       :   int							,					UpperCamelCase__       :   Tuple							,					UpperCamelCase__       :   Optional[Any]							,					UpperCamelCase__       :   int							,					UpperCamelCase__       :   List[str]							,					UpperCamelCase__       :   int							,					UpperCamelCase__       :   str							,					UpperCamelCase__       :   Tuple							,					):






										'''simple docstring'''






										lowercase_  							=			True
										lowercase_  							=			True
										lowercase_  							=			OpenLlamaForCausalLM(config=UpperCamelCase__       )
										model.to(UpperCamelCase__       )
										model.eval()

										# first forward pass
										lowercase_  							=			model(
										    UpperCamelCase__							,					attention_mask=UpperCamelCase__							,					encoder_hidden_states=UpperCamelCase__							,					encoder_attention_mask=UpperCamelCase__							,					use_cache=UpperCamelCase__							,					)
										lowercase_  							=			outputs.past_key_values

										# create hypothetical multiple next token and extent to next_input_ids
										lowercase_  							=			ids_tensor((self.batch_size, 3)							,					config.vocab_size       )
										lowercase_  							=			ids_tensor((self.batch_size, 3)							,					vocab_size=2       )

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

										lowercase_  							=			model(
										    UpperCamelCase__							,					attention_mask=UpperCamelCase__							,					encoder_hidden_states=UpperCamelCase__							,					encoder_attention_mask=UpperCamelCase__							,					output_hidden_states=UpperCamelCase__							,					)["""hidden_states"""][0]
										lowercase_  							=			model(
										    UpperCamelCase__							,					attention_mask=UpperCamelCase__							,					encoder_hidden_states=UpperCamelCase__							,					encoder_attention_mask=UpperCamelCase__							,					past_key_values=UpperCamelCase__							,					output_hidden_states=UpperCamelCase__							,					)["""hidden_states"""][0]

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







					def   UpperCAmelCase__       (     self       :   Optional[Any]       ):






										'''simple docstring'''






										lowercase_  							=			self.prepare_config_and_inputs()
										(
										    (
										    lowercase_
										)							,					(
										    lowercase_
										)							,					(
										    lowercase_
										)							,					(
										    lowercase_
										)							,					(
										    lowercase_
										)							,					(
										    lowercase_
										)							,					(
										    lowercase_
										)							,					
										)  							=			config_and_inputs
										lowercase_  							=			{"""input_ids""": input_ids, """attention_mask""": input_mask}
										return config, inputs_dict







@require_torch
class        UpperCamelCase__   (	__magic_name__							,				__magic_name__							,				__magic_name__							,				unittest.TestCase   ):
					__SCREAMING_SNAKE_CASE       :  Union[str, Any]						=   (
					    (OpenLlamaModel, OpenLlamaForCausalLM, OpenLlamaForSequenceClassification) if is_torch_available() else ()
					)
					__SCREAMING_SNAKE_CASE       :  List[str]						=   (OpenLlamaForCausalLM,) if is_torch_available() else ()
					__SCREAMING_SNAKE_CASE       :  List[Any]						=   (
					    {
					        'feature-extraction': OpenLlamaModel,
					        'text-classification': OpenLlamaForSequenceClassification,
					        'text-generation': OpenLlamaForCausalLM,
					        'zero-shot': OpenLlamaForSequenceClassification,
					    }
					    if is_torch_available()
					    else {}
					)
					__SCREAMING_SNAKE_CASE       :  Tuple						=   False
					__SCREAMING_SNAKE_CASE       :  Optional[int]						=   False

					def   UpperCAmelCase__       (     self       :   List[Any]       ):






										'''simple docstring'''






										lowercase_  							=			OpenLlamaModelTester(self       )
										lowercase_  							=			ConfigTester(self							,					config_class=UpperCamelCase__							,					hidden_size=37       )

					def   UpperCAmelCase__       (     self       :   Optional[Any]       ):






										'''simple docstring'''






										self.config_tester.run_common_tests()

					def   UpperCAmelCase__       (     self       :   str       ):






										'''simple docstring'''






										lowercase_  							=			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*UpperCamelCase__       )

					def   UpperCAmelCase__       (     self       :   Dict       ):






										'''simple docstring'''






										lowercase_  							=			self.model_tester.prepare_config_and_inputs()
										for type in ["absolute", "relative_key", "relative_key_query"]:
															lowercase_  							=			type
															self.model_tester.create_and_check_model(*UpperCamelCase__       )

					def   UpperCAmelCase__       (     self       :   List[Any]       ):






										'''simple docstring'''






										lowercase_							,					lowercase_  							=			self.model_tester.prepare_config_and_inputs_for_common()
										lowercase_  							=			3
										lowercase_  							=			input_dict["""input_ids"""]
										lowercase_  							=			input_ids.ne(1       ).to(UpperCamelCase__       )
										lowercase_  							=			ids_tensor([self.model_tester.batch_size]							,					self.model_tester.type_sequence_label_size       )
										lowercase_  							=			OpenLlamaForSequenceClassification(UpperCamelCase__       )
										model.to(UpperCamelCase__       )
										model.eval()
										lowercase_  							=			model(UpperCamelCase__							,					attention_mask=UpperCamelCase__							,					labels=UpperCamelCase__       )
										self.assertEqual(result.logits.shape							,					(self.model_tester.batch_size, self.model_tester.num_labels)       )

					def   UpperCAmelCase__       (     self       :   Union[str, Any]       ):






										'''simple docstring'''






										lowercase_							,					lowercase_  							=			self.model_tester.prepare_config_and_inputs_for_common()
										lowercase_  							=			3
										lowercase_  							=			"""single_label_classification"""
										lowercase_  							=			input_dict["""input_ids"""]
										lowercase_  							=			input_ids.ne(1       ).to(UpperCamelCase__       )
										lowercase_  							=			ids_tensor([self.model_tester.batch_size]							,					self.model_tester.type_sequence_label_size       )
										lowercase_  							=			OpenLlamaForSequenceClassification(UpperCamelCase__       )
										model.to(UpperCamelCase__       )
										model.eval()
										lowercase_  							=			model(UpperCamelCase__							,					attention_mask=UpperCamelCase__							,					labels=UpperCamelCase__       )
										self.assertEqual(result.logits.shape							,					(self.model_tester.batch_size, self.model_tester.num_labels)       )

					def   UpperCAmelCase__       (     self       :   Dict       ):






										'''simple docstring'''






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






										'''simple docstring'''






										lowercase_							,					lowercase_  							=			self.model_tester.prepare_config_and_inputs_for_common()
										lowercase_  							=			ids_tensor([1, 10]							,					config.vocab_size       )
										lowercase_  							=			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
										lowercase_  							=			OpenLlamaModel(UpperCamelCase__       )
										original_model.to(UpperCamelCase__       )
										original_model.eval()
										lowercase_  							=			original_model(UpperCamelCase__       ).last_hidden_state
										lowercase_  							=			original_model(UpperCamelCase__       ).last_hidden_state

										set_seed(42       )  # Fixed seed at init time so the two models get the same random weights
										lowercase_  							=			{"""type""": scaling_type, """factor""": 10.0}
										lowercase_  							=			OpenLlamaModel(UpperCamelCase__       )
										scaled_model.to(UpperCamelCase__       )
										scaled_model.eval()
										lowercase_  							=			scaled_model(UpperCamelCase__       ).last_hidden_state
										lowercase_  							=			scaled_model(UpperCamelCase__       ).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(UpperCamelCase__							,					UpperCamelCase__							,					atol=1e-5       )       )
										else:
															self.assertFalse(torch.allclose(UpperCamelCase__							,					UpperCamelCase__							,					atol=1e-5       )       )

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


