configuration_auto.py 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  1. # Copyright 2018 The HuggingFace Inc. team.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Auto Config class."""
  15. import importlib
  16. import os
  17. import re
  18. from collections import OrderedDict
  19. from collections.abc import Callable, Iterator, KeysView, ValuesView
  20. from typing import Any, TypeVar
  21. from ...configuration_utils import PreTrainedConfig
  22. from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
  23. from ...utils import CONFIG_NAME, logging
  24. logger = logging.get_logger(__name__)
  25. _CallableT = TypeVar("_CallableT", bound=Callable[..., Any])
  26. CONFIG_MAPPING_NAMES = OrderedDict[str, str](
  27. [
  28. # Add configs here
  29. ("afmoe", "AfmoeConfig"),
  30. ("aimv2", "Aimv2Config"),
  31. ("aimv2_vision_model", "Aimv2VisionConfig"),
  32. ("albert", "AlbertConfig"),
  33. ("align", "AlignConfig"),
  34. ("altclip", "AltCLIPConfig"),
  35. ("apertus", "ApertusConfig"),
  36. ("arcee", "ArceeConfig"),
  37. ("aria", "AriaConfig"),
  38. ("aria_text", "AriaTextConfig"),
  39. ("audio-spectrogram-transformer", "ASTConfig"),
  40. ("audioflamingo3", "AudioFlamingo3Config"),
  41. ("audioflamingo3_encoder", "AudioFlamingo3EncoderConfig"),
  42. ("autoformer", "AutoformerConfig"),
  43. ("aya_vision", "AyaVisionConfig"),
  44. ("bamba", "BambaConfig"),
  45. ("bark", "BarkConfig"),
  46. ("bart", "BartConfig"),
  47. ("beit", "BeitConfig"),
  48. ("bert", "BertConfig"),
  49. ("bert-generation", "BertGenerationConfig"),
  50. ("big_bird", "BigBirdConfig"),
  51. ("bigbird_pegasus", "BigBirdPegasusConfig"),
  52. ("biogpt", "BioGptConfig"),
  53. ("bit", "BitConfig"),
  54. ("bitnet", "BitNetConfig"),
  55. ("blenderbot", "BlenderbotConfig"),
  56. ("blenderbot-small", "BlenderbotSmallConfig"),
  57. ("blip", "BlipConfig"),
  58. ("blip-2", "Blip2Config"),
  59. ("blip_2_qformer", "Blip2QFormerConfig"),
  60. ("bloom", "BloomConfig"),
  61. ("blt", "BltConfig"),
  62. ("bridgetower", "BridgeTowerConfig"),
  63. ("bros", "BrosConfig"),
  64. ("camembert", "CamembertConfig"),
  65. ("canine", "CanineConfig"),
  66. ("chameleon", "ChameleonConfig"),
  67. ("chinese_clip", "ChineseCLIPConfig"),
  68. ("chinese_clip_vision_model", "ChineseCLIPVisionConfig"),
  69. ("chmv2", "CHMv2Config"),
  70. ("clap", "ClapConfig"),
  71. ("clip", "CLIPConfig"),
  72. ("clip_text_model", "CLIPTextConfig"),
  73. ("clip_vision_model", "CLIPVisionConfig"),
  74. ("clipseg", "CLIPSegConfig"),
  75. ("clvp", "ClvpConfig"),
  76. ("code_llama", "LlamaConfig"),
  77. ("codegen", "CodeGenConfig"),
  78. ("cohere", "CohereConfig"),
  79. ("cohere2", "Cohere2Config"),
  80. ("cohere2_vision", "Cohere2VisionConfig"),
  81. ("cohere_asr", "CohereAsrConfig"),
  82. ("colmodernvbert", "ColModernVBertConfig"),
  83. ("colpali", "ColPaliConfig"),
  84. ("colqwen2", "ColQwen2Config"),
  85. ("conditional_detr", "ConditionalDetrConfig"),
  86. ("convbert", "ConvBertConfig"),
  87. ("convnext", "ConvNextConfig"),
  88. ("convnextv2", "ConvNextV2Config"),
  89. ("cpmant", "CpmAntConfig"),
  90. ("csm", "CsmConfig"),
  91. ("ctrl", "CTRLConfig"),
  92. ("cvt", "CvtConfig"),
  93. ("cwm", "CwmConfig"),
  94. ("d_fine", "DFineConfig"),
  95. ("dab-detr", "DabDetrConfig"),
  96. ("dac", "DacConfig"),
  97. ("data2vec-audio", "Data2VecAudioConfig"),
  98. ("data2vec-text", "Data2VecTextConfig"),
  99. ("data2vec-vision", "Data2VecVisionConfig"),
  100. ("dbrx", "DbrxConfig"),
  101. ("deberta", "DebertaConfig"),
  102. ("deberta-v2", "DebertaV2Config"),
  103. ("decision_transformer", "DecisionTransformerConfig"),
  104. ("deepseek_v2", "DeepseekV2Config"),
  105. ("deepseek_v3", "DeepseekV3Config"),
  106. ("deepseek_vl", "DeepseekVLConfig"),
  107. ("deepseek_vl_hybrid", "DeepseekVLHybridConfig"),
  108. ("deformable_detr", "DeformableDetrConfig"),
  109. ("deit", "DeiTConfig"),
  110. ("depth_anything", "DepthAnythingConfig"),
  111. ("depth_pro", "DepthProConfig"),
  112. ("detr", "DetrConfig"),
  113. ("dia", "DiaConfig"),
  114. ("diffllama", "DiffLlamaConfig"),
  115. ("dinat", "DinatConfig"),
  116. ("dinov2", "Dinov2Config"),
  117. ("dinov2_with_registers", "Dinov2WithRegistersConfig"),
  118. ("dinov3_convnext", "DINOv3ConvNextConfig"),
  119. ("dinov3_vit", "DINOv3ViTConfig"),
  120. ("distilbert", "DistilBertConfig"),
  121. ("doge", "DogeConfig"),
  122. ("donut-swin", "DonutSwinConfig"),
  123. ("dots1", "Dots1Config"),
  124. ("dpr", "DPRConfig"),
  125. ("dpt", "DPTConfig"),
  126. ("edgetam", "EdgeTamConfig"),
  127. ("edgetam_video", "EdgeTamVideoConfig"),
  128. ("edgetam_vision_model", "EdgeTamVisionConfig"),
  129. ("efficientloftr", "EfficientLoFTRConfig"),
  130. ("efficientnet", "EfficientNetConfig"),
  131. ("electra", "ElectraConfig"),
  132. ("emu3", "Emu3Config"),
  133. ("encodec", "EncodecConfig"),
  134. ("encoder-decoder", "EncoderDecoderConfig"),
  135. ("eomt", "EomtConfig"),
  136. ("eomt_dinov3", "EomtDinov3Config"),
  137. ("ernie", "ErnieConfig"),
  138. ("ernie4_5", "Ernie4_5Config"),
  139. ("ernie4_5_moe", "Ernie4_5_MoeConfig"),
  140. ("ernie4_5_vl_moe", "Ernie4_5_VLMoeConfig"),
  141. ("esm", "EsmConfig"),
  142. ("eurobert", "EuroBertConfig"),
  143. ("evolla", "EvollaConfig"),
  144. ("exaone4", "Exaone4Config"),
  145. ("exaone_moe", "ExaoneMoeConfig"),
  146. ("falcon", "FalconConfig"),
  147. ("falcon_h1", "FalconH1Config"),
  148. ("falcon_mamba", "FalconMambaConfig"),
  149. ("fast_vlm", "FastVlmConfig"),
  150. ("fastspeech2_conformer", "FastSpeech2ConformerConfig"),
  151. ("fastspeech2_conformer_with_hifigan", "FastSpeech2ConformerWithHifiGanConfig"),
  152. ("flaubert", "FlaubertConfig"),
  153. ("flava", "FlavaConfig"),
  154. ("flex_olmo", "FlexOlmoConfig"),
  155. ("florence2", "Florence2Config"),
  156. ("fnet", "FNetConfig"),
  157. ("focalnet", "FocalNetConfig"),
  158. ("fsmt", "FSMTConfig"),
  159. ("funnel", "FunnelConfig"),
  160. ("fuyu", "FuyuConfig"),
  161. ("gemma", "GemmaConfig"),
  162. ("gemma2", "Gemma2Config"),
  163. ("gemma3", "Gemma3Config"),
  164. ("gemma3_text", "Gemma3TextConfig"),
  165. ("gemma3n", "Gemma3nConfig"),
  166. ("gemma3n_audio", "Gemma3nAudioConfig"),
  167. ("gemma3n_text", "Gemma3nTextConfig"),
  168. ("gemma3n_vision", "Gemma3nVisionConfig"),
  169. ("gemma4", "Gemma4Config"),
  170. ("gemma4_audio", "Gemma4AudioConfig"),
  171. ("gemma4_text", "Gemma4TextConfig"),
  172. ("gemma4_vision", "Gemma4VisionConfig"),
  173. ("git", "GitConfig"),
  174. ("glm", "GlmConfig"),
  175. ("glm4", "Glm4Config"),
  176. ("glm46v", "Glm46VConfig"),
  177. ("glm4_moe", "Glm4MoeConfig"),
  178. ("glm4_moe_lite", "Glm4MoeLiteConfig"),
  179. ("glm4v", "Glm4vConfig"),
  180. ("glm4v_moe", "Glm4vMoeConfig"),
  181. ("glm4v_moe_text", "Glm4vMoeTextConfig"),
  182. ("glm4v_moe_vision", "Glm4vMoeVisionConfig"),
  183. ("glm4v_text", "Glm4vTextConfig"),
  184. ("glm4v_vision", "Glm4vVisionConfig"),
  185. ("glm_image", "GlmImageConfig"),
  186. ("glm_image_text", "GlmImageTextConfig"),
  187. ("glm_image_vision", "GlmImageVisionConfig"),
  188. ("glm_image_vqmodel", "GlmImageVQVAEConfig"),
  189. ("glm_moe_dsa", "GlmMoeDsaConfig"),
  190. ("glm_ocr", "GlmOcrConfig"),
  191. ("glm_ocr_text", "GlmOcrTextConfig"),
  192. ("glm_ocr_vision", "GlmOcrVisionConfig"),
  193. ("glmasr", "GlmAsrConfig"),
  194. ("glmasr_encoder", "GlmAsrEncoderConfig"),
  195. ("glpn", "GLPNConfig"),
  196. ("got_ocr2", "GotOcr2Config"),
  197. ("gpt-sw3", "GPT2Config"),
  198. ("gpt2", "GPT2Config"),
  199. ("gpt_bigcode", "GPTBigCodeConfig"),
  200. ("gpt_neo", "GPTNeoConfig"),
  201. ("gpt_neox", "GPTNeoXConfig"),
  202. ("gpt_neox_japanese", "GPTNeoXJapaneseConfig"),
  203. ("gpt_oss", "GptOssConfig"),
  204. ("gptj", "GPTJConfig"),
  205. ("granite", "GraniteConfig"),
  206. ("granite_speech", "GraniteSpeechConfig"),
  207. ("granitemoe", "GraniteMoeConfig"),
  208. ("granitemoehybrid", "GraniteMoeHybridConfig"),
  209. ("granitemoeshared", "GraniteMoeSharedConfig"),
  210. ("granitevision", "LlavaNextConfig"),
  211. ("grounding-dino", "GroundingDinoConfig"),
  212. ("groupvit", "GroupViTConfig"),
  213. ("helium", "HeliumConfig"),
  214. ("hgnet_v2", "HGNetV2Config"),
  215. ("hiera", "HieraConfig"),
  216. ("higgs_audio_v2", "HiggsAudioV2Config"),
  217. ("higgs_audio_v2_tokenizer", "HiggsAudioV2TokenizerConfig"),
  218. ("hubert", "HubertConfig"),
  219. ("hunyuan_v1_dense", "HunYuanDenseV1Config"),
  220. ("hunyuan_v1_moe", "HunYuanMoEV1Config"),
  221. ("ibert", "IBertConfig"),
  222. ("idefics", "IdeficsConfig"),
  223. ("idefics2", "Idefics2Config"),
  224. ("idefics3", "Idefics3Config"),
  225. ("idefics3_vision", "Idefics3VisionConfig"),
  226. ("ijepa", "IJepaConfig"),
  227. ("imagegpt", "ImageGPTConfig"),
  228. ("informer", "InformerConfig"),
  229. ("instructblip", "InstructBlipConfig"),
  230. ("instructblipvideo", "InstructBlipVideoConfig"),
  231. ("internvl", "InternVLConfig"),
  232. ("internvl_vision", "InternVLVisionConfig"),
  233. ("jais2", "Jais2Config"),
  234. ("jamba", "JambaConfig"),
  235. ("janus", "JanusConfig"),
  236. ("jetmoe", "JetMoeConfig"),
  237. ("jina_embeddings_v3", "JinaEmbeddingsV3Config"),
  238. ("kosmos-2", "Kosmos2Config"),
  239. ("kosmos-2.5", "Kosmos2_5Config"),
  240. ("kyutai_speech_to_text", "KyutaiSpeechToTextConfig"),
  241. ("lasr_ctc", "LasrCTCConfig"),
  242. ("lasr_encoder", "LasrEncoderConfig"),
  243. ("layoutlm", "LayoutLMConfig"),
  244. ("layoutlmv2", "LayoutLMv2Config"),
  245. ("layoutlmv3", "LayoutLMv3Config"),
  246. ("layoutxlm", "LayoutXLMConfig"),
  247. ("led", "LEDConfig"),
  248. ("levit", "LevitConfig"),
  249. ("lfm2", "Lfm2Config"),
  250. ("lfm2_moe", "Lfm2MoeConfig"),
  251. ("lfm2_vl", "Lfm2VlConfig"),
  252. ("lightglue", "LightGlueConfig"),
  253. ("lighton_ocr", "LightOnOcrConfig"),
  254. ("lilt", "LiltConfig"),
  255. ("llama", "LlamaConfig"),
  256. ("llama4", "Llama4Config"),
  257. ("llama4_text", "Llama4TextConfig"),
  258. ("llava", "LlavaConfig"),
  259. ("llava_next", "LlavaNextConfig"),
  260. ("llava_next_video", "LlavaNextVideoConfig"),
  261. ("llava_onevision", "LlavaOnevisionConfig"),
  262. ("longcat_flash", "LongcatFlashConfig"),
  263. ("longformer", "LongformerConfig"),
  264. ("longt5", "LongT5Config"),
  265. ("luke", "LukeConfig"),
  266. ("lw_detr", "LwDetrConfig"),
  267. ("lw_detr_vit", "LwDetrViTConfig"),
  268. ("lxmert", "LxmertConfig"),
  269. ("m2m_100", "M2M100Config"),
  270. ("mamba", "MambaConfig"),
  271. ("mamba2", "Mamba2Config"),
  272. ("marian", "MarianConfig"),
  273. ("markuplm", "MarkupLMConfig"),
  274. ("mask2former", "Mask2FormerConfig"),
  275. ("maskformer", "MaskFormerConfig"),
  276. ("maskformer-swin", "MaskFormerSwinConfig"),
  277. ("mbart", "MBartConfig"),
  278. ("megatron-bert", "MegatronBertConfig"),
  279. ("metaclip_2", "MetaClip2Config"),
  280. ("mgp-str", "MgpstrConfig"),
  281. ("mimi", "MimiConfig"),
  282. ("minimax", "MiniMaxConfig"),
  283. ("minimax_m2", "MiniMaxM2Config"),
  284. ("ministral", "MinistralConfig"),
  285. ("ministral3", "Ministral3Config"),
  286. ("mistral", "MistralConfig"),
  287. ("mistral3", "Mistral3Config"),
  288. ("mistral4", "Mistral4Config"),
  289. ("mixtral", "MixtralConfig"),
  290. ("mlcd", "MLCDVisionConfig"), # Keep this to make some original hub repositories (from `DeepGlint-AI`) works
  291. ("mlcd_vision_model", "MLCDVisionConfig"),
  292. ("mllama", "MllamaConfig"),
  293. ("mm-grounding-dino", "MMGroundingDinoConfig"),
  294. ("mobilebert", "MobileBertConfig"),
  295. ("mobilenet_v1", "MobileNetV1Config"),
  296. ("mobilenet_v2", "MobileNetV2Config"),
  297. ("mobilevit", "MobileViTConfig"),
  298. ("mobilevitv2", "MobileViTV2Config"),
  299. ("modernbert", "ModernBertConfig"),
  300. ("modernbert-decoder", "ModernBertDecoderConfig"),
  301. ("modernvbert", "ModernVBertConfig"),
  302. ("moonshine", "MoonshineConfig"),
  303. ("moonshine_streaming", "MoonshineStreamingConfig"),
  304. ("moonshine_streaming_encoder", "MoonshineStreamingEncoderConfig"),
  305. ("moshi", "MoshiConfig"),
  306. ("mpnet", "MPNetConfig"),
  307. ("mpt", "MptConfig"),
  308. ("mra", "MraConfig"),
  309. ("mt5", "MT5Config"),
  310. ("musicflamingo", "MusicFlamingoConfig"),
  311. ("musicflamingo_encoder", "AudioFlamingo3EncoderConfig"),
  312. ("musicgen", "MusicgenConfig"),
  313. ("musicgen_melody", "MusicgenMelodyConfig"),
  314. ("mvp", "MvpConfig"),
  315. ("nanochat", "NanoChatConfig"),
  316. ("nemotron", "NemotronConfig"),
  317. ("nemotron_h", "NemotronHConfig"),
  318. ("nllb-moe", "NllbMoeConfig"),
  319. ("nomic_bert", "NomicBertConfig"),
  320. ("nougat", "VisionEncoderDecoderConfig"),
  321. ("nystromformer", "NystromformerConfig"),
  322. ("olmo", "OlmoConfig"),
  323. ("olmo2", "Olmo2Config"),
  324. ("olmo3", "Olmo3Config"),
  325. ("olmo_hybrid", "OlmoHybridConfig"),
  326. ("olmoe", "OlmoeConfig"),
  327. ("omdet-turbo", "OmDetTurboConfig"),
  328. ("oneformer", "OneFormerConfig"),
  329. ("openai-gpt", "OpenAIGPTConfig"),
  330. ("opt", "OPTConfig"),
  331. ("ovis2", "Ovis2Config"),
  332. ("owlv2", "Owlv2Config"),
  333. ("owlvit", "OwlViTConfig"),
  334. ("paddleocr_vl", "PaddleOCRVLConfig"),
  335. ("paligemma", "PaliGemmaConfig"),
  336. ("parakeet_ctc", "ParakeetCTCConfig"),
  337. ("parakeet_encoder", "ParakeetEncoderConfig"),
  338. ("patchtsmixer", "PatchTSMixerConfig"),
  339. ("patchtst", "PatchTSTConfig"),
  340. ("pe_audio", "PeAudioConfig"),
  341. ("pe_audio_encoder", "PeAudioEncoderConfig"),
  342. ("pe_audio_video", "PeAudioVideoConfig"),
  343. ("pe_audio_video_encoder", "PeAudioVideoEncoderConfig"),
  344. ("pe_video", "PeVideoConfig"),
  345. ("pe_video_encoder", "PeVideoEncoderConfig"),
  346. ("pegasus", "PegasusConfig"),
  347. ("pegasus_x", "PegasusXConfig"),
  348. ("perceiver", "PerceiverConfig"),
  349. ("perception_lm", "PerceptionLMConfig"),
  350. ("persimmon", "PersimmonConfig"),
  351. ("phi", "PhiConfig"),
  352. ("phi3", "Phi3Config"),
  353. ("phi4_multimodal", "Phi4MultimodalConfig"),
  354. ("phimoe", "PhimoeConfig"),
  355. ("pi0", "PI0Config"),
  356. ("pix2struct", "Pix2StructConfig"),
  357. ("pixio", "PixioConfig"),
  358. ("pixtral", "PixtralVisionConfig"),
  359. ("plbart", "PLBartConfig"),
  360. ("poolformer", "PoolFormerConfig"),
  361. ("pop2piano", "Pop2PianoConfig"),
  362. ("pp_chart2table", "PPChart2TableConfig"),
  363. ("pp_doclayout_v2", "PPDocLayoutV2Config"),
  364. ("pp_doclayout_v3", "PPDocLayoutV3Config"),
  365. ("pp_lcnet", "PPLCNetConfig"),
  366. ("pp_lcnet_v3", "PPLCNetV3Config"),
  367. ("pp_ocrv5_mobile_det", "PPOCRV5MobileDetConfig"),
  368. ("pp_ocrv5_mobile_rec", "PPOCRV5MobileRecConfig"),
  369. ("pp_ocrv5_server_det", "PPOCRV5ServerDetConfig"),
  370. ("pp_ocrv5_server_rec", "PPOCRV5ServerRecConfig"),
  371. ("prompt_depth_anything", "PromptDepthAnythingConfig"),
  372. ("prophetnet", "ProphetNetConfig"),
  373. ("pvt", "PvtConfig"),
  374. ("pvt_v2", "PvtV2Config"),
  375. ("qwen2", "Qwen2Config"),
  376. ("qwen2_5_omni", "Qwen2_5OmniConfig"),
  377. ("qwen2_5_vl", "Qwen2_5_VLConfig"),
  378. ("qwen2_5_vl_text", "Qwen2_5_VLTextConfig"),
  379. ("qwen2_audio", "Qwen2AudioConfig"),
  380. ("qwen2_audio_encoder", "Qwen2AudioEncoderConfig"),
  381. ("qwen2_moe", "Qwen2MoeConfig"),
  382. ("qwen2_vl", "Qwen2VLConfig"),
  383. ("qwen2_vl_text", "Qwen2VLTextConfig"),
  384. ("qwen3", "Qwen3Config"),
  385. ("qwen3_5", "Qwen3_5Config"),
  386. ("qwen3_5_moe", "Qwen3_5MoeConfig"),
  387. ("qwen3_5_moe_text", "Qwen3_5MoeTextConfig"),
  388. ("qwen3_5_text", "Qwen3_5TextConfig"),
  389. ("qwen3_moe", "Qwen3MoeConfig"),
  390. ("qwen3_next", "Qwen3NextConfig"),
  391. ("qwen3_omni_moe", "Qwen3OmniMoeConfig"),
  392. ("qwen3_vl", "Qwen3VLConfig"),
  393. ("qwen3_vl_moe", "Qwen3VLMoeConfig"),
  394. ("qwen3_vl_moe_text", "Qwen3VLMoeTextConfig"),
  395. ("qwen3_vl_text", "Qwen3VLTextConfig"),
  396. ("rag", "RagConfig"),
  397. ("recurrent_gemma", "RecurrentGemmaConfig"),
  398. ("reformer", "ReformerConfig"),
  399. ("regnet", "RegNetConfig"),
  400. ("rembert", "RemBertConfig"),
  401. ("resnet", "ResNetConfig"),
  402. ("roberta", "RobertaConfig"),
  403. ("roberta-prelayernorm", "RobertaPreLayerNormConfig"),
  404. ("roc_bert", "RoCBertConfig"),
  405. ("roformer", "RoFormerConfig"),
  406. ("rt_detr", "RTDetrConfig"),
  407. ("rt_detr_resnet", "RTDetrResNetConfig"),
  408. ("rt_detr_v2", "RTDetrV2Config"),
  409. ("rwkv", "RwkvConfig"),
  410. ("sam", "SamConfig"),
  411. ("sam2", "Sam2Config"),
  412. ("sam2_hiera_det_model", "Sam2HieraDetConfig"),
  413. ("sam2_video", "Sam2VideoConfig"),
  414. ("sam2_vision_model", "Sam2VisionConfig"),
  415. ("sam3", "Sam3Config"),
  416. ("sam3_tracker", "Sam3TrackerConfig"),
  417. ("sam3_tracker_video", "Sam3TrackerVideoConfig"),
  418. ("sam3_video", "Sam3VideoConfig"),
  419. ("sam3_vision_model", "Sam3VisionConfig"),
  420. ("sam3_vit_model", "Sam3ViTConfig"),
  421. ("sam_hq", "SamHQConfig"),
  422. ("sam_hq_vision_model", "SamHQVisionConfig"),
  423. ("sam_vision_model", "SamVisionConfig"),
  424. ("seamless_m4t", "SeamlessM4TConfig"),
  425. ("seamless_m4t_v2", "SeamlessM4Tv2Config"),
  426. ("seed_oss", "SeedOssConfig"),
  427. ("segformer", "SegformerConfig"),
  428. ("seggpt", "SegGptConfig"),
  429. ("sew", "SEWConfig"),
  430. ("sew-d", "SEWDConfig"),
  431. ("shieldgemma2", "ShieldGemma2Config"),
  432. ("siglip", "SiglipConfig"),
  433. ("siglip2", "Siglip2Config"),
  434. ("siglip2_vision_model", "Siglip2VisionConfig"),
  435. ("siglip_vision_model", "SiglipVisionConfig"),
  436. ("slanext", "SLANeXtConfig"),
  437. ("smollm3", "SmolLM3Config"),
  438. ("smolvlm", "SmolVLMConfig"),
  439. ("smolvlm_vision", "SmolVLMVisionConfig"),
  440. ("solar_open", "SolarOpenConfig"),
  441. ("speech-encoder-decoder", "SpeechEncoderDecoderConfig"),
  442. ("speech_to_text", "Speech2TextConfig"),
  443. ("speecht5", "SpeechT5Config"),
  444. ("splinter", "SplinterConfig"),
  445. ("squeezebert", "SqueezeBertConfig"),
  446. ("stablelm", "StableLmConfig"),
  447. ("starcoder2", "Starcoder2Config"),
  448. ("superglue", "SuperGlueConfig"),
  449. ("superpoint", "SuperPointConfig"),
  450. ("swiftformer", "SwiftFormerConfig"),
  451. ("swin", "SwinConfig"),
  452. ("swin2sr", "Swin2SRConfig"),
  453. ("swinv2", "Swinv2Config"),
  454. ("switch_transformers", "SwitchTransformersConfig"),
  455. ("t5", "T5Config"),
  456. ("t5gemma", "T5GemmaConfig"),
  457. ("t5gemma2", "T5Gemma2Config"),
  458. ("t5gemma2_encoder", "T5Gemma2EncoderConfig"),
  459. ("table-transformer", "TableTransformerConfig"),
  460. ("tapas", "TapasConfig"),
  461. ("textnet", "TextNetConfig"),
  462. ("time_series_transformer", "TimeSeriesTransformerConfig"),
  463. ("timesfm", "TimesFmConfig"),
  464. ("timesfm2_5", "TimesFm2_5Config"),
  465. ("timesformer", "TimesformerConfig"),
  466. ("timm_backbone", "TimmBackboneConfig"),
  467. ("timm_wrapper", "TimmWrapperConfig"),
  468. ("trocr", "TrOCRConfig"),
  469. ("tvp", "TvpConfig"),
  470. ("udop", "UdopConfig"),
  471. ("umt5", "UMT5Config"),
  472. ("unispeech", "UniSpeechConfig"),
  473. ("unispeech-sat", "UniSpeechSatConfig"),
  474. ("univnet", "UnivNetConfig"),
  475. ("upernet", "UperNetConfig"),
  476. ("uvdoc", "UVDocConfig"),
  477. ("uvdoc_backbone", "UVDocBackboneConfig"),
  478. ("vaultgemma", "VaultGemmaConfig"),
  479. ("vibevoice_acoustic_tokenizer", "VibeVoiceAcousticTokenizerConfig"),
  480. ("vibevoice_acoustic_tokenizer_decoder", "VibeVoiceAcousticTokenizerDecoderConfig"),
  481. ("vibevoice_acoustic_tokenizer_encoder", "VibeVoiceAcousticTokenizerEncoderConfig"),
  482. ("vibevoice_asr", "VibeVoiceAsrConfig"),
  483. ("video_llama_3", "VideoLlama3Config"),
  484. ("video_llama_3_vision", "VideoLlama3VisionConfig"),
  485. ("video_llava", "VideoLlavaConfig"),
  486. ("videomae", "VideoMAEConfig"),
  487. ("videomt", "VideomtConfig"),
  488. ("vilt", "ViltConfig"),
  489. ("vipllava", "VipLlavaConfig"),
  490. ("vision-encoder-decoder", "VisionEncoderDecoderConfig"),
  491. ("vision-text-dual-encoder", "VisionTextDualEncoderConfig"),
  492. ("visual_bert", "VisualBertConfig"),
  493. ("vit", "ViTConfig"),
  494. ("vit_mae", "ViTMAEConfig"),
  495. ("vit_msn", "ViTMSNConfig"),
  496. ("vitdet", "VitDetConfig"),
  497. ("vitmatte", "VitMatteConfig"),
  498. ("vitpose", "VitPoseConfig"),
  499. ("vitpose_backbone", "VitPoseBackboneConfig"),
  500. ("vits", "VitsConfig"),
  501. ("vivit", "VivitConfig"),
  502. ("vjepa2", "VJEPA2Config"),
  503. ("voxtral", "VoxtralConfig"),
  504. ("voxtral_encoder", "VoxtralEncoderConfig"),
  505. ("voxtral_realtime", "VoxtralRealtimeConfig"),
  506. ("voxtral_realtime_encoder", "VoxtralRealtimeEncoderConfig"),
  507. ("voxtral_realtime_text", "VoxtralRealtimeTextConfig"),
  508. ("wav2vec2", "Wav2Vec2Config"),
  509. ("wav2vec2-bert", "Wav2Vec2BertConfig"),
  510. ("wav2vec2-conformer", "Wav2Vec2ConformerConfig"),
  511. ("wavlm", "WavLMConfig"),
  512. ("whisper", "WhisperConfig"),
  513. ("xclip", "XCLIPConfig"),
  514. ("xcodec", "XcodecConfig"),
  515. ("xglm", "XGLMConfig"),
  516. ("xlm", "XLMConfig"),
  517. ("xlm-roberta", "XLMRobertaConfig"),
  518. ("xlm-roberta-xl", "XLMRobertaXLConfig"),
  519. ("xlnet", "XLNetConfig"),
  520. ("xlstm", "xLSTMConfig"),
  521. ("xmod", "XmodConfig"),
  522. ("yolos", "YolosConfig"),
  523. ("yoso", "YosoConfig"),
  524. ("youtu", "YoutuConfig"),
  525. ("zamba", "ZambaConfig"),
  526. ("zamba2", "Zamba2Config"),
  527. ("zoedepth", "ZoeDepthConfig"),
  528. ]
  529. )
  530. MODEL_NAMES_MAPPING = OrderedDict[str, str](
  531. [
  532. # Add full (and cased) model names here
  533. ("afmoe", "AFMoE"),
  534. ("aimv2", "AIMv2"),
  535. ("aimv2_vision_model", "Aimv2VisionModel"),
  536. ("albert", "ALBERT"),
  537. ("align", "ALIGN"),
  538. ("altclip", "AltCLIP"),
  539. ("apertus", "Apertus"),
  540. ("arcee", "Arcee"),
  541. ("aria", "Aria"),
  542. ("aria_text", "AriaText"),
  543. ("audio-spectrogram-transformer", "Audio Spectrogram Transformer"),
  544. ("audioflamingo3", "AudioFlamingo3"),
  545. ("audioflamingo3_encoder", "AudioFlamingo3Encoder"),
  546. ("autoformer", "Autoformer"),
  547. ("aya_vision", "AyaVision"),
  548. ("bamba", "Bamba"),
  549. ("bark", "Bark"),
  550. ("bart", "BART"),
  551. ("barthez", "BARThez"),
  552. ("bartpho", "BARTpho"),
  553. ("beit", "BEiT"),
  554. ("bert", "BERT"),
  555. ("bert-generation", "Bert Generation"),
  556. ("bert-japanese", "BertJapanese"),
  557. ("bertweet", "BERTweet"),
  558. ("big_bird", "BigBird"),
  559. ("bigbird_pegasus", "BigBird-Pegasus"),
  560. ("biogpt", "BioGpt"),
  561. ("bit", "BiT"),
  562. ("bitnet", "BitNet"),
  563. ("blenderbot", "Blenderbot"),
  564. ("blenderbot-small", "BlenderbotSmall"),
  565. ("blip", "BLIP"),
  566. ("blip-2", "BLIP-2"),
  567. ("blip_2_qformer", "BLIP-2 QFormer"),
  568. ("bloom", "BLOOM"),
  569. ("blt", "Blt"),
  570. ("bridgetower", "BridgeTower"),
  571. ("bros", "BROS"),
  572. ("byt5", "ByT5"),
  573. ("camembert", "CamemBERT"),
  574. ("canine", "CANINE"),
  575. ("chameleon", "Chameleon"),
  576. ("chinese_clip", "Chinese-CLIP"),
  577. ("chinese_clip_vision_model", "ChineseCLIPVisionModel"),
  578. ("chmv2", "CHMv2"),
  579. ("clap", "CLAP"),
  580. ("clip", "CLIP"),
  581. ("clip_text_model", "CLIPTextModel"),
  582. ("clip_vision_model", "CLIPVisionModel"),
  583. ("clipseg", "CLIPSeg"),
  584. ("clvp", "CLVP"),
  585. ("code_llama", "CodeLlama"),
  586. ("codegen", "CodeGen"),
  587. ("cohere", "Cohere"),
  588. ("cohere2", "Cohere2"),
  589. ("cohere2_vision", "Cohere2Vision"),
  590. ("cohere_asr", "CohereASR"),
  591. ("colmodernvbert", "ColModernVBert"),
  592. ("colpali", "ColPali"),
  593. ("colqwen2", "ColQwen2"),
  594. ("conditional_detr", "Conditional DETR"),
  595. ("convbert", "ConvBERT"),
  596. ("convnext", "ConvNeXT"),
  597. ("convnextv2", "ConvNeXTV2"),
  598. ("cpm", "CPM"),
  599. ("cpmant", "CPM-Ant"),
  600. ("csm", "CSM"),
  601. ("ctrl", "CTRL"),
  602. ("cvt", "CvT"),
  603. ("cwm", "Code World Model (CWM)"),
  604. ("d_fine", "D-FINE"),
  605. ("dab-detr", "DAB-DETR"),
  606. ("dac", "DAC"),
  607. ("data2vec-audio", "Data2VecAudio"),
  608. ("data2vec-text", "Data2VecText"),
  609. ("data2vec-vision", "Data2VecVision"),
  610. ("dbrx", "DBRX"),
  611. ("deberta", "DeBERTa"),
  612. ("deberta-v2", "DeBERTa-v2"),
  613. ("decision_transformer", "Decision Transformer"),
  614. ("deepseek_v2", "DeepSeek-V2"),
  615. ("deepseek_v3", "DeepSeek-V3"),
  616. ("deepseek_vl", "DeepseekVL"),
  617. ("deepseek_vl_hybrid", "DeepseekVLHybrid"),
  618. ("deformable_detr", "Deformable DETR"),
  619. ("deit", "DeiT"),
  620. ("deplot", "DePlot"),
  621. ("depth_anything", "Depth Anything"),
  622. ("depth_anything_v2", "Depth Anything V2"),
  623. ("depth_pro", "DepthPro"),
  624. ("detr", "DETR"),
  625. ("dia", "Dia"),
  626. ("dialogpt", "DialoGPT"),
  627. ("diffllama", "DiffLlama"),
  628. ("dinat", "DiNAT"),
  629. ("dinov2", "DINOv2"),
  630. ("dinov2_with_registers", "DINOv2 with Registers"),
  631. ("dinov3_convnext", "DINOv3 ConvNext"),
  632. ("dinov3_vit", "DINOv3 ViT"),
  633. ("distilbert", "DistilBERT"),
  634. ("dit", "DiT"),
  635. ("doge", "Doge"),
  636. ("donut-swin", "DonutSwin"),
  637. ("dots1", "dots1"),
  638. ("dpr", "DPR"),
  639. ("dpt", "DPT"),
  640. ("edgetam", "EdgeTAM"),
  641. ("edgetam_video", "EdgeTamVideo"),
  642. ("edgetam_vision_model", "EdgeTamVisionModel"),
  643. ("efficientloftr", "EfficientLoFTR"),
  644. ("efficientnet", "EfficientNet"),
  645. ("electra", "ELECTRA"),
  646. ("emu3", "Emu3"),
  647. ("encodec", "EnCodec"),
  648. ("encoder-decoder", "Encoder decoder"),
  649. ("eomt", "EoMT"),
  650. ("eomt_dinov3", "EoMT-DINOv3"),
  651. ("ernie", "ERNIE"),
  652. ("ernie4_5", "Ernie4_5"),
  653. ("ernie4_5_moe", "Ernie4_5_MoE"),
  654. ("ernie4_5_vl_moe", "Ernie4_5_VLMoE"),
  655. ("esm", "ESM"),
  656. ("eurobert", "EuroBERT"),
  657. ("evolla", "Evolla"),
  658. ("exaone4", "EXAONE-4.0"),
  659. ("exaone_moe", "EXAONE-MoE"),
  660. ("falcon", "Falcon"),
  661. ("falcon3", "Falcon3"),
  662. ("falcon_h1", "FalconH1"),
  663. ("falcon_mamba", "FalconMamba"),
  664. ("fast_vlm", "FastVlm"),
  665. ("fastspeech2_conformer", "FastSpeech2Conformer"),
  666. ("fastspeech2_conformer_with_hifigan", "FastSpeech2ConformerWithHifiGan"),
  667. ("flan-t5", "FLAN-T5"),
  668. ("flan-ul2", "FLAN-UL2"),
  669. ("flaubert", "FlauBERT"),
  670. ("flava", "FLAVA"),
  671. ("flex_olmo", "FlexOlmo"),
  672. ("florence2", "Florence2"),
  673. ("fnet", "FNet"),
  674. ("focalnet", "FocalNet"),
  675. ("fsmt", "FairSeq Machine-Translation"),
  676. ("funnel", "Funnel Transformer"),
  677. ("fuyu", "Fuyu"),
  678. ("gemma", "Gemma"),
  679. ("gemma2", "Gemma2"),
  680. ("gemma3", "Gemma3ForConditionalGeneration"),
  681. ("gemma3_text", "Gemma3ForCausalLM"),
  682. ("gemma3n", "Gemma3nForConditionalGeneration"),
  683. ("gemma3n_audio", "Gemma3nAudioEncoder"),
  684. ("gemma3n_text", "Gemma3nForCausalLM"),
  685. ("gemma3n_vision", "TimmWrapperModel"),
  686. ("gemma4", "Gemma4ForConditionalGeneration"),
  687. ("gemma4_audio", "Gemma4AudioModel"),
  688. ("gemma4_text", "Gemma4ForCausalLM"),
  689. ("gemma4_vision", "Gemma4VisionModel"),
  690. ("git", "GIT"),
  691. ("glm", "GLM"),
  692. ("glm4", "GLM4"),
  693. ("glm46v", "Glm46V"),
  694. ("glm4_moe", "Glm4MoE"),
  695. ("glm4_moe_lite", "Glm4MoELite"),
  696. ("glm4v", "GLM4V"),
  697. ("glm4v_moe", "GLM4VMOE"),
  698. ("glm4v_moe_text", "GLM4VMOE"),
  699. ("glm4v_moe_vision", "Glm4vMoeVisionModel"),
  700. ("glm4v_text", "GLM4V"),
  701. ("glm4v_vision", "Glm4vVisionModel"),
  702. ("glm_image", "GlmImage"),
  703. ("glm_image_text", "GlmImageText"),
  704. ("glm_image_vision", "GlmImageVisionModel"),
  705. ("glm_image_vqmodel", "GlmImageVQVAE"),
  706. ("glm_moe_dsa", "GlmMoeDsa"),
  707. ("glm_ocr", "Glmocr"),
  708. ("glm_ocr_text", "GlmOcrText"),
  709. ("glm_ocr_vision", "GlmOcrVisionModel"),
  710. ("glmasr", "GLM-ASR"),
  711. ("glmasr_encoder", "GLM-ASR Encoder"),
  712. ("glpn", "GLPN"),
  713. ("got_ocr2", "GOT-OCR2"),
  714. ("gpt-sw3", "GPT-Sw3"),
  715. ("gpt2", "OpenAI GPT-2"),
  716. ("gpt_bigcode", "GPTBigCode"),
  717. ("gpt_neo", "GPT Neo"),
  718. ("gpt_neox", "GPT NeoX"),
  719. ("gpt_neox_japanese", "GPT NeoX Japanese"),
  720. ("gpt_oss", "GptOss"),
  721. ("gptj", "GPT-J"),
  722. ("granite", "Granite"),
  723. ("granite_speech", "GraniteSpeech"),
  724. ("granitemoe", "GraniteMoeMoe"),
  725. ("granitemoehybrid", "GraniteMoeHybrid"),
  726. ("granitemoeshared", "GraniteMoeSharedMoe"),
  727. ("granitevision", "LLaVA-NeXT"),
  728. ("grounding-dino", "Grounding DINO"),
  729. ("groupvit", "GroupViT"),
  730. ("helium", "Helium"),
  731. ("herbert", "HerBERT"),
  732. ("hgnet_v2", "HGNet-V2"),
  733. ("hiera", "Hiera"),
  734. ("higgs_audio_v2", "HiggsAudioV2"),
  735. ("higgs_audio_v2_tokenizer", "HiggsAudioV2Tokenizer"),
  736. ("hubert", "Hubert"),
  737. ("hunyuan_v1_dense", "HunYuanDenseV1"),
  738. ("hunyuan_v1_moe", "HunYuanMoeV1"),
  739. ("ibert", "I-BERT"),
  740. ("idefics", "IDEFICS"),
  741. ("idefics2", "Idefics2"),
  742. ("idefics3", "Idefics3"),
  743. ("idefics3_vision", "Idefics3VisionTransformer"),
  744. ("ijepa", "I-JEPA"),
  745. ("imagegpt", "ImageGPT"),
  746. ("informer", "Informer"),
  747. ("instructblip", "InstructBLIP"),
  748. ("instructblipvideo", "InstructBlipVideo"),
  749. ("internvl", "InternVL"),
  750. ("internvl_vision", "InternVLVision"),
  751. ("jais2", "Jais2"),
  752. ("jamba", "Jamba"),
  753. ("janus", "Janus"),
  754. ("jetmoe", "JetMoe"),
  755. ("jina_embeddings_v3", "JinaEmbeddingsV3"),
  756. ("kosmos-2", "KOSMOS-2"),
  757. ("kosmos-2.5", "KOSMOS-2.5"),
  758. ("kyutai_speech_to_text", "KyutaiSpeechToText"),
  759. ("lasr", "Lasr"),
  760. ("lasr_ctc", "Lasr"),
  761. ("lasr_encoder", "LasrEncoder"),
  762. ("layoutlm", "LayoutLM"),
  763. ("layoutlmv2", "LayoutLMv2"),
  764. ("layoutlmv3", "LayoutLMv3"),
  765. ("layoutxlm", "LayoutXLM"),
  766. ("led", "LED"),
  767. ("levit", "LeViT"),
  768. ("lfm2", "Lfm2"),
  769. ("lfm2_moe", "Lfm2Moe"),
  770. ("lfm2_vl", "Lfm2Vl"),
  771. ("lightglue", "LightGlue"),
  772. ("lighton_ocr", "LightOnOcr"),
  773. ("lilt", "LiLT"),
  774. ("llama", "LLaMA"),
  775. ("llama2", "Llama2"),
  776. ("llama3", "Llama3"),
  777. ("llama4", "Llama4"),
  778. ("llama4_text", "Llama4ForCausalLM"),
  779. ("llava", "LLaVa"),
  780. ("llava_next", "LLaVA-NeXT"),
  781. ("llava_next_video", "LLaVa-NeXT-Video"),
  782. ("llava_onevision", "LLaVA-Onevision"),
  783. ("longcat_flash", "LongCatFlash"),
  784. ("longformer", "Longformer"),
  785. ("longt5", "LongT5"),
  786. ("luke", "LUKE"),
  787. ("lw_detr", "LwDetr"),
  788. ("lw_detr_vit", "LwDetrVit"),
  789. ("lxmert", "LXMERT"),
  790. ("m2m_100", "M2M100"),
  791. ("madlad-400", "MADLAD-400"),
  792. ("mamba", "Mamba"),
  793. ("mamba2", "mamba2"),
  794. ("marian", "Marian"),
  795. ("markuplm", "MarkupLM"),
  796. ("mask2former", "Mask2Former"),
  797. ("maskformer", "MaskFormer"),
  798. ("maskformer-swin", "MaskFormerSwin"),
  799. ("matcha", "MatCha"),
  800. ("mbart", "mBART"),
  801. ("mbart50", "mBART-50"),
  802. ("megatron-bert", "Megatron-BERT"),
  803. ("megatron_gpt2", "Megatron-GPT2"),
  804. ("metaclip_2", "MetaCLIP 2"),
  805. ("mgp-str", "MGP-STR"),
  806. ("mimi", "Mimi"),
  807. ("minimax", "MiniMax"),
  808. ("minimax_m2", "MiniMax-M2"),
  809. ("ministral", "Ministral"),
  810. ("ministral3", "Ministral3"),
  811. ("mistral", "Mistral"),
  812. ("mistral3", "Mistral3"),
  813. ("mistral4", "Mistral4"),
  814. ("mixtral", "Mixtral"),
  815. ("mlcd", "MLCD"), # Keep this to make some original hub repositories (from `DeepGlint-AI`) works
  816. ("mlcd_vision_model", "MLCD"),
  817. ("mllama", "Mllama"),
  818. ("mluke", "mLUKE"),
  819. ("mm-grounding-dino", "MM Grounding DINO"),
  820. ("mms", "MMS"),
  821. ("mobilebert", "MobileBERT"),
  822. ("mobilenet_v1", "MobileNetV1"),
  823. ("mobilenet_v2", "MobileNetV2"),
  824. ("mobilevit", "MobileViT"),
  825. ("mobilevitv2", "MobileViTV2"),
  826. ("modernbert", "ModernBERT"),
  827. ("modernbert-decoder", "ModernBertDecoder"),
  828. ("modernvbert", "ModernVBert"),
  829. ("moonshine", "Moonshine"),
  830. ("moonshine_streaming", "MoonshineStreaming"),
  831. ("moonshine_streaming_encoder", "MoonshineStreamingEncoder"),
  832. ("moshi", "Moshi"),
  833. ("mpnet", "MPNet"),
  834. ("mpt", "MPT"),
  835. ("mra", "MRA"),
  836. ("mt5", "MT5"),
  837. ("musicflamingo", "MusicFlamingo"),
  838. ("musicflamingo_encoder", "AudioFlamingo3Encoder"),
  839. ("musicgen", "MusicGen"),
  840. ("musicgen_melody", "MusicGen Melody"),
  841. ("mvp", "MVP"),
  842. ("myt5", "myt5"),
  843. ("nanochat", "NanoChat"),
  844. ("nemotron", "Nemotron"),
  845. ("nemotron_h", "NemotronH"),
  846. ("nllb", "NLLB"),
  847. ("nllb-moe", "NLLB-MOE"),
  848. ("nomic_bert", "NomicBERT"),
  849. ("nougat", "Nougat"),
  850. ("nystromformer", "Nyströmformer"),
  851. ("olmo", "OLMo"),
  852. ("olmo2", "OLMo2"),
  853. ("olmo3", "Olmo3"),
  854. ("olmo_hybrid", "OlmoHybrid"),
  855. ("olmoe", "OLMoE"),
  856. ("omdet-turbo", "OmDet-Turbo"),
  857. ("oneformer", "OneFormer"),
  858. ("openai-gpt", "OpenAI GPT"),
  859. ("opt", "OPT"),
  860. ("ovis2", "Ovis2"),
  861. ("owlv2", "OWLv2"),
  862. ("owlvit", "OWL-ViT"),
  863. ("paddleocr_vl", "PaddleOCRVL"),
  864. ("paligemma", "PaliGemma"),
  865. ("parakeet", "Parakeet"),
  866. ("parakeet_ctc", "Parakeet"),
  867. ("parakeet_encoder", "ParakeetEncoder"),
  868. ("patchtsmixer", "PatchTSMixer"),
  869. ("patchtst", "PatchTST"),
  870. ("pe_audio", "PeAudio"),
  871. ("pe_audio_encoder", "PeAudioEncoder"),
  872. ("pe_audio_video", "PeAudioVideo"),
  873. ("pe_audio_video_encoder", "PeAudioVideoEncoder"),
  874. ("pe_video", "PeVideo"),
  875. ("pe_video_encoder", "PeVideoEncoder"),
  876. ("pegasus", "Pegasus"),
  877. ("pegasus_x", "PEGASUS-X"),
  878. ("perceiver", "Perceiver"),
  879. ("perception_lm", "PerceptionLM"),
  880. ("persimmon", "Persimmon"),
  881. ("phi", "Phi"),
  882. ("phi3", "Phi3"),
  883. ("phi4_multimodal", "Phi4Multimodal"),
  884. ("phimoe", "Phimoe"),
  885. ("phobert", "PhoBERT"),
  886. ("pi0", "PI0"),
  887. ("pix2struct", "Pix2Struct"),
  888. ("pixio", "Pixio"),
  889. ("pixtral", "Pixtral"),
  890. ("plbart", "PLBart"),
  891. ("poolformer", "PoolFormer"),
  892. ("pop2piano", "Pop2Piano"),
  893. ("pp_chart2table", "PPChart2Table"),
  894. ("pp_doclayout_v2", "PPDocLayoutV2"),
  895. ("pp_doclayout_v3", "PPDocLayoutV3"),
  896. ("pp_lcnet", "PPLCNet"),
  897. ("pp_lcnet_v3", "PPLCNetV3"),
  898. ("pp_ocrv5_mobile_det", "PPOCRV5MobileDet"),
  899. ("pp_ocrv5_mobile_rec", "PPOCRV5MobileRec"),
  900. ("pp_ocrv5_server_det", "PPOCRV5ServerDet"),
  901. ("pp_ocrv5_server_rec", "PPOCRV5ServerRec"),
  902. ("prompt_depth_anything", "PromptDepthAnything"),
  903. ("prophetnet", "ProphetNet"),
  904. ("pvt", "PVT"),
  905. ("pvt_v2", "PVTv2"),
  906. ("qwen2", "Qwen2"),
  907. ("qwen2_5_omni", "Qwen2_5Omni"),
  908. ("qwen2_5_vl", "Qwen2_5_VL"),
  909. ("qwen2_5_vl_text", "Qwen2_5_VL"),
  910. ("qwen2_audio", "Qwen2Audio"),
  911. ("qwen2_audio_encoder", "Qwen2AudioEncoder"),
  912. ("qwen2_moe", "Qwen2MoE"),
  913. ("qwen2_vl", "Qwen2VL"),
  914. ("qwen2_vl_text", "Qwen2VL"),
  915. ("qwen3", "Qwen3"),
  916. ("qwen3_5", "Qwen3_5"),
  917. ("qwen3_5_moe", "Qwen3_5Moe"),
  918. ("qwen3_5_moe_text", "Qwen3_5MoeText"),
  919. ("qwen3_5_text", "Qwen3_5Text"),
  920. ("qwen3_moe", "Qwen3MoE"),
  921. ("qwen3_next", "Qwen3Next"),
  922. ("qwen3_omni_moe", "Qwen3OmniMoE"),
  923. ("qwen3_vl", "Qwen3VL"),
  924. ("qwen3_vl_moe", "Qwen3VLMoe"),
  925. ("qwen3_vl_moe_text", "Qwen3VLMoe"),
  926. ("qwen3_vl_text", "Qwen3VL"),
  927. ("rag", "RAG"),
  928. ("recurrent_gemma", "RecurrentGemma"),
  929. ("reformer", "Reformer"),
  930. ("regnet", "RegNet"),
  931. ("rembert", "RemBERT"),
  932. ("resnet", "ResNet"),
  933. ("roberta", "RoBERTa"),
  934. ("roberta-prelayernorm", "RoBERTa-PreLayerNorm"),
  935. ("roc_bert", "RoCBert"),
  936. ("roformer", "RoFormer"),
  937. ("rt_detr", "RT-DETR"),
  938. ("rt_detr_resnet", "RT-DETR-ResNet"),
  939. ("rt_detr_v2", "RT-DETRv2"),
  940. ("rwkv", "RWKV"),
  941. ("sam", "SAM"),
  942. ("sam2", "SAM2"),
  943. ("sam2_hiera_det_model", "Sam2HieraDetModel"),
  944. ("sam2_video", "Sam2VideoModel"),
  945. ("sam2_vision_model", "Sam2VisionModel"),
  946. ("sam3", "SAM3"),
  947. ("sam3_tracker", "Sam3Tracker"),
  948. ("sam3_tracker_video", "Sam3TrackerVideo"),
  949. ("sam3_video", "Sam3VideoModel"),
  950. ("sam3_vision_model", "Sam3VisionModel"),
  951. ("sam3_vit_model", "Sam3ViTModel"),
  952. ("sam_hq", "SAM-HQ"),
  953. ("sam_hq_vision_model", "SamHQVisionModel"),
  954. ("sam_vision_model", "SamVisionModel"),
  955. ("seamless_m4t", "SeamlessM4T"),
  956. ("seamless_m4t_v2", "SeamlessM4Tv2"),
  957. ("seed_oss", "SeedOss"),
  958. ("segformer", "SegFormer"),
  959. ("seggpt", "SegGPT"),
  960. ("sew", "SEW"),
  961. ("sew-d", "SEW-D"),
  962. ("shieldgemma2", "Shieldgemma2"),
  963. ("siglip", "SigLIP"),
  964. ("siglip2", "SigLIP2"),
  965. ("siglip2_vision_model", "Siglip2VisionModel"),
  966. ("siglip_vision_model", "SiglipVisionModel"),
  967. ("slanext", "SLANeXt"),
  968. ("smollm3", "SmolLM3"),
  969. ("smolvlm", "SmolVLM"),
  970. ("smolvlm_vision", "SmolVLMVisionTransformer"),
  971. ("solar_open", "SolarOpen"),
  972. ("speech-encoder-decoder", "Speech Encoder decoder"),
  973. ("speech_to_text", "Speech2Text"),
  974. ("speecht5", "SpeechT5"),
  975. ("splinter", "Splinter"),
  976. ("squeezebert", "SqueezeBERT"),
  977. ("stablelm", "StableLm"),
  978. ("starcoder2", "Starcoder2"),
  979. ("superglue", "SuperGlue"),
  980. ("superpoint", "SuperPoint"),
  981. ("swiftformer", "SwiftFormer"),
  982. ("swin", "Swin Transformer"),
  983. ("swin2sr", "Swin2SR"),
  984. ("swinv2", "Swin Transformer V2"),
  985. ("switch_transformers", "SwitchTransformers"),
  986. ("t5", "T5"),
  987. ("t5gemma", "T5Gemma"),
  988. ("t5gemma2", "T5Gemma2"),
  989. ("t5gemma2_encoder", "T5Gemma2Encoder"),
  990. ("t5v1.1", "T5v1.1"),
  991. ("table-transformer", "Table Transformer"),
  992. ("tapas", "TAPAS"),
  993. ("textnet", "TextNet"),
  994. ("time_series_transformer", "Time Series Transformer"),
  995. ("timesfm", "TimesFm"),
  996. ("timesfm2_5", "TimesFm2p5"),
  997. ("timesformer", "TimeSformer"),
  998. ("timm_backbone", "TimmBackbone"),
  999. ("timm_wrapper", "TimmWrapperModel"),
  1000. ("trocr", "TrOCR"),
  1001. ("tvp", "TVP"),
  1002. ("udop", "UDOP"),
  1003. ("ul2", "UL2"),
  1004. ("umt5", "UMT5"),
  1005. ("unispeech", "UniSpeech"),
  1006. ("unispeech-sat", "UniSpeechSat"),
  1007. ("univnet", "UnivNet"),
  1008. ("upernet", "UPerNet"),
  1009. ("uvdoc", "UVDoc"),
  1010. ("uvdoc_backbone", "UVDocBackbone"),
  1011. ("vaultgemma", "VaultGemma"),
  1012. ("vibevoice_acoustic_tokenizer", "VibeVoiceAcousticTokenizer"),
  1013. ("vibevoice_acoustic_tokenizer_decoder", "VibeVoiceAcousticTokenizerDecoderConfig"),
  1014. ("vibevoice_acoustic_tokenizer_encoder", "VibeVoiceAcousticTokenizerEncoderConfig"),
  1015. ("vibevoice_asr", "VibeVoiceAsr"),
  1016. ("video_llama_3", "VideoLlama3"),
  1017. ("video_llama_3_vision", "VideoLlama3Vision"),
  1018. ("video_llava", "VideoLlava"),
  1019. ("videomae", "VideoMAE"),
  1020. ("videomt", "VidEoMT"),
  1021. ("vilt", "ViLT"),
  1022. ("vipllava", "VipLlava"),
  1023. ("vision-encoder-decoder", "Vision Encoder decoder"),
  1024. ("vision-text-dual-encoder", "VisionTextDualEncoder"),
  1025. ("visual_bert", "VisualBERT"),
  1026. ("vit", "ViT"),
  1027. ("vit_mae", "ViTMAE"),
  1028. ("vit_msn", "ViTMSN"),
  1029. ("vitdet", "VitDet"),
  1030. ("vitmatte", "ViTMatte"),
  1031. ("vitpose", "ViTPose"),
  1032. ("vitpose_backbone", "ViTPoseBackbone"),
  1033. ("vits", "VITS"),
  1034. ("vivit", "ViViT"),
  1035. ("vjepa2", "VJEPA2Model"),
  1036. ("voxtral", "Voxtral"),
  1037. ("voxtral_encoder", "Voxtral Encoder"),
  1038. ("voxtral_realtime", "VoxtralRealtime"),
  1039. ("voxtral_realtime_encoder", "VoxtralRealtime Encoder"),
  1040. ("voxtral_realtime_text", "VoxtralRealtime Text Model"),
  1041. ("wav2vec2", "Wav2Vec2"),
  1042. ("wav2vec2-bert", "Wav2Vec2-BERT"),
  1043. ("wav2vec2-conformer", "Wav2Vec2-Conformer"),
  1044. ("wav2vec2_phoneme", "Wav2Vec2Phoneme"),
  1045. ("wavlm", "WavLM"),
  1046. ("whisper", "Whisper"),
  1047. ("xclip", "X-CLIP"),
  1048. ("xcodec", "X-CODEC"),
  1049. ("xglm", "XGLM"),
  1050. ("xlm", "XLM"),
  1051. ("xlm-roberta", "XLM-RoBERTa"),
  1052. ("xlm-roberta-xl", "XLM-RoBERTa-XL"),
  1053. ("xlm-v", "XLM-V"),
  1054. ("xlnet", "XLNet"),
  1055. ("xls_r", "XLS-R"),
  1056. ("xlsr_wav2vec2", "XLSR-Wav2Vec2"),
  1057. ("xlstm", "xLSTM"),
  1058. ("xmod", "X-MOD"),
  1059. ("yolos", "YOLOS"),
  1060. ("yoso", "YOSO"),
  1061. ("youtu", "Youtu"),
  1062. ("zamba", "Zamba"),
  1063. ("zamba2", "Zamba2"),
  1064. ("zoedepth", "ZoeDepth"),
  1065. ]
  1066. )
  1067. # This is tied to the processing `-` -> `_` in `model_type_to_module_name`. For example, instead of putting
  1068. # `transfo-xl` (as in `CONFIG_MAPPING_NAMES`), we should use `transfo_xl`.
  1069. DEPRECATED_MODELS = []
  1070. SPECIAL_MODEL_TYPE_TO_MODULE_NAME = OrderedDict[str, str](
  1071. [
  1072. ("audioflamingo3_encoder", "audioflamingo3"),
  1073. ("musicflamingo_encoder", "musicflamingo"),
  1074. ("openai-gpt", "openai"),
  1075. ("blip-2", "blip_2"),
  1076. ("data2vec-audio", "data2vec"),
  1077. ("data2vec-text", "data2vec"),
  1078. ("data2vec-vision", "data2vec"),
  1079. ("donut-swin", "donut"),
  1080. ("kosmos-2", "kosmos2"),
  1081. ("kosmos-2.5", "kosmos2_5"),
  1082. ("mlcd_vision_model", "mlcd"),
  1083. ("omdet-turbo", "omdet_turbo"),
  1084. ("maskformer-swin", "maskformer"),
  1085. ("xclip", "x_clip"),
  1086. ("clip_vision_model", "clip"),
  1087. ("qwen2_audio_encoder", "qwen2_audio"),
  1088. ("voxtral_encoder", "voxtral"),
  1089. ("voxtral_realtime_encoder", "voxtral_realtime"),
  1090. ("voxtral_realtime_text", "voxtral_realtime"),
  1091. ("clip_text_model", "clip"),
  1092. ("aria_text", "aria"),
  1093. ("gemma3_text", "gemma3"),
  1094. ("gemma3n_audio", "gemma3n"),
  1095. ("gemma3n_text", "gemma3n"),
  1096. ("gemma3n_vision", "gemma3n"),
  1097. ("gemma4_audio", "gemma4"),
  1098. ("gemma4_text", "gemma4"),
  1099. ("gemma4_vision", "gemma4"),
  1100. ("glm4v_vision", "glm4v"),
  1101. ("glm4v_moe_vision", "glm4v_moe"),
  1102. ("glm4v_text", "glm4v"),
  1103. ("glm4v_moe_text", "glm4v_moe"),
  1104. ("glm_image_vision", "glm_image"),
  1105. ("glm_image_vqmodel", "glm_image"),
  1106. ("glm_image_text", "glm_image"),
  1107. ("glm_ocr_vision", "glm_ocr"),
  1108. ("glm_ocr_vqmodel", "glm_ocr"),
  1109. ("glm_ocr_text", "glm_ocr"),
  1110. ("glmasr_encoder", "glmasr"),
  1111. ("grounding-dino", "grounding_dino"),
  1112. ("moonshine_streaming_encoder", "moonshine_streaming"),
  1113. ("mm-grounding-dino", "mm_grounding_dino"),
  1114. ("idefics3_vision", "idefics3"),
  1115. ("mgp-str", "mgp_str"),
  1116. ("siglip_vision_model", "siglip"),
  1117. ("siglip2_vision_model", "siglip2"),
  1118. ("aimv2_vision_model", "aimv2"),
  1119. ("smolvlm_vision", "smolvlm"),
  1120. ("chinese_clip_vision_model", "chinese_clip"),
  1121. ("rt_detr_resnet", "rt_detr"),
  1122. ("granitevision", "llava_next"),
  1123. ("internvl_vision", "internvl"),
  1124. ("qwen2_5_vl_text", "qwen2_5_vl"),
  1125. ("qwen2_vl_text", "qwen2_vl"),
  1126. ("qwen3_vl_text", "qwen3_vl"),
  1127. ("qwen3_vl_moe_text", "qwen3_vl_moe"),
  1128. ("qwen3_5_text", "qwen3_5"),
  1129. ("qwen3_5_moe_text", "qwen3_5_moe"),
  1130. ("sam_vision_model", "sam"),
  1131. ("sam2_vision_model", "sam2"),
  1132. ("sam2_hiera_det_model", "sam2"),
  1133. ("sam3_vit_model", "sam3"),
  1134. ("sam3_vision_model", "sam3"),
  1135. ("edgetam_vision_model", "edgetam"),
  1136. ("sam_hq_vision_model", "sam_hq"),
  1137. ("t5gemma2_encoder", "t5gemma2"),
  1138. ("llama4_text", "llama4"),
  1139. ("blip_2_qformer", "blip_2"),
  1140. ("fastspeech2_conformer_with_hifigan", "fastspeech2_conformer"),
  1141. ("perception_encoder", "perception_lm"),
  1142. ("pe_audio_encoder", "pe_audio"),
  1143. ("pe_video_encoder", "pe_video"),
  1144. ("pe_audio_video_encoder", "pe_audio_video"),
  1145. ("video_llama_3_vision", "video_llama_3"),
  1146. ("parakeet_encoder", "parakeet"),
  1147. ("lw_detr_vit", "lw_detr"),
  1148. ("parakeet_ctc", "parakeet"),
  1149. ("lasr_encoder", "lasr"),
  1150. ("lasr_ctc", "lasr"),
  1151. ("wav2vec2-bert", "wav2vec2_bert"),
  1152. ("vibevoice_acoustic_tokenizer_encoder", "vibevoice_acoustic_tokenizer"),
  1153. ("vibevoice_acoustic_tokenizer_decoder", "vibevoice_acoustic_tokenizer"),
  1154. ("uvdoc_backbone", "uvdoc"),
  1155. ]
  1156. )
  1157. def model_type_to_module_name(key) -> str:
  1158. """Converts a config key to the corresponding module."""
  1159. # Special treatment
  1160. if key in SPECIAL_MODEL_TYPE_TO_MODULE_NAME:
  1161. key = SPECIAL_MODEL_TYPE_TO_MODULE_NAME[key]
  1162. if key in DEPRECATED_MODELS:
  1163. key = f"deprecated.{key}"
  1164. return key
  1165. key = key.replace("-", "_")
  1166. if key in DEPRECATED_MODELS:
  1167. key = f"deprecated.{key}"
  1168. return key
  1169. def config_class_to_model_type(config) -> str | None:
  1170. """Converts a config class name to the corresponding model type"""
  1171. for key, cls in CONFIG_MAPPING_NAMES.items():
  1172. if cls == config:
  1173. return key
  1174. # if key not found check in extra content
  1175. for key, cls in CONFIG_MAPPING._extra_content.items():
  1176. if cls.__name__ == config:
  1177. return key
  1178. return None
  1179. class _LazyConfigMapping(OrderedDict[str, type[PreTrainedConfig]]):
  1180. """
  1181. A dictionary that lazily load its values when they are requested.
  1182. """
  1183. def __init__(self, mapping) -> None:
  1184. self._mapping = mapping
  1185. self._extra_content = {}
  1186. self._modules = {}
  1187. def __getitem__(self, key: str) -> type[PreTrainedConfig]:
  1188. if key in self._extra_content:
  1189. return self._extra_content[key]
  1190. if key not in self._mapping:
  1191. raise KeyError(key)
  1192. value = self._mapping[key]
  1193. module_name = model_type_to_module_name(key)
  1194. if module_name not in self._modules:
  1195. self._modules[module_name] = importlib.import_module(f".{module_name}", "transformers.models")
  1196. if hasattr(self._modules[module_name], value):
  1197. return getattr(self._modules[module_name], value)
  1198. # Some of the mappings have entries model_type -> config of another model type. In that case we try to grab the
  1199. # object at the top level.
  1200. transformers_module = importlib.import_module("transformers")
  1201. return getattr(transformers_module, value)
  1202. def keys(self) -> list[str]:
  1203. return list(self._mapping.keys()) + list(self._extra_content.keys())
  1204. def values(self) -> list[type[PreTrainedConfig]]:
  1205. return [self[k] for k in self._mapping] + list(self._extra_content.values())
  1206. def items(self) -> list[tuple[str, type[PreTrainedConfig]]]:
  1207. return [(k, self[k]) for k in self._mapping] + list(self._extra_content.items())
  1208. def __iter__(self) -> Iterator[str]:
  1209. return iter(list(self._mapping.keys()) + list(self._extra_content.keys()))
  1210. def __contains__(self, item: object) -> bool:
  1211. return item in self._mapping or item in self._extra_content
  1212. def register(self, key: str, value: type[PreTrainedConfig], exist_ok=False) -> None:
  1213. """
  1214. Register a new configuration in this mapping.
  1215. """
  1216. if key in self._mapping and not exist_ok:
  1217. raise ValueError(f"'{key}' is already used by a Transformers config, pick another name.")
  1218. self._extra_content[key] = value
  1219. CONFIG_MAPPING = _LazyConfigMapping(CONFIG_MAPPING_NAMES)
  1220. class _LazyLoadAllMappings(OrderedDict[str, str]):
  1221. """
  1222. A mapping that will load all pairs of key values at the first access (either by indexing, requestions keys, values,
  1223. etc.)
  1224. Args:
  1225. mapping: The mapping to load.
  1226. """
  1227. def __init__(self, mapping):
  1228. self._mapping = mapping
  1229. self._initialized = False
  1230. self._data = {}
  1231. def _initialize(self):
  1232. if self._initialized:
  1233. return
  1234. for model_type, map_name in self._mapping.items():
  1235. module_name = model_type_to_module_name(model_type)
  1236. module = importlib.import_module(f".{module_name}", "transformers.models")
  1237. mapping = getattr(module, map_name)
  1238. self._data.update(mapping)
  1239. self._initialized = True
  1240. def __getitem__(self, key):
  1241. self._initialize()
  1242. return self._data[key]
  1243. def keys(self) -> KeysView[str]:
  1244. self._initialize()
  1245. return self._data.keys()
  1246. def values(self) -> ValuesView[str]:
  1247. self._initialize()
  1248. return self._data.values()
  1249. def items(self) -> KeysView[str]:
  1250. self._initialize()
  1251. return self._data.keys()
  1252. def __iter__(self) -> Iterator[str]:
  1253. self._initialize()
  1254. return iter(self._data)
  1255. def __contains__(self, item: object) -> bool:
  1256. self._initialize()
  1257. return item in self._data
  1258. def _get_class_name(model_class: str | list[str]):
  1259. if isinstance(model_class, (list, tuple)):
  1260. return " or ".join([f"[`{c}`]" for c in model_class if c is not None])
  1261. return f"[`{model_class}`]"
  1262. def _list_model_options(indent, config_to_class=None, use_model_types=True):
  1263. if config_to_class is None and not use_model_types:
  1264. raise ValueError("Using `use_model_types=False` requires a `config_to_class` dictionary.")
  1265. if use_model_types:
  1266. if config_to_class is None:
  1267. model_type_to_name = {model_type: f"[`{config}`]" for model_type, config in CONFIG_MAPPING_NAMES.items()}
  1268. else:
  1269. model_type_to_name = {
  1270. model_type: _get_class_name(model_class)
  1271. for model_type, model_class in config_to_class.items()
  1272. if model_type in MODEL_NAMES_MAPPING
  1273. }
  1274. lines = [
  1275. f"{indent}- **{model_type}** -- {model_type_to_name[model_type]} ({MODEL_NAMES_MAPPING[model_type]} model)"
  1276. for model_type in sorted(model_type_to_name.keys())
  1277. ]
  1278. else:
  1279. config_to_name = {
  1280. CONFIG_MAPPING_NAMES[config]: _get_class_name(clas)
  1281. for config, clas in config_to_class.items()
  1282. if config in CONFIG_MAPPING_NAMES
  1283. }
  1284. config_to_model_name = {
  1285. config: MODEL_NAMES_MAPPING[model_type] for model_type, config in CONFIG_MAPPING_NAMES.items()
  1286. }
  1287. lines = [
  1288. f"{indent}- [`{config_name}`] configuration class:"
  1289. f" {config_to_name[config_name]} ({config_to_model_name[config_name]} model)"
  1290. for config_name in sorted(config_to_name.keys())
  1291. ]
  1292. return "\n".join(lines)
  1293. def replace_list_option_in_docstrings(
  1294. config_to_class=None, use_model_types: bool = True
  1295. ) -> Callable[[_CallableT], _CallableT]:
  1296. def docstring_decorator(fn):
  1297. docstrings = fn.__doc__
  1298. if docstrings is None:
  1299. # Example: -OO
  1300. return fn
  1301. lines = docstrings.split("\n")
  1302. i = 0
  1303. while i < len(lines) and re.search(r"^(\s*)List options\s*$", lines[i]) is None:
  1304. i += 1
  1305. if i < len(lines):
  1306. indent = re.search(r"^(\s*)List options\s*$", lines[i]).groups()[0]
  1307. if use_model_types:
  1308. indent = f"{indent} "
  1309. lines[i] = _list_model_options(indent, config_to_class=config_to_class, use_model_types=use_model_types)
  1310. docstrings = "\n".join(lines)
  1311. else:
  1312. raise ValueError(
  1313. f"The function {fn} should have an empty 'List options' in its docstring as placeholder, current"
  1314. f" docstring is:\n{docstrings}"
  1315. )
  1316. fn.__doc__ = docstrings
  1317. return fn
  1318. return docstring_decorator
  1319. class AutoConfig:
  1320. r"""
  1321. This is a generic configuration class that will be instantiated as one of the configuration classes of the library
  1322. when created with the [`~AutoConfig.from_pretrained`] class method.
  1323. This class cannot be instantiated directly using `__init__()` (throws an error).
  1324. """
  1325. def __init__(self) -> None:
  1326. raise OSError(
  1327. "AutoConfig is designed to be instantiated "
  1328. "using the `AutoConfig.from_pretrained(pretrained_model_name_or_path)` method."
  1329. )
  1330. @classmethod
  1331. def for_model(cls, model_type: str, *args, **kwargs) -> PreTrainedConfig:
  1332. if model_type in CONFIG_MAPPING:
  1333. config_class = CONFIG_MAPPING[model_type]
  1334. return config_class(*args, **kwargs)
  1335. raise ValueError(
  1336. f"Unrecognized model identifier: {model_type}. Should contain one of {', '.join(CONFIG_MAPPING.keys())}"
  1337. )
  1338. @classmethod
  1339. @replace_list_option_in_docstrings()
  1340. def from_pretrained(cls, pretrained_model_name_or_path: str | os.PathLike[str], **kwargs):
  1341. r"""
  1342. Instantiate one of the configuration classes of the library from a pretrained model configuration.
  1343. The configuration class to instantiate is selected based on the `model_type` property of the config object that
  1344. is loaded, or when it's missing, by falling back to using pattern matching on `pretrained_model_name_or_path`:
  1345. List options
  1346. Args:
  1347. pretrained_model_name_or_path (`str` or `os.PathLike`):
  1348. Can be either:
  1349. - A string, the *model id* of a pretrained model configuration hosted inside a model repo on
  1350. huggingface.co.
  1351. - A path to a *directory* containing a configuration file saved using the
  1352. [`~PreTrainedConfig.save_pretrained`] method, or the [`~PreTrainedModel.save_pretrained`] method,
  1353. e.g., `./my_model_directory/`.
  1354. - a path to a saved configuration JSON *file*, e.g.,
  1355. `./my_model_directory/configuration.json`.
  1356. cache_dir (`str` or `os.PathLike`, *optional*):
  1357. Path to a directory in which a downloaded pretrained model configuration should be cached if the
  1358. standard cache should not be used.
  1359. force_download (`bool`, *optional*, defaults to `False`):
  1360. Whether or not to force the (re-)download the model weights and configuration files and override the
  1361. cached versions if they exist.
  1362. proxies (`dict[str, str]`, *optional*):
  1363. A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
  1364. 'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
  1365. revision (`str`, *optional*, defaults to `"main"`):
  1366. The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
  1367. git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
  1368. identifier allowed by git.
  1369. return_unused_kwargs (`bool`, *optional*, defaults to `False`):
  1370. If `False`, then this function returns just the final configuration object.
  1371. If `True`, then this functions returns a `Tuple(config, unused_kwargs)` where *unused_kwargs* is a
  1372. dictionary consisting of the key/value pairs whose keys are not configuration attributes: i.e., the
  1373. part of `kwargs` which has not been used to update `config` and is otherwise ignored.
  1374. trust_remote_code (`bool`, *optional*, defaults to `False`):
  1375. Whether or not to allow for custom models defined on the Hub in their own modeling files. This option
  1376. should only be set to `True` for repositories you trust and in which you have read the code, as it will
  1377. execute code present on the Hub on your local machine.
  1378. kwargs(additional keyword arguments, *optional*):
  1379. The values in kwargs of any keys which are configuration attributes will be used to override the loaded
  1380. values. Behavior concerning key/value pairs whose keys are *not* configuration attributes is controlled
  1381. by the `return_unused_kwargs` keyword parameter.
  1382. Examples:
  1383. ```python
  1384. >>> from transformers import AutoConfig
  1385. >>> # Download configuration from huggingface.co and cache.
  1386. >>> config = AutoConfig.from_pretrained("google-bert/bert-base-uncased")
  1387. >>> # Download configuration from huggingface.co (user-uploaded) and cache.
  1388. >>> config = AutoConfig.from_pretrained("dbmdz/bert-base-german-cased")
  1389. >>> # If configuration file is in a directory (e.g., was saved using *save_pretrained('./test/saved_model/')*).
  1390. >>> config = AutoConfig.from_pretrained("./test/bert_saved_model/")
  1391. >>> # Load a specific configuration file.
  1392. >>> config = AutoConfig.from_pretrained("./test/bert_saved_model/my_configuration.json")
  1393. >>> # Change some config attributes when loading a pretrained config.
  1394. >>> config = AutoConfig.from_pretrained("google-bert/bert-base-uncased", output_attentions=True, foo=False)
  1395. >>> config.output_attentions
  1396. True
  1397. >>> config, unused_kwargs = AutoConfig.from_pretrained(
  1398. ... "google-bert/bert-base-uncased", output_attentions=True, foo=False, return_unused_kwargs=True
  1399. ... )
  1400. >>> config.output_attentions
  1401. True
  1402. >>> unused_kwargs
  1403. {'foo': False}
  1404. ```
  1405. """
  1406. kwargs["_from_auto"] = True
  1407. kwargs["name_or_path"] = pretrained_model_name_or_path
  1408. trust_remote_code = kwargs.pop("trust_remote_code", None)
  1409. code_revision = kwargs.pop("code_revision", None)
  1410. config_dict, unused_kwargs = PreTrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
  1411. has_remote_code = "auto_map" in config_dict and "AutoConfig" in config_dict["auto_map"]
  1412. has_local_code = "model_type" in config_dict and config_dict["model_type"] in CONFIG_MAPPING
  1413. explicit_local_code = has_local_code and not CONFIG_MAPPING[config_dict["model_type"]].__module__.startswith(
  1414. "transformers."
  1415. )
  1416. if has_remote_code:
  1417. class_ref = config_dict["auto_map"]["AutoConfig"]
  1418. if "--" in class_ref:
  1419. upstream_repo = class_ref.split("--")[0]
  1420. else:
  1421. upstream_repo = None
  1422. trust_remote_code = resolve_trust_remote_code(
  1423. trust_remote_code, pretrained_model_name_or_path, has_local_code, has_remote_code, upstream_repo
  1424. )
  1425. if has_remote_code and trust_remote_code and not explicit_local_code:
  1426. config_class = get_class_from_dynamic_module(
  1427. class_ref, pretrained_model_name_or_path, code_revision=code_revision, **kwargs
  1428. )
  1429. config_class.register_for_auto_class()
  1430. return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
  1431. elif "model_type" in config_dict:
  1432. # Apply heuristic: if model_type is mistral but layer_types is present, treat as ministral
  1433. if config_dict["model_type"] == "mistral" and "layer_types" in config_dict:
  1434. logger.info(
  1435. "Detected mistral model with layer_types, treating as ministral for alternating attention compatibility. "
  1436. )
  1437. config_dict["model_type"] = "ministral"
  1438. try:
  1439. config_class = CONFIG_MAPPING[config_dict["model_type"]]
  1440. except KeyError:
  1441. raise ValueError(
  1442. f"The checkpoint you are trying to load has model type `{config_dict['model_type']}` "
  1443. "but Transformers does not recognize this architecture. This could be because of an "
  1444. "issue with the checkpoint, or because your version of Transformers is out of date.\n\n"
  1445. "You can update Transformers with the command `pip install --upgrade transformers`. If this "
  1446. "does not work, and the checkpoint is very new, then there may not be a release version "
  1447. "that supports this model yet. In this case, you can get the most up-to-date code by installing "
  1448. "Transformers from source with the command "
  1449. "`pip install git+https://github.com/huggingface/transformers.git`"
  1450. )
  1451. return config_class.from_dict(config_dict, **unused_kwargs)
  1452. raise ValueError(
  1453. f"Unrecognized model in {pretrained_model_name_or_path}. "
  1454. f"Should have a `model_type` key in its {CONFIG_NAME}."
  1455. )
  1456. @staticmethod
  1457. def register(model_type, config, exist_ok=False) -> None:
  1458. """
  1459. Register a new configuration for this class.
  1460. Args:
  1461. model_type (`str`): The model type like "bert" or "gpt".
  1462. config ([`PreTrainedConfig`]): The config to register.
  1463. """
  1464. if issubclass(config, PreTrainedConfig) and config.model_type != model_type:
  1465. raise ValueError(
  1466. "The config you are passing has a `model_type` attribute that is not consistent with the model type "
  1467. f"you passed (config has {config.model_type} and you passed {model_type}. Fix one of those so they "
  1468. "match!"
  1469. )
  1470. CONFIG_MAPPING.register(model_type, config, exist_ok=exist_ok)
  1471. __all__ = ["CONFIG_MAPPING", "MODEL_NAMES_MAPPING", "AutoConfig"]