


'''simple docstring'''
import importlib
import json
import os
from collections import OrderedDict
from typing import Dict, Optional, Union

# Build the list of all feature extractors
from ...configuration_utils import PretrainedConfig
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
from ...feature_extraction_utils import FeatureExtractionMixin
from ...utils import CONFIG_NAME, FEATURE_EXTRACTOR_NAME, get_file_from_repo, logging
from .auto_factory import _LazyAutoMapping
from .configuration_auto import (
    CONFIG_MAPPING_NAMES,
    AutoConfig,
    model_type_to_module_name,
    replace_list_option_in_docstrings,
)


UpperCAmelCase_ :     Union[str, Any]								=      logging.get_logger(__name__)

UpperCAmelCase_ :     Optional[Any]								=      OrderedDict(
    [
        ('audio-spectrogram-transformer', 'ASTFeatureExtractor'),
        ('beit', 'BeitFeatureExtractor'),
        ('chinese_clip', 'ChineseCLIPFeatureExtractor'),
        ('clap', 'ClapFeatureExtractor'),
        ('clip', 'CLIPFeatureExtractor'),
        ('clipseg', 'ViTFeatureExtractor'),
        ('conditional_detr', 'ConditionalDetrFeatureExtractor'),
        ('convnext', 'ConvNextFeatureExtractor'),
        ('cvt', 'ConvNextFeatureExtractor'),
        ('data2vec-audio', 'Wav2Vec2FeatureExtractor'),
        ('data2vec-vision', 'BeitFeatureExtractor'),
        ('deformable_detr', 'DeformableDetrFeatureExtractor'),
        ('deit', 'DeiTFeatureExtractor'),
        ('detr', 'DetrFeatureExtractor'),
        ('dinat', 'ViTFeatureExtractor'),
        ('donut-swin', 'DonutFeatureExtractor'),
        ('dpt', 'DPTFeatureExtractor'),
        ('encodec', 'EncodecFeatureExtractor'),
        ('flava', 'FlavaFeatureExtractor'),
        ('glpn', 'GLPNFeatureExtractor'),
        ('groupvit', 'CLIPFeatureExtractor'),
        ('hubert', 'Wav2Vec2FeatureExtractor'),
        ('imagegpt', 'ImageGPTFeatureExtractor'),
        ('layoutlmv2', 'LayoutLMv2FeatureExtractor'),
        ('layoutlmv3', 'LayoutLMv3FeatureExtractor'),
        ('levit', 'LevitFeatureExtractor'),
        ('maskformer', 'MaskFormerFeatureExtractor'),
        ('mctct', 'MCTCTFeatureExtractor'),
        ('mobilenet_v1', 'MobileNetV1FeatureExtractor'),
        ('mobilenet_v2', 'MobileNetV2FeatureExtractor'),
        ('mobilevit', 'MobileViTFeatureExtractor'),
        ('nat', 'ViTFeatureExtractor'),
        ('owlvit', 'OwlViTFeatureExtractor'),
        ('perceiver', 'PerceiverFeatureExtractor'),
        ('poolformer', 'PoolFormerFeatureExtractor'),
        ('regnet', 'ConvNextFeatureExtractor'),
        ('resnet', 'ConvNextFeatureExtractor'),
        ('segformer', 'SegformerFeatureExtractor'),
        ('sew', 'Wav2Vec2FeatureExtractor'),
        ('sew-d', 'Wav2Vec2FeatureExtractor'),
        ('speech_to_text', 'Speech2TextFeatureExtractor'),
        ('speecht5', 'SpeechT5FeatureExtractor'),
        ('swiftformer', 'ViTFeatureExtractor'),
        ('swin', 'ViTFeatureExtractor'),
        ('swinv2', 'ViTFeatureExtractor'),
        ('table-transformer', 'DetrFeatureExtractor'),
        ('timesformer', 'VideoMAEFeatureExtractor'),
        ('tvlt', 'TvltFeatureExtractor'),
        ('unispeech', 'Wav2Vec2FeatureExtractor'),
        ('unispeech-sat', 'Wav2Vec2FeatureExtractor'),
        ('van', 'ConvNextFeatureExtractor'),
        ('videomae', 'VideoMAEFeatureExtractor'),
        ('vilt', 'ViltFeatureExtractor'),
        ('vit', 'ViTFeatureExtractor'),
        ('vit_mae', 'ViTFeatureExtractor'),
        ('vit_msn', 'ViTFeatureExtractor'),
        ('wav2vec2', 'Wav2Vec2FeatureExtractor'),
        ('wav2vec2-conformer', 'Wav2Vec2FeatureExtractor'),
        ('wavlm', 'Wav2Vec2FeatureExtractor'),
        ('whisper', 'WhisperFeatureExtractor'),
        ('xclip', 'CLIPFeatureExtractor'),
        ('yolos', 'YolosFeatureExtractor'),
    ]
)

UpperCAmelCase_ :     int								=      _LazyAutoMapping(CONFIG_MAPPING_NAMES, FEATURE_EXTRACTOR_MAPPING_NAMES)


def 			_lowercase       (				UpperCamelCase__       :					str			):
 for module_name, extractors in FEATURE_EXTRACTOR_MAPPING_NAMES.items():
  if class_name in extractors:
   __A  :		Optional[Any]       =			model_type_to_module_name(UpperCamelCase__			)

   __A  :		str       =			importlib.import_module(f""".{module_name}""",				'transformers.models'			)
   try:
    return getattr(UpperCamelCase__,				UpperCamelCase__			)
   except AttributeError:
    continue

 for _, extractor in FEATURE_EXTRACTOR_MAPPING._extra_content.items():
  if getattr(UpperCamelCase__,				'__name__',				UpperCamelCase__			) == class_name:
   return extractor

    # We did not fine the class, but maybe it's because a dep is missing. In that case, the class will be in the main
    # init and we return the proper dummy to get an appropriate error message.
 __A  :		List[Any]       =			importlib.import_module('transformers'			)
 if hasattr(UpperCamelCase__,				UpperCamelCase__			):
  return getattr(UpperCamelCase__,				UpperCamelCase__			)

 return None


def 			_lowercase       (				UpperCamelCase__       :					Union[str, os.PathLike],				UpperCamelCase__       :					Optional[Union[str, os.PathLike]] = None,				UpperCamelCase__       :					bool = False,				UpperCamelCase__       :					bool = False,				UpperCamelCase__       :					Optional[Dict[str, str]] = None,				UpperCamelCase__       :					Optional[Union[bool, str]] = None,				UpperCamelCase__       :					Optional[str] = None,				UpperCamelCase__       :					bool = False,				**UpperCamelCase__       :					Tuple,				):
 __A  :		int       =			get_file_from_repo(
     UpperCamelCase__,				UpperCamelCase__,				cache_dir=UpperCamelCase__,				force_download=UpperCamelCase__,				resume_download=UpperCamelCase__,				proxies=UpperCamelCase__,				use_auth_token=UpperCamelCase__,				revision=UpperCamelCase__,				local_files_only=UpperCamelCase__,				)
 if resolved_config_file is None:
  logger.info(
      'Could not locate the feature extractor configuration file, will try to use the model config instead.'			)
  return {}

 with open(UpperCamelCase__,				encoding='utf-8'			) as reader:
  return json.load(UpperCamelCase__			)


class 						_lowerCamelCase					:




 '''simple docstring'''


 def __init__(      self						):

  """simple docstring"""







  raise EnvironmentError(
      'AutoFeatureExtractor is designed to be instantiated '
      'using the `AutoFeatureExtractor.from_pretrained(pretrained_model_name_or_path)` method.'						)


 @classmethod
 @replace_list_option_in_docstrings(__lowercase						)
 def  snake_case__   (      cls      ,      __lowercase      ,      **__lowercase						):

  """simple docstring"""







  __A  :		Optional[Any]       =			kwargs.pop('config'      ,      __lowercase						)
  __A  :		List[Any]       =			kwargs.pop('trust_remote_code'      ,      __lowercase						)
  __A  :		Union[str, Any]       =			True

  __A     ,__A  :		Tuple       =			FeatureExtractionMixin.get_feature_extractor_dict(__lowercase      ,      **__lowercase						)
  __A  :		List[str]       =			config_dict.get('feature_extractor_type'      ,      __lowercase						)
  __A  :		Dict       =			None
  if "AutoFeatureExtractor" in config_dict.get('auto_map'      ,      {}						):
   __A  :		List[Any]       =			config_dict['auto_map']['AutoFeatureExtractor']

  # If we don't find the feature extractor class in the feature extractor config, let's try the model config.
  if feature_extractor_class is None and feature_extractor_auto_map is None:
   if not isinstance(__lowercase      ,      __lowercase						):
    __A  :		Any       =			AutoConfig.from_pretrained(__lowercase      ,      **__lowercase						)
   # It could be in `config.feature_extractor_type``
   __A  :		Dict       =			getattr(__lowercase      ,      'feature_extractor_type'      ,      __lowercase						)
   if hasattr(__lowercase      ,      'auto_map'						) and "AutoFeatureExtractor" in config.auto_map:
    __A  :		Union[str, Any]       =			config.auto_map['AutoFeatureExtractor']

  if feature_extractor_class is not None:
   __A  :		Tuple       =			feature_extractor_class_from_name(__lowercase						)

  __A  :		Optional[Any]       =			feature_extractor_auto_map is not None
  __A  :		Union[str, Any]       =			feature_extractor_class is not None or type(__lowercase						) in FEATURE_EXTRACTOR_MAPPING
  __A  :		Tuple       =			resolve_trust_remote_code(
      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase						)

  if has_remote_code and trust_remote_code:
   __A  :		Optional[int]       =			get_class_from_dynamic_module(
       __lowercase      ,      __lowercase      ,      **__lowercase						)
   __A  :		Union[str, Any]       =			kwargs.pop('code_revision'      ,      __lowercase						)
   if os.path.isdir(__lowercase						):
    feature_extractor_class.register_for_auto_class()
   return feature_extractor_class.from_dict(__lowercase      ,      **__lowercase						)
  elif feature_extractor_class is not None:
   return feature_extractor_class.from_dict(__lowercase      ,      **__lowercase						)
  # Last try: we use the FEATURE_EXTRACTOR_MAPPING.
  elif type(__lowercase						) in FEATURE_EXTRACTOR_MAPPING:
   __A  :		Any       =			FEATURE_EXTRACTOR_MAPPING[type(__lowercase						)]
   return feature_extractor_class.from_dict(__lowercase      ,      **__lowercase						)

  raise ValueError(
      F"""Unrecognized feature extractor in {pretrained_model_name_or_path}. Should have a """
      F"""`feature_extractor_type` key in its {FEATURE_EXTRACTOR_NAME} of {CONFIG_NAME}, or one of the following """
      F"""`model_type` keys in its {CONFIG_NAME}: {', '.join(c for c in FEATURE_EXTRACTOR_MAPPING_NAMES.keys()						)}"""						)







 @staticmethod
 def  snake_case__   (      __lowercase      ,      __lowercase						):

  """simple docstring"""







  FEATURE_EXTRACTOR_MAPPING.register(__lowercase      ,      __lowercase						)










'''simple docstring'''
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      ,      __lowercase      ,      __lowercase=13      ,      __lowercase=7      ,      __lowercase=True      ,      __lowercase=True      ,      __lowercase=False      ,      __lowercase=True      ,      __lowercase=99      ,      __lowercase=32      ,      __lowercase=5      ,      __lowercase=4      ,      __lowercase=37      ,      __lowercase="gelu"      ,      __lowercase=0.1      ,      __lowercase=0.1      ,      __lowercase=512      ,      __lowercase=16      ,      __lowercase=2      ,      __lowercase=0.0_2      ,      __lowercase=3      ,      __lowercase=4      ,      __lowercase=None      ,      ):

  """simple docstring"""







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


 def  snake_case__   (      self						):

  """simple docstring"""







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

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

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

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

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

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


 def  snake_case__   (      self						):

  """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=__lowercase      ,      initializer_range=self.initializer_range      ,      use_stable_embedding=__lowercase      ,      )


 def  snake_case__   (      self      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase						):

  """simple docstring"""







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


 def  snake_case__   (      self      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      ):

  """simple docstring"""







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


 def  snake_case__   (      self      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      ):

  """simple docstring"""







  __A  :		Dict       =			OpenLlamaForCausalLM(config=__lowercase						)
  model.to(__lowercase						)
  model.eval()
  __A  :		Optional[Any]       =			model(__lowercase      ,      attention_mask=__lowercase      ,      labels=__lowercase						)
  self.parent.assertEqual(result.logits.shape      ,      (self.batch_size, self.seq_length, self.vocab_size)						)


 def  snake_case__   (      self      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      __lowercase      ,      ):

  """simple docstring"""







  __A  :		List[Any]       =			True
  __A  :		Optional[int]       =			True
  __A  :		Dict       =			OpenLlamaForCausalLM(config=__lowercase						)
  model.to(__lowercase						)
  model.eval()

  # first forward pass
  __A  :		List[str]       =			model(
      __lowercase      ,      attention_mask=__lowercase      ,      encoder_hidden_states=__lowercase      ,      encoder_attention_mask=__lowercase      ,      use_cache=__lowercase      ,      )
  __A  :		Optional[Any]       =			outputs.past_key_values

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

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

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

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







 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		int       =			self.prepare_config_and_inputs()
  (
      (
      __A
  )     ,(
      __A
  )     ,(
      __A
  )     ,(
      __A
  )     ,(
      __A
  )     ,(
      __A
  )     ,(
      __A
  )     ,
  )  :		Optional[Any]       =			config_and_inputs
  __A  :		Optional[int]       =			{'input_ids': input_ids, 'attention_mask': input_mask}
  return config, inputs_dict


@require_torch
class 						_lowerCamelCase					(    snake_case_    ,		snake_case_    ,		snake_case_    ,		unittest.TestCase				):




 '''simple docstring'''
 __lowercase				:		List[str]    							=						(
     (OpenLlamaModel, OpenLlamaForCausalLM, OpenLlamaForSequenceClassification) if is_torch_available() else ()
 )
 __lowercase				:		List[Any]    							=						(OpenLlamaForCausalLM,) if is_torch_available() else ()
 __lowercase				:		Optional[int]    							=						(
     {
         '''feature-extraction''': OpenLlamaModel,
         '''text-classification''': OpenLlamaForSequenceClassification,
         '''text-generation''': OpenLlamaForCausalLM,
         '''zero-shot''': OpenLlamaForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 __lowercase				:		Union[str, Any]    							=						False
 __lowercase				:		Union[str, Any]    							=						False


 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		Optional[int]       =			OpenLlamaModelTester(self						)
  __A  :		List[str]       =			ConfigTester(self      ,      config_class=__lowercase      ,      hidden_size=37						)


 def  snake_case__   (      self						):

  """simple docstring"""







  self.config_tester.run_common_tests()


 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		int       =			self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_model(*__lowercase						)


 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		int       =			self.model_tester.prepare_config_and_inputs()
  for type in ["absolute", "relative_key", "relative_key_query"]:
   __A  :		List[str]       =			type
   self.model_tester.create_and_check_model(*__lowercase						)


 def  snake_case__   (      self						):

  """simple docstring"""







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


 def  snake_case__   (      self						):

  """simple docstring"""







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


 def  snake_case__   (      self						):

  """simple docstring"""







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

  """simple docstring"""







  pass







 @parameterized.expand([('linear',), ('dynamic',)]						)
 def  snake_case__   (      self      ,      __lowercase						):

  """simple docstring"""







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

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

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






