U
    4Af                  )  @   s  d Z ddlZddlZddlZddlZddlmZ ddlmZm	Z	 ddl
mZ ddlmZmZ ddlmZmZ eeZed	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd ddddddddd	d
ddddddgZedddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddÐdĐdŐdƐdǐdȐdɐdʐdːd̐d͐dΐdϐdАdѐdҐdӐdԐdՐd֐dאdؐdِdڐdېdܐdݐdސdߐddddddddddddddddddddddddddddddddd ddddddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8g(Zd9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPgZedQdRdSdTdUdVdWdXdYdZd[d\gZd]d^ Zd_d` ZG dadb dbeZeeZG dcdd ddeZe	eee f dedfdgZdodidjZ dpdkdlZ!G dmdn dnZ"dS (q  zAuto Config class.    N)OrderedDict)ListUnion   )PretrainedConfig)get_class_from_dynamic_moduleresolve_trust_remote_code)CONFIG_NAMElogging)albertZAlbertConfig)alignZAlignConfig)altclipZAltCLIPConfig)audio-spectrogram-transformerZ	ASTConfig)
autoformerZAutoformerConfig)barkZ
BarkConfig)bartZ
BartConfig)beitZ
BeitConfig)bertZ
BertConfig)bert-generationZBertGenerationConfig)big_birdZBigBirdConfig)bigbird_pegasusZBigBirdPegasusConfig)biogptZBioGptConfig)bitZ	BitConfig)
blenderbotZBlenderbotConfig)blenderbot-smallZBlenderbotSmallConfig)blipZ
BlipConfig)blip-2ZBlip2Config)bloomZBloomConfig)bridgetowerZBridgeTowerConfig)brosZ
BrosConfig)	camembertZCamembertConfig)canineZCanineConfig)	chameleonZChameleonConfig)chinese_clipZChineseCLIPConfig)chinese_clip_vision_modelZChineseCLIPVisionConfig)clapZ
ClapConfig)clipZ
CLIPConfig)clip_vision_modelZCLIPVisionConfig)clipsegZCLIPSegConfig)clvpZ
ClvpConfig)
code_llamaLlamaConfig)codegenZCodeGenConfig)cohereZCohereConfig)conditional_detrZConditionalDetrConfig)convbertZConvBertConfig)convnextZConvNextConfig)
convnextv2ZConvNextV2Config)cpmantZCpmAntConfig)ctrlZ
CTRLConfig)cvtZ	CvtConfig)data2vec-audioZData2VecAudioConfig)data2vec-textZData2VecTextConfig)data2vec-visionZData2VecVisionConfig)dbrxZ
DbrxConfig)debertaZDebertaConfig)
deberta-v2ZDebertaV2Config)decision_transformerZDecisionTransformerConfig)deformable_detrZDeformableDetrConfig)deitZ
DeiTConfig)depth_anythingZDepthAnythingConfig)detaZ
DetaConfig)detrZ
DetrConfig)dinatZDinatConfig)dinov2ZDinov2Config)
distilbertZDistilBertConfig)
donut-swinZDonutSwinConfig)dprZ	DPRConfig)dptZ	DPTConfig)efficientformerZEfficientFormerConfig)efficientnetZEfficientNetConfig)electraZElectraConfig)encodecZEncodecConfig)encoder-decoderZEncoderDecoderConfig)ernieZErnieConfig)ernie_mZErnieMConfig)esmZ	EsmConfig)falconZFalconConfig)fastspeech2_conformerZFastSpeech2ConformerConfig)flaubertZFlaubertConfig)flavaZFlavaConfig)fnetZ
FNetConfig)focalnetZFocalNetConfig)fsmtZ
FSMTConfig)funnelZFunnelConfig)fuyuZ
FuyuConfig)gemmaZGemmaConfig)gemma2ZGemma2Config)gitZ	GitConfig)glpnZ
GLPNConfig)gpt-sw3
GPT2Config)gpt2r]   )gpt_bigcodeZGPTBigCodeConfig)gpt_neoZGPTNeoConfig)gpt_neoxZGPTNeoXConfig)gpt_neox_japaneseZGPTNeoXJapaneseConfig)gptjZ
GPTJConfig)gptsan-japaneseZGPTSanJapaneseConfig)
graphormerZGraphormerConfig)grounding-dinoZGroundingDinoConfig)groupvitZGroupViTConfig)hieraZHieraConfig)hubertZHubertConfig)ibertZIBertConfig)ideficsZIdeficsConfig)idefics2ZIdefics2Config)imagegptZImageGPTConfig)informerZInformerConfig)instructblipZInstructBlipConfig)instructblipvideoZInstructBlipVideoConfig)jambaZJambaConfig)jetmoeZJetMoeConfig)jukeboxZJukeboxConfig)kosmos-2ZKosmos2Config)layoutlmZLayoutLMConfig)
layoutlmv2ZLayoutLMv2Config)
layoutlmv3ZLayoutLMv3Config)ledZ	LEDConfig)levitZLevitConfig)liltZ
LiltConfig)llamar+   )llavaZLlavaConfig)llava-next-videoZLlavaNextVideoConfig)
llava_nextZLlavaNextConfig)
longformerZLongformerConfig)longt5ZLongT5Config)lukeZ
LukeConfig)lxmertZLxmertConfig)m2m_100ZM2M100Config)mambaZMambaConfig)mamba2ZMamba2Config)marianZMarianConfig)markuplmZMarkupLMConfig)mask2formerZMask2FormerConfig)
maskformerZMaskFormerConfig)maskformer-swinZMaskFormerSwinConfig)mbartZMBartConfig)mctctZMCTCTConfig)megaZ
MegaConfig)megatron-bertZMegatronBertConfig)mgp-strZMgpstrConfig)mistralZMistralConfig)mixtralZMixtralConfig)
mobilebertZMobileBertConfig)mobilenet_v1ZMobileNetV1Config)mobilenet_v2ZMobileNetV2Config)	mobilevitZMobileViTConfig)mobilevitv2ZMobileViTV2Config)mpnetZMPNetConfig)mptZ	MptConfig)mraZ	MraConfig)mt5Z	MT5Config)musicgenZMusicgenConfig)musicgen_melodyZMusicgenMelodyConfig)mvpZ	MvpConfig)natZ	NatConfig)nemotronZNemotronConfig)nezhaZNezhaConfig)nllb-moeZNllbMoeConfig)nougatVisionEncoderDecoderConfig)nystromformerZNystromformerConfig)olmoZ
OlmoConfig)	oneformerZOneFormerConfig)
open-llamaZOpenLlamaConfig)
openai-gptZOpenAIGPTConfig)optZ	OPTConfig)owlv2ZOwlv2Config)owlvitZOwlViTConfig)	paligemmaZPaliGemmaConfig)patchtsmixerZPatchTSMixerConfig)patchtstZPatchTSTConfig)pegasusZPegasusConfig)	pegasus_xZPegasusXConfig)	perceiverZPerceiverConfig)	persimmonZPersimmonConfig)phiZ	PhiConfig)phi3Z
Phi3Config)
pix2structZPix2StructConfig)plbartZPLBartConfig)
poolformerZPoolFormerConfig)	pop2pianoZPop2PianoConfig)
prophetnetZProphetNetConfig)pvtZ	PvtConfig)pvt_v2ZPvtV2Config)qdqbertZQDQBertConfig)qwen2ZQwen2Config)	qwen2_moeZQwen2MoeConfig)ragZ	RagConfig)realmZRealmConfig)recurrent_gemmaZRecurrentGemmaConfig)reformerZReformerConfig)regnetZRegNetConfig)rembertZRemBertConfig)resnetZResNetConfig)	retribertZRetriBertConfig)robertaZRobertaConfig)roberta-prelayernormZRobertaPreLayerNormConfig)roc_bertZRoCBertConfig)roformerZRoFormerConfig)rt_detrZRTDetrConfig)rt_detr_resnetZRTDetrResNetConfig)rwkvZ
RwkvConfig)samZ	SamConfig)seamless_m4tZSeamlessM4TConfig)seamless_m4t_v2ZSeamlessM4Tv2Config)	segformerZSegformerConfig)seggptZSegGptConfig)sewZ	SEWConfig)sew-dZ
SEWDConfig)siglipZSiglipConfig)siglip_vision_modelZSiglipVisionConfig)speech-encoder-decoderZSpeechEncoderDecoderConfig)speech_to_textZSpeech2TextConfig)speech_to_text_2ZSpeech2Text2Config)speecht5ZSpeechT5Config)splinterZSplinterConfig)squeezebertZSqueezeBertConfig)stablelmZStableLmConfig)
starcoder2ZStarcoder2Config)
superpointZSuperPointConfig)swiftformerZSwiftFormerConfig)swinZ
SwinConfig)swin2srZSwin2SRConfig)swinv2ZSwinv2Config)switch_transformersZSwitchTransformersConfig)t5ZT5Config)table-transformerZTableTransformerConfig)tapasZTapasConfig)time_series_transformerZTimeSeriesTransformerConfig)timesformerZTimesformerConfig)timm_backboneZTimmBackboneConfig)trajectory_transformerZTrajectoryTransformerConfig)
transfo-xlZTransfoXLConfig)trocrZTrOCRConfig)tvltZ
TvltConfig)tvpZ	TvpConfig)udopZ
UdopConfig)umt5Z
UMT5Config)	unispeechZUniSpeechConfig)unispeech-satZUniSpeechSatConfig)univnetZUnivNetConfig)upernetZUperNetConfig)vanZ	VanConfig)video_llavaZVideoLlavaConfig)videomaeZVideoMAEConfig)viltZ
ViltConfig)vipllavaZVipLlavaConfig)vision-encoder-decoderr   )vision-text-dual-encoderZVisionTextDualEncoderConfig)visual_bertZVisualBertConfig)vitZ	ViTConfig)
vit_hybridZViTHybridConfig)vit_maeZViTMAEConfig)vit_msnZViTMSNConfig)vitdetZVitDetConfig)vitmatteZVitMatteConfig)vitsZ
VitsConfig)vivitZVivitConfig)wav2vec2ZWav2Vec2Config)wav2vec2-bertZWav2Vec2BertConfig)wav2vec2-conformerZWav2Vec2ConformerConfig)wavlmZWavLMConfig)whisperZWhisperConfig)xclipZXCLIPConfig)xglmZ
XGLMConfig)xlmZ	XLMConfig)xlm-prophetnetZXLMProphetNetConfig)xlm-robertaZXLMRobertaConfig)xlm-roberta-xlZXLMRobertaXLConfig)xlnetZXLNetConfig)xmodZ
XmodConfig)yolosZYolosConfig)yosoZ
YosoConfig)zoedepthZZoeDepthConfig)r   ZALBERT)r   ZALIGN)r   ZAltCLIP)r   zAudio Spectrogram Transformer)r   Z
Autoformer)r   ZBark)r   ZBART)ZbarthezZBARThez)ZbartphoZBARTpho)r   ZBEiT)r   ZBERT)r   zBert Generation)zbert-japaneseZBertJapanese)ZbertweetZBERTweet)r   ZBigBird)r   zBigBird-Pegasus)r   ZBioGpt)r   ZBiT)r   Z
Blenderbot)r   ZBlenderbotSmall)r   ZBLIP)r   zBLIP-2)r   ZBLOOM)bortZBORT)r   ZBridgeTower)r   ZBROS)Zbyt5ZByT5)r    Z	CamemBERT)r!   ZCANINE)r"   Z	Chameleon)r#   zChinese-CLIP)r$   ZChineseCLIPVisionModel)r%   ZCLAP)r&   ZCLIP)r'   ZCLIPVisionModel)r(   ZCLIPSeg)r)   ZCLVP)r*   Z	CodeLlama)r,   ZCodeGen)r-   ZCohere)r.   zConditional DETR)r/   ZConvBERT)r0   ZConvNeXT)r1   Z
ConvNeXTV2)ZcpmZCPM)r2   zCPM-Ant)r3   ZCTRL)r4   ZCvT)r5   ZData2VecAudio)r6   ZData2VecText)r7   ZData2VecVision)r8   ZDBRX)r9   ZDeBERTa)r:   z
DeBERTa-v2)r;   zDecision Transformer)r<   zDeformable DETR)r=   ZDeiT)ZdeplotZDePlot)r>   zDepth Anything)Zdepth_anything_v2zDepth Anything V2)r?   ZDETA)r@   ZDETR)ZdialogptZDialoGPT)rA   ZDiNAT)rB   ZDINOv2)rC   Z
DistilBERT)ZditZDiT)rD   Z	DonutSwin)rE   ZDPR)rF   ZDPT)rG   ZEfficientFormer)rH   ZEfficientNet)rI   ZELECTRA)rJ   ZEnCodec)rK   zEncoder decoder)rL   ZERNIE)rM   ZErnieM)rN   ZESM)rO   ZFalcon)rP   ZFastSpeech2Conformer)zflan-t5zFLAN-T5)zflan-ul2zFLAN-UL2)rQ   ZFlauBERT)rR   ZFLAVA)rS   ZFNet)rT   ZFocalNet)rU   zFairSeq Machine-Translation)rV   zFunnel Transformer)rW   ZFuyu)rX   ZGemma)rY   ZGemma2)rZ   ZGIT)r[   ZGLPN)r\   zGPT-Sw3)r^   zOpenAI GPT-2)r_   Z
GPTBigCode)r`   zGPT Neo)ra   zGPT NeoX)rb   zGPT NeoX Japanese)rc   zGPT-J)rd   zGPTSAN-japanese)re   Z
Graphormer)rf   zGrounding DINO)rg   ZGroupViT)ZherbertZHerBERT)rh   ZHiera)ri   ZHubert)rj   zI-BERT)rk   ZIDEFICS)rl   ZIdefics2)rm   ZImageGPT)rn   ZInformer)ro   ZInstructBLIP)rp   ZInstructBlipVideo)rq   ZJamba)rr   ZJetMoe)rs   ZJukebox)rt   zKOSMOS-2)ru   ZLayoutLM)rv   Z
LayoutLMv2)rw   Z
LayoutLMv3)Z	layoutxlmZ	LayoutXLM)rx   ZLED)ry   ZLeViT)rz   ZLiLT)r{   ZLLaMA)Zllama2ZLlama2)Zllama3ZLlama3)r|   ZLLaVa)r}   zLLaVa-NeXT-Video)r~   z
LLaVA-NeXT)r   Z
Longformer)r   ZLongT5)r   ZLUKE)r   ZLXMERT)r   ZM2M100)z
madlad-400z
MADLAD-400)r   ZMamba)r   r   )r   ZMarian)r   ZMarkupLM)r   ZMask2Former)r   Z
MaskFormer)r   ZMaskFormerSwin)ZmatchaZMatCha)r   ZmBART)Zmbart50zmBART-50)r   zM-CTC-T)r   ZMEGA)r   zMegatron-BERT)Zmegatron_gpt2zMegatron-GPT2)r   zMGP-STR)r   ZMistral)r   ZMixtral)ZmlukeZmLUKE)mmsZMMS)r   Z
MobileBERT)r   ZMobileNetV1)r   ZMobileNetV2)r   Z	MobileViT)r   ZMobileViTV2)r   ZMPNet)r   ZMPT)r   ZMRA)r   ZMT5)r   ZMusicGen)r   zMusicGen Melody)r   ZMVP)r   ZNAT)r   ZNemotron)r   ZNezha)ZnllbZNLLB)r   zNLLB-MOE)r   ZNougat)r   u   Nyströmformer)r   ZOLMo)r   Z	OneFormer)r   Z	OpenLlama)r   z
OpenAI GPT)r   OPT)r   ZOWLv2)r   zOWL-ViT)r   Z	PaliGemma)r   ZPatchTSMixer)r   ZPatchTST)r   ZPegasus)r   z	PEGASUS-X)r   Z	Perceiver)r   Z	Persimmon)r   Phi)r   ZPhi3)ZphobertZPhoBERT)r   Z
Pix2Struct)r   ZPLBart)r   Z
PoolFormer)r   Z	Pop2Piano)r   Z
ProphetNet)r   ZPVT)r   ZPVTv2)r   ZQDQBert)r   ZQwen2)r   ZQwen2MoE)r   ZRAG)r   ZREALM)r   ZRecurrentGemma)r   ZReformer)r   ZRegNet)r   ZRemBERT)r   ZResNet)r   Z	RetriBERT)r   ZRoBERTa)r   zRoBERTa-PreLayerNorm)r   ZRoCBert)r   ZRoFormer)r   zRT-DETR)r   zRT-DETR-ResNet)r   ZRWKV)r   ZSAM)r   ZSeamlessM4T)r   ZSeamlessM4Tv2)r   Z	SegFormer)r   ZSegGPT)r   ZSEW)r   zSEW-D)r   ZSigLIP)r   ZSiglipVisionModel)r   zSpeech Encoder decoder)r   ZSpeech2Text)r   ZSpeech2Text2)r   ZSpeechT5)r   ZSplinter)r   ZSqueezeBERT)r   ZStableLm)r   Z
Starcoder2)r   Z
SuperPoint)r   ZSwiftFormer)r   zSwin Transformer)r   ZSwin2SR)r   zSwin Transformer V2)r   ZSwitchTransformers)r   ZT5)zt5v1.1zT5v1.1)r   zTable Transformer)r   ZTAPAS)tapexZTAPEX)r   zTime Series Transformer)r   ZTimeSformer)r   ZTimmBackbone)r   zTrajectory Transformer)r   zTransformer-XL)r   ZTrOCR)r   ZTVLT)r   ZTVP)r   ZUDOP)Zul2ZUL2)r   ZUMT5)r   Z	UniSpeech)r   ZUniSpeechSat)r   ZUnivNet)r   ZUPerNet)r   ZVAN)r   Z
VideoLlava)r   ZVideoMAE)r   ZViLT)r   ZVipLlava)r   zVision Encoder decoder)r   ZVisionTextDualEncoder)r   Z
VisualBERT)r   ZViT)r   z
ViT Hybrid)r   ZViTMAE)r  ZViTMSN)r  ZVitDet)r  ZViTMatte)r  ZVITS)r  ZViViT)r  ZWav2Vec2)r  zWav2Vec2-BERT)r  zWav2Vec2-Conformer)Zwav2vec2_phonemeZWav2Vec2Phoneme)r	  ZWavLM)r
  ZWhisper)r  zX-CLIP)r  ZXGLM)r  ZXLM)r  zXLM-ProphetNet)r  zXLM-RoBERTa)r  zXLM-RoBERTa-XL)zxlm-vzXLM-V)r  ZXLNet)Zxls_rzXLS-R)Zxlsr_wav2vec2zXLSR-Wav2Vec2)r  zX-MOD)r  ZYOLOS)r  ZYOSO)r  ZZoeDepthr  r?   rG   rM   Zgptsan_japanesere   rs   r   r   Zmmbtr   r   Z
open_llamar   r   r   r   r  r   Z
transfo_xlr   r   r   Zxlm_prophetnet)r   Zopenai)r5   data2vec)r6   r  )r7   r  )rD   Zdonut)rt   Zkosmos2)r   r   )r  Zx_clip)r'   r&   )r   r   )r$   r#   )r   r   c                 C   sH   | t kr&t |  } | tkr"d|  } | S | dd} | tkrDd|  } | S )z2Converts a config key to the corresponding module.zdeprecated.-_)!SPECIAL_MODEL_TYPE_TO_MODULE_NAMEDEPRECATED_MODELSreplace)key r"  O/tmp/pip-unpacked-wheel-zw5xktn0/transformers/models/auto/configuration_auto.pymodel_type_to_module_name  s    

r$  c                 C   sL   t  D ]\}}|| kr|  S qtj D ]\}}|j| kr,|  S q,dS )z<Converts a config class name to the corresponding model typeN)CONFIG_MAPPING_NAMESitemsCONFIG_MAPPING_extra_content__name__)configr!  clsr"  r"  r#  config_class_to_model_type  s    


r,  c                   @   sR   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dddZdS )_LazyConfigMappingzK
    A dictionary that lazily load its values when they are requested.
    c                 C   s   || _ i | _i | _d S N)_mappingr(  _modulesselfmappingr"  r"  r#  __init__  s    z_LazyConfigMapping.__init__c                 C   s   || j kr| j | S || jkr&t|| j| }t|}|| jkrZtd| d| j|< t| j| |rzt| j| |S td}t||S )N.transformers.modelsZtransformers)	r(  r/  KeyErrorr$  r0  	importlibimport_modulehasattrgetattr)r2  r!  valuemodule_nameZtransformers_moduler"  r"  r#  __getitem__  s    





z_LazyConfigMapping.__getitem__c                 C   s   t | j t | j  S r.  )listr/  keysr(  r2  r"  r"  r#  r@    s    z_LazyConfigMapping.keysc                    s&    fdd j  D t j  S )Nc                    s   g | ]} | qS r"  r"  .0krA  r"  r#  
<listcomp>  s     z-_LazyConfigMapping.values.<locals>.<listcomp>)r/  r@  r?  r(  valuesrA  r"  rA  r#  rF    s    z_LazyConfigMapping.valuesc                    s&    fdd j  D t j  S )Nc                    s   g | ]}| | fqS r"  r"  rB  rA  r"  r#  rE    s     z,_LazyConfigMapping.items.<locals>.<listcomp>)r/  r@  r?  r(  r&  rA  r"  rA  r#  r&    s    z_LazyConfigMapping.itemsc                 C   s    t t| j t| j  S r.  )iterr?  r/  r@  r(  rA  r"  r"  r#  __iter__  s    z_LazyConfigMapping.__iter__c                 C   s   || j kp|| jkS r.  )r/  r(  r2  itemr"  r"  r#  __contains__  s    z_LazyConfigMapping.__contains__Fc                 C   s0   || j  kr"|s"td| d|| j|< dS )z?
        Register a new configuration in this mapping.
        'z>' is already used by a Transformers config, pick another name.N)r/  r@  
ValueErrorr(  )r2  r!  r<  exist_okr"  r"  r#  register  s    z_LazyConfigMapping.registerN)F)r)  
__module____qualname____doc__r4  r>  r@  rF  r&  rH  rK  rO  r"  r"  r"  r#  r-    s   r-  c                   @   sP   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdS )_LazyLoadAllMappingsz
    A mapping that will load all pairs of key values at the first access (either by indexing, requestions keys, values,
    etc.)

    Args:
        mapping: The mapping to load.
    c                 C   s   || _ d| _i | _d S )NF)r/  _initialized_datar1  r"  r"  r#  r4    s    z_LazyLoadAllMappings.__init__c                 C   sX   | j r
d S | j D ]8\}}t|}td| d}t||}| j| qd| _ d S )Nr5  r6  T)	rT  r/  r&  r$  r8  r9  r;  rU  update)r2  
model_typeZmap_namer=  moduler3  r"  r"  r#  _initialize  s    
z _LazyLoadAllMappings._initializec                 C   s   |    | j| S r.  rY  rU  )r2  r!  r"  r"  r#  r>    s    z _LazyLoadAllMappings.__getitem__c                 C   s   |    | j S r.  rY  rU  r@  rA  r"  r"  r#  r@    s    z_LazyLoadAllMappings.keysc                 C   s   |    | j S r.  )rY  rU  rF  rA  r"  r"  r#  rF    s    z_LazyLoadAllMappings.valuesc                 C   s   |    | j S r.  r[  rA  r"  r"  r#  r&    s    z_LazyLoadAllMappings.itemsc                 C   s   |    t| jS r.  )rY  rG  rU  rA  r"  r"  r#  rH  	  s    z_LazyLoadAllMappings.__iter__c                 C   s   |    || jkS r.  rZ  rI  r"  r"  r#  rK    s    z!_LazyLoadAllMappings.__contains__N)r)  rP  rQ  rR  r4  rY  r>  r@  rF  r&  rH  rK  r"  r"  r"  r#  rS    s   rS  model_classc                 C   s.   t | ttfr"ddd | D S d|  dS )Nz or c                 S   s    g | ]}|d k	rd| dqS )N[``]r"  )rC  cr"  r"  r#  rE    s      z#_get_class_name.<locals>.<listcomp>r^  r_  )
isinstancer?  tuplejoinr\  r"  r"  r#  _get_class_name  s    rd  Tc                    s   |d kr|st d|rd|d kr4dd t D ndd | D fddt D }nBdd | D dd t D   fd	dt D }d
|S )NzFUsing `use_model_types=False` requires a `config_to_class` dictionary.c                 S   s   i | ]\}}|d | dqS )r^  r_  r"  rC  rW  r*  r"  r"  r#  
<dictcomp>  s      z'_list_model_options.<locals>.<dictcomp>c                 S   s"   i | ]\}}|t kr|t|qS r"  )MODEL_NAMES_MAPPINGrd  )rC  rW  r]  r"  r"  r#  rf    s    c              
      s0   g | ](}  d | d|  dt |  dqS )z- **z** --  ( model)rg  )rC  rW  )indentmodel_type_to_namer"  r#  rE  $  s   z'_list_model_options.<locals>.<listcomp>c                 S   s&   i | ]\}}|t krt | t|qS r"  )r%  rd  )rC  r*  Zclasr"  r"  r#  rf  )  s    c                 S   s   i | ]\}}|t | qS r"  rj  re  r"  r"  r#  rf  .  s     c              
      s0   g | ](} d | d|  d |  dqS )z- [`z`] configuration class: rh  ri  r"  )rC  Zconfig_name)config_to_model_nameconfig_to_namerk  r"  r#  rE  1  s   
)rM  r%  r&  sortedr@  rc  )rk  config_to_classuse_model_typeslinesr"  )rm  rn  rk  rl  r#  _list_model_options  s*    

rt  c                    s    fdd}|S )Nc                    s   | j }|d kr| S |d}d}|t|k rJtd|| d krJ|d7 }q |t|k rtd||  d }r|| d}t| d||< d|}ntd|  d| || _ | S )	Nro  r   z^(\s*)List options\s*$   z    rq  rr  zThe function z\ should have an empty 'List options' in its docstring as placeholder, current docstring is:
)	rR  splitlenresearchgroupsrt  rc  rM  )fnZ
docstringsrs  irk  rv  r"  r#  docstring_decorator:  s$    
 

z>replace_list_option_in_docstrings.<locals>.docstring_decoratorr"  )rq  rr  r~  r"  rv  r#  !replace_list_option_in_docstrings9  s    r  c                   @   sJ   e Zd ZdZdd ZeedddZee dd Z	e
dd
dZdS )
AutoConfiga  
    This is a generic configuration class that will be instantiated as one of the configuration classes of the library
    when created with the [`~AutoConfig.from_pretrained`] class method.

    This class cannot be instantiated directly using `__init__()` (throws an error).
    c                 C   s   t dd S )NzwAutoConfig is designed to be instantiated using the `AutoConfig.from_pretrained(pretrained_model_name_or_path)` method.)EnvironmentErrorrA  r"  r"  r#  r4  \  s    zAutoConfig.__init__)rW  c                 O   s<   |t krt | }|||S td| ddt   d S )NzUnrecognized model identifier: z. Should contain one of , )r'  rM  rc  r@  )r+  rW  argskwargsconfig_classr"  r"  r#  	for_modelb  s    
zAutoConfig.for_modelc              
   K   s  | dd}|dk	r@tdt |dddk	r8td||d< d|d< ||d< | d	d}| d
d}tj|f|\}}d|kod|d k}d|ko|d tk}	t	|||	|}|r|r|d d }
t
|
|fd
|i|}tj|r|  |j|f|S d|krPzt|d  }W n* tk
r@   td|d  dY nX |j|f|S tt tddD ]*}|t|krbt| j|f|  S qbtd| dt ddt  dS )a  
        Instantiate one of the configuration classes of the library from a pretrained model configuration.

        The configuration class to instantiate is selected based on the `model_type` property of the config object that
        is loaded, or when it's missing, by falling back to using pattern matching on `pretrained_model_name_or_path`:

        List options

        Args:
            pretrained_model_name_or_path (`str` or `os.PathLike`):
                Can be either:

                    - A string, the *model id* of a pretrained model configuration hosted inside a model repo on
                      huggingface.co.
                    - A path to a *directory* containing a configuration file saved using the
                      [`~PretrainedConfig.save_pretrained`] method, or the [`~PreTrainedModel.save_pretrained`] method,
                      e.g., `./my_model_directory/`.
                    - A path or url to a saved configuration JSON *file*, e.g.,
                      `./my_model_directory/configuration.json`.
            cache_dir (`str` or `os.PathLike`, *optional*):
                Path to a directory in which a downloaded pretrained model configuration should be cached if the
                standard cache should not be used.
            force_download (`bool`, *optional*, defaults to `False`):
                Whether or not to force the (re-)download the model weights and configuration files and override the
                cached versions if they exist.
            resume_download:
                Deprecated and ignored. All downloads are now resumed by default when possible.
                Will be removed in v5 of Transformers.
            proxies (`Dict[str, str]`, *optional*):
                A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
                'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
            revision (`str`, *optional*, defaults to `"main"`):
                The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
                git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
                identifier allowed by git.
            return_unused_kwargs (`bool`, *optional*, defaults to `False`):
                If `False`, then this function returns just the final configuration object.

                If `True`, then this functions returns a `Tuple(config, unused_kwargs)` where *unused_kwargs* is a
                dictionary consisting of the key/value pairs whose keys are not configuration attributes: i.e., the
                part of `kwargs` which has not been used to update `config` and is otherwise ignored.
            trust_remote_code (`bool`, *optional*, defaults to `False`):
                Whether or not to allow for custom models defined on the Hub in their own modeling files. This option
                should only be set to `True` for repositories you trust and in which you have read the code, as it will
                execute code present on the Hub on your local machine.
            kwargs(additional keyword arguments, *optional*):
                The values in kwargs of any keys which are configuration attributes will be used to override the loaded
                values. Behavior concerning key/value pairs whose keys are *not* configuration attributes is controlled
                by the `return_unused_kwargs` keyword parameter.

        Examples:

        ```python
        >>> from transformers import AutoConfig

        >>> # Download configuration from huggingface.co and cache.
        >>> config = AutoConfig.from_pretrained("google-bert/bert-base-uncased")

        >>> # Download configuration from huggingface.co (user-uploaded) and cache.
        >>> config = AutoConfig.from_pretrained("dbmdz/bert-base-german-cased")

        >>> # If configuration file is in a directory (e.g., was saved using *save_pretrained('./test/saved_model/')*).
        >>> config = AutoConfig.from_pretrained("./test/bert_saved_model/")

        >>> # Load a specific configuration file.
        >>> config = AutoConfig.from_pretrained("./test/bert_saved_model/my_configuration.json")

        >>> # Change some config attributes when loading a pretrained config.
        >>> config = AutoConfig.from_pretrained("google-bert/bert-base-uncased", output_attentions=True, foo=False)
        >>> config.output_attentions
        True

        >>> config, unused_kwargs = AutoConfig.from_pretrained(
        ...     "google-bert/bert-base-uncased", output_attentions=True, foo=False, return_unused_kwargs=True
        ... )
        >>> config.output_attentions
        True

        >>> unused_kwargs
        {'foo': False}
        ```use_auth_tokenNzrThe `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.tokenzV`token` and `use_auth_token` are both specified. Please set only the argument `token`.TZ
_from_autoZname_or_pathtrust_remote_codecode_revisionZauto_mapr  rW  z6The checkpoint you are trying to load has model type `z` but Transformers does not recognize this architecture. This could be because of an issue with the checkpoint, or because your version of Transformers is out of date.)r!  reversezUnrecognized model in z(. Should have a `model_type` key in its z7, or contain one of the following strings in its name: r  )popwarningswarnFutureWarninggetrM  r   Zget_config_dictr'  r   r   ospathisdirZregister_for_auto_classfrom_pretrainedr7  	from_dictrp  r@  rx  strr	   rc  )r+  Zpretrained_model_name_or_pathr  r  r  r  Zconfig_dictZunused_kwargsZhas_remote_codeZhas_local_codeZ	class_refr  patternr"  r"  r#  r  k  sf    T    

zAutoConfig.from_pretrainedFc                 C   s@   t |tr,|j| kr,td|j d|  dtj| ||d dS )z
        Register a new configuration for this class.

        Args:
            model_type (`str`): The model type like "bert" or "gpt".
            config ([`PretrainedConfig`]): The config to register.
        zzThe config you are passing has a `model_type` attribute that is not consistent with the model type you passed (config has z and you passed z!. Fix one of those so they match!)rN  N)
issubclassr   rW  rM  r'  rO  )rW  r*  rN  r"  r"  r#  rO    s
    	zAutoConfig.registerN)F)r)  rP  rQ  rR  r4  classmethodr  r  r  r  staticmethodrO  r"  r"  r"  r#  r  T  s    
r  )NT)NT)#rR  r8  r  ry  r  collectionsr   typingr   r   Zconfiguration_utilsr   Zdynamic_module_utilsr   r   utilsr	   r
   Z
get_loggerr)  loggerr%  rg  r  r  r$  r,  r-  r'  rS  r  rd  rt  r  r  r"  r"  r"  r#  <module>   s  
        333 !