





import copy
import json
import os
import tempfile

from transformers import is_torch_available

from .test_configuration_utils import config_common_kwargs



class 				_UpperCAmelCase    (    _UpperCAmelCase    ):

  """simple docstring"""


  def __init__(				self :		Optional[Any]					,  lowerCAmelCase_ :		List[str]					,  lowerCAmelCase_ :		int=None					,  lowerCAmelCase_ :		Tuple=True					,  lowerCAmelCase_ :		int=None					,  **lowerCAmelCase_ :		Tuple     )							->						Union[str, Any]:
     __lowerCAmelCase								=	parent
     __lowerCAmelCase								=	config_class
     __lowerCAmelCase								=	has_text_modality
     __lowerCAmelCase								=	kwargs
     __lowerCAmelCase								=	common_properties






  def 				lowercase		(				self :		int     )							->						List[Any]:
     __lowerCAmelCase								=	self.config_class(**self.inputs_dict     )
     __lowerCAmelCase								=	(
         ['hidden_size', 'num_attention_heads', 'num_hidden_layers']
         if self.common_properties is None
         else self.common_properties
     )

     # Add common fields for text models
     if self.has_text_modality:
        common_properties.extend(['vocab_size']     )

     # Test that config has the common properties as getters
     for prop in common_properties:
        self.parent.assertTrue(hasattr(SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_     )					,  msg=f"""`{prop}` does not exist"""     )

     # Test that config has the common properties as setter
     for idx, name in enumerate(SCREAMING_SNAKE_CASE_     ):
        try:
           setattr(SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_     )
           self.parent.assertEqual(
               getattr(SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_     )					,  SCREAMING_SNAKE_CASE_					,  msg=f"""`{name} value {idx} expected, but was {getattr(SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_     )}"""     )
        except NotImplementedError:
           # Some models might not be able to implement setters for common_properties
           # In that case, a NotImplementedError is raised
           pass

        # Test if config class can be called with Config(prop_name=..)
     for idx, name in enumerate(SCREAMING_SNAKE_CASE_     ):
        try:
           __lowerCAmelCase								=	self.config_class(**{name: idx}     )
           self.parent.assertEqual(
               getattr(SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_     )					,  SCREAMING_SNAKE_CASE_					,  msg=f"""`{name} value {idx} expected, but was {getattr(SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_     )}"""     )
        except NotImplementedError:
           # Some models might not be able to implement setters for common_properties
           # In that case, a NotImplementedError is raised
           pass






  def 				lowercase		(				self :		Dict     )							->						List[str]:
     __lowerCAmelCase								=	self.config_class(**self.inputs_dict     )
     __lowerCAmelCase								=	json.loads(config.to_json_string()     )
     for key, value in self.inputs_dict.items():
        self.parent.assertEqual(obj[key]					,  SCREAMING_SNAKE_CASE_     )






  def 				lowercase		(				self :		Dict     )							->						str:
     __lowerCAmelCase								=	self.config_class(**self.inputs_dict     )

     with tempfile.TemporaryDirectory() as tmpdirname:
        __lowerCAmelCase								=	os.path.join(SCREAMING_SNAKE_CASE_					,  'config.json'     )
        config_first.to_json_file(SCREAMING_SNAKE_CASE_     )
        __lowerCAmelCase								=	self.config_class.from_json_file(SCREAMING_SNAKE_CASE_     )

     self.parent.assertEqual(config_second.to_dict()					,  config_first.to_dict()     )






  def 				lowercase		(				self :		Optional[int]     )							->						List[Any]:
     __lowerCAmelCase								=	self.config_class(**self.inputs_dict     )

     with tempfile.TemporaryDirectory() as tmpdirname:
        config_first.save_pretrained(SCREAMING_SNAKE_CASE_     )
        __lowerCAmelCase								=	self.config_class.from_pretrained(SCREAMING_SNAKE_CASE_     )

     self.parent.assertEqual(config_second.to_dict()					,  config_first.to_dict()     )






  def 				lowercase		(				self :		List[str]     )							->						List[str]:
     __lowerCAmelCase								=	self.config_class(**self.inputs_dict     )

     __lowerCAmelCase								=	'test'
     with tempfile.TemporaryDirectory() as tmpdirname:
        __lowerCAmelCase								=	os.path.join(SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_     )
        config_first.save_pretrained(SCREAMING_SNAKE_CASE_     )
        __lowerCAmelCase								=	self.config_class.from_pretrained(SCREAMING_SNAKE_CASE_					,  subfolder=SCREAMING_SNAKE_CASE_     )

     self.parent.assertEqual(config_second.to_dict()					,  config_first.to_dict()     )






  def 				lowercase		(				self :		Dict     )							->						List[str]:
     __lowerCAmelCase								=	self.config_class(**self.inputs_dict					,  num_labels=5     )
     self.parent.assertEqual(len(config.idalabel     )					,  5     )
     self.parent.assertEqual(len(config.labelaid     )					,  5     )

     __lowerCAmelCase								=	3
     self.parent.assertEqual(len(config.idalabel     )					,  3     )
     self.parent.assertEqual(len(config.labelaid     )					,  3     )






  def 				lowercase		(				self :		Dict     )							->						Any:
     if self.config_class.is_composition:
        return
     __lowerCAmelCase								=	self.config_class()
     self.parent.assertIsNotNone(SCREAMING_SNAKE_CASE_     )






  def 				lowercase		(				self :		List[str]     )							->						Optional[int]:
     __lowerCAmelCase								=	copy.deepcopy(SCREAMING_SNAKE_CASE_     )
     __lowerCAmelCase								=	self.config_class(**SCREAMING_SNAKE_CASE_     )
     __lowerCAmelCase								=	[]
     for key, value in config_common_kwargs.items():
        if key == "torch_dtype":
           if not is_torch_available():
              continue
           else:
              import torch

              if config.torch_dtype != torch.floataa:
                 wrong_values.append(('torch_dtype', config.torch_dtype, torch.floataa)     )
        elif getattr(SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_     ) != value:
           wrong_values.append((key, getattr(SCREAMING_SNAKE_CASE_					,  SCREAMING_SNAKE_CASE_     ), value)     )

     if len(SCREAMING_SNAKE_CASE_     ) > 0:
        __lowerCAmelCase								=	'\n'.join([f"""- {v[0]}: got {v[1]} instead of {v[2]}""" for v in wrong_values]     )
        raise ValueError(f"""The following keys were not properly set in the config:\n{errors}"""     )






  def 				lowercase		(				self :		int     )							->						Optional[Any]:
     self.create_and_test_config_common_properties()
     self.create_and_test_config_to_json_string()
     self.create_and_test_config_to_json_file()
     self.create_and_test_config_from_and_save_pretrained()
     self.create_and_test_config_from_and_save_pretrained_subfolder()
     self.create_and_test_config_with_num_labels()
     self.check_config_can_be_init_without_params()
     self.check_config_arguments_init()





'''simple docstring'''



from . import (
    albert,
    align,
    altclip,
    audio_spectrogram_transformer,
    auto,
    autoformer,
    bark,
    bart,
    barthez,
    bartpho,
    beit,
    bert,
    bert_generation,
    bert_japanese,
    bertweet,
    big_bird,
    bigbird_pegasus,
    biogpt,
    bit,
    blenderbot,
    blenderbot_small,
    blip,
    blip_a,
    bloom,
    bridgetower,
    byta,
    camembert,
    canine,
    chinese_clip,
    clap,
    clip,
    clipseg,
    codegen,
    conditional_detr,
    convbert,
    convnext,
    convnextva,
    cpm,
    cpmant,
    ctrl,
    cvt,
    dataavec,
    deberta,
    deberta_va,
    decision_transformer,
    deformable_detr,
    deit,
    deprecated,
    deta,
    detr,
    dialogpt,
    dinat,
    distilbert,
    dit,
    donut,
    dpr,
    dpt,
    efficientformer,
    efficientnet,
    electra,
    encodec,
    encoder_decoder,
    ernie,
    ernie_m,
    esm,
    falcon,
    flaubert,
    flava,
    fnet,
    focalnet,
    fsmt,
    funnel,
    git,
    glpn,
    gpta,
    gpt_bigcode,
    gpt_neo,
    gpt_neox,
    gpt_neox_japanese,
    gpt_swa,
    gptj,
    gptsan_japanese,
    graphormer,
    groupvit,
    herbert,
    hubert,
    ibert,
    imagegpt,
    informer,
    instructblip,
    jukebox,
    layoutlm,
    layoutlmva,
    layoutlmva,
    layoutxlm,
    led,
    levit,
    lilt,
    llama,
    longformer,
    longta,
    luke,
    lxmert,
    mam_aaa,
    marian,
    markuplm,
    maskaformer,
    maskformer,
    mbart,
    mbartaa,
    mega,
    megatron_bert,
    megatron_gpta,
    mgp_str,
    mluke,
    mobilebert,
    mobilenet_va,
    mobilenet_va,
    mobilevit,
    mobilevitva,
    mpnet,
    mra,
    mta,
    musicgen,
    mvp,
    nat,
    nezha,
    nllb,
    nllb_moe,
    nystromformer,
    oneformer,
    open_llama,
    openai,
    opt,
    owlvit,
    pegasus,
    pegasus_x,
    perceiver,
    phobert,
    pixastruct,
    plbart,
    poolformer,
    prophetnet,
    qdqbert,
    rag,
    realm,
    reformer,
    regnet,
    rembert,
    resnet,
    roberta,
    roberta_prelayernorm,
    roc_bert,
    roformer,
    rwkv,
    sam,
    segformer,
    sew,
    sew_d,
    speech_encoder_decoder,
    speech_to_text,
    speech_to_text_a,
    speechta,
    splinter,
    squeezebert,
    swiftformer,
    swin,
    swinasr,
    swinva,
    switch_transformers,
    ta,
    table_transformer,
    tapas,
    time_series_transformer,
    timesformer,
    timm_backbone,
    transfo_xl,
    trocr,
    tvlt,
    umta,
    unispeech,
    unispeech_sat,
    upernet,
    videomae,
    vilt,
    vision_encoder_decoder,
    vision_text_dual_encoder,
    visual_bert,
    vit,
    vit_hybrid,
    vit_mae,
    vit_msn,
    vivit,
    wavaveca,
    wavaveca_conformer,
    wavaveca_phoneme,
    wavaveca_with_lm,
    wavlm,
    whisper,
    x_clip,
    xglm,
    xlm,
    xlm_prophetnet,
    xlm_roberta,
    xlm_roberta_xl,
    xlnet,
    xmod,
    yolos,
    yoso,
)






