



'''simple docstring'''

from copy import deepcopy
from typing import Optional, Union

import numpy as np

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding
from ...utils import TensorType, is_tf_available, is_torch_available


if is_torch_available():
							import torch

if is_tf_available():
							import tensorflow as tf

class       __magic_name__		(       _UpperCamelCase  ):
							lowerCAmelCase			:       Optional[Any]  							=   ['image_processor']
							lowerCAmelCase			:       Optional[int]  							=   'SamImageProcessor'







							def __init__(				self   :			Optional[Any]      ,_UpperCAmelCase   :			Optional[int]						):
									super().__init__(lowerCamelCase_						)
									_a	: List[Any]								=				self.image_processor
									_a	: Dict								=				-10
									_a	: List[Any]								=				self.image_processor.size['longest_edge']







							def __call__(				self   :			Any      ,_UpperCAmelCase   :			List[str]=None      ,_UpperCAmelCase   :			Union[str, Any]=None      ,_UpperCAmelCase   :			Any=None      ,_UpperCAmelCase   :			int=None      ,_UpperCAmelCase   :			Optional[Union[str, TensorType]] = None      ,**_UpperCAmelCase   :			Union[str, Any]      ,):
									_a	: Union[str, Any]								=				self.image_processor(
									    lowerCamelCase_      ,return_tensors=lowerCamelCase_      ,**lowerCamelCase_      ,)

									# pop arguments that are not used in the foward but used nevertheless
									_a	: Any								=				encoding_image_processor['original_sizes']

									if hasattr(lowerCamelCase_      ,'numpy'						):  # Checks if Torch or TF tensor
											_a	: Tuple								=				original_sizes.numpy()

									_a	: Dict								=				self._check_and_preprocess_points(
									    input_points=lowerCamelCase_      ,input_labels=lowerCamelCase_      ,input_boxes=lowerCamelCase_      ,)

									_a	: Union[str, Any]								=				self._normalize_and_convert(
									    lowerCamelCase_      ,lowerCamelCase_      ,input_points=lowerCamelCase_      ,input_labels=lowerCamelCase_      ,input_boxes=lowerCamelCase_      ,return_tensors=lowerCamelCase_      ,)

									return encoding_image_processor







							def 				__lowercase     (				self   :			List[str]      ,_UpperCAmelCase   :			str      ,_UpperCAmelCase   :			Any      ,_UpperCAmelCase   :			Optional[int]=None      ,_UpperCAmelCase   :			Optional[int]=None      ,_UpperCAmelCase   :			str=None      ,_UpperCAmelCase   :			Any="pt"      ,):
									if input_points is not None:
											if len(lowerCamelCase_						) != len(lowerCamelCase_						):
													_a	: Optional[Any]								=				[
													    self._normalize_coordinates(self.target_size      ,lowerCamelCase_      ,original_sizes[0]						) for point in input_points
													]
											else:
													_a	: List[str]								=				[
													    self._normalize_coordinates(self.target_size      ,lowerCamelCase_      ,lowerCamelCase_						)
													    for point, original_size in zip(lowerCamelCase_      ,lowerCamelCase_						)
													]
											# check that all arrays have the same shape
											if not all(point.shape == input_points[0].shape for point in input_points						):
													if input_labels is not None:
															_a	: int								=				self._pad_points_and_labels(lowerCamelCase_      ,lowerCamelCase_						)

											_a	: int								=				np.array(lowerCamelCase_						)

									if input_labels is not None:
											_a	: Optional[int]								=				np.array(lowerCamelCase_						)

									if input_boxes is not None:
											if len(lowerCamelCase_						) != len(lowerCamelCase_						):
													_a	: Dict								=				[
													    self._normalize_coordinates(self.target_size      ,lowerCamelCase_      ,original_sizes[0]      ,is_bounding_box=lowerCamelCase_						)
													    for box in input_boxes
													]
											else:
													_a	: Optional[Any]								=				[
													    self._normalize_coordinates(self.target_size      ,lowerCamelCase_      ,lowerCamelCase_      ,is_bounding_box=lowerCamelCase_						)
													    for box, original_size in zip(lowerCamelCase_      ,lowerCamelCase_						)
													]
											_a	: List[Any]								=				np.array(lowerCamelCase_						)

									if input_boxes is not None:
											if return_tensors == "pt":
													_a	: List[Any]								=				torch.from_numpy(lowerCamelCase_						)
													# boxes batch size of 1 by default
													_a	: Optional[int]								=				input_boxes.unsqueeze(1						) if len(input_boxes.shape						) != 3 else input_boxes
											elif return_tensors == "tf":
													_a	: Optional[int]								=				tf.convert_to_tensor(lowerCamelCase_						)
													# boxes batch size of 1 by default
													_a	: Optional[Any]								=				tf.expand_dims(lowerCamelCase_      ,1						) if len(input_boxes.shape						) != 3 else input_boxes
											encoding_image_processor.update({'input_boxes': input_boxes}						)
									if input_points is not None:
											if return_tensors == "pt":
													_a	: List[str]								=				torch.from_numpy(lowerCamelCase_						)
													# point batch size of 1 by default
													_a	: Tuple								=				input_points.unsqueeze(1						) if len(input_points.shape						) != 4 else input_points
											elif return_tensors == "tf":
													_a	: Tuple								=				tf.convert_to_tensor(lowerCamelCase_						)
													# point batch size of 1 by default
													_a	: Optional[int]								=				tf.expand_dims(lowerCamelCase_      ,1						) if len(input_points.shape						) != 4 else input_points
											encoding_image_processor.update({'input_points': input_points}						)
									if input_labels is not None:
											if return_tensors == "pt":
													_a	: str								=				torch.from_numpy(lowerCamelCase_						)
													# point batch size of 1 by default
													_a	: Any								=				input_labels.unsqueeze(1						) if len(input_labels.shape						) != 3 else input_labels
											elif return_tensors == "tf":
													_a	: List[str]								=				tf.convert_to_tensor(lowerCamelCase_						)
													# point batch size of 1 by default
													_a	: str								=				tf.expand_dims(lowerCamelCase_      ,1						) if len(input_labels.shape						) != 3 else input_labels
											encoding_image_processor.update({'input_labels': input_labels}						)

									return encoding_image_processor







							def 				__lowercase     (				self   :			Optional[Any]      ,_UpperCAmelCase   :			Optional[Any]      ,_UpperCAmelCase   :			Union[str, Any]						):
									_a	: Any								=				max([point.shape[0] for point in input_points]						)
									_a	: Optional[int]								=				[]
									for i, point in enumerate(lowerCamelCase_						):
											if point.shape[0] != expected_nb_points:
													_a	: Optional[Any]								=				np.concatenate(
													    [point, np.zeros((expected_nb_points - point.shape[0], 2)						) + self.point_pad_value]      ,axis=0						)
													_a	: Any								=				np.append(input_labels[i]      ,[self.point_pad_value]						)
											processed_input_points.append(lowerCamelCase_						)
									_a	: str								=				processed_input_points
									return input_points, input_labels







							def 				__lowercase     (				self   :			str      ,_UpperCAmelCase   :			int      ,_UpperCAmelCase   :			np.ndarray      ,_UpperCAmelCase   :			Union[str, Any]      ,_UpperCAmelCase   :			int=False						):
									_a	: Dict								=				original_size
									_a	: Union[str, Any]								=				self.image_processor._get_preprocess_shape(lowerCamelCase_      ,longest_edge=lowerCamelCase_						)
									_a	: List[str]								=				deepcopy(lowerCamelCase_						).astype(lowerCamelCase_						)

									if is_bounding_box:
											_a	: int								=				coords.reshape(-1      ,2      ,2						)

									_a	: Any								=				coords[..., 0] * (new_w / old_w)
									_a	: Dict								=				coords[..., 1] * (new_h / old_h)

									if is_bounding_box:
											_a	: int								=				coords.reshape(-1      ,4						)

									return coords







							def 				__lowercase     (				self   :			Tuple      ,_UpperCAmelCase   :			str=None      ,_UpperCAmelCase   :			Dict=None      ,_UpperCAmelCase   :			Tuple=None      ,):
									if input_points is not None:
											if hasattr(lowerCamelCase_      ,'numpy'						):  # Checks for TF or Torch tensor
													_a	: Dict								=				input_points.numpy().tolist()

											if not isinstance(lowerCamelCase_      ,lowerCamelCase_						) or not isinstance(input_points[0]      ,lowerCamelCase_						):
													raise ValueError('Input points must be a list of list of floating points.'						)
											_a	: Optional[int]								=				[np.array(lowerCamelCase_						) for input_point in input_points]
									else:
											_a	: Any								=				None

									if input_labels is not None:
											if hasattr(lowerCamelCase_      ,'numpy'						):
													_a	: str								=				input_labels.numpy().tolist()

											if not isinstance(lowerCamelCase_      ,lowerCamelCase_						) or not isinstance(input_labels[0]      ,lowerCamelCase_						):
													raise ValueError('Input labels must be a list of list integers.'						)
											_a	: Any								=				[np.array(lowerCamelCase_						) for label in input_labels]
									else:
											_a	: Dict								=				None

									if input_boxes is not None:
											if hasattr(lowerCamelCase_      ,'numpy'						):
													_a	: Dict								=				input_boxes.numpy().tolist()

											if (
											    not isinstance(lowerCamelCase_      ,lowerCamelCase_						)
											    or not isinstance(input_boxes[0]      ,lowerCamelCase_						)
											    or not isinstance(input_boxes[0][0]      ,lowerCamelCase_						)
											):
													raise ValueError('Input boxes must be a list of list of list of floating points.'						)
											_a	: Any								=				[np.array(lowerCamelCase_						).astype(np.floataa						) for box in input_boxes]
									else:
											_a	: Optional[int]								=				None

									return input_points, input_labels, input_boxes







							@property
							def 				__lowercase     (				self   :			List[str]						):
									_a	: str								=				self.image_processor.model_input_names
									return list(dict.fromkeys(lowerCamelCase_						)						)







							def 				__lowercase     (				self   :			str      ,*_UpperCAmelCase   :			List[str]      ,**_UpperCAmelCase   :			Optional[Any]						):
									return self.image_processor.post_process_masks(*lowerCamelCase_      ,**lowerCamelCase_						)











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					:


	'''simple docstring'''





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

	def    snake_case__(						self:						Union[str, Any]			):
			lowercase__					:      Any      =		ids_tensor([self.batch_size, self.seq_length],					self.vocab_size			)

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

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

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

			lowercase__					:      Tuple      =		self.get_config()

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

	def    snake_case__(						self:						Tuple			):
			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=lowerCamelCase_,					initializer_range=self.initializer_range,					use_stable_embedding=lowerCamelCase_,					)

	def    snake_case__(						self:						Optional[int],					lowerCamelCase_:						Optional[int],					lowerCamelCase_:						List[Any],					lowerCamelCase_:						List[str],					lowerCamelCase_:						Optional[int],					lowerCamelCase_:						Dict,					lowerCamelCase_:						Optional[int],					lowerCamelCase_:						str			):
			lowercase__					:      Union[str, Any]      =		OpenLlamaModel(config=lowerCamelCase_			)
			model.to(lowerCamelCase_			)
			model.eval()
			lowercase__					:      Union[str, Any]      =		model(lowerCamelCase_,					attention_mask=lowerCamelCase_			)
			lowercase__					:      List[Any]      =		model(lowerCamelCase_			)
			self.parent.assertEqual(result.last_hidden_state.shape,					(self.batch_size, self.seq_length, self.hidden_size)			)

	def    snake_case__(						self:						str,					lowerCamelCase_:						Optional[Any],					lowerCamelCase_:						str,					lowerCamelCase_:						str,					lowerCamelCase_:						Optional[Any],					lowerCamelCase_:						Tuple,					lowerCamelCase_:						Optional[Any],					lowerCamelCase_:						List[str],					lowerCamelCase_:						Dict,					lowerCamelCase_:						Union[str, Any],					):
			lowercase__					:      Tuple      =		True
			lowercase__					:      int      =		OpenLlamaModel(lowerCamelCase_			)
			model.to(lowerCamelCase_			)
			model.eval()
			lowercase__					:      List[Any]      =		model(
			    lowerCamelCase_,					attention_mask=lowerCamelCase_,					encoder_hidden_states=lowerCamelCase_,					encoder_attention_mask=lowerCamelCase_,					)
			lowercase__					:      Optional[int]      =		model(
			    lowerCamelCase_,					attention_mask=lowerCamelCase_,					encoder_hidden_states=lowerCamelCase_,					)
			lowercase__					:      str      =		model(lowerCamelCase_,					attention_mask=lowerCamelCase_			)
			self.parent.assertEqual(result.last_hidden_state.shape,					(self.batch_size, self.seq_length, self.hidden_size)			)

	def    snake_case__(						self:						List[Any],					lowerCamelCase_:						Optional[Any],					lowerCamelCase_:						Any,					lowerCamelCase_:						str,					lowerCamelCase_:						List[str],					lowerCamelCase_:						Any,					lowerCamelCase_:						Dict,					lowerCamelCase_:						int,					lowerCamelCase_:						Any,					lowerCamelCase_:						str,					):
			lowercase__					:      Optional[Any]      =		OpenLlamaForCausalLM(config=lowerCamelCase_			)
			model.to(lowerCamelCase_			)
			model.eval()
			lowercase__					:      List[Any]      =		model(lowerCamelCase_,					attention_mask=lowerCamelCase_,					labels=lowerCamelCase_			)
			self.parent.assertEqual(result.logits.shape,					(self.batch_size, self.seq_length, self.vocab_size)			)

	def    snake_case__(						self:						Tuple,					lowerCamelCase_:						str,					lowerCamelCase_:						Optional[Any],					lowerCamelCase_:						Optional[int],					lowerCamelCase_:						str,					lowerCamelCase_:						List[Any],					lowerCamelCase_:						List[Any],					lowerCamelCase_:						str,					lowerCamelCase_:						Optional[Any],					lowerCamelCase_:						Union[str, Any],					):
			lowercase__					:      Optional[int]      =		True
			lowercase__					:      Optional[int]      =		True
			lowercase__					:      Tuple      =		OpenLlamaForCausalLM(config=lowerCamelCase_			)
			model.to(lowerCamelCase_			)
			model.eval()

			# first forward pass
			lowercase__					:      Any      =		model(
			    lowerCamelCase_,					attention_mask=lowerCamelCase_,					encoder_hidden_states=lowerCamelCase_,					encoder_attention_mask=lowerCamelCase_,					use_cache=lowerCamelCase_,					)
			lowercase__					:      str      =		outputs.past_key_values

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

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

			lowercase__					:      int      =		model(
			    lowerCamelCase_,					attention_mask=lowerCamelCase_,					encoder_hidden_states=lowerCamelCase_,					encoder_attention_mask=lowerCamelCase_,					output_hidden_states=lowerCamelCase_,					)['hidden_states'][0]
			lowercase__					:      int      =		model(
			    lowerCamelCase_,					attention_mask=lowerCamelCase_,					encoder_hidden_states=lowerCamelCase_,					encoder_attention_mask=lowerCamelCase_,					past_key_values=lowerCamelCase_,					output_hidden_states=lowerCamelCase_,					)['hidden_states'][0]

			# select random slice
			lowercase__					:      Tuple      =		ids_tensor((1,),					output_from_past.shape[-1]			).item()
			lowercase__					:      Union[str, Any]      =		output_from_no_past[:, -3:, random_slice_idx].detach()
			lowercase__					:      Tuple      =		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(lowerCamelCase_,					lowerCamelCase_,					atol=1E-3			)			)





	def    snake_case__(						self:						Optional[Any]			):
			lowercase__					:      Dict      =		self.prepare_config_and_inputs()
			(
			    (
			    lowercase__
			)   ,				(
			    lowercase__
			)   ,				(
			    lowercase__
			)   ,				(
			    lowercase__
			)   ,				(
			    lowercase__
			)   ,				(
			    lowercase__
			)   ,				(
			    lowercase__
			)   ,				
			)					:      List[str]      =		config_and_inputs
			lowercase__					:      Any      =		{'input_ids': input_ids, 'attention_mask': input_mask}
			return config, inputs_dict


@require_torch
class       __lowerCAmelCase					(       _UpperCamelCase   ,    _UpperCamelCase   ,    _UpperCamelCase   ,    unittest.TestCase      ):


	'''simple docstring'''





	_A													=				(
	    (OpenLlamaModel, OpenLlamaForCausalLM, OpenLlamaForSequenceClassification) if is_torch_available() else ()
	)
	_A													=				(OpenLlamaForCausalLM,) if is_torch_available() else ()
	_A													=				(
	    {
	        "feature-extraction": OpenLlamaModel,
	        "text-classification": OpenLlamaForSequenceClassification,
	        "text-generation": OpenLlamaForCausalLM,
	        "zero-shot": OpenLlamaForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)
	_A													=				False
	_A													=				False

	def    snake_case__(						self:						Any			):
			lowercase__					:      List[Any]      =		OpenLlamaModelTester(self			)
			lowercase__					:      Dict      =		ConfigTester(self,					config_class=lowerCamelCase_,					hidden_size=37			)

	def    snake_case__(						self:						Any			):
			self.config_tester.run_common_tests()

	def    snake_case__(						self:						Dict			):
			lowercase__					:      Any      =		self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_model(*lowerCamelCase_			)

	def    snake_case__(						self:						str			):
			lowercase__					:      Any      =		self.model_tester.prepare_config_and_inputs()
			for type in ["absolute", "relative_key", "relative_key_query"]:
					lowercase__					:      Dict      =		type
					self.model_tester.create_and_check_model(*lowerCamelCase_			)

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

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

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





	@parameterized.expand([('linear',), ('dynamic',)]			)
	def    snake_case__(						self:						Any,					lowerCamelCase_:						List[Any]			):
			lowercase__   ,				lowercase__					:      Optional[Any]      =		self.model_tester.prepare_config_and_inputs_for_common()
			lowercase__					:      Optional[int]      =		ids_tensor([1, 10],					config.vocab_size			)
			lowercase__					:      Optional[Any]      =		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__					:      str      =		OpenLlamaModel(lowerCamelCase_			)
			original_model.to(lowerCamelCase_			)
			original_model.eval()
			lowercase__					:      Union[str, Any]      =		original_model(lowerCamelCase_			).last_hidden_state
			lowercase__					:      List[str]      =		original_model(lowerCamelCase_			).last_hidden_state

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

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


