Auto 类
在许多情况下,可以推断出要使用的架构,依据是提供给 from_pretrained() 方法的预训练模型的名称或路径。
实例化 AutoConfig、AutoModel 或 AutoTokenizer 会自动创建相应的架构类。例如:
model = AutoModel.from_pretrained("google-bert/bert-base-cased", device_map="auto")这将创建一个 BertModel 的模型实例。
每个任务都有一个对应的 AutoModel 类。
扩展 Auto 类
每个 auto 类都提供了一个方法,允许其通过自定义类进行扩展。例如,如果你定义了一个自定义模型类 NewModel,请确保同时定义一个对应的 NewModelConfig。然后,你可以按照下面的方式将它们注册到 auto 类中:
from transformers import AutoConfig, AutoModel
AutoConfig.register("new-model", NewModelConfig)
AutoModel.register(NewModelConfig, NewModel)然后,您可以像往常一样使用 auto 类。
如果您的
NewModelConfig是 PreTrainedConfig 的子类,请确保其model_type属性设置为与注册该配置时使用的键相同(此处为"new-model")。同样,如果你的
NewModel是 PreTrainedModel 的子类,请确保其config_class属性被设置为你在注册模型时使用的同一个类(此处为NewModelConfig)。
AutoConfig
这是一个通用配置类,当使用 from_pretrained() 类方法创建时,它会被实例化为该库中的某个配置类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_pretrained
< source >( pretrained_model_name_or_path: str | os.PathLike[str]**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,即托管在 huggingface.co 模型仓库中的预训练模型配置的 model id。
- 指向一个目录的路径,该目录包含使用save_pretrained()方法或save_pretrained()方法保存的配置文件,例如
./my_model_directory/。 - 指向已保存的配置 JSON 文件的路径,例如
./my_model_directory/configuration.json。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,并在存在缓存版本时覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - return_unused_kwargs (
bool, 可选, 默认值为False) — 如果False, 为 False,则此函数仅返回最终的配置对象。如果为 True,则此函数返回一个 Tuple(config, unused_kwargs),其中 unused_kwargs 是一个字典,包含那些键不是配置属性的键值对:即 kwargs 中未用于更新 config 且被忽略的部分。如果
True,则此函数返回一个Tuple(config, unused_kwargs),其中 unused_kwargs 是一个字典,包含键不是配置属性的键值对:即kwargs中未用于更新config且被忽略的部分。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - kwargs(additional 关键字参数,可选) —
kwargs 中任何作为配置属性的键的值,将用于覆盖加载的值。对于键 不是 配置属性的键值对,其行为由
return_unused_kwargs关键字参数控制。
从预训练模型配置中实例化该库的某个配置类。
要实例化的配置类是根据加载的配置对象的 model_type 属性来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- EvollaModel — EvollaConfig(EvollaConfig 模型)
- afmoe — AfmoeConfig(AfmoeConfig 模型)
- aimv2 — Aimv2Config(Aimv2Config 模型)
- aimv2_text_model — Aimv2TextConfig(Aimv2TextConfig 模型)
- aimv2_vision_model — Aimv2VisionConfig(Aimv2VisionConfig 模型)
- albert — AlbertConfig(AlbertConfig 模型)
- align — AlignConfig(AlignConfig 模型)
- align_text_model — AlignTextConfig(AlignTextConfig 模型)
- align_vision_model — AlignVisionConfig(AlignVisionConfig 模型)
- altclip — AltCLIPConfig(AltCLIPConfig 模型)
- altclip_text_model — AltCLIPTextConfig(AltCLIPTextConfig 模型)
- altclip_vision_model — AltCLIPVisionConfig(AltCLIPVisionConfig 模型)
- apertus — ApertusConfig(ApertusConfig 模型)
- arcee — ArceeConfig(ArceeConfig 模型)
- aria — AriaConfig(AriaConfig 模型)
- aria_text — AriaTextConfig(AriaTextConfig 模型)
- audio-spectrogram-transformer — ASTConfig(ASTConfig 模型)
- audioflamingo3 — AudioFlamingo3Config(AudioFlamingo3Config 模型)
- audioflamingo3_encoder — AudioFlamingo3EncoderConfig(AudioFlamingo3EncoderConfig 模型)
- autoformer — AutoformerConfig(AutoformerConfig 模型)
- axk1 — AXK1Config(AXK1Config 模型)
- axk2 — AXK2Config(AXK2Config 模型)
- aya_vision — AyaVisionConfig(AyaVisionConfig 模型)
- bailing_hybrid — BailingHybridConfig(BailingHybridConfig 模型)
- bamba — BambaConfig(BambaConfig 模型)
- bark — BarkConfig(BarkConfig 模型)
- bart — BartConfig(BartConfig 模型)
- beam — BeamConfig(BeamConfig 模型)
- beit — BeitConfig(BeitConfig 模型)
- bert — BertConfig(BertConfig 模型)
- bert-generation — BertGenerationConfig(BertGenerationConfig 模型)
- big_bird — BigBirdConfig(BigBirdConfig 模型)
- bigbird_pegasus — BigBirdPegasusConfig(BigBirdPegasusConfig 模型)
- biogpt — BioGptConfig(BioGptConfig 模型)
- bit — BitConfig(BitConfig 模型)
- bitnet — BitNetConfig(BitNetConfig 模型)
- blenderbot — BlenderbotConfig(BlenderbotConfig 模型)
- blenderbot-small — BlenderbotSmallConfig(BlenderbotSmallConfig 模型)
- blip — BlipConfig(BlipConfig 模型)
- blip-2 — Blip2Config(Blip2Config 模型)
- blip_2_qformer — Blip2QFormerConfig(Blip2QFormerConfig 模型)
- blip_2_vision_model — Blip2VisionConfig(Blip2VisionConfig 模型)
- blip_text_model — BlipTextConfig(BlipTextConfig 模型)
- blip_vision_model — BlipVisionConfig(BlipVisionConfig 模型)
- bloom — BloomConfig(BloomConfig 模型)
- blt — BltConfig(BltConfig 模型)
- blt_global_transformer —
BltGlobalTransformerConfig(BltGlobalTransformerConfig 模型) - blt_local_decoder —
BltLocalDecoderConfig(BltLocalDecoderConfig 模型) - blt_local_encoder —
BltLocalEncoderConfig(BltLocalEncoderConfig 模型) - blt_patcher —
BltPatcherConfig(BltPatcherConfig 模型) - bridgetower — BridgeTowerConfig(BridgeTowerConfig 模型)
- bridgetower_text_model — BridgeTowerTextConfig(BridgeTowerTextConfig 模型)
- bridgetower_vision_model — BridgeTowerVisionConfig(BridgeTowerVisionConfig 模型)
- bros — BrosConfig(BrosConfig 模型)
- camembert — CamembertConfig(CamembertConfig 模型)
- canary — CanaryConfig(CanaryConfig 模型)
- canary_decoder — CanaryDecoderConfig(CanaryDecoderConfig 模型)
- canine — CanineConfig(CanineConfig 模型)
- chameleon — ChameleonConfig(ChameleonConfig 模型)
- chameleon_vqgan — ChameleonVQVAEConfig(ChameleonVQVAEConfig 模型)
- chinese_clip — ChineseCLIPConfig(ChineseCLIPConfig 模型)
- chinese_clip_text_model — ChineseCLIPTextConfig(ChineseCLIPTextConfig 模型)
- chinese_clip_vision_model — ChineseCLIPVisionConfig(ChineseCLIPVisionConfig 模型)
- chmv2 — CHMv2Config(CHMv2Config 模型)
- clap — ClapConfig(ClapConfig 模型)
- clap_audio_model — ClapAudioConfig(ClapAudioConfig 模型)
- clap_text_model — ClapTextConfig(ClapTextConfig 模型)
- clip — CLIPConfig(CLIPConfig 模型)
- clip_text_model — CLIPTextConfig(CLIPTextConfig 模型)
- clip_vision_model — CLIPVisionConfig(CLIPVisionConfig 模型)
- clipseg — CLIPSegConfig(CLIPSegConfig 模型)
- clipseg_text_model — CLIPSegTextConfig(CLIPSegTextConfig 模型)
- clipseg_vision_model — CLIPSegVisionConfig(CLIPSegVisionConfig 模型)
- clvp — ClvpConfig(ClvpConfig 模型)
- clvp_decoder — ClvpDecoderConfig(ClvpDecoderConfig 模型)
- clvp_encoder — ClvpEncoderConfig(ClvpEncoderConfig 模型)
- codegen — CodeGenConfig(CodeGenConfig 模型)
- cohere — CohereConfig(CohereConfig 模型)
- cohere2 — Cohere2Config(Cohere2Config 模型)
- cohere2_moe — Cohere2MoeConfig(Cohere2MoeConfig 模型)
- cohere2_vision — Cohere2VisionConfig(Cohere2VisionConfig 模型)
- cohere_asr — CohereAsrConfig(CohereAsrConfig 模型)
- cohere_compass — CohereCompassConfig(CohereCompassConfig 模型)
- cohere_compass_text — CohereCompassTextConfig(CohereCompassTextConfig 模型)
- cohere_compass_vision — CohereCompassVisionConfig(CohereCompassVisionConfig 模型)
- colmodernvbert — ColModernVBertConfig(ColModernVBertConfig 模型)
- colpali — ColPaliConfig(ColPaliConfig 模型)
- colqwen2 — ColQwen2Config(ColQwen2Config 模型)
- conditional_detr — ConditionalDetrConfig(ConditionalDetrConfig 模型)
- convbert — ConvBertConfig(ConvBertConfig 模型)
- convnext — ConvNextConfig(ConvNextConfig 模型)
- convnextv2 — ConvNextV2Config(ConvNextV2Config 模型)
- cosmos3_edge — Cosmos3EdgeConfig(Cosmos3EdgeConfig 模型)
- cosmos3_edge_text — Cosmos3EdgeTextConfig(Cosmos3EdgeTextConfig 模型)
- cosmos3_edge_vision — Cosmos3EdgeVisionConfig(Cosmos3EdgeVisionConfig 模型)
- cosmos3_omni — Cosmos3OmniConfig(Cosmos3OmniConfig 模型)
- cpmant — CpmAntConfig(CpmAntConfig 模型)
- csm — CsmConfig(CsmConfig 模型)
- csm_depth_decoder_model — CsmDepthDecoderConfig(CsmDepthDecoderConfig 模型)
- ctrl — CTRLConfig(CTRLConfig 模型)
- cvt — CvtConfig(CvtConfig 模型)
- cwm — CwmConfig(CwmConfig 模型)
- d_fine — DFineConfig(DFineConfig 模型)
- dab-detr — DabDetrConfig(DabDetrConfig 模型)
- dac — DacConfig(DacConfig 模型)
- data2vec-audio — Data2VecAudioConfig(Data2VecAudioConfig 模型)
- data2vec-text — Data2VecTextConfig(Data2VecTextConfig 模型)
- data2vec-vision — Data2VecVisionConfig(Data2VecVisionConfig 模型)
- dbrx — DbrxConfig(DbrxConfig 模型)
- deberta — DebertaConfig(DebertaConfig 模型)
- deberta-v2 — DebertaV2Config(DebertaV2Config 模型)
- decision_transformer — DecisionTransformerConfig(DecisionTransformerConfig 模型)
- deepseek_ocr2 — DeepseekOcr2Config(DeepseekOcr2Config 模型)
- deepseek_ocr2_encoder — DeepseekOcr2VisionEncoderConfig(DeepseekOcr2VisionEncoderConfig 模型)
- deepseek_ocr2_sam_vision_model — DeepseekOcr2SamVisionConfig(DeepseekOcr2SamVisionConfig 模型)
- deepseek_ocr2_text — DeepseekOcr2TextConfig(DeepseekOcr2TextConfig 模型)
- deepseek_ocr2_vision — DeepseekOcr2VisionConfig(DeepseekOcr2VisionConfig 模型)
- deepseek_v2 — DeepseekV2Config(DeepseekV2Config 模型)
- deepseek_v3 — DeepseekV3Config(DeepseekV3Config 模型)
- deepseek_v32 — DeepseekV32Config(DeepseekV32Config 模型)
- deepseek_v4 — DeepseekV4Config(DeepseekV4Config 模型)
- deepseek_vl — DeepseekVLConfig(DeepseekVLConfig 模型)
- deepseek_vl_hybrid — DeepseekVLHybridConfig(DeepseekVLHybridConfig 模型)
- deformable_detr — DeformableDetrConfig(DeformableDetrConfig 模型)
- deimv2 — Deimv2Config(Deimv2Config 模型)
- deit — DeiTConfig(DeiTConfig 模型)
- depth_anything — DepthAnythingConfig(DepthAnythingConfig 模型)
- depth_pro — DepthProConfig(DepthProConfig 模型)
- detr — DetrConfig(DetrConfig 模型)
- dia — DiaConfig(DiaConfig 模型)
- dia_decoder — DiaDecoderConfig(DiaDecoderConfig 模型)
- dia_encoder — DiaEncoderConfig(DiaEncoderConfig 模型)
- diffllama — DiffLlamaConfig(DiffLlamaConfig 模型)
- diffusion_gemma — DiffusionGemmaConfig(DiffusionGemmaConfig 模型)
- diffusion_gemma_text — DiffusionGemmaTextConfig(DiffusionGemmaTextConfig 模型)
- dinat — DinatConfig(DinatConfig 模型)
- dinov2 — Dinov2Config(Dinov2Config 模型)
- dinov2_with_registers — Dinov2WithRegistersConfig(Dinov2WithRegistersConfig 模型)
- dinov3_convnext — DINOv3ConvNextConfig(DINOv3ConvNextConfig 模型)
- dinov3_vit — DINOv3ViTConfig(DINOv3ViTConfig 模型)
- distilbert — DistilBertConfig(DistilBertConfig 模型)
- doge — DogeConfig(DogeConfig 模型)
- donut-swin — DonutSwinConfig(DonutSwinConfig 模型)
- dots1 — Dots1Config(Dots1Config 模型)
- dpr — DPRConfig(DPRConfig 模型)
- dpt — DPTConfig(DPTConfig 模型)
- edgetam — EdgeTamConfig(EdgeTamConfig 模型)
- edgetam_mask_decoder — EdgeTamMaskDecoderConfig(EdgeTamMaskDecoderConfig 模型)
- edgetam_prompt_encoder — EdgeTamPromptEncoderConfig(EdgeTamPromptEncoderConfig 模型)
- edgetam_video — EdgeTamVideoConfig(EdgeTamVideoConfig 模型)
- edgetam_video_mask_decoder — EdgeTamVideoMaskDecoderConfig(EdgeTamVideoMaskDecoderConfig 模型)
- edgetam_video_prompt_encoder — EdgeTamVideoPromptEncoderConfig(EdgeTamVideoPromptEncoderConfig 模型)
- edgetam_vision_model — EdgeTamVisionConfig(EdgeTamVisionConfig 模型)
- efficientloftr — EfficientLoFTRConfig(EfficientLoFTRConfig 模型)
- efficientnet — EfficientNetConfig(EfficientNetConfig 模型)
- electra — ElectraConfig(ElectraConfig 模型)
- embedding_gemma2 — EmbeddingGemma2Config(EmbeddingGemma2Config 模型)
- embedding_gemma2_text — EmbeddingGemma2TextConfig(EmbeddingGemma2TextConfig 模型)
- emu3 — Emu3Config(Emu3Config 模型)
- emu3_text_model — Emu3TextConfig(Emu3TextConfig 模型)
- emu3_vqgan — Emu3VQVAEConfig(Emu3VQVAEConfig 模型)
- encodec — EncodecConfig(EncodecConfig 模型)
- encoder-decoder — EncoderDecoderConfig(EncoderDecoderConfig 模型)
- eomt — EomtConfig(EomtConfig 模型)
- eomt_dinov3 — EomtDinov3Config(EomtDinov3Config 模型)
- ernie — ErnieConfig(ErnieConfig 模型)
- ernie4_5 — Ernie4_5Config(Ernie4_5Config 模型)
- ernie4_5_moe — Ernie4_5_MoeConfig(Ernie4_5_MoeConfig 模型)
- ernie4_5_vl_moe — Ernie4_5_VLMoeConfig(Ernie4_5_VLMoeConfig 模型)
- ernie4_5_vl_moe_text — Ernie4_5_VLMoeTextConfig(Ernie4_5_VLMoeTextConfig 模型)
- ernie4_5_vl_moe_vision — Ernie4_5_VLMoeVisionConfig(Ernie4_5_VLMoeVisionConfig 模型)
- esm — EsmConfig(EsmConfig 模型)
- esmc — EsmcConfig(EsmcConfig 模型)
- esmfold2 — EsmFold2Config(EsmFold2Config 模型)
- eurobert — EuroBertConfig(EuroBertConfig 模型)
- evolla — EvollaConfig(EvollaConfig 模型)
- exaone4 — Exaone4Config(Exaone4Config 模型)
- exaone4_5 — Exaone4_5_Config(Exaone4_5_Config 模型)
- exaone4_5_vision — Exaone4_5_VisionConfig(Exaone4_5_VisionConfig 模型)
- exaone_moe — ExaoneMoeConfig(ExaoneMoeConfig 模型)
- falcon — FalconConfig(FalconConfig 模型)
- falcon_h1 — FalconH1Config(FalconH1Config 模型)
- falcon_mamba — FalconMambaConfig(FalconMambaConfig 模型)
- fast_vlm — FastVlmConfig(FastVlmConfig 模型)
- fastspeech2_conformer — FastSpeech2ConformerConfig(FastSpeech2ConformerConfig 模型)
- fastspeech2_conformer_hifigan — FastSpeech2ConformerHifiGanConfig(FastSpeech2ConformerHifiGanConfig 模型)
- fastspeech2_conformer_with_hifigan — FastSpeech2ConformerWithHifiGanConfig(FastSpeech2ConformerWithHifiGanConfig 模型)
- flaubert — FlaubertConfig(FlaubertConfig 模型)
- flava — FlavaConfig(FlavaConfig 模型)
- flava_image_codebook — FlavaImageCodebookConfig(FlavaImageCodebookConfig 模型)
- flava_image_model — FlavaImageConfig(FlavaImageConfig 模型)
- flava_multimodal_model — FlavaMultimodalConfig(FlavaMultimodalConfig 模型)
- flava_text_model — FlavaTextConfig(FlavaTextConfig 模型)
- flex_olmo — FlexOlmoConfig(FlexOlmoConfig 模型)
- flint — FlintConfig(FlintConfig 模型)
- florence2 — Florence2Config(Florence2Config 模型)
- florence_vision — Florence2VisionConfig(Florence2VisionConfig 模型)
- fnet — FNetConfig(FNetConfig 模型)
- focalnet — FocalNetConfig(FocalNetConfig 模型)
- fsmt — FSMTConfig(FSMTConfig 模型)
- fun_asr_nano — FunAsrNanoConfig(FunAsrNanoConfig 模型)
- fun_asr_nano_encoder — FunAsrNanoEncoderConfig(FunAsrNanoEncoderConfig 模型)
- funnel — FunnelConfig(FunnelConfig 模型)
- fuyu — FuyuConfig(FuyuConfig 模型)
- gemma — GemmaConfig(GemmaConfig 模型)
- gemma2 — Gemma2Config(Gemma2Config 模型)
- gemma3 — Gemma3Config(Gemma3Config 模型)
- gemma3_text — Gemma3TextConfig(Gemma3TextConfig 模型)
- gemma3n — Gemma3nConfig(Gemma3nConfig 模型)
- gemma3n_audio — Gemma3nAudioConfig(Gemma3nAudioConfig 模型)
- gemma3n_text — Gemma3nTextConfig(Gemma3nTextConfig 模型)
- gemma3n_vision — Gemma3nVisionConfig(Gemma3nVisionConfig 模型)
- gemma4 — Gemma4Config(Gemma4Config 模型)
- gemma4_assistant — Gemma4AssistantConfig(Gemma4AssistantConfig 模型)
- gemma4_audio — Gemma4AudioConfig(Gemma4AudioConfig 模型)
- gemma4_text — Gemma4TextConfig(Gemma4TextConfig 模型)
- gemma4_unified — Gemma4UnifiedConfig(Gemma4UnifiedConfig 模型)
- gemma4_unified_assistant — Gemma4UnifiedAssistantConfig(Gemma4UnifiedAssistantConfig 模型)
- gemma4_unified_audio — Gemma4UnifiedAudioConfig(Gemma4UnifiedAudioConfig 模型)
- gemma4_unified_text — Gemma4UnifiedTextConfig(Gemma4UnifiedTextConfig 模型)
- gemma4_unified_vision — Gemma4UnifiedVisionConfig(Gemma4UnifiedVisionConfig 模型)
- gemma4_vision — Gemma4VisionConfig(Gemma4VisionConfig 模型)
- git — GitConfig(GitConfig 模型)
- git_vision_model — GitVisionConfig(GitVisionConfig 模型)
- glm — GlmConfig(GlmConfig 模型)
- glm4 — Glm4Config(Glm4Config 模型)
- glm46v — Glm46VConfig(Glm46VConfig 模型)
- glm4_moe — Glm4MoeConfig(Glm4MoeConfig 模型)
- glm4_moe_lite — Glm4MoeLiteConfig(Glm4MoeLiteConfig 模型)
- glm4v — Glm4vConfig(Glm4vConfig 模型)
- glm4v_moe — Glm4vMoeConfig(Glm4vMoeConfig 模型)
- glm4v_moe_text — Glm4vMoeTextConfig(Glm4vMoeTextConfig 模型)
- glm4v_moe_vision — Glm4vMoeVisionConfig(Glm4vMoeVisionConfig 模型)
- glm4v_text — Glm4vTextConfig(Glm4vTextConfig 模型)
- glm4v_vision — Glm4vVisionConfig(Glm4vVisionConfig 模型)
- glm5_next — Glm5NextConfig(Glm5NextConfig 模型)
- glm5_next_text — Glm5NextTextConfig(Glm5NextTextConfig 模型)
- glm5_next_vision — Glm5NextVisionConfig(Glm5NextVisionConfig 模型)
- glm_image — GlmImageConfig(GlmImageConfig 模型)
- glm_image_text — GlmImageTextConfig(GlmImageTextConfig 模型)
- glm_image_vision — GlmImageVisionConfig(GlmImageVisionConfig 模型)
- glm_image_vqmodel — GlmImageVQVAEConfig(GlmImageVQVAEConfig 模型)
- glm_moe_dsa — GlmMoeDsaConfig(GlmMoeDsaConfig 模型)
- glm_ocr — GlmOcrConfig(GlmOcrConfig 模型)
- glm_ocr_text — GlmOcrTextConfig(GlmOcrTextConfig 模型)
- glm_ocr_vision — GlmOcrVisionConfig(GlmOcrVisionConfig 模型)
- glmasr — GlmAsrConfig(GlmAsrConfig 模型)
- glmasr_encoder — GlmAsrEncoderConfig(GlmAsrEncoderConfig 模型)
- glmga — GlmgaConfig(GlmgaConfig 模型)
- glpn — GLPNConfig(GLPNConfig 模型)
- got_ocr2 — GotOcr2Config(GotOcr2Config 模型)
- got_ocr2_vision — GotOcr2VisionConfig(GotOcr2VisionConfig 模型)
- gpt-sw3 — GPT2Config(GPT2Config 模型)
- gpt2 — GPT2Config(GPT2Config 模型)
- gpt_bigcode — GPTBigCodeConfig(GPTBigCodeConfig 模型)
- gpt_neo — GPTNeoConfig(GPTNeoConfig 模型)
- gpt_neox — GPTNeoXConfig(GPTNeoXConfig 模型)
- gpt_neox_japanese — GPTNeoXJapaneseConfig(GPTNeoXJapaneseConfig 模型)
- gpt_oss — GptOssConfig(GptOssConfig 模型)
- gptj — GPTJConfig(GPTJConfig 模型)
- gradium_phonon_tts — GradiumPhononTTSConfig(GradiumPhononTTSConfig 模型)
- granite — GraniteConfig(GraniteConfig 模型)
- granite4_vision — Granite4VisionConfig(Granite4VisionConfig 模型)
- granite4_vision_text — Granite4VisionTextConfig(Granite4VisionTextConfig 模型)
- granite_speech — GraniteSpeechConfig(GraniteSpeechConfig 模型)
- granite_speech5_ctc — GraniteSpeech5CTCConfig(GraniteSpeech5CTCConfig 模型)
- granite_speech5_encoder — GraniteSpeech5EncoderConfig(GraniteSpeech5EncoderConfig 模型)
- granite_speech_encoder — GraniteSpeechEncoderConfig(GraniteSpeechEncoderConfig 模型)
- granite_speech_plus — GraniteSpeechPlusConfig(GraniteSpeechPlusConfig 模型)
- granite_speech_plus_encoder — GraniteSpeechPlusEncoderConfig(GraniteSpeechPlusEncoderConfig 模型)
- granite_swa — GraniteSWAConfig(GraniteSWAConfig 模型)
- granitemoe — GraniteMoeConfig(GraniteMoeConfig 模型)
- granitemoe_swa — GraniteMoeSWAConfig(GraniteMoeSWAConfig 模型)
- granitemoehybrid — GraniteMoeHybridConfig(GraniteMoeHybridConfig 模型)
- granitemoeshared — GraniteMoeSharedConfig(GraniteMoeSharedConfig 模型)
- grounding-dino — GroundingDinoConfig(GroundingDinoConfig 模型)
- groupvit — GroupViTConfig(GroupViTConfig 模型)
- groupvit_text_model — GroupViTTextConfig(GroupViTTextConfig 模型)
- groupvit_vision_model — GroupViTVisionConfig(GroupViTVisionConfig 模型)
- gte — GteConfig(GteConfig 模型)
- helium — HeliumConfig(HeliumConfig 模型)
- hgnet_v2 — HGNetV2Config(HGNetV2Config 模型)
- hiera — HieraConfig(HieraConfig 模型)
- higgs_audio_v2 — HiggsAudioV2Config(HiggsAudioV2Config 模型)
- higgs_audio_v2_tokenizer — HiggsAudioV2TokenizerConfig(HiggsAudioV2TokenizerConfig 模型)
- hrm_text — HrmTextConfig(HrmTextConfig 模型)
- hubert — HubertConfig(HubertConfig 模型)
- hunyuan_v1_dense — HunYuanDenseV1Config(HunYuanDenseV1Config 模型)
- hunyuan_v1_moe — HunYuanMoEV1Config(HunYuanMoEV1Config 模型)
- hunyuan_vl — HunYuanVLConfig(HunYuanVLConfig 模型)
- hunyuan_vl_text — HunYuanVLTextConfig(HunYuanVLTextConfig 模型)
- hunyuan_vl_vision — HunYuanVLVisionConfig(HunYuanVLVisionConfig 模型)
- hy_v3 — HYV3Config(HYV3Config 模型)
- hy_v4 — HYV4Config(HYV4Config 模型)
- hyperclovax — HyperCLOVAXConfig(HyperCLOVAXConfig 模型)
- hyperclovax_vision_v2 — HyperCLOVAXVisionV2Config(HyperCLOVAXVisionV2Config 模型)
- ibert — IBertConfig(IBertConfig 模型)
- idefics — IdeficsConfig(IdeficsConfig 模型)
- idefics2 — Idefics2Config(Idefics2Config 模型)
- idefics2_perceiver — Idefics2PerceiverConfig(Idefics2PerceiverConfig 模型)
- idefics2_vision — Idefics2VisionConfig(Idefics2VisionConfig 模型)
- idefics3 — Idefics3Config(Idefics3Config 模型)
- idefics3_vision — Idefics3VisionConfig(Idefics3VisionConfig 模型)
- idefics_perciever — IdeficsPerceiverConfig(IdeficsPerceiverConfig 模型)
- idefics_vision — IdeficsVisionConfig(IdeficsVisionConfig 模型)
- ijepa — IJepaConfig(IJepaConfig 模型)
- imagegpt — ImageGPTConfig(ImageGPTConfig 模型)
- informer — InformerConfig(InformerConfig 模型)
- inkling_audio — InklingAudioConfig(InklingAudioConfig 模型)
- inkling_mm_model — InklingConfig(InklingConfig 模型)
- inkling_text — InklingTextConfig(InklingTextConfig 模型)
- inkling_vision — InklingVisionConfig(InklingVisionConfig 模型)
- instructblip — InstructBlipConfig(InstructBlipConfig 模型)
- instructblip_qformer — InstructBlipQFormerConfig(InstructBlipQFormerConfig 模型)
- instructblip_vision_model — InstructBlipVisionConfig(InstructBlipVisionConfig 模型)
- instructblipvideo — InstructBlipVideoConfig(InstructBlipVideoConfig 模型)
- instructblipvideo_qformer — InstructBlipVideoQFormerConfig(InstructBlipVideoQFormerConfig 模型)
- instructblipvideo_vision_model — InstructBlipVideoVisionConfig(InstructBlipVideoVisionConfig 模型)
- internvl — InternVLConfig(InternVLConfig 模型)
- internvl_vision — InternVLVisionConfig(InternVLVisionConfig 模型)
- jais2 — Jais2Config(Jais2Config 模型)
- jamba — JambaConfig(JambaConfig 模型)
- janus — JanusConfig(JanusConfig 模型)
- janus_vision_model — JanusVisionConfig(JanusVisionConfig 模型)
- janus_vqgan — JanusVQVAEConfig(JanusVQVAEConfig 模型)
- jetmoe — JetMoeConfig(JetMoeConfig 模型)
- jina_embeddings_v3 — JinaEmbeddingsV3Config(JinaEmbeddingsV3Config 模型)
- kimi_k25 — Kimi_K25Config(Kimi_K25Config 模型)
- kimi_k25_vision — Kimi_K25VisionConfig(Kimi_K25VisionConfig 模型)
- kimi_linear — KimiLinearConfig(KimiLinearConfig 模型)
- kolibri1 — Kolibri1Config(Kolibri1Config 模型)
- kosmos-2 — Kosmos2Config(Kosmos2Config 模型)
- kosmos-2.5 — Kosmos2_5Config(Kosmos2_5Config 模型)
- kosmos_2_5_text_model — Kosmos2_5TextConfig(Kosmos2_5TextConfig 模型)
- kosmos_2_5_vision_model — Kosmos2_5VisionConfig(Kosmos2_5VisionConfig 模型)
- kosmos_2_text_model — Kosmos2TextConfig(Kosmos2TextConfig 模型)
- kosmos_2_vision_model — Kosmos2VisionConfig(Kosmos2VisionConfig 模型)
- kyutai_speech_to_text — KyutaiSpeechToTextConfig(KyutaiSpeechToTextConfig 模型)
- laguna — LagunaConfig(LagunaConfig 模型)
- lasr_ctc — LasrCTCConfig(LasrCTCConfig 模型)
- lasr_encoder — LasrEncoderConfig(LasrEncoderConfig 模型)
- layoutlm — LayoutLMConfig(LayoutLMConfig 模型)
- layoutlmv2 — LayoutLMv2Config(LayoutLMv2Config 模型)
- layoutlmv3 — LayoutLMv3Config(LayoutLMv3Config 模型)
- layoutxlm — LayoutXLMConfig(LayoutXLMConfig 模型)
- led — LEDConfig(LEDConfig 模型)
- levit — LevitConfig(LevitConfig 模型)
- lfm2 — Lfm2Config(Lfm2Config 模型)
- lfm2_moe — Lfm2MoeConfig(Lfm2MoeConfig 模型)
- lfm2_vl — Lfm2VlConfig(Lfm2VlConfig 模型)
- lfm3 — Lfm3Config(Lfm3Config 模型)
- lightglue — LightGlueConfig(LightGlueConfig 模型)
- lighton_ocr — LightOnOcrConfig(LightOnOcrConfig 模型)
- lilt — LiltConfig(LiltConfig 模型)
- llama — LlamaConfig(LlamaConfig 模型)
- llama4 — Llama4Config(Llama4Config 模型)
- llama4_text — Llama4TextConfig(Llama4TextConfig 模型)
- llama4_vision_model — Llama4VisionConfig(Llama4VisionConfig 模型)
- llava — LlavaConfig(LlavaConfig 模型)
- llava_next — LlavaNextConfig(LlavaNextConfig 模型)
- llava_next_video — LlavaNextVideoConfig(LlavaNextVideoConfig 模型)
- llava_onevision — LlavaOnevisionConfig(LlavaOnevisionConfig 模型)
- longcat_flash — LongcatFlashConfig(LongcatFlashConfig 模型)
- longformer — LongformerConfig(LongformerConfig 模型)
- longt5 — LongT5Config(LongT5Config 模型)
- luke — LukeConfig(LukeConfig 模型)
- lw_detr — LwDetrConfig(LwDetrConfig 模型)
- lw_detr_vit — LwDetrViTConfig(LwDetrViTConfig 模型)
- lxmert — LxmertConfig(LxmertConfig 模型)
- m2m_100 — M2M100Config(M2M100Config 模型)
- mamba — MambaConfig(MambaConfig 模型)
- mamba2 — Mamba2Config(Mamba2Config 模型)
- marian — MarianConfig(MarianConfig 模型)
- markuplm — MarkupLMConfig(MarkupLMConfig 模型)
- mask2former — Mask2FormerConfig(Mask2FormerConfig 模型)
- maskformer — MaskFormerConfig(MaskFormerConfig 模型)
- maskformer-swin —
MaskFormerSwinConfig(MaskFormerSwinConfig 模型) - mbart — MBartConfig(MBartConfig 模型)
- megatron-bert — MegatronBertConfig(MegatronBertConfig 模型)
- mellum — MellumConfig(MellumConfig 模型)
- metaclip_2 — MetaClip2Config(MetaClip2Config 模型)
- metaclip_2_text_model — MetaClip2TextConfig(MetaClip2TextConfig 模型)
- metaclip_2_vision_model — MetaClip2VisionConfig(MetaClip2VisionConfig 模型)
- mgp-str — MgpstrConfig(MgpstrConfig 模型)
- mimi — MimiConfig(MimiConfig 模型)
- mimi_decoder — MimiDecoderConfig(MimiDecoderConfig 模型)
- mimi_encoder — MimiEncoderConfig(MimiEncoderConfig 模型)
- mimo_v2_flash — MiMoV2FlashConfig(MiMoV2FlashConfig 模型)
- minicpm3 — MiniCPM3Config(MiniCPM3Config 模型)
- minicpm_ocr — MiniCPMOcrConfig(MiniCPMOcrConfig 模型)
- minicpm_ocr_vision — MiniCPMOcrVisionConfig(MiniCPMOcrVisionConfig 模型)
- minicpmv4_6 — MiniCPMV4_6Config(MiniCPMV4_6Config 模型)
- minicpmv4_6_vision — MiniCPMV4_6VisionConfig(MiniCPMV4_6VisionConfig 模型)
- minicpmv4_7 — MiniCPMV4_7Config(MiniCPMV4_7Config 模型)
- minicpmv4_7_vision — MiniCPMV4_7VisionConfig(MiniCPMV4_7VisionConfig 模型)
- minimax — MiniMaxConfig(MiniMaxConfig 模型)
- minimax_m2 — MiniMaxM2Config(MiniMaxM2Config 模型)
- minimax_m3_vl — MiniMaxM3VLConfig(MiniMaxM3VLConfig 模型)
- minimax_m3_vl_text — MiniMaxM3VLTextConfig(MiniMaxM3VLTextConfig 模型)
- minimax_m3_vl_vision — MiniMaxM3VLVisionConfig(MiniMaxM3VLVisionConfig 模型)
- ministral — MinistralConfig(MinistralConfig 模型)
- ministral3 — Ministral3Config(Ministral3Config 模型)
- mistral — MistralConfig(MistralConfig 模型)
- mistral3 — Mistral3Config(Mistral3Config 模型)
- mistral4 — Mistral4Config(Mistral4Config 模型)
- mistral_large4 — MistralLarge4Config(MistralLarge4Config 模型)
- mistral_large4_text — MistralLarge4TextConfig(MistralLarge4TextConfig 模型)
- mixtral — MixtralConfig(MixtralConfig 模型)
- mlcd — MLCDVisionConfig(MLCDVisionConfig 模型)
- mlcd_vision_model — MLCDVisionConfig(MLCDVisionConfig 模型)
- mllama — MllamaConfig(MllamaConfig 模型)
- mllama_text_model — MllamaTextConfig(MllamaTextConfig 模型)
- mllama_vision_model — MllamaVisionConfig(MllamaVisionConfig 模型)
- mm-grounding-dino — MMGroundingDinoConfig(MMGroundingDinoConfig 模型)
- mobilebert — MobileBertConfig(MobileBertConfig 模型)
- mobilenet_v1 — MobileNetV1Config(MobileNetV1Config 模型)
- mobilenet_v2 — MobileNetV2Config(MobileNetV2Config 模型)
- mobilevit — MobileViTConfig(MobileViTConfig 模型)
- mobilevitv2 — MobileViTV2Config(MobileViTV2Config 模型)
- modernbert — ModernBertConfig(ModernBertConfig 模型)
- modernbert-decoder — ModernBertDecoderConfig(ModernBertDecoderConfig 模型)
- modernvbert — ModernVBertConfig(ModernVBertConfig 模型)
- molmo2 — Molmo2Config(Molmo2Config 模型)
- molmo2_adapter — Molmo2AdapterConfig(Molmo2AdapterConfig 模型)
- molmo2_text — Molmo2TextConfig(Molmo2TextConfig 模型)
- molmo2_vision — Molmo2VisionConfig(Molmo2VisionConfig 模型)
- moonshine — MoonshineConfig(MoonshineConfig 模型)
- moonshine_streaming — MoonshineStreamingConfig(MoonshineStreamingConfig 模型)
- moonshine_streaming_encoder — MoonshineStreamingEncoderConfig(MoonshineStreamingEncoderConfig 模型)
- moshi — MoshiConfig(MoshiConfig 模型)
- moshi_depth — MoshiDepthConfig(MoshiDepthConfig 模型)
- moss_transcribe_diarize — MossTranscribeDiarizeConfig(MossTranscribeDiarizeConfig 模型)
- moss_transcribe_diarize_audio — MossTranscribeDiarizeAudioConfig(MossTranscribeDiarizeAudioConfig 模型)
- mpnet — MPNetConfig(MPNetConfig 模型)
- mpt — MptConfig(MptConfig 模型)
- mra — MraConfig(MraConfig 模型)
- mt5 — MT5Config(MT5Config 模型)
- muse_glimmer — MuseGlimmerConfig(MuseGlimmerConfig 模型)
- muse_glimmer_assistant — MuseGlimmerAssistantConfig(MuseGlimmerAssistantConfig 模型)
- muse_glimmer_text — MuseGlimmerTextConfig(MuseGlimmerTextConfig 模型)
- muse_glimmer_vision — MuseGlimmerVisionConfig(MuseGlimmerVisionConfig 模型)
- muse_spark — MuseSparkConfig(MuseSparkConfig 模型)
- muse_spark_audio — MuseSparkAudioConfig(MuseSparkAudioConfig 模型)
- muse_spark_text — MuseSparkTextConfig(MuseSparkTextConfig 模型)
- muse_spark_vision — MuseSparkVisionConfig(MuseSparkVisionConfig 模型)
- musicflamingo — MusicFlamingoConfig(MusicFlamingoConfig 模型)
- musicgen — MusicgenConfig(MusicgenConfig 模型)
- musicgen_decoder — MusicgenDecoderConfig(MusicgenDecoderConfig 模型)
- musicgen_melody — MusicgenMelodyConfig(MusicgenMelodyConfig 模型)
- musicgen_melody_decoder — MusicgenMelodyDecoderConfig(MusicgenMelodyDecoderConfig 模型)
- mvp — MvpConfig(MvpConfig 模型)
- nanochat — NanoChatConfig(NanoChatConfig 模型)
- nemo_speechlm — Nemotron3_5TranscribeConfig(Nemotron3_5TranscribeConfig 模型)
- nemotron — NemotronConfig(NemotronConfig 模型)
- nemotron3_5_asr — Nemotron3_5AsrConfig(Nemotron3_5AsrConfig 模型)
- nemotron3_5_transcribe_asr_audio — Nemotron3_5TranscribeAsrAudioConfig(Nemotron3_5TranscribeAsrAudioConfig 模型)
- nemotron3_5_transcribe_audio — Nemotron3_5TranscribeAudioConfig(Nemotron3_5TranscribeAudioConfig 模型)
- nemotron3_5_transcribe_word_timestamp — Nemotron3_5TranscribeWordTimestampConfig(Nemotron3_5TranscribeWordTimestampConfig 模型)
- nemotron3_diarization — Nemotron3DiarizationConfig(Nemotron3DiarizationConfig 模型)
- nemotron3_diarization_audio — Nemotron3DiarizationAudioConfig(Nemotron3DiarizationAudioConfig 模型)
- nemotron_asr_streaming — NemotronAsrStreamingConfig(NemotronAsrStreamingConfig 模型)
- nemotron_asr_streaming_encoder — NemotronAsrStreamingEncoderConfig(NemotronAsrStreamingEncoderConfig 模型)
- nemotron_h — NemotronHConfig(NemotronHConfig 模型)
- nemotron_h_omni — NemotronH_Omni_Reasoning_V3_Config(NemotronH_Omni_Reasoning_V3_Config 模型)
- neomme — NeoMMEConfig(NeoMMEConfig 模型)
- neucodec — NeuCodecConfig(NeuCodecConfig 模型)
- nllb-moe — NllbMoeConfig(NllbMoeConfig 模型)
- nomic_bert — NomicBertConfig(NomicBertConfig 模型)
- nougat — NougatConfig(NougatConfig 模型)
- nystromformer — NystromformerConfig(NystromformerConfig 模型)
- olmo — OlmoConfig(OlmoConfig 模型)
- olmo2 — Olmo2Config(Olmo2Config 模型)
- olmo3 — Olmo3Config(Olmo3Config 模型)
- olmo_hybrid — OlmoHybridConfig(OlmoHybridConfig 模型)
- olmoe — OlmoeConfig(OlmoeConfig 模型)
- omdet-turbo — OmDetTurboConfig(OmDetTurboConfig 模型)
- oneformer — OneFormerConfig(OneFormerConfig 模型)
- openai-gpt — OpenAIGPTConfig(OpenAIGPTConfig 模型)
- openai_privacy_filter — OpenAIPrivacyFilterConfig(OpenAIPrivacyFilterConfig 模型)
- opt — OPTConfig(OPTConfig 模型)
- ovis2 — Ovis2Config(Ovis2Config 模型)
- ovis2_vision — Ovis2VisionConfig(Ovis2VisionConfig 模型)
- owlv2 — Owlv2Config(Owlv2Config 模型)
- owlv2_text_model — Owlv2TextConfig(Owlv2TextConfig 模型)
- owlv2_vision_model — Owlv2VisionConfig(Owlv2VisionConfig 模型)
- owlvit — OwlViTConfig(OwlViTConfig 模型)
- owlvit_text_model — OwlViTTextConfig(OwlViTTextConfig 模型)
- owlvit_vision_model — OwlViTVisionConfig(OwlViTVisionConfig 模型)
- paddleocr_vl — PaddleOCRVLConfig(PaddleOCRVLConfig 模型)
- paddleocr_vl_text — PaddleOCRTextConfig(PaddleOCRTextConfig 模型)
- paddleocr_vl_vision — PaddleOCRVisionConfig(PaddleOCRVisionConfig 模型)
- paligemma — PaliGemmaConfig(PaliGemmaConfig 模型)
- parakeet_ctc — ParakeetCTCConfig(ParakeetCTCConfig 模型)
- parakeet_encoder — ParakeetEncoderConfig(ParakeetEncoderConfig 模型)
- parakeet_rnnt — ParakeetRNNTConfig(ParakeetRNNTConfig 模型)
- parakeet_tdt — ParakeetTDTConfig(ParakeetTDTConfig 模型)
- patchtsmixer — PatchTSMixerConfig(PatchTSMixerConfig 模型)
- patchtst — PatchTSTConfig(PatchTSTConfig 模型)
- pe_audio — PeAudioConfig(PeAudioConfig 模型)
- pe_audio_encoder — PeAudioEncoderConfig(PeAudioEncoderConfig 模型)
- pe_audio_video — PeAudioVideoConfig(PeAudioVideoConfig 模型)
- pe_audio_video_encoder — PeAudioVideoEncoderConfig(PeAudioVideoEncoderConfig 模型)
- pe_video — PeVideoConfig(PeVideoConfig 模型)
- pe_video_encoder — PeVideoEncoderConfig(PeVideoEncoderConfig 模型)
- pegasus — PegasusConfig(PegasusConfig 模型)
- pegasus_x — PegasusXConfig(PegasusXConfig 模型)
- perceiver — PerceiverConfig(PerceiverConfig 模型)
- perception_lm — PerceptionLMConfig(PerceptionLMConfig 模型)
- persimmon — PersimmonConfig(PersimmonConfig 模型)
- phi — PhiConfig(PhiConfig 模型)
- phi3 — Phi3Config(Phi3Config 模型)
- phi4_multimodal — Phi4MultimodalConfig(Phi4MultimodalConfig 模型)
- phi4_multimodal_audio — Phi4MultimodalAudioConfig(Phi4MultimodalAudioConfig 模型)
- phi4_multimodal_vision — Phi4MultimodalVisionConfig(Phi4MultimodalVisionConfig 模型)
- phimoe — PhimoeConfig(PhimoeConfig 模型)
- pi0 — PI0Config(PI0Config 模型)
- pix2struct — Pix2StructConfig(Pix2StructConfig 模型)
- pix2struct_text_model — Pix2StructTextConfig(Pix2StructTextConfig 模型)
- pix2struct_vision_model — Pix2StructVisionConfig(Pix2StructVisionConfig 模型)
- pixio — PixioConfig(PixioConfig 模型)
- pixtral — PixtralVisionConfig(PixtralVisionConfig 模型)
- plbart — PLBartConfig(PLBartConfig 模型)
- pocket_tts — PocketTTSConfig(PocketTTSConfig 模型)
- pocket_tts_audio_tokenizer — PocketTTSAudioTokenizerConfig(PocketTTSAudioTokenizerConfig 模型)
- pocket_tts_audio_tokenizer_decoder — PocketTTSAudioTokenizerDecoderConfig(PocketTTSAudioTokenizerDecoderConfig 模型)
- pocket_tts_audio_tokenizer_encoder — PocketTTSAudioTokenizerEncoderConfig(PocketTTSAudioTokenizerEncoderConfig 模型)
- poolformer — PoolFormerConfig(PoolFormerConfig 模型)
- pop2piano — Pop2PianoConfig(Pop2PianoConfig 模型)
- pp_chart2table — PPChart2TableConfig(PPChart2TableConfig 模型)
- pp_chart2table_vision — PPChart2TableVisionConfig(PPChart2TableVisionConfig 模型)
- pp_doclayout_v2 — PPDocLayoutV2Config(PPDocLayoutV2Config 模型)
- pp_doclayout_v3 — PPDocLayoutV3Config(PPDocLayoutV3Config 模型)
- pp_doclayout_v4 — PPDocLayoutV4Config(PPDocLayoutV4Config 模型)
- pp_formulanet — PPFormulaNetConfig(PPFormulaNetConfig 模型)
- pp_formulanet_text — PPFormulaNetTextConfig(PPFormulaNetTextConfig 模型)
- pp_formulanet_vision — PPFormulaNetVisionConfig(PPFormulaNetVisionConfig 模型)
- pp_lcnet — PPLCNetConfig(PPLCNetConfig 模型)
- pp_lcnet_v3 — PPLCNetV3Config(PPLCNetV3Config 模型)
- pp_lcnet_v4 — PPLCNetV4Config(PPLCNetV4Config 模型)
- pp_ocrv5_mobile_det — PPOCRV5MobileDetConfig(PPOCRV5MobileDetConfig 模型)
- pp_ocrv5_mobile_rec — PPOCRV5MobileRecConfig(PPOCRV5MobileRecConfig 模型)
- pp_ocrv5_server_det — PPOCRV5ServerDetConfig(PPOCRV5ServerDetConfig 模型)
- pp_ocrv5_server_rec — PPOCRV5ServerRecConfig(PPOCRV5ServerRecConfig 模型)
- pp_ocrv6_medium_det — PPOCRV6MediumDetConfig(PPOCRV6MediumDetConfig 模型)
- pp_ocrv6_small_det — PPOCRV6SmallDetConfig(PPOCRV6SmallDetConfig 模型)
- pp_ocrv6_small_rec — PPOCRV6SmallRecConfig(PPOCRV6SmallRecConfig 模型)
- pp_ocrv6_tiny_rec — PPOCRV6TinyRecConfig(PPOCRV6TinyRecConfig 模型)
- prompt_depth_anything — PromptDepthAnythingConfig(PromptDepthAnythingConfig 模型)
- prophetnet — ProphetNetConfig(ProphetNetConfig 模型)
- pvt — PvtConfig(PvtConfig 模型)
- pvt_v2 — PvtV2Config(PvtV2Config 模型)
- qianfan_ocr — QianfanOCRConfig(QianfanOCRConfig 模型)
- qianfan_ocr_vision — QianfanOCRVisionConfig(QianfanOCRVisionConfig 模型)
- qwen2 — Qwen2Config(Qwen2Config 模型)
- qwen2_5_omni — Qwen2_5OmniConfig(Qwen2_5OmniConfig 模型)
- qwen2_5_omni_audio_encoder — Qwen2_5OmniAudioEncoderConfig(Qwen2_5OmniAudioEncoderConfig 模型)
- qwen2_5_omni_bigvgan — Qwen2_5OmniBigVGANConfig(Qwen2_5OmniBigVGANConfig 模型)
- qwen2_5_omni_dit — Qwen2_5OmniDiTConfig(Qwen2_5OmniDiTConfig 模型)
- qwen2_5_omni_talker — Qwen2_5OmniTalkerConfig(Qwen2_5OmniTalkerConfig 模型)
- qwen2_5_omni_text — Qwen2_5OmniTextConfig(Qwen2_5OmniTextConfig 模型)
- qwen2_5_omni_thinker — Qwen2_5OmniThinkerConfig(Qwen2_5OmniThinkerConfig 模型)
- qwen2_5_omni_token2wav — Qwen2_5OmniToken2WavConfig(Qwen2_5OmniToken2WavConfig 模型)
- qwen2_5_omni_vision_encoder — Qwen2_5OmniVisionEncoderConfig(Qwen2_5OmniVisionEncoderConfig 模型)
- qwen2_5_vl — Qwen2_5_VLConfig(Qwen2_5_VLConfig 模型)
- qwen2_5_vl_text — Qwen2_5_VLTextConfig(Qwen2_5_VLTextConfig 模型)
- qwen2_5_vl_vision — Qwen2_5_VLVisionConfig(Qwen2_5_VLVisionConfig 模型)
- qwen2_audio — Qwen2AudioConfig(Qwen2AudioConfig 模型)
- qwen2_audio_encoder — Qwen2AudioEncoderConfig(Qwen2AudioEncoderConfig 模型)
- qwen2_moe — Qwen2MoeConfig(Qwen2MoeConfig 模型)
- qwen2_vl — Qwen2VLConfig(Qwen2VLConfig 模型)
- qwen2_vl_text — Qwen2VLTextConfig(Qwen2VLTextConfig 模型)
- qwen2_vl_vision — Qwen2VLVisionConfig(Qwen2VLVisionConfig 模型)
- qwen3 — Qwen3Config(Qwen3Config 模型)
- qwen3_5 — Qwen3_5Config(Qwen3_5Config 模型)
- qwen3_5_moe — Qwen3_5MoeConfig(Qwen3_5MoeConfig 模型)
- qwen3_5_moe_text — Qwen3_5MoeTextConfig(Qwen3_5MoeTextConfig 模型)
- qwen3_5_moe_vision — Qwen3_5MoeVisionConfig(Qwen3_5MoeVisionConfig 模型)
- qwen3_5_text — Qwen3_5TextConfig(Qwen3_5TextConfig 模型)
- qwen3_5_vision — Qwen3_5VisionConfig(Qwen3_5VisionConfig 模型)
- qwen3_asr — Qwen3ASRConfig(Qwen3ASRConfig 模型)
- qwen3_asr_encoder — Qwen3ASREncoderConfig(Qwen3ASREncoderConfig 模型)
- qwen3_moe — Qwen3MoeConfig(Qwen3MoeConfig 模型)
- qwen3_next — Qwen3NextConfig(Qwen3NextConfig 模型)
- qwen3_omni_moe — Qwen3OmniMoeConfig(Qwen3OmniMoeConfig 模型)
- qwen3_omni_moe_audio_encoder — Qwen3OmniMoeAudioEncoderConfig(Qwen3OmniMoeAudioEncoderConfig 模型)
- qwen3_omni_moe_talker_code_predictor — Qwen3OmniMoeTalkerCodePredictorConfig(Qwen3OmniMoeTalkerCodePredictorConfig 模型)
- qwen3_omni_moe_talker_text — Qwen3OmniMoeTalkerTextConfig(Qwen3OmniMoeTalkerTextConfig 模型)
- qwen3_omni_moe_text — Qwen3OmniMoeTextConfig(Qwen3OmniMoeTextConfig 模型)
- qwen3_omni_moe_thinker — Qwen3OmniMoeThinkerConfig(Qwen3OmniMoeThinkerConfig 模型)
- qwen3_omni_moe_vision_encoder — Qwen3OmniMoeVisionEncoderConfig(Qwen3OmniMoeVisionEncoderConfig 模型)
- qwen3_vl — Qwen3VLConfig(Qwen3VLConfig 模型)
- qwen3_vl_moe — Qwen3VLMoeConfig(Qwen3VLMoeConfig 模型)
- qwen3_vl_moe_text — Qwen3VLMoeTextConfig(Qwen3VLMoeTextConfig 模型)
- qwen3_vl_moe_vision — Qwen3VLMoeVisionConfig(Qwen3VLMoeVisionConfig 模型)
- qwen3_vl_text — Qwen3VLTextConfig(Qwen3VLTextConfig 模型)
- qwen3_vl_vision — Qwen3VLVisionConfig(Qwen3VLVisionConfig 模型)
- qwen4_exp — Qwen4ExpConfig(Qwen4ExpConfig 模型)
- qwen4_exp_text — Qwen4ExpTextConfig(Qwen4ExpTextConfig 模型)
- qwen4_exp_vision — Qwen4ExpVisionConfig(Qwen4ExpVisionConfig 模型)
- radio — RadioConfig(RadioConfig 模型)
- rag — RagConfig(RagConfig 模型)
- recurrent_gemma — RecurrentGemmaConfig(RecurrentGemmaConfig 模型)
- reformer — ReformerConfig(ReformerConfig 模型)
- regnet — RegNetConfig(RegNetConfig 模型)
- rembert — RemBertConfig(RemBertConfig 模型)
- resnet — ResNetConfig(ResNetConfig 模型)
- rf_detr — RfDetrConfig(RfDetrConfig 模型)
- rf_detr_dinov2 — RfDetrDinov2Config(RfDetrDinov2Config 模型)
- roberta — RobertaConfig(RobertaConfig 模型)
- roberta-prelayernorm — RobertaPreLayerNormConfig(RobertaPreLayerNormConfig 模型)
- roc_bert — RoCBertConfig(RoCBertConfig 模型)
- roformer — RoFormerConfig(RoFormerConfig 模型)
- rt_detr — RTDetrConfig(RTDetrConfig 模型)
- rt_detr_resnet — RTDetrResNetConfig(RTDetrResNetConfig 模型)
- rt_detr_v2 — RTDetrV2Config(RTDetrV2Config 模型)
- rwkv — RwkvConfig(RwkvConfig 模型)
- sam — SamConfig(SamConfig 模型)
- sam2 — Sam2Config(Sam2Config 模型)
- sam2_hiera_det_model — Sam2HieraDetConfig(Sam2HieraDetConfig 模型)
- sam2_mask_decoder — Sam2MaskDecoderConfig(Sam2MaskDecoderConfig 模型)
- sam2_prompt_encoder — Sam2PromptEncoderConfig(Sam2PromptEncoderConfig 模型)
- sam2_video — Sam2VideoConfig(Sam2VideoConfig 模型)
- sam2_video_mask_decoder — Sam2VideoMaskDecoderConfig(Sam2VideoMaskDecoderConfig 模型)
- sam2_video_prompt_encoder — Sam2VideoPromptEncoderConfig(Sam2VideoPromptEncoderConfig 模型)
- sam2_vision_model — Sam2VisionConfig(Sam2VisionConfig 模型)
- sam3 — Sam3Config(Sam3Config 模型)
- sam3_detr_decoder — Sam3DETRDecoderConfig(Sam3DETRDecoderConfig 模型)
- sam3_detr_encoder — Sam3DETREncoderConfig(Sam3DETREncoderConfig 模型)
- sam3_geometry_encoder — Sam3GeometryEncoderConfig(Sam3GeometryEncoderConfig 模型)
- sam3_lite_text — Sam3LiteTextConfig(Sam3LiteTextConfig 模型)
- sam3_lite_text_detr_decoder — Sam3LiteTextDETRDecoderConfig(Sam3LiteTextDETRDecoderConfig 模型)
- sam3_lite_text_detr_encoder — Sam3LiteTextDETREncoderConfig(Sam3LiteTextDETREncoderConfig 模型)
- sam3_lite_text_geometry_encoder — Sam3LiteTextGeometryEncoderConfig(Sam3LiteTextGeometryEncoderConfig 模型)
- sam3_lite_text_mask_decoder — Sam3LiteTextMaskDecoderConfig(Sam3LiteTextMaskDecoderConfig 模型)
- sam3_lite_text_text_model — Sam3LiteTextTextConfig(Sam3LiteTextTextConfig 模型)
- sam3_mask_decoder — Sam3MaskDecoderConfig(Sam3MaskDecoderConfig 模型)
- sam3_tracker — Sam3TrackerConfig(Sam3TrackerConfig 模型)
- sam3_tracker_mask_decoder — Sam3TrackerMaskDecoderConfig(Sam3TrackerMaskDecoderConfig 模型)
- sam3_tracker_prompt_encoder — Sam3TrackerPromptEncoderConfig(Sam3TrackerPromptEncoderConfig 模型)
- sam3_tracker_video — Sam3TrackerVideoConfig(Sam3TrackerVideoConfig 模型)
- sam3_tracker_video_mask_decoder — Sam3TrackerVideoMaskDecoderConfig(Sam3TrackerVideoMaskDecoderConfig 模型)
- sam3_tracker_video_prompt_encoder — Sam3TrackerVideoPromptEncoderConfig(Sam3TrackerVideoPromptEncoderConfig 模型)
- sam3_video — Sam3VideoConfig(Sam3VideoConfig 模型)
- sam3_vision_model — Sam3VisionConfig(Sam3VisionConfig 模型)
- sam3_vit_model — Sam3ViTConfig(Sam3ViTConfig 模型)
- sam_hq — SamHQConfig(SamHQConfig 模型)
- sam_hq_mask_decoder — SamHQMaskDecoderConfig(SamHQMaskDecoderConfig 模型)
- sam_hq_prompt_encoder — SamHQPromptEncoderConfig(SamHQPromptEncoderConfig 模型)
- sam_hq_vision_model — SamHQVisionConfig(SamHQVisionConfig 模型)
- sam_mask_decoder — SamMaskDecoderConfig(SamMaskDecoderConfig 模型)
- sam_prompt_encoder — SamPromptEncoderConfig(SamPromptEncoderConfig 模型)
- sam_vision_model — SamVisionConfig(SamVisionConfig 模型)
- sapiens2 — Sapiens2Config(Sapiens2Config 模型)
- sapiens2_head — Sapiens2HeadConfig(Sapiens2HeadConfig 模型)
- seamless_m4t — SeamlessM4TConfig(SeamlessM4TConfig 模型)
- seamless_m4t_v2 — SeamlessM4Tv2Config(SeamlessM4Tv2Config 模型)
- seed_oss — SeedOssConfig(SeedOssConfig 模型)
- segformer — SegformerConfig(SegformerConfig 模型)
- seggpt — SegGptConfig(SegGptConfig 模型)
- sew — SEWConfig(SEWConfig 模型)
- sew-d — SEWDConfig(SEWDConfig 模型)
- shieldgemma2 — ShieldGemma2Config(ShieldGemma2Config 模型)
- siglip — SiglipConfig(SiglipConfig 模型)
- siglip2 — Siglip2Config(Siglip2Config 模型)
- siglip2_text_model — Siglip2TextConfig(Siglip2TextConfig 模型)
- siglip2_vision_model — Siglip2VisionConfig(Siglip2VisionConfig 模型)
- siglip_text_model — SiglipTextConfig(SiglipTextConfig 模型)
- siglip_vision_model — SiglipVisionConfig(SiglipVisionConfig 模型)
- slanet — SLANetConfig(SLANetConfig 模型)
- slanext — SLANeXtConfig(SLANeXtConfig 模型)
- slanext_vision — SLANeXtVisionConfig(SLANeXtVisionConfig 模型)
- smollm3 — SmolLM3Config(SmolLM3Config 模型)
- smolvlm — SmolVLMConfig(SmolVLMConfig 模型)
- smolvlm_vision — SmolVLMVisionConfig(SmolVLMVisionConfig 模型)
- solar_open — SolarOpenConfig(SolarOpenConfig 模型)
- speech-encoder-decoder — SpeechEncoderDecoderConfig(SpeechEncoderDecoderConfig 模型)
- speech_to_text — Speech2TextConfig(Speech2TextConfig 模型)
- speecht5 — SpeechT5Config(SpeechT5Config 模型)
- speecht5_hifigan — SpeechT5HifiGanConfig(SpeechT5HifiGanConfig 模型)
- splinter — SplinterConfig(SplinterConfig 模型)
- squeezebert — SqueezeBertConfig(SqueezeBertConfig 模型)
- stablelm — StableLmConfig(StableLmConfig 模型)
- starcoder2 — Starcoder2Config(Starcoder2Config 模型)
- step3p5 — Step3p7TextConfig(Step3p7TextConfig 模型)
- step3p5_vision — Step3p7VisionConfig(Step3p7VisionConfig 模型)
- step3p7 — Step3p7Config(Step3p7Config 模型)
- superglue — SuperGlueConfig(SuperGlueConfig 模型)
- superpoint — SuperPointConfig(SuperPointConfig 模型)
- swiftformer — SwiftFormerConfig(SwiftFormerConfig 模型)
- swin — SwinConfig(SwinConfig 模型)
- swin2sr — Swin2SRConfig(Swin2SRConfig 模型)
- swinv2 — Swinv2Config(Swinv2Config 模型)
- switch_transformers — SwitchTransformersConfig(SwitchTransformersConfig 模型)
- t5 — T5Config(T5Config 模型)
- t5_gemma_module — T5GemmaModuleConfig(T5GemmaModuleConfig 模型)
- t5gemma — T5GemmaConfig(T5GemmaConfig 模型)
- t5gemma2 — T5Gemma2Config(T5Gemma2Config 模型)
- t5gemma2_decoder — T5Gemma2DecoderConfig(T5Gemma2DecoderConfig 模型)
- t5gemma2_encoder — T5Gemma2EncoderConfig(T5Gemma2EncoderConfig 模型)
- t5gemma2_text — T5Gemma2TextConfig(T5Gemma2TextConfig 模型)
- table-transformer — TableTransformerConfig(TableTransformerConfig 模型)
- tapas — TapasConfig(TapasConfig 模型)
- textnet — TextNetConfig(TextNetConfig 模型)
- time_series_transformer — TimeSeriesTransformerConfig(TimeSeriesTransformerConfig 模型)
- timesfm — TimesFmConfig(TimesFmConfig 模型)
- timesfm2_5 — TimesFm2_5Config(TimesFm2_5Config 模型)
- timesformer — TimesformerConfig(TimesformerConfig 模型)
- timm_backbone — TimmBackboneConfig(TimmBackboneConfig 模型)
- timm_wrapper — TimmWrapperConfig(TimmWrapperConfig 模型)
- tipsv2 — Tipsv2Config(Tipsv2Config 模型)
- tipsv2_dpt — Tipsv2DptConfig(Tipsv2DptConfig 模型)
- tipsv2_text_model — Tipsv2TextConfig(Tipsv2TextConfig 模型)
- tipsv2_vision_model — Tipsv2VisionConfig(Tipsv2VisionConfig 模型)
- trocr — TrOCRConfig(TrOCRConfig 模型)
- tvp — TvpConfig(TvpConfig 模型)
- udop — UdopConfig(UdopConfig 模型)
- ultrabert — UltrabertConfig(UltrabertConfig 模型)
- ultravbert — UltraVBertConfig(UltraVBertConfig 模型)
- umt5 — UMT5Config(UMT5Config 模型)
- unispeech — UniSpeechConfig(UniSpeechConfig 模型)
- unispeech-sat — UniSpeechSatConfig(UniSpeechSatConfig 模型)
- univnet — UnivNetConfig(UnivNetConfig 模型)
- unlimited_ocr — UnlimitedOcrConfig(UnlimitedOcrConfig 模型)
- unlimited_ocr_sam_vision_model — UnlimitedOcrSamVisionConfig(UnlimitedOcrSamVisionConfig 模型)
- unlimited_ocr_text — UnlimitedOcrTextConfig(UnlimitedOcrTextConfig 模型)
- unlimited_ocr_vision — UnlimitedOcrVisionConfig(UnlimitedOcrVisionConfig 模型)
- unlimited_ocr_vision_encoder — UnlimitedOcrVisionEncoderConfig(UnlimitedOcrVisionEncoderConfig 模型)
- upernet — UperNetConfig(UperNetConfig 模型)
- uvdoc — UVDocConfig(UVDocConfig 模型)
- uvdoc_backbone — UVDocBackboneConfig(UVDocBackboneConfig 模型)
- vaultgemma — VaultGemmaConfig(VaultGemmaConfig 模型)
- vibevoice — VibeVoiceConfig(VibeVoiceConfig 模型)
- vibevoice_acoustic_tokenizer — VibeVoiceAcousticTokenizerConfig(VibeVoiceAcousticTokenizerConfig 模型)
- vibevoice_acoustic_tokenizer_decoder — VibeVoiceAcousticTokenizerDecoderConfig(VibeVoiceAcousticTokenizerDecoderConfig 模型)
- vibevoice_acoustic_tokenizer_encoder — VibeVoiceAcousticTokenizerEncoderConfig(VibeVoiceAcousticTokenizerEncoderConfig 模型)
- vibevoice_asr — VibeVoiceAsrConfig(VibeVoiceAsrConfig 模型)
- vibevoice_diffusion — VibeVoiceDiffusionHeadConfig(VibeVoiceDiffusionHeadConfig 模型)
- video_llama_3 — VideoLlama3Config(VideoLlama3Config 模型)
- video_llama_3_vision — VideoLlama3VisionConfig(VideoLlama3VisionConfig 模型)
- video_llava — VideoLlavaConfig(VideoLlavaConfig 模型)
- videomae — VideoMAEConfig(VideoMAEConfig 模型)
- videomt — VideomtConfig(VideomtConfig 模型)
- videoprism — VideoPrismConfig(VideoPrismConfig 模型)
- videoprism_text_model — VideoPrismTextConfig(VideoPrismTextConfig 模型)
- videoprism_vision_model — VideoPrismVisionConfig(VideoPrismVisionConfig 模型)
- vilt — ViltConfig(ViltConfig 模型)
- vipllava — VipLlavaConfig(VipLlavaConfig 模型)
- vision-encoder-decoder — VisionEncoderDecoderConfig(VisionEncoderDecoderConfig 模型)
- vision-text-dual-encoder — VisionTextDualEncoderConfig(VisionTextDualEncoderConfig 模型)
- visual_bert — VisualBertConfig(VisualBertConfig 模型)
- vit — ViTConfig(ViTConfig 模型)
- vit_mae — ViTMAEConfig(ViTMAEConfig 模型)
- vit_msn — ViTMSNConfig(ViTMSNConfig 模型)
- vitdet — VitDetConfig(VitDetConfig 模型)
- vitmatte — VitMatteConfig(VitMatteConfig 模型)
- vitpose — VitPoseConfig(VitPoseConfig 模型)
- vitpose_backbone —
VitPoseBackboneConfig(VitPoseBackboneConfig 模型) - vits — VitsConfig(VitsConfig 模型)
- vivit — VivitConfig(VivitConfig 模型)
- vjepa2 — VJEPA2Config(VJEPA2Config 模型)
- voxtral — VoxtralConfig(VoxtralConfig 模型)
- voxtral_encoder — VoxtralEncoderConfig(VoxtralEncoderConfig 模型)
- voxtral_realtime — VoxtralRealtimeConfig(VoxtralRealtimeConfig 模型)
- voxtral_realtime_encoder — VoxtralRealtimeEncoderConfig(VoxtralRealtimeEncoderConfig 模型)
- voxtral_realtime_text — VoxtralRealtimeTextConfig(VoxtralRealtimeTextConfig 模型)
- wav2vec2 — Wav2Vec2Config(Wav2Vec2Config 模型)
- wav2vec2-bert — Wav2Vec2BertConfig(Wav2Vec2BertConfig 模型)
- wav2vec2-conformer — Wav2Vec2ConformerConfig(Wav2Vec2ConformerConfig 模型)
- wavlm — WavLMConfig(WavLMConfig 模型)
- whisper — WhisperConfig(WhisperConfig 模型)
- xclip — XCLIPConfig(XCLIPConfig 模型)
- xclip_text_model — XCLIPTextConfig(XCLIPTextConfig 模型)
- xclip_vision_model — XCLIPVisionConfig(XCLIPVisionConfig 模型)
- xcodec — XcodecConfig(XcodecConfig 模型)
- xcodec2 — Xcodec2Config(Xcodec2Config 模型)
- xglm — XGLMConfig(XGLMConfig 模型)
- xlm — XLMConfig(XLMConfig 模型)
- xlm-roberta — XLMRobertaConfig(XLMRobertaConfig 模型)
- xlm-roberta-xl — XLMRobertaXLConfig(XLMRobertaXLConfig 模型)
- xlnet — XLNetConfig(XLNetConfig 模型)
- xlstm — xLSTMConfig(xLSTMConfig 模型)
- xmod — XmodConfig(XmodConfig 模型)
- yolos — YolosConfig(YolosConfig 模型)
- yoso — YosoConfig(YosoConfig 模型)
- youtu — YoutuConfig(YoutuConfig 模型)
- zamba — ZambaConfig(ZambaConfig 模型)
- zamba2 — Zamba2Config(Zamba2Config 模型)
- zaya — ZayaConfig(ZayaConfig 模型)
- zoedepth — ZoeDepthConfig(ZoeDepthConfig 模型)
示例:
>>> 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}注册
< source >( model_typeconfigexist_ok = False )
参数
- model_type (
str) — 模型类型,例如 “bert” 或 “gpt”。 - config (PreTrainedConfig) — 要注册的配置。
为此类注册一个新的配置。
AutoTokenizer
这是一个通用的分词器类,当通过 AutoTokenizer.from_pretrained() 类方法创建时,它会被实例化为该库中的某个分词器类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_pretrained
< source >( pretrained_model_name_or_path*inputs**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,即托管在 huggingface.co 上某个模型仓库中的预定义分词器的 model id。
- 指向包含分词器所需词汇文件的目录的路径,例如使用 save_pretrained() 方法保存的路径,如
./my_model_directory/。 - 仅当分词器只需要单个词表文件(例如 Bert 或 XLNet)时,才指定指向单个已保存词表文件的路径,例如:
./my_model_directory/vocab.txt。(不适用于所有派生类)
- inputs(额外的位置参数,可选)—
将传递给 Tokenizer 的
__init__()方法。 - config (PreTrainedConfig,可选) — 用于确定要实例化的分词器类的配置对象。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,并在存在缓存版本时覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - subfolder (
str, 可选) — 如果相关文件位于 huggingface.co 上模型仓库的子文件夹中(例如 facebook/rag-token-base),请在此处指定。 - tokenizer_type (
str, 可选) — 要加载的 Tokenizer 类型。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - kwargs(额外的关键字参数,可选) —
将传递给 Tokenizer 的
__init__()方法。可用于设置特殊标记,例如bos_token、eos_token、unk_token、sep_token、pad_token、cls_token、mask_token、additional_special_tokens。有关更多详细信息,请参阅__init__()中的参数。
从预训练模型词表中实例化该库的某个分词器类。
要实例化的分词器类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- EvollaModel — TokenizersBackend(EvollaConfig 模型)
- aimv2 — CLIPTokenizer(Aimv2Config 模型)
- albert — AlbertTokenizer(AlbertConfig 模型)
- align — BertTokenizer(AlignConfig 模型)
- aria — TokenizersBackend(AriaConfig 模型)
- audioflamingo3 — Qwen2Tokenizer(AudioFlamingo3Config 模型)
- aya_vision — CohereTokenizer(AyaVisionConfig 模型)
- bark — BertTokenizer(BarkConfig 模型)
- bart — RobertaTokenizer(BartConfig 模型)
- beam — TokenizersBackend(BeamConfig 模型)
- bert — BertTokenizer(BertConfig 模型)
- bert-generation — BertGenerationTokenizer(BertGenerationConfig 模型)
- big_bird — BigBirdTokenizer(BigBirdConfig 模型)
- bigbird_pegasus — TokenizersBackend(BigBirdPegasusConfig 模型)
- biogpt — BioGptTokenizer(BioGptConfig 模型)
- blenderbot — BlenderbotTokenizer(BlenderbotConfig 模型)
- blenderbot-small — BlenderbotSmallTokenizer(BlenderbotSmallConfig 模型)
- blip — BertTokenizer(BlipConfig 模型)
- blip-2 — GPT2Tokenizer(Blip2Config 模型)
- bridgetower — RobertaTokenizer(BridgeTowerConfig 模型)
- bros — BertTokenizer(BrosConfig 模型)
- camembert — CamembertTokenizer(CamembertConfig 模型)
- canary — TokenizersBackend(CanaryConfig 模型)
- canine — CanineTokenizer(CanineConfig 模型)
- chinese_clip — BertTokenizer(ChineseCLIPConfig 模型)
- clap — RobertaTokenizer(ClapConfig 模型)
- clip — CLIPTokenizer(CLIPConfig 模型)
- clipseg — CLIPTokenizer(CLIPSegConfig 模型)
- clvp — ClvpTokenizer(ClvpConfig 模型)
- codegen — GPT2Tokenizer(CodeGenConfig 模型)
- cohere — CohereTokenizer(CohereConfig 模型)
- cohere2 — CohereTokenizer(Cohere2Config 模型)
- cohere_asr — TokenizersBackend(CohereAsrConfig 模型)
- colqwen2 — Qwen2Tokenizer(ColQwen2Config 模型)
- convbert — BertTokenizer(ConvBertConfig 模型)
- cosmos3_omni — Qwen2Tokenizer(Cosmos3OmniConfig 模型)
- cpmant — CpmAntTokenizer(CpmAntConfig 模型)
- ctrl — CTRLTokenizer(CTRLConfig 模型)
- data2vec-audio — Wav2Vec2CTCTokenizer(Data2VecAudioConfig 模型)
- data2vec-text — RobertaTokenizer(Data2VecTextConfig 模型)
- dbrx — GPT2Tokenizer(DbrxConfig 模型)
- deberta — DebertaTokenizer(DebertaConfig 模型)
- deberta-v2 — DebertaV2Tokenizer(DebertaV2Config 模型)
- dia — DiaTokenizer(DiaConfig 模型)
- diffusion_gemma — GemmaTokenizer(DiffusionGemmaConfig 模型)
- distilbert — BertTokenizer(DistilBertConfig 模型)
- dpr — DPRQuestionEncoderTokenizer(DPRConfig 模型)
- electra — BertTokenizer(ElectraConfig 模型)
- emu3 — GPT2Tokenizer(Emu3Config 模型)
- ernie — BertTokenizer(ErnieConfig 模型)
- ernie4_5 — TokenizersBackend(Ernie4_5Config 模型)
- ernie4_5_moe — TokenizersBackend(Ernie4_5_MoeConfig 模型)
- esm — EsmTokenizer(EsmConfig 模型)
- esmc — EsmcTokenizer(EsmcConfig 模型)
- esmfold2 — EsmcTokenizer(EsmFold2Config 模型)
- falcon_mamba — GPTNeoXTokenizer(FalconMambaConfig 模型)
- fastspeech2_conformer —
None(FastSpeech2ConformerConfig 模型) - flaubert — FlaubertTokenizer(FlaubertConfig 模型)
- flava — BertTokenizer(FlavaConfig 模型)
- flex_olmo — TokenizersBackend(FlexOlmoConfig 模型)
- florence2 — BartTokenizer(Florence2Config 模型)
- fnet — FNetTokenizer(FNetConfig 模型)
- fsmt — FSMTTokenizer(FSMTConfig 模型)
- fun_asr_nano — Qwen2Tokenizer(FunAsrNanoConfig 模型)
- funnel — FunnelTokenizer(FunnelConfig 模型)
- fuyu — TokenizersBackend(FuyuConfig 模型)
- gemma — GemmaTokenizer(GemmaConfig 模型)
- gemma2 — GemmaTokenizer(Gemma2Config 模型)
- gemma3 — GemmaTokenizer(Gemma3Config 模型)
- gemma3_text — GemmaTokenizer(Gemma3TextConfig 模型)
- gemma3n — GemmaTokenizer(Gemma3nConfig 模型)
- gemma3n_text — GemmaTokenizer(Gemma3nTextConfig 模型)
- git — BertTokenizer(GitConfig 模型)
- glm — TokenizersBackend(GlmConfig 模型)
- glm4 — TokenizersBackend(Glm4Config 模型)
- glm4_moe — TokenizersBackend(Glm4MoeConfig 模型)
- glm4_moe_lite — TokenizersBackend(Glm4MoeLiteConfig 模型)
- glm4v — TokenizersBackend(Glm4vConfig 模型)
- glm4v_moe — TokenizersBackend(Glm4vMoeConfig 模型)
- glm_image — TokenizersBackend(GlmImageConfig 模型)
- glmasr — TokenizersBackend(GlmAsrConfig 模型)
- got_ocr2 — TokenizersBackend(GotOcr2Config 模型)
- gpt-sw3 — GPTSw3Tokenizer(GPT2Config 模型)
- gpt2 — GPT2Tokenizer(GPT2Config 模型)
- gpt_bigcode — TokenizersBackend(GPTBigCodeConfig 模型)
- gpt_neo — GPT2Tokenizer(GPTNeoConfig 模型)
- gpt_neox — GPTNeoXTokenizer(GPTNeoXConfig 模型)
- gpt_neox_japanese — GPTNeoXJapaneseTokenizer(GPTNeoXJapaneseConfig 模型)
- gptj — GPT2Tokenizer(GPTJConfig 模型)
- gradium_phonon_tts — TokenizersBackend(GradiumPhononTTSConfig 模型)
- granite — TokenizersBackend(GraniteConfig 模型)
- granite_speech5_ctc — ParakeetTokenizer(GraniteSpeech5CTCConfig 模型)
- granitemoe — TokenizersBackend(GraniteMoeConfig 模型)
- granitemoehybrid — TokenizersBackend(GraniteMoeHybridConfig 模型)
- granitemoeshared — TokenizersBackend(GraniteMoeSharedConfig 模型)
- grounding-dino — BertTokenizer(GroundingDinoConfig 模型)
- groupvit — CLIPTokenizer(GroupViTConfig 模型)
- gte — XLMRobertaTokenizer(GteConfig 模型)
- hubert — Wav2Vec2CTCTokenizer(HubertConfig 模型)
- hunyuan_vl — Qwen2Tokenizer(HunYuanVLConfig 模型)
- hyperclovax — TokenizersBackend(HyperCLOVAXConfig 模型)
- hyperclovax_vision_v2 — GPT2Tokenizer(HyperCLOVAXVisionV2Config 模型)
- ibert — RobertaTokenizer(IBertConfig 模型)
- idefics — LlamaTokenizer(IdeficsConfig 模型)
- idefics2 — LlamaTokenizer(Idefics2Config 模型)
- instructblip — GPT2Tokenizer(InstructBlipConfig 模型)
- instructblipvideo — GPT2Tokenizer(InstructBlipVideoConfig 模型)
- internvl — Qwen2Tokenizer(InternVLConfig 模型)
- jais2 — GPT2Tokenizer(Jais2Config 模型)
- jamba — TokenizersBackend(JambaConfig 模型)
- jina_embeddings_v3 — XLMRobertaTokenizer(JinaEmbeddingsV3Config 模型)
- kimi_k25 — TokenizersBackend(Kimi_K25Config 模型)
- kimi_linear — TokenizersBackend(KimiLinearConfig 模型)
- kosmos-2 — TokenizersBackend(Kosmos2Config 模型)
- lasr_ctc — LasrTokenizer(LasrCTCConfig 模型)
- lasr_encoder — LasrTokenizer(LasrEncoderConfig 模型)
- layoutlm — BertTokenizer(LayoutLMConfig 模型)
- layoutlmv2 — LayoutLMv2Tokenizer(LayoutLMv2Config 模型)
- layoutlmv3 — LayoutLMv3Tokenizer(LayoutLMv3Config 模型)
- layoutxlm — LayoutXLMTokenizer(LayoutXLMConfig 模型)
- led — LEDTokenizer(LEDConfig 模型)
- lighton_ocr — Qwen2TokenizerFast(LightOnOcrConfig 模型)
- lilt — RobertaTokenizer(LiltConfig 模型)
- llava — TokenizersBackend(LlavaConfig 模型)
- llava_next — TokenizersBackend(LlavaNextConfig 模型)
- longformer — RobertaTokenizer(LongformerConfig 模型)
- luke — LukeTokenizer(LukeConfig 模型)
- lxmert — LxmertTokenizer(LxmertConfig 模型)
- m2m_100 — M2M100Tokenizer(M2M100Config 模型)
- mamba — GPTNeoXTokenizer(MambaConfig 模型)
- mamba2 — GPTNeoXTokenizer(Mamba2Config 模型)
- marian — MarianTokenizer(MarianConfig 模型)
- markuplm — MarkupLMTokenizer(MarkupLMConfig 模型)
- mbart — MBartTokenizer(MBartConfig 模型)
- megatron-bert — BertTokenizer(MegatronBertConfig 模型)
- metaclip_2 — XLMRobertaTokenizer(MetaClip2Config 模型)
- mgp-str — MgpstrTokenizer(MgpstrConfig 模型)
- mimo_v2_flash — TokenizersBackend(MiMoV2FlashConfig 模型)
- minicpm3 — TokenizersBackend(MiniCPM3Config 模型)
- minicpm_ocr — TokenizersBackend(MiniCPMOcrConfig 模型)
- minicpmv4_6 — TokenizersBackend(MiniCPMV4_6Config 模型)
- minicpmv4_7 — TokenizersBackend(MiniCPMV4_7Config 模型)
- minimax_m2 — TokenizersBackend(MiniMaxM2Config 模型)
- ministral — MistralCommonBackend(MinistralConfig 模型)
- ministral3 — MistralCommonBackend(Ministral3Config 模型)
- mistral — MistralCommonBackend(MistralConfig 模型)
- mistral3 — MistralCommonBackend(Mistral3Config 模型)
- mistral_large4 — MistralCommonBackend(MistralLarge4Config 模型)
- mixtral — MistralCommonBackend(MixtralConfig 模型)
- mm-grounding-dino — BertTokenizer(MMGroundingDinoConfig 模型)
- mobilebert — MobileBertTokenizer(MobileBertConfig 模型)
- modernbert — TokenizersBackend(ModernBertConfig 模型)
- modernbert-decoder — TokenizersBackend(ModernBertDecoderConfig 模型)
- molmo2 — TokenizersBackend(Molmo2Config 模型)
- moss_transcribe_diarize — Qwen2Tokenizer(MossTranscribeDiarizeConfig 模型)
- mpnet — MPNetTokenizer(MPNetConfig 模型)
- mpt — GPTNeoXTokenizer(MptConfig 模型)
- mra — RobertaTokenizer(MraConfig 模型)
- mt5 — T5Tokenizer(MT5Config 模型)
- musicgen — T5Tokenizer(MusicgenConfig 模型)
- musicgen_melody — T5Tokenizer(MusicgenMelodyConfig 模型)
- mvp — MvpTokenizer(MvpConfig 模型)
- nemo_speechlm — TokenizersBackend(Nemotron3_5TranscribeConfig 模型)
- nemotron — TokenizersBackend(NemotronConfig 模型)
- nemotron3_5_asr — ParakeetTokenizer(Nemotron3_5AsrConfig 模型)
- nemotron_asr_streaming — ParakeetTokenizer(NemotronAsrStreamingConfig 模型)
- nllb-moe — NllbTokenizer(NllbMoeConfig 模型)
- nomic_bert — BertTokenizer(NomicBertConfig 模型)
- nougat — NougatTokenizer(NougatConfig 模型)
- nystromformer — TokenizersBackend(NystromformerConfig 模型)
- olmo — GPTNeoXTokenizer(OlmoConfig 模型)
- olmo2 — TokenizersBackend(Olmo2Config 模型)
- olmo3 — TokenizersBackend(Olmo3Config 模型)
- olmo_hybrid — TokenizersBackend(OlmoHybridConfig 模型)
- olmoe — GPTNeoXTokenizer(OlmoeConfig 模型)
- omdet-turbo — CLIPTokenizer(OmDetTurboConfig 模型)
- oneformer — CLIPTokenizer(OneFormerConfig 模型)
- openai-gpt — OpenAIGPTTokenizer(OpenAIGPTConfig 模型)
- opt — GPT2Tokenizer(OPTConfig 模型)
- ovis2 — Qwen2Tokenizer(Ovis2Config 模型)
- owlv2 — CLIPTokenizer(Owlv2Config 模型)
- owlvit — CLIPTokenizer(OwlViTConfig 模型)
- paddleocr_vl — TokenizersBackend(PaddleOCRVLConfig 模型)
- parakeet_ctc — ParakeetTokenizer(ParakeetCTCConfig 模型)
- parakeet_rnnt — ParakeetTokenizer(ParakeetRNNTConfig 模型)
- parakeet_tdt — ParakeetTokenizer(ParakeetTDTConfig 模型)
- pegasus — PegasusTokenizer(PegasusConfig 模型)
- pegasus_x — TokenizersBackend(PegasusXConfig 模型)
- perceiver — PerceiverTokenizer(PerceiverConfig 模型)
- persimmon — TokenizersBackend(PersimmonConfig 模型)
- phi — GPT2Tokenizer(PhiConfig 模型)
- phi3 — TokenizersBackend(Phi3Config 模型)
- phimoe — TokenizersBackend(PhimoeConfig 模型)
- pix2struct — TokenizersBackend(Pix2StructConfig 模型)
- pixtral — MistralCommonBackend(PixtralVisionConfig 模型)
- plbart — PLBartTokenizer(PLBartConfig 模型)
- pocket_tts — TokenizersBackend(PocketTTSConfig 模型)
- pp_formulanet — NougatTokenizer(PPFormulaNetConfig 模型)
- prophetnet — ProphetNetTokenizer(ProphetNetConfig 模型)
- qianfan_ocr — Qwen2Tokenizer(QianfanOCRConfig 模型)
- qwen2 — Qwen2Tokenizer(Qwen2Config 模型)
- qwen2_5_omni — Qwen2Tokenizer(Qwen2_5OmniConfig 模型)
- qwen2_5_vl — Qwen2Tokenizer(Qwen2_5_VLConfig 模型)
- qwen2_audio — Qwen2Tokenizer(Qwen2AudioConfig 模型)
- qwen2_moe — Qwen2Tokenizer(Qwen2MoeConfig 模型)
- qwen2_vl — Qwen2Tokenizer(Qwen2VLConfig 模型)
- qwen3 — Qwen2Tokenizer(Qwen3Config 模型)
- qwen3_5 — Qwen3_5Tokenizer(Qwen3_5Config 模型)
- qwen3_5_moe — Qwen3_5Tokenizer(Qwen3_5MoeConfig 模型)
- qwen3_5_moe_text — Qwen3_5Tokenizer(Qwen3_5MoeTextConfig 模型)
- qwen3_5_text — Qwen3_5Tokenizer(Qwen3_5TextConfig 模型)
- qwen3_asr — Qwen2Tokenizer(Qwen3ASRConfig 模型)
- qwen3_moe — Qwen2Tokenizer(Qwen3MoeConfig 模型)
- qwen3_next — Qwen2Tokenizer(Qwen3NextConfig 模型)
- qwen3_omni_moe — Qwen2Tokenizer(Qwen3OmniMoeConfig 模型)
- qwen3_vl — Qwen2Tokenizer(Qwen3VLConfig 模型)
- qwen3_vl_moe — Qwen2Tokenizer(Qwen3VLMoeConfig 模型)
- qwen4_exp — Qwen3_5Tokenizer(Qwen4ExpConfig 模型)
- rag — RagTokenizer(RagConfig 模型)
- recurrent_gemma — GemmaTokenizer(RecurrentGemmaConfig 模型)
- reformer — ReformerTokenizer(ReformerConfig 模型)
- rembert — RemBertTokenizer(RemBertConfig 模型)
- roberta — RobertaTokenizer(RobertaConfig 模型)
- roberta-prelayernorm — RobertaTokenizer(RobertaPreLayerNormConfig 模型)
- roc_bert — RoCBertTokenizer(RoCBertConfig 模型)
- roformer — RoFormerTokenizer(RoFormerConfig 模型)
- rwkv — GPTNeoXTokenizer(RwkvConfig 模型)
- sam3 — CLIPTokenizer(Sam3Config 模型)
- sam3_video — CLIPTokenizer(Sam3VideoConfig 模型)
- seamless_m4t — SeamlessM4TTokenizer(SeamlessM4TConfig 模型)
- seamless_m4t_v2 — SeamlessM4TTokenizer(SeamlessM4Tv2Config 模型)
- shieldgemma2 — GemmaTokenizer(ShieldGemma2Config 模型)
- siglip — SiglipTokenizer(SiglipConfig 模型)
- siglip2 — Siglip2Tokenizer(Siglip2Config 模型)
- smolvlm — TokenizersBackend(SmolVLMConfig 模型)
- speech_to_text — Speech2TextTokenizer(Speech2TextConfig 模型)
- speecht5 — SpeechT5Tokenizer(SpeechT5Config 模型)
- splinter — SplinterTokenizer(SplinterConfig 模型)
- squeezebert — BertTokenizer(SqueezeBertConfig 模型)
- stablelm — TokenizersBackend(StableLmConfig 模型)
- starcoder2 — GPT2Tokenizer(Starcoder2Config 模型)
- switch_transformers — T5Tokenizer(SwitchTransformersConfig 模型)
- t5 — T5Tokenizer(T5Config 模型)
- t5gemma — GemmaTokenizer(T5GemmaConfig 模型)
- tapas — TapasTokenizer(TapasConfig 模型)
- tipsv2 — Tipsv2Tokenizer(Tipsv2Config 模型)
- trocr — XLMRobertaTokenizer(TrOCRConfig 模型)
- tvp — BertTokenizer(TvpConfig 模型)
- udop — UdopTokenizer(UdopConfig 模型)
- umt5 — TokenizersBackend(UMT5Config 模型)
- unispeech — Wav2Vec2CTCTokenizer(UniSpeechConfig 模型)
- unispeech-sat — Wav2Vec2CTCTokenizer(UniSpeechSatConfig 模型)
- vibevoice — Qwen2TokenizerFast(VibeVoiceConfig 模型)
- videoprism — VideoPrismTokenizer(VideoPrismConfig 模型)
- vilt — BertTokenizer(ViltConfig 模型)
- vipllava — TokenizersBackend(VipLlavaConfig 模型)
- visual_bert — BertTokenizer(VisualBertConfig 模型)
- vits — VitsTokenizer(VitsConfig 模型)
- voxtral — MistralCommonBackend(VoxtralConfig 模型)
- voxtral_realtime — MistralCommonBackend(VoxtralRealtimeConfig 模型)
- wav2vec2 — Wav2Vec2CTCTokenizer(Wav2Vec2Config 模型)
- wav2vec2-bert — Wav2Vec2CTCTokenizer(Wav2Vec2BertConfig 模型)
- wav2vec2-conformer — Wav2Vec2CTCTokenizer(Wav2Vec2ConformerConfig 模型)
- whisper — WhisperTokenizer(WhisperConfig 模型)
- xclip — CLIPTokenizer(XCLIPConfig 模型)
- xglm — XGLMTokenizer(XGLMConfig 模型)
- xlm — XLMTokenizer(XLMConfig 模型)
- xlm-roberta — XLMRobertaTokenizer(XLMRobertaConfig 模型)
- xlm-roberta-xl — TokenizersBackend(XLMRobertaXLConfig 模型)
- xlnet — XLNetTokenizer(XLNetConfig 模型)
- xlstm — GPTNeoXTokenizer(xLSTMConfig 模型)
- xmod — XLMRobertaTokenizer(XmodConfig 模型)
- yoso — AlbertTokenizer(YosoConfig 模型)
- zaya — GemmaTokenizer(ZayaConfig 模型)
示例:
>>> from transformers import AutoTokenizer
>>> # Download vocabulary from huggingface.co and cache.
>>> tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-uncased")
>>> # Download vocabulary from huggingface.co (user-uploaded) and cache.
>>> tokenizer = AutoTokenizer.from_pretrained("dbmdz/bert-base-german-cased")
>>> # If vocabulary files are in a directory (e.g. tokenizer was saved using *save_pretrained('./test/saved_model/')*)
>>> # tokenizer = AutoTokenizer.from_pretrained("./test/bert_saved_model/")
>>> # Download vocabulary from huggingface.co and define model-specific arguments
>>> tokenizer = AutoTokenizer.from_pretrained("FacebookAI/roberta-base", add_prefix_space=True)注册
< source >( config_classtokenizer_class = Noneslow_tokenizer_class = Nonefast_tokenizer_class = Noneexist_ok = False )
参数
- config_class (PreTrainedConfig) — 与要注册的模型对应的配置。
- tokenizer_class — 要注册的 tokenizer 类(V5 - 首选参数)。
- slow_tokenizer_class —(已弃用)要注册的慢速分词器。
- fast_tokenizer_class —(已弃用)要注册的快速分词器。
在此映射中注册一个新的分词器。
AutoFeatureExtractor
这是一个通用的特征提取器类,当使用 AutoFeatureExtractor.from_pretrained() 类方法创建时,它会被实例化为该库中的某个特征提取器类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_pretrained
< source >( pretrained_model_name_or_path**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,即托管在 huggingface.co 上某个模型仓库中的预训练 feature_extractor 的 model id。
- 指向一个目录的路径,该目录包含使用
save_pretrained() 方法保存的特征提取器文件,例如
./my_model_directory/。 - 指向已保存的特征提取器 JSON 文件的路径,例如
./my_model_directory/preprocessor_config.json。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则下载预训练模型特征提取器时应缓存到的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载特征提取器文件,并在缓存版本存在时覆盖它们。 - proxies (
dict[str, str], 可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}.每次请求都会使用这些代理。 - token(
str或 bool,可选)— 用于远程文件的 HTTP 承载者授权令牌。如果为True,则使用运行hf auth login时生成的令牌(存储在~/.huggingface中)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - return_unused_kwargs (
bool,可选,默认为False) — 如果为False,则此函数仅返回最终的 feature extractor 对象。如果为True,则此函数返回一个Tuple(feature_extractor, unused_kwargs),其中 unused_kwargs 是一个字典,包含那些键不是 feature extractor 属性的键值对:即kwargs中未用于更新feature_extractor且被忽略的部分。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - kwargs (
dict[str, Any], 可选) — kwargs 中任何作为特征提取器属性的键的值,将用于覆盖已加载的值。对于键不是特征提取器属性的键值对,其行为由return_unused_kwargs关键字参数控制。
从预训练模型词表中实例化该库的某个特征提取器类。
要实例化的特征提取器类是根据配置对象的 model_type 属性来选择的(该属性可以作为参数传入,或者在可能的情况下从 pretrained_model_name_or_path 加载),如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- audio-spectrogram-transformer — ASTFeatureExtractor(ASTConfig 模型)
- audioflamingo3 — WhisperFeatureExtractor(AudioFlamingo3Config 模型)
- canary — ParakeetFeatureExtractor(CanaryConfig 模型)
- clap — ClapFeatureExtractor(ClapConfig 模型)
- clvp — ClvpFeatureExtractor(ClvpConfig 模型)
- cohere_asr — CohereAsrFeatureExtractor(CohereAsrConfig 模型)
- csm — EncodecFeatureExtractor(CsmConfig 模型)
- dac — DacFeatureExtractor(DacConfig 模型)
- data2vec-audio — Wav2Vec2FeatureExtractor(Data2VecAudioConfig 模型)
- dia — DiaFeatureExtractor(DiaConfig 模型)
- embedding_gemma2 — Gemma4AudioFeatureExtractor(EmbeddingGemma2Config 模型)
- encodec — EncodecFeatureExtractor(EncodecConfig 模型)
- fun_asr_nano — FunAsrNanoFeatureExtractor(FunAsrNanoConfig 模型)
- gemma3n — Gemma3nAudioFeatureExtractor(Gemma3nConfig 模型)
- gemma4 — Gemma4AudioFeatureExtractor(Gemma4Config 模型)
- gemma4_unified — Gemma4UnifiedAudioFeatureExtractor(Gemma4UnifiedConfig 模型)
- glmasr — WhisperFeatureExtractor(GlmAsrConfig 模型)
- gradium_phonon_tts — PocketTTSFeatureExtractor(GradiumPhononTTSConfig 模型)
- granite_speech — GraniteSpeechFeatureExtractor(GraniteSpeechConfig 模型)
- granite_speech5_ctc — GraniteSpeech5FeatureExtractor(GraniteSpeech5CTCConfig 模型)
- granite_speech5_encoder — GraniteSpeech5FeatureExtractor(GraniteSpeech5EncoderConfig 模型)
- granite_speech_plus — GraniteSpeechFeatureExtractor(GraniteSpeechPlusConfig 模型)
- higgs_audio_v2_tokenizer — DacFeatureExtractor(HiggsAudioV2TokenizerConfig 模型)
- hubert — Wav2Vec2FeatureExtractor(HubertConfig 模型)
- inkling_mm_model — InklingFeatureExtractor(InklingConfig 模型)
- kyutai_speech_to_text — KyutaiSpeechToTextFeatureExtractor(KyutaiSpeechToTextConfig 模型)
- lasr_ctc — LasrFeatureExtractor(LasrCTCConfig 模型)
- lasr_encoder — LasrFeatureExtractor(LasrEncoderConfig 模型)
- mimi — EncodecFeatureExtractor(MimiConfig 模型)
- moonshine — Wav2Vec2FeatureExtractor(MoonshineConfig 模型)
- moshi — EncodecFeatureExtractor(MoshiConfig 模型)
- moss_transcribe_diarize — MossTranscribeDiarizeFeatureExtractor(MossTranscribeDiarizeConfig 模型)
- muse_spark — MuseSparkFeatureExtractor(MuseSparkConfig 模型)
- musicgen — EncodecFeatureExtractor(MusicgenConfig 模型)
- musicgen_melody — MusicgenMelodyFeatureExtractor(MusicgenMelodyConfig 模型)
- nemo_speechlm — NemotronAsrStreamingFeatureExtractor(Nemotron3_5TranscribeConfig 模型)
- nemotron3_5_asr — NemotronAsrStreamingFeatureExtractor(Nemotron3_5AsrConfig 模型)
- nemotron3_diarization — NemotronAsrStreamingFeatureExtractor(Nemotron3DiarizationConfig 模型)
- nemotron_asr_streaming — NemotronAsrStreamingFeatureExtractor(NemotronAsrStreamingConfig 模型)
- nemotron_asr_streaming_encoder — NemotronAsrStreamingFeatureExtractor(NemotronAsrStreamingEncoderConfig 模型)
- neucodec — NeuCodecFeatureExtractor(NeuCodecConfig 模型)
- parakeet_ctc — ParakeetFeatureExtractor(ParakeetCTCConfig 模型)
- parakeet_encoder — ParakeetFeatureExtractor(ParakeetEncoderConfig 模型)
- parakeet_rnnt — ParakeetFeatureExtractor(ParakeetRNNTConfig 模型)
- parakeet_tdt — ParakeetFeatureExtractor(ParakeetTDTConfig 模型)
- pe_audio — PeAudioFeatureExtractor(PeAudioConfig 模型)
- pe_audio_video — PeAudioFeatureExtractor(PeAudioVideoConfig 模型)
- phi4_multimodal — Phi4MultimodalFeatureExtractor(Phi4MultimodalConfig 模型)
- pocket_tts — PocketTTSFeatureExtractor(PocketTTSConfig 模型)
- pocket_tts_audio_tokenizer — EncodecFeatureExtractor(PocketTTSAudioTokenizerConfig 模型)
- pop2piano — Pop2PianoFeatureExtractor(Pop2PianoConfig 模型)
- qwen2_5_omni — WhisperFeatureExtractor(Qwen2_5OmniConfig 模型)
- qwen2_audio — WhisperFeatureExtractor(Qwen2AudioConfig 模型)
- qwen3_asr — Qwen3ASRFeatureExtractor(Qwen3ASRConfig 模型)
- qwen3_omni_moe — WhisperFeatureExtractor(Qwen3OmniMoeConfig 模型)
- seamless_m4t — SeamlessM4TFeatureExtractor(SeamlessM4TConfig 模型)
- seamless_m4t_v2 — SeamlessM4TFeatureExtractor(SeamlessM4Tv2Config 模型)
- sew — Wav2Vec2FeatureExtractor(SEWConfig 模型)
- sew-d — Wav2Vec2FeatureExtractor(SEWDConfig 模型)
- speech_to_text — Speech2TextFeatureExtractor(Speech2TextConfig 模型)
- speecht5 — SpeechT5FeatureExtractor(SpeechT5Config 模型)
- unispeech — Wav2Vec2FeatureExtractor(UniSpeechConfig 模型)
- unispeech-sat — Wav2Vec2FeatureExtractor(UniSpeechSatConfig 模型)
- univnet — UnivNetFeatureExtractor(UnivNetConfig 模型)
- vibevoice — VibeVoiceAcousticTokenizerFeatureExtractor(VibeVoiceConfig 模型)
- vibevoice_acoustic_tokenizer — VibeVoiceAcousticTokenizerFeatureExtractor(VibeVoiceAcousticTokenizerConfig 模型)
- vibevoice_asr — VibeVoiceAcousticTokenizerFeatureExtractor(VibeVoiceAsrConfig 模型)
- voxtral — WhisperFeatureExtractor(VoxtralConfig 模型)
- voxtral_realtime — VoxtralRealtimeFeatureExtractor(VoxtralRealtimeConfig 模型)
- wav2vec2 — Wav2Vec2FeatureExtractor(Wav2Vec2Config 模型)
- wav2vec2-bert — Wav2Vec2FeatureExtractor(Wav2Vec2BertConfig 模型)
- wav2vec2-conformer — Wav2Vec2FeatureExtractor(Wav2Vec2ConformerConfig 模型)
- wavlm — Wav2Vec2FeatureExtractor(WavLMConfig 模型)
- whisper — WhisperFeatureExtractor(WhisperConfig 模型)
- xcodec — DacFeatureExtractor(XcodecConfig 模型)
- xcodec2 — Xcodec2FeatureExtractor(Xcodec2Config 模型)
若要使用私有模型,必须传入
token=True。
示例:
>>> from transformers import AutoFeatureExtractor
>>> # Download feature extractor from huggingface.co and cache.
>>> feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/wav2vec2-base-960h")
>>> # If feature extractor files are in a directory (e.g. feature extractor was saved using *save_pretrained('./test/saved_model/')*)
>>> # feature_extractor = AutoFeatureExtractor.from_pretrained("./test/saved_model/")注册
< source >( config_classfeature_extractor_classexist_ok = False )
参数
- config_class (PreTrainedConfig) — 与要注册的模型对应的配置。
- feature_extractor_class (
FeatureExtractorMixin) — 要注册的特征提取器。
为此类注册一个新的特征提取器。
AutoImageProcessor
这是一个通用的图像处理器类,当通过 AutoImageProcessor.from_pretrained() 类方法创建时,它会被实例化为该库中的某个图像处理器类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_pretrained
< source >( pretrained_model_name_or_path*inputs**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,即托管在 huggingface.co 上某个模型仓库中的预训练 model id 的 image_processor。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 方法保存的图像处理器文件,例如
./my_model_directory/。 - 指向已保存的图像处理器 JSON 文件的路径,例如
./my_model_directory/preprocessor_config.json。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则下载的预训练模型图像处理器应缓存到的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载图像处理器文件,并在缓存版本已存在时覆盖它们。 - proxies (
dict[str, str], 可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}.每次请求都会使用这些代理。 - token(
str或 bool,可选)— 用于远程文件的 HTTP 承载者授权令牌。如果为True,则使用运行hf auth login时生成的令牌(存储在~/.huggingface中)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - use_fast (
bool,可选,默认为False) — 已弃用:请改用backend="torchvision"。此参数仅为保持向后兼容而保留。 如果给定模型支持,则使用基于 torchvision 的快速图像处理器。 如果给定模型没有可用的快速图像处理器,则返回常规的基于 numpy 的图像处理器。 - backend (
str, 可选, 默认为None) — 用于图像处理的后端。可以是:None:自动选择最佳可用后端(如果可用则使用 torchvision,否则使用 pil)"torchvision":使用 Torchvision 后端(GPU 加速,速度更快)"pil":使用 PIL 后端(可移植,仅支持 CPU)- 通过
register()方法注册的任何自定义后端名称
- return_unused_kwargs (
bool,可选,默认为False) — 如果为False,则此函数仅返回最终的图像处理器对象。如果为True,则此函数返回一个Tuple(image_processor, unused_kwargs),其中 unused_kwargs 是一个字典,包含那些键不是图像处理器属性的键值对:即kwargs中未用于更新image_processor且被忽略的部分。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - image_processor_filename (
str,可选,默认为"config.json") — 模型目录中用于图像处理器配置的文件名。 - kwargs (
dict[str, Any], optional) — The values in kwargs of any keys which are image processor attributes will be used to override the loaded values. Behavior concerning key/value pairs whose keys are not image processor attributes is controlled by thereturn_unused_kwargskeyword parameter.
从预训练模型词表中实例化该库的某个图像处理器类。
根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择要实例化的图像处理器类;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- aimv2 —
{'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(Aimv2Config 模型) - aimv2_vision_model —
{'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(Aimv2VisionConfig 模型) - align —
{'torchvision': 'EfficientNetImageProcessor', 'pil': 'EfficientNetImageProcessorPil'}(AlignConfig 模型) - altclip —
{'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(AltCLIPConfig 模型) - aria —
{'pil': 'AriaImageProcessorPil', 'torchvision': 'AriaImageProcessor'}(AriaConfig 模型) - aya_vision —
{'torchvision': 'GotOcr2ImageProcessor', 'pil': 'GotOcr2ImageProcessorPil'}(AyaVisionConfig 模型) - beit —
{'pil': 'BeitImageProcessorPil', 'torchvision': 'BeitImageProcessor'}(BeitConfig 模型) - bit —
{'pil': 'BitImageProcessorPil', 'torchvision': 'BitImageProcessor'}(BitConfig 模型) - blip —
{'pil': 'BlipImageProcessorPil', 'torchvision': 'BlipImageProcessor'}(BlipConfig 模型) - blip-2 —
{'torchvision': 'BlipImageProcessor', 'pil': 'BlipImageProcessorPil'}(Blip2Config 模型) - bridgetower —
{'pil': 'BridgeTowerImageProcessorPil', 'torchvision': 'BridgeTowerImageProcessor'}(BridgeTowerConfig 模型) - chameleon —
{'pil': 'ChameleonImageProcessorPil', 'torchvision': 'ChameleonImageProcessor'}(ChameleonConfig 模型) - chinese_clip —
{'pil': 'ChineseCLIPImageProcessorPil', 'torchvision': 'ChineseCLIPImageProcessor'}(ChineseCLIPConfig 模型) - chmv2 —
{'torchvision': 'CHMv2ImageProcessor'}(CHMv2Config 模型) - clip —
{'pil': 'CLIPImageProcessorPil', 'torchvision': 'CLIPImageProcessor'}(CLIPConfig 模型) - clipseg —
{'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(CLIPSegConfig 模型) - cohere2_vision —
{'torchvision': 'Cohere2VisionImageProcessor'}(Cohere2VisionConfig 模型) - cohere_compass —
{'pil': 'CohereCompassImageProcessorPil', 'torchvision': 'CohereCompassImageProcessor'}(CohereCompassConfig 模型) - colpali —
{'torchvision': 'SiglipImageProcessor', 'pil': 'SiglipImageProcessorPil'}(ColPaliConfig 模型) - colqwen2 —
{'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(ColQwen2Config 模型) - conditional_detr —
{'pil': 'ConditionalDetrImageProcessorPil', 'torchvision': 'ConditionalDetrImageProcessor'}(ConditionalDetrConfig 模型) - convnext —
{'pil': 'ConvNextImageProcessorPil', 'torchvision': 'ConvNextImageProcessor'}(ConvNextConfig 模型) - convnextv2 —
{'torchvision': 'ConvNextImageProcessor', 'pil': 'ConvNextImageProcessorPil'}(ConvNextV2Config 模型) - cosmos3_edge —
{'pil': 'Cosmos3EdgeImageProcessorPil', 'torchvision': 'Cosmos3EdgeImageProcessor'}(Cosmos3EdgeConfig 模型) - cosmos3_omni —
{'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Cosmos3OmniConfig 模型) - cvt —
{'torchvision': 'ConvNextImageProcessor', 'pil': 'ConvNextImageProcessorPil'}(CvtConfig 模型) - data2vec-vision —
{'torchvision': 'BeitImageProcessor', 'pil': 'BeitImageProcessorPil'}(Data2VecVisionConfig 模型) - deepseek_ocr2 —
{'pil': 'DeepseekOcr2ImageProcessorPil', 'torchvision': 'DeepseekOcr2ImageProcessor'}(DeepseekOcr2Config 模型) - deepseek_vl —
{'pil': 'DeepseekVLImageProcessorPil', 'torchvision': 'DeepseekVLImageProcessor'}(DeepseekVLConfig 模型) - deepseek_vl_hybrid —
{'pil': 'DeepseekVLHybridImageProcessorPil', 'torchvision': 'DeepseekVLHybridImageProcessor'}(DeepseekVLHybridConfig 模型) - deformable_detr —
{'pil': 'DeformableDetrImageProcessorPil', 'torchvision': 'DeformableDetrImageProcessor'}(DeformableDetrConfig 模型) - deimv2 —
{'torchvision': 'RTDetrImageProcessor', 'pil': 'RTDetrImageProcessorPil'}(Deimv2Config 模型) - deit —
{'pil': 'DeiTImageProcessorPil', 'torchvision': 'DeiTImageProcessor'}(DeiTConfig 模型) - depth_anything —
{'torchvision': 'DPTImageProcessor', 'pil': 'DPTImageProcessorPil'}(DepthAnythingConfig 模型) - depth_pro —
{'torchvision': 'DepthProImageProcessor'}(DepthProConfig 模型) - detr —
{'pil': 'DetrImageProcessorPil', 'torchvision': 'DetrImageProcessor'}(DetrConfig 模型) - dinat —
{'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(DinatConfig 模型) - dinov2 —
{'torchvision': 'BitImageProcessor', 'pil': 'BitImageProcessorPil'}(Dinov2Config 模型) - dinov3_vit —
{'torchvision': 'DINOv3ViTImageProcessor'}(DINOv3ViTConfig 模型) - donut-swin —
{'torchvision': 'DonutImageProcessor', 'pil': 'DonutImageProcessorPil'}(DonutSwinConfig 模型) - dpt —
{'pil': 'DPTImageProcessorPil', 'torchvision': 'DPTImageProcessor'}(DPTConfig 模型) - edgetam —
{'torchvision': 'Sam2ImageProcessor'}(EdgeTamConfig 模型) - efficientloftr —
{'pil': 'EfficientLoFTRImageProcessorPil', 'torchvision': 'EfficientLoFTRImageProcessor'}(EfficientLoFTRConfig 模型) - efficientnet —
{'pil': 'EfficientNetImageProcessorPil', 'torchvision': 'EfficientNetImageProcessor'}(EfficientNetConfig 模型) - embedding_gemma2 —
{'pil': 'Gemma4ImageProcessorPil', 'torchvision': 'Gemma4ImageProcessor'}(EmbeddingGemma2Config 模型) - emu3 —
{'pil': 'Emu3ImageProcessor'}(Emu3Config 模型) - eomt —
{'pil': 'EomtImageProcessorPil', 'torchvision': 'EomtImageProcessor'}(EomtConfig 模型) - eomt_dinov3 —
{'torchvision': 'EomtImageProcessor', 'pil': 'EomtImageProcessorPil'}(EomtDinov3Config 模型) - ernie4_5_vl_moe —
{'pil': 'Ernie4_5_VLMoeImageProcessorPil', 'torchvision': 'Ernie4_5_VLMoeImageProcessor'}(Ernie4_5_VLMoeConfig 模型) - exaone4_5 —
{'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Exaone4_5_Config 模型) - flava —
{'pil': 'FlavaImageProcessorPil', 'torchvision': 'FlavaImageProcessor'}(FlavaConfig 模型) - florence2 —
{'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(Florence2Config 模型) - focalnet —
{'torchvision': 'BitImageProcessor', 'pil': 'BitImageProcessorPil'}(FocalNetConfig 模型) - fuyu —
{'pil': 'FuyuImageProcessorPil', 'torchvision': 'FuyuImageProcessor'}(FuyuConfig 模型) - gemma3 —
{'pil': 'Gemma3ImageProcessorPil', 'torchvision': 'Gemma3ImageProcessor'}(Gemma3Config 模型) - gemma3n —
{'torchvision': 'SiglipImageProcessor', 'pil': 'SiglipImageProcessorPil'}(Gemma3nConfig 模型) - gemma4 —
{'pil': 'Gemma4ImageProcessorPil', 'torchvision': 'Gemma4ImageProcessor'}(Gemma4Config 模型) - gemma4_unified —
{'torchvision': 'Gemma4UnifiedImageProcessor'}(Gemma4UnifiedConfig 模型) - git —
{'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(GitConfig 模型) - glm46v —
{'pil': 'Glm46VImageProcessorPil', 'torchvision': 'Glm46VImageProcessor'}(Glm46VConfig 模型) - glm4v —
{'pil': 'Glm4vImageProcessorPil', 'torchvision': 'Glm4vImageProcessor'}(Glm4vConfig 模型) - glm5_next —
{'pil': 'Glm5NextImageProcessorPil', 'torchvision': 'Glm5NextImageProcessor'}(Glm5NextConfig 模型) - glm_image —
{'pil': 'GlmImageImageProcessorPil', 'torchvision': 'GlmImageImageProcessor'}(GlmImageConfig 模型) - glmga —
{'pil': 'GlmgaImageProcessorPil', 'torchvision': 'GlmgaImageProcessor'}(GlmgaConfig 模型) - glpn —
{'pil': 'GLPNImageProcessorPil', 'torchvision': 'GLPNImageProcessor'}(GLPNConfig 模型) - got_ocr2 —
{'pil': 'GotOcr2ImageProcessorPil', 'torchvision': 'GotOcr2ImageProcessor'}(GotOcr2Config 模型) - granite4_vision —
{'torchvision': 'LlavaNextImageProcessor', 'pil': 'LlavaNextImageProcessorPil'}(Granite4VisionConfig 模型) - grounding-dino —
{'pil': 'GroundingDinoImageProcessorPil', 'torchvision': 'GroundingDinoImageProcessor'}(GroundingDinoConfig 模型) - groupvit —
{'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(GroupViTConfig 模型) - hiera —
{'torchvision': 'BitImageProcessor', 'pil': 'BitImageProcessorPil'}(HieraConfig 模型) - hunyuan_vl —
{'pil': 'HunYuanVLImageProcessorPil', 'torchvision': 'HunYuanVLImageProcessor'}(HunYuanVLConfig 模型) - hyperclovax_vision_v2 —
{'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(HyperCLOVAXVisionV2Config 模型) - idefics —
{'pil': 'IdeficsImageProcessorPil', 'torchvision': 'IdeficsImageProcessor'}(IdeficsConfig 模型) - idefics2 —
{'pil': 'Idefics2ImageProcessorPil', 'torchvision': 'Idefics2ImageProcessor'}(Idefics2Config 模型) - idefics3 —
{'pil': 'Idefics3ImageProcessorPil', 'torchvision': 'Idefics3ImageProcessor'}(Idefics3Config 模型) - ijepa —
{'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(IJepaConfig 模型) - imagegpt —
{'pil': 'ImageGPTImageProcessorPil', 'torchvision': 'ImageGPTImageProcessor'}(ImageGPTConfig 模型) - inkling_mm_model —
{'torchvision': 'InklingImageProcessor'}(InklingConfig 模型) - instructblip —
{'torchvision': 'BlipImageProcessor', 'pil': 'BlipImageProcessorPil'}(InstructBlipConfig 模型) - internvl —
{'torchvision': 'GotOcr2ImageProcessor', 'pil': 'GotOcr2ImageProcessorPil'}(InternVLConfig 模型) - janus —
{'pil': 'JanusImageProcessorPil', 'torchvision': 'JanusImageProcessor'}(JanusConfig 模型) - kimi_k25 —
{'torchvision': 'Kimi_K25ImageProcessor'}(Kimi_K25Config 模型) - kosmos-2 —
{'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(Kosmos2Config 模型) - kosmos-2.5 —
{'torchvision': 'Kosmos2_5ImageProcessor', 'pil': 'Kosmos2_5ImageProcessorPil'}(Kosmos2_5Config 模型) - layoutlmv2 —
{'pil': 'LayoutLMv2ImageProcessorPil', 'torchvision': 'LayoutLMv2ImageProcessor'}(LayoutLMv2Config 模型) - layoutlmv3 —
{'pil': 'LayoutLMv3ImageProcessorPil', 'torchvision': 'LayoutLMv3ImageProcessor'}(LayoutLMv3Config 模型) - layoutxlm —
{'torchvision': 'LayoutLMv2ImageProcessor', 'pil': 'LayoutLMv2ImageProcessorPil'}(LayoutXLMConfig 模型) - levit —
{'pil': 'LevitImageProcessorPil', 'torchvision': 'LevitImageProcessor'}(LevitConfig 模型) - lfm2_vl —
{'torchvision': 'Lfm2VlImageProcessor'}(Lfm2VlConfig 模型) - lightglue —
{'pil': 'LightGlueImageProcessorPil', 'torchvision': 'LightGlueImageProcessor'}(LightGlueConfig 模型) - lighton_ocr —
{'torchvision': 'PixtralImageProcessor', 'pil': 'PixtralImageProcessorPil'}(LightOnOcrConfig 模型) - llama4 —
{'torchvision': 'Llama4ImageProcessor'}(Llama4Config 模型) - llava —
{'pil': 'LlavaImageProcessorPil', 'torchvision': 'LlavaImageProcessor'}(LlavaConfig 模型) - llava_next —
{'pil': 'LlavaNextImageProcessorPil', 'torchvision': 'LlavaNextImageProcessor'}(LlavaNextConfig 模型) - llava_next_video —
{'torchvision': 'LlavaNextImageProcessor', 'pil': 'LlavaNextImageProcessorPil'}(LlavaNextVideoConfig 模型) - llava_onevision —
{'pil': 'LlavaOnevisionImageProcessorPil', 'torchvision': 'LlavaOnevisionImageProcessor'}(LlavaOnevisionConfig 模型) - lw_detr —
{'torchvision': 'DeformableDetrImageProcessor', 'pil': 'DeformableDetrImageProcessorPil'}(LwDetrConfig 模型) - mask2former —
{'pil': 'Mask2FormerImageProcessorPil', 'torchvision': 'Mask2FormerImageProcessor'}(Mask2FormerConfig 模型) - maskformer —
{'pil': 'MaskFormerImageProcessorPil', 'torchvision': 'MaskFormerImageProcessor'}(MaskFormerConfig 模型) - metaclip_2 —
{'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(MetaClip2Config 模型) - mgp-str —
{'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(MgpstrConfig 模型) - minicpm_ocr —
{'torchvision': 'MiniCPMOcrImageProcessor'}(MiniCPMOcrConfig 模型) - minicpmv4_6 —
{'pil': 'MiniCPMV4_6ImageProcessorPil', 'torchvision': 'MiniCPMV4_6ImageProcessor'}(MiniCPMV4_6Config 模型) - minicpmv4_7 —
{'pil': 'MiniCPMV4_6ImageProcessorPil', 'torchvision': 'MiniCPMV4_6ImageProcessor'}(MiniCPMV4_7Config 模型) - minimax_m3_vl —
{'torchvision': 'MiniMaxM3VLImageProcessor'}(MiniMaxM3VLConfig 模型) - mistral3 —
{'torchvision': 'PixtralImageProcessor', 'pil': 'PixtralImageProcessorPil'}(Mistral3Config 模型) - mistral_large4 —
{'torchvision': 'PixtralImageProcessor', 'pil': 'PixtralImageProcessorPil'}(MistralLarge4Config 模型) - mlcd —
{'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(MLCDVisionConfig 模型) - mllama —
{'pil': 'MllamaImageProcessorPil', 'torchvision': 'MllamaImageProcessor'}(MllamaConfig 模型) - mm-grounding-dino —
{'torchvision': 'GroundingDinoImageProcessor', 'pil': 'GroundingDinoImageProcessorPil'}(MMGroundingDinoConfig 模型) - mobilenet_v1 —
{'pil': 'MobileNetV1ImageProcessorPil', 'torchvision': 'MobileNetV1ImageProcessor'}(MobileNetV1Config 模型) - mobilenet_v2 —
{'pil': 'MobileNetV2ImageProcessorPil', 'torchvision': 'MobileNetV2ImageProcessor'}(MobileNetV2Config 模型) - mobilevit —
{'pil': 'MobileViTImageProcessorPil', 'torchvision': 'MobileViTImageProcessor'}(MobileViTConfig 模型) - mobilevitv2 —
{'torchvision': 'MobileViTImageProcessor', 'pil': 'MobileViTImageProcessorPil'}(MobileViTV2Config 模型) - molmo2 —
{'torchvision': 'Molmo2ImageProcessor'}(Molmo2Config 模型) - muse_glimmer —
{'torchvision': 'MuseGlimmerImageProcessor'}(MuseGlimmerConfig 模型) - muse_spark —
{'torchvision': 'MuseGlimmerImageProcessor'}(MuseSparkConfig 模型) - nemotron_h_omni —
{'torchvision': 'NemotronH_Omni_Reasoning_V3ImageProcessor'}(NemotronH_Omni_Reasoning_V3_Config 模型) - neomme —
{'torchvision': 'NeoMMEImageProcessor'}(NeoMMEConfig 模型) - nougat —
{'pil': 'NougatImageProcessorPil', 'torchvision': 'NougatImageProcessor'}(NougatConfig 模型) - omdet-turbo —
{'torchvision': 'DetrImageProcessor', 'pil': 'DetrImageProcessorPil'}(OmDetTurboConfig 模型) - oneformer —
{'pil': 'OneFormerImageProcessorPil', 'torchvision': 'OneFormerImageProcessor'}(OneFormerConfig 模型) - ovis2 —
{'pil': 'Ovis2ImageProcessorPil', 'torchvision': 'Ovis2ImageProcessor'}(Ovis2Config 模型) - owlv2 —
{'pil': 'Owlv2ImageProcessorPil', 'torchvision': 'Owlv2ImageProcessor'}(Owlv2Config 模型) - owlvit —
{'pil': 'OwlViTImageProcessorPil', 'torchvision': 'OwlViTImageProcessor'}(OwlViTConfig 模型) - paddleocr_vl —
{'pil': 'PaddleOCRVLImageProcessorPil', 'torchvision': 'PaddleOCRVLImageProcessor'}(PaddleOCRVLConfig 模型) - paligemma —
{'torchvision': 'SiglipImageProcessor', 'pil': 'SiglipImageProcessorPil'}(PaliGemmaConfig 模型) - perceiver —
{'pil': 'PerceiverImageProcessorPil', 'torchvision': 'PerceiverImageProcessor'}(PerceiverConfig 模型) - perception_lm —
{'torchvision': 'PerceptionLMImageProcessor'}(PerceptionLMConfig 模型) - phi4_multimodal —
{'torchvision': 'Phi4MultimodalImageProcessor'}(Phi4MultimodalConfig 模型) - pi0 —
{'torchvision': 'PI0ImageProcessor'}(PI0Config 模型) - pix2struct —
{'pil': 'Pix2StructImageProcessorPil', 'torchvision': 'Pix2StructImageProcessor'}(Pix2StructConfig 模型) - pixio —
{'torchvision': 'BitImageProcessor', 'pil': 'BitImageProcessorPil'}(PixioConfig 模型) - pixtral —
{'pil': 'PixtralImageProcessorPil', 'torchvision': 'PixtralImageProcessor'}(PixtralVisionConfig 模型) - poolformer —
{'pil': 'PoolFormerImageProcessorPil', 'torchvision': 'PoolFormerImageProcessor'}(PoolFormerConfig 模型) - pp_chart2table —
{'pil': 'PPChart2TableImageProcessorPil', 'torchvision': 'PPChart2TableImageProcessor'}(PPChart2TableConfig 模型) - pp_doclayout_v2 —
{'torchvision': 'PPDocLayoutV2ImageProcessor'}(PPDocLayoutV2Config 模型) - pp_doclayout_v3 —
{'torchvision': 'PPDocLayoutV3ImageProcessor'}(PPDocLayoutV3Config 模型) - pp_doclayout_v4 —
{'torchvision': 'PPDocLayoutV4ImageProcessor'}(PPDocLayoutV4Config 模型) - pp_formulanet —
{'torchvision': 'PPFormulaNetImageProcessor'}(PPFormulaNetConfig 模型) - pp_lcnet —
{'torchvision': 'PPLCNetImageProcessor'}(PPLCNetConfig 模型) - pp_ocrv5_mobile_det —
{'torchvision': 'PPOCRV5ServerDetImageProcessor'}(PPOCRV5MobileDetConfig 模型) - pp_ocrv5_mobile_rec —
{'torchvision': 'PPOCRV5ServerRecImageProcessor'}(PPOCRV5MobileRecConfig 模型) - pp_ocrv5_server_det —
{'torchvision': 'PPOCRV5ServerDetImageProcessor'}(PPOCRV5ServerDetConfig 模型) - pp_ocrv5_server_rec —
{'torchvision': 'PPOCRV5ServerRecImageProcessor'}(PPOCRV5ServerRecConfig 模型) - pp_ocrv6_medium_det —
{'torchvision': 'PPOCRV5ServerDetImageProcessor'}(PPOCRV6MediumDetConfig 模型) - pp_ocrv6_small_det —
{'torchvision': 'PPOCRV5ServerDetImageProcessor'}(PPOCRV6SmallDetConfig 模型) - pp_ocrv6_small_rec —
{'torchvision': 'PPOCRV6SmallRecImageProcessor'}(PPOCRV6SmallRecConfig 模型) - pp_ocrv6_tiny_rec —
{'torchvision': 'PPOCRV6SmallRecImageProcessor'}(PPOCRV6TinyRecConfig 模型) - prompt_depth_anything —
{'pil': 'PromptDepthAnythingImageProcessorPil', 'torchvision': 'PromptDepthAnythingImageProcessor'}(PromptDepthAnythingConfig 模型) - pvt —
{'pil': 'PvtImageProcessorPil', 'torchvision': 'PvtImageProcessor'}(PvtConfig 模型) - pvt_v2 —
{'torchvision': 'PvtImageProcessor', 'pil': 'PvtImageProcessorPil'}(PvtV2Config 模型) - qianfan_ocr —
{'torchvision': 'GotOcr2ImageProcessor', 'pil': 'GotOcr2ImageProcessorPil'}(QianfanOCRConfig 模型) - qwen2_5_omni —
{'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Qwen2_5OmniConfig 模型) - qwen2_5_vl —
{'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Qwen2_5_VLConfig 模型) - qwen2_vl —
{'pil': 'Qwen2VLImageProcessorPil', 'torchvision': 'Qwen2VLImageProcessor'}(Qwen2VLConfig 模型) - qwen3_5 —
{'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Qwen3_5Config 模型) - qwen3_5_moe —
{'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Qwen3_5MoeConfig 模型) - qwen3_omni_moe —
{'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Qwen3OmniMoeConfig 模型) - qwen3_vl —
{'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Qwen3VLConfig 模型) - qwen4_exp —
{'torchvision': 'Qwen2VLImageProcessor', 'pil': 'Qwen2VLImageProcessorPil'}(Qwen4ExpConfig 模型) - regnet —
{'torchvision': 'ConvNextImageProcessor', 'pil': 'ConvNextImageProcessorPil'}(RegNetConfig 模型) - resnet —
{'torchvision': 'ConvNextImageProcessor', 'pil': 'ConvNextImageProcessorPil'}(ResNetConfig 模型) - rf_detr —
{'torchvision': 'RfDetrImageProcessor'}(RfDetrConfig 模型) - rt_detr —
{'pil': 'RTDetrImageProcessorPil', 'torchvision': 'RTDetrImageProcessor'}(RTDetrConfig 模型) - sam —
{'pil': 'SamImageProcessorPil', 'torchvision': 'SamImageProcessor'}(SamConfig 模型) - sam2 —
{'torchvision': 'Sam2ImageProcessor'}(Sam2Config 模型) - sam2_video —
{'torchvision': 'Sam2ImageProcessor'}(Sam2VideoConfig 模型) - sam3 —
{'torchvision': 'Sam3ImageProcessor'}(Sam3Config 模型) - sam3_lite_text —
{'torchvision': 'Sam3ImageProcessor'}(Sam3LiteTextConfig 模型) - sam3_tracker —
{'torchvision': 'Sam3ImageProcessor'}(Sam3TrackerConfig 模型) - sam3_tracker_video —
{'torchvision': 'Sam3ImageProcessor'}(Sam3TrackerVideoConfig 模型) - sam3_video —
{'torchvision': 'Sam3ImageProcessor'}(Sam3VideoConfig 模型) - sam_hq —
{'torchvision': 'SamImageProcessor', 'pil': 'SamImageProcessorPil'}(SamHQConfig 模型) - sapiens2 —
{'torchvision': 'Sapiens2ImageProcessor'}(Sapiens2Config 模型) - segformer —
{'pil': 'SegformerImageProcessorPil', 'torchvision': 'SegformerImageProcessor'}(SegformerConfig 模型) - seggpt —
{'pil': 'SegGptImageProcessorPil', 'torchvision': 'SegGptImageProcessor'}(SegGptConfig 模型) - shieldgemma2 —
{'torchvision': 'Gemma3ImageProcessor', 'pil': 'Gemma3ImageProcessorPil'}(ShieldGemma2Config 模型) - siglip —
{'pil': 'SiglipImageProcessorPil', 'torchvision': 'SiglipImageProcessor'}(SiglipConfig 模型) - siglip2 —
{'pil': 'Siglip2ImageProcessorPil', 'torchvision': 'Siglip2ImageProcessor'}(Siglip2Config 模型) - slanet —
{'torchvision': 'SLANeXtImageProcessor'}(SLANetConfig 模型) - slanext —
{'torchvision': 'SLANeXtImageProcessor'}(SLANeXtConfig 模型) - smolvlm —
{'pil': 'SmolVLMImageProcessorPil', 'torchvision': 'SmolVLMImageProcessor'}(SmolVLMConfig 模型) - step3p7 —
{'torchvision': 'Step3p7ImageProcessor'}(Step3p7Config 模型) - superglue —
{'pil': 'SuperGlueImageProcessorPil', 'torchvision': 'SuperGlueImageProcessor'}(SuperGlueConfig 模型) - superpoint —
{'pil': 'SuperPointImageProcessorPil', 'torchvision': 'SuperPointImageProcessor'}(SuperPointConfig 模型) - swiftformer —
{'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(SwiftFormerConfig 模型) - swin —
{'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(SwinConfig 模型) - swin2sr —
{'pil': 'Swin2SRImageProcessorPil', 'torchvision': 'Swin2SRImageProcessor'}(Swin2SRConfig 模型) - swinv2 —
{'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(Swinv2Config 模型) - t5gemma2 —
{'torchvision': 'Gemma3ImageProcessor', 'pil': 'Gemma3ImageProcessorPil'}(T5Gemma2Config 模型) - t5gemma2_encoder —
{'torchvision': 'Gemma3ImageProcessor', 'pil': 'Gemma3ImageProcessorPil'}(T5Gemma2EncoderConfig 模型) - table-transformer —
{'torchvision': 'DetrImageProcessor', 'pil': 'DetrImageProcessorPil'}(TableTransformerConfig 模型) - textnet —
{'pil': 'TextNetImageProcessorPil', 'torchvision': 'TextNetImageProcessor'}(TextNetConfig 模型) - timesformer —
{'pil': 'VideoMAEImageProcessorPil', 'torchvision': 'VideoMAEImageProcessor'}(TimesformerConfig 模型) - timm_wrapper —
{'pil': 'TimmWrapperImageProcessor'}(TimmWrapperConfig 模型) - tipsv2 —
{'torchvision': 'Tipsv2ImageProcessor'}(Tipsv2Config 模型) - tipsv2_dpt —
{'torchvision': 'Tipsv2DptImageProcessor'}(Tipsv2DptConfig 模型) - trocr —
{'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(TrOCRConfig 模型) - tvp —
{'pil': 'TvpImageProcessorPil', 'torchvision': 'TvpImageProcessor'}(TvpConfig 模型) - udop —
{'torchvision': 'LayoutLMv3ImageProcessor', 'pil': 'LayoutLMv3ImageProcessorPil'}(UdopConfig 模型) - ultravbert —
{'torchvision': 'UltraVBertImageProcessor'}(UltraVBertConfig 模型) - unlimited_ocr —
{'torchvision': 'UnlimitedOcrImageProcessor'}(UnlimitedOcrConfig 模型) - upernet —
{'torchvision': 'SegformerImageProcessor', 'pil': 'SegformerImageProcessorPil'}(UperNetConfig 模型) - uvdoc —
{'torchvision': 'UVDocImageProcessor'}(UVDocConfig 模型) - video_llama_3 —
{'pil': 'VideoLlama3ImageProcessorPil', 'torchvision': 'VideoLlama3ImageProcessor'}(VideoLlama3Config 模型) - video_llava —
{'pil': 'VideoLlavaImageProcessor'}(VideoLlavaConfig 模型) - videomae —
{'pil': 'VideoMAEImageProcessorPil', 'torchvision': 'VideoMAEImageProcessor'}(VideoMAEConfig 模型) - vilt —
{'pil': 'ViltImageProcessorPil', 'torchvision': 'ViltImageProcessor'}(ViltConfig 模型) - vipllava —
{'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(VipLlavaConfig 模型) - vit —
{'pil': 'ViTImageProcessorPil', 'torchvision': 'ViTImageProcessor'}(ViTConfig 模型) - vit_mae —
{'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(ViTMAEConfig 模型) - vit_msn —
{'torchvision': 'ViTImageProcessor', 'pil': 'ViTImageProcessorPil'}(ViTMSNConfig 模型) - vitmatte —
{'pil': 'VitMatteImageProcessorPil', 'torchvision': 'VitMatteImageProcessor'}(VitMatteConfig 模型) - vitpose —
{'pil': 'VitPoseImageProcessorPil', 'torchvision': 'VitPoseImageProcessor'}(VitPoseConfig 模型) - vivit —
{'torchvision': 'VivitImageProcessor'}(VivitConfig 模型) - xclip —
{'torchvision': 'CLIPImageProcessor', 'pil': 'CLIPImageProcessorPil'}(XCLIPConfig 模型) - yolos —
{'pil': 'YolosImageProcessorPil', 'torchvision': 'YolosImageProcessor'}(YolosConfig 模型) - zoedepth —
{'pil': 'ZoeDepthImageProcessorPil', 'torchvision': 'ZoeDepthImageProcessor'}(ZoeDepthConfig 模型)
若要使用私有模型,必须传入
token=True。
示例:
>>> from transformers import AutoImageProcessor
>>> # Download image processor from huggingface.co and cache.
>>> image_processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224-in21k")
>>> # If image processor files are in a directory (e.g. image processor was saved using *save_pretrained('./test/saved_model/')*)
>>> # image_processor = AutoImageProcessor.from_pretrained("./test/saved_model/")注册
< source >( config_classslow_image_processor_class: type | None = Nonefast_image_processor_class: type | None = Noneimage_processor_classes: dict[str, type] | None = Noneexist_ok: bool = False )
参数
- config_class (PreTrainedConfig) — 与要注册的模型对应的配置。
- slow_image_processor_class (
type,可选) — PIL 后端图像处理器类(已弃用,请使用image_processor_classes={"pil": ...})。 - fast_image_processor_class (
type,可选) — Torchvision 后端图像处理器类(已弃用,请使用image_processor_classes={"torchvision": ...})。 - image_processor_classes (
dict[str, type],可选) — 将后端名称映射到图像处理器类的字典。允许注册自定义后端。 示例:{"pil": MyPilProcessor, "torchvision": MyTorchvisionProcessor, "custom": MyCustomProcessor} - exist_ok (
bool,可选,默认为False) — 如果为True,则允许覆盖已存在的注册项。
为此类注册一个新的图像处理器。
AutoVideoProcessor
有关后端选择、自定义注册以及保存和重新加载,请参阅 视频处理器后端。
这是一个通用的视频处理器类,当通过 AutoVideoProcessor.from_pretrained() 类方法创建时,它将被实例化为该库中的某个视频处理器类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_pretrained
< source >( pretrained_model_name_or_path*inputs**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,即托管在 huggingface.co 上某个模型仓库中的预训练 model id 的 video_processor。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 方法保存的视频处理器文件,例如
./my_model_directory/。 - 指向已保存的视频处理器 JSON 文件的路径,例如
./my_model_directory/preprocessor_config.json。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则下载预训练模型视频处理器时应缓存到的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载视频处理器文件,并在缓存版本已存在时覆盖它们。 - proxies (
dict[str, str], 可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}.每次请求都会使用这些代理。 - token(
str或 bool,可选)— 用于远程文件的 HTTP 承载者授权令牌。如果为True,则使用运行hf auth login时生成的令牌(存储在~/.huggingface中)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - return_unused_kwargs (
bool,可选,默认为False) — 如果False,则此函数仅返回最终的 video processor 对象。如果True,则此函数返回一个Tuple(video_processor, unused_kwargs),其中 unused_kwargs 是一个字典,包含那些键不是 video processor 属性的键值对:即kwargs中未用于更新video_processor且被忽略的部分。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - kwargs (
dict[str, Any], optional) — The values in kwargs of any keys which are video processor attributes will be used to override the loaded values. Behavior concerning key/value pairs whose keys are not video processor attributes is controlled by thereturn_unused_kwargskeyword parameter.
从预训练模型词表中实例化该库的某个视频处理器类。
要实例化的视频处理器类是根据配置对象的 model_type 属性来选择的(该属性可以作为参数传入,或者在可能的情况下从 pretrained_model_name_or_path 加载),如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- cohere_compass —
{'torchvision': 'CohereCompassVideoProcessor'}(CohereCompassConfig 模型) - cosmos3_edge —
{'torchvision': 'Cosmos3EdgeVideoProcessor'}(Cosmos3EdgeConfig 模型) - cosmos3_omni —
{'torchvision': 'Qwen3VLVideoProcessor'}(Cosmos3OmniConfig 模型) - embedding_gemma2 —
{'torchvision': 'EmbeddingGemma2VideoProcessor'}(EmbeddingGemma2Config 模型) - ernie4_5_vl_moe —
{'torchvision': 'Ernie4_5_VLMoeVideoProcessor'}(Ernie4_5_VLMoeConfig 模型) - exaone4_5 —
{'torchvision': 'Qwen2VLVideoProcessor'}(Exaone4_5_Config 模型) - gemma4 —
{'torchvision': 'Gemma4VideoProcessor'}(Gemma4Config 模型) - gemma4_unified —
{'torchvision': 'Gemma4UnifiedVideoProcessor'}(Gemma4UnifiedConfig 模型) - glm46v —
{'torchvision': 'Glm46VVideoProcessor'}(Glm46VConfig 模型) - glm4v —
{'torchvision': 'Glm4vVideoProcessor'}(Glm4vConfig 模型) - glm5_next —
{'torchvision': 'Glm5NextVideoProcessor'}(Glm5NextConfig 模型) - glmga —
{'torchvision': 'GlmgaVideoProcessor'}(GlmgaConfig 模型) - hyperclovax_vision_v2 —
{'torchvision': 'Qwen2VLVideoProcessor'}(HyperCLOVAXVisionV2Config 模型) - instructblip —
{'torchvision': 'InstructBlipVideoVideoProcessor'}(InstructBlipConfig 模型) - instructblipvideo —
{'torchvision': 'InstructBlipVideoVideoProcessor'}(InstructBlipVideoConfig 模型) - internvl —
{'torchvision': 'InternVLVideoProcessor'}(InternVLConfig 模型) - kimi_k25 —
{'torchvision': 'Kimi_K25VideoProcessor'}(Kimi_K25Config 模型) - llava_next_video —
{'torchvision': 'LlavaNextVideoVideoProcessor'}(LlavaNextVideoConfig 模型) - llava_onevision —
{'torchvision': 'LlavaOnevisionVideoProcessor'}(LlavaOnevisionConfig 模型) - minicpm_ocr —
{'torchvision': 'MiniCPMOcrVideoProcessor'}(MiniCPMOcrConfig 模型) - minicpmv4_6 —
{'torchvision': 'MiniCPMV4_6VideoProcessor'}(MiniCPMV4_6Config 模型) - minicpmv4_7 —
{'torchvision': 'MiniCPMV4_6VideoProcessor'}(MiniCPMV4_7Config 模型) - minimax_m3_vl —
{'torchvision': 'MiniMaxM3VLVideoProcessor'}(MiniMaxM3VLConfig 模型) - molmo2 —
{'torchvision': 'Molmo2VideoProcessor'}(Molmo2Config 模型) - muse_glimmer —
{'torchvision': 'MuseGlimmerVideoProcessor'}(MuseGlimmerConfig 模型) - muse_spark —
{'torchvision': 'MuseGlimmerVideoProcessor'}(MuseSparkConfig 模型) - nemotron_h_omni —
{'torchvision': 'NemotronH_Omni_Reasoning_V3VideoProcessor'}(NemotronH_Omni_Reasoning_V3_Config 模型) - pe_audio_video —
{'torchvision': 'PeVideoVideoProcessor'}(PeAudioVideoConfig 模型) - pe_video —
{'torchvision': 'PeVideoVideoProcessor'}(PeVideoConfig 模型) - perception_lm —
{'torchvision': 'PerceptionLMVideoProcessor'}(PerceptionLMConfig 模型) - qwen2_5_omni —
{'torchvision': 'Qwen2VLVideoProcessor'}(Qwen2_5OmniConfig 模型) - qwen2_5_vl —
{'torchvision': 'Qwen2VLVideoProcessor'}(Qwen2_5_VLConfig 模型) - qwen2_vl —
{'torchvision': 'Qwen2VLVideoProcessor'}(Qwen2VLConfig 模型) - qwen3_5 —
{'torchvision': 'Qwen3VLVideoProcessor'}(Qwen3_5Config 模型) - qwen3_5_moe —
{'torchvision': 'Qwen3VLVideoProcessor'}(Qwen3_5MoeConfig 模型) - qwen3_omni_moe —
{'torchvision': 'Qwen2VLVideoProcessor'}(Qwen3OmniMoeConfig 模型) - qwen3_vl —
{'torchvision': 'Qwen3VLVideoProcessor'}(Qwen3VLConfig 模型) - qwen3_vl_moe —
{'torchvision': 'Qwen3VLVideoProcessor'}(Qwen3VLMoeConfig 模型) - qwen4_exp —
{'torchvision': 'Qwen3VLVideoProcessor'}(Qwen4ExpConfig 模型) - sam2_video —
{'torchvision': 'Sam2VideoVideoProcessor'}(Sam2VideoConfig 模型) - smolvlm —
{'torchvision': 'SmolVLMVideoProcessor'}(SmolVLMConfig 模型) - timesformer —
{'torchvision': 'TimesformerVideoProcessor'}(TimesformerConfig 模型) - video_llama_3 —
{'torchvision': 'VideoLlama3VideoProcessor'}(VideoLlama3Config 模型) - video_llava —
{'torchvision': 'VideoLlavaVideoProcessor'}(VideoLlavaConfig 模型) - videomae —
{'torchvision': 'VideoMAEVideoProcessor'}(VideoMAEConfig 模型) - videomt —
{'torchvision': 'VideomtVideoProcessor'}(VideomtConfig 模型) - videoprism —
{'torchvision': 'LlavaOnevisionVideoProcessor'}(VideoPrismConfig 模型) - vivit —
{'torchvision': 'VivitVideoProcessor'}(VivitConfig 模型) - vjepa2 —
{'torchvision': 'VJEPA2VideoProcessor'}(VJEPA2Config 模型)
若要使用私有模型,必须传入
token=True。
示例:
>>> from transformers import AutoVideoProcessor
>>> # Download video processor from huggingface.co and cache.
>>> video_processor = AutoVideoProcessor.from_pretrained("llava-hf/llava-onevision-qwen2-0.5b-ov-hf")
>>> # If video processor files are in a directory (e.g. video processor was saved using *save_pretrained('./test/saved_model/')*)
>>> # video_processor = AutoVideoProcessor.from_pretrained("./test/saved_model/")注册
< source >( config_classvideo_processor_class: type | None = Nonevideo_processor_classes: dict[str, type] | None = Noneexist_ok: bool = False )
参数
- config_class (PreTrainedConfig) — 与要注册的模型对应的配置。
- video_processor_class (BaseVideoProcessor) — 要注册的视觉处理器。
- video_processor_classes (
dict[str, type], 可选) — 将后端名称映射到视频处理器类的字典。允许注册自定义后端。 示例:{"pil": MyPilVideoProcessor, "torchvision": MyTorchvisionVideoProcessor, "custom": MyCustomVideoProcessor} - exist_ok (
bool,可选,默认为False) — 如果为True,则允许覆盖已存在的注册项。
为此类注册一个新的视频处理器。
AutoProcessor
这是一个通用的处理器类,当通过 AutoProcessor.from_pretrained() 类方法创建时,它会被实例化为该库中的某个处理器类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_pretrained
< source >( pretrained_model_name_or_path**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,即托管在 huggingface.co 上某个模型仓库中的预训练 feature_extractor 的 model id。
- 指向一个目录的路径,该目录包含使用
save_pretrained()方法保存的处理器文件,例如./my_model_directory/。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则下载预训练模型特征提取器时应缓存到的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载特征提取器文件,并在缓存版本存在时覆盖它们。 - proxies (
dict[str, str], 可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}.每次请求都会使用这些代理。 - token(
str或 bool,可选)— 用于远程文件的 HTTP 承载者授权令牌。如果为True,则使用运行hf auth login时生成的令牌(存储在~/.huggingface中)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - return_unused_kwargs (
bool,可选,默认为False) — 如果为False,则此函数仅返回最终的 feature extractor 对象。如果为True,则此函数返回一个Tuple(feature_extractor, unused_kwargs),其中 unused_kwargs 是一个字典,包含那些键不是 feature extractor 属性的键值对:即kwargs中未用于更新feature_extractor且被忽略的部分。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - kwargs (
dict[str, Any], 可选) — kwargs 中任何作为特征提取器属性的键的值,将用于覆盖已加载的值。对于键不是特征提取器属性的键值对,其行为由return_unused_kwargs关键字参数控制。
从预训练模型词表中实例化该库的某个处理器类。
要实例化的处理器类是根据配置对象的 model_type 属性来选择的(该属性可以通过参数传入,或者在可能的情况下从 pretrained_model_name_or_path 加载):
- aimv2 — CLIPProcessor(Aimv2Config 模型)
- align — AlignProcessor(AlignConfig 模型)
- altclip — AltCLIPProcessor(AltCLIPConfig 模型)
- aria — AriaProcessor(AriaConfig 模型)
- audioflamingo3 — AudioFlamingo3Processor(AudioFlamingo3Config 模型)
- aya_vision — AyaVisionProcessor(AyaVisionConfig 模型)
- bark — BarkProcessor(BarkConfig 模型)
- blip — BlipProcessor(BlipConfig 模型)
- blip-2 — Blip2Processor(Blip2Config 模型)
- bridgetower — BridgeTowerProcessor(BridgeTowerConfig 模型)
- bros — BrosProcessor(BrosConfig 模型)
- canary — CanaryProcessor(CanaryConfig 模型)
- chameleon — ChameleonProcessor(ChameleonConfig 模型)
- chinese_clip — ChineseCLIPProcessor(ChineseCLIPConfig 模型)
- clap — ClapProcessor(ClapConfig 模型)
- clip — CLIPProcessor(CLIPConfig 模型)
- clipseg — CLIPSegProcessor(CLIPSegConfig 模型)
- clvp — ClvpProcessor(ClvpConfig 模型)
- cohere2_vision — Cohere2VisionProcessor(Cohere2VisionConfig 模型)
- cohere_asr — CohereAsrProcessor(CohereAsrConfig 模型)
- cohere_compass — CohereCompassProcessor(CohereCompassConfig 模型)
- colmodernvbert — ColModernVBertProcessor(ColModernVBertConfig 模型)
- colpali — ColPaliProcessor(ColPaliConfig 模型)
- colqwen2 — ColQwen2Processor(ColQwen2Config 模型)
- cosmos3_edge — Cosmos3EdgeProcessor(Cosmos3EdgeConfig 模型)
- csm — CsmProcessor(CsmConfig 模型)
- deepseek_ocr2 — DeepseekOcr2Processor(DeepseekOcr2Config 模型)
- deepseek_vl — DeepseekVLProcessor(DeepseekVLConfig 模型)
- deepseek_vl_hybrid — DeepseekVLHybridProcessor(DeepseekVLHybridConfig 模型)
- dia — DiaProcessor(DiaConfig 模型)
- diffusion_gemma — Gemma4Processor(DiffusionGemmaConfig 模型)
- edgetam — Sam2Processor(EdgeTamConfig 模型)
- embedding_gemma2 — EmbeddingGemma2Processor(EmbeddingGemma2Config 模型)
- emu3 — Emu3Processor(Emu3Config 模型)
- ernie4_5_vl_moe — Ernie4_5_VLMoeProcessor(Ernie4_5_VLMoeConfig 模型)
- evolla — EvollaProcessor(EvollaConfig 模型)
- exaone4_5 — Exaone4_5_Processor(Exaone4_5_Config 模型)
- flava — FlavaProcessor(FlavaConfig 模型)
- florence2 — Florence2Processor(Florence2Config 模型)
- fun_asr_nano — FunAsrNanoProcessor(FunAsrNanoConfig 模型)
- fuyu — FuyuProcessor(FuyuConfig 模型)
- gemma3 — Gemma3Processor(Gemma3Config 模型)
- gemma3n — Gemma3nProcessor(Gemma3nConfig 模型)
- gemma4 — Gemma4Processor(Gemma4Config 模型)
- gemma4_unified — Gemma4UnifiedProcessor(Gemma4UnifiedConfig 模型)
- git — GitProcessor(GitConfig 模型)
- glm46v — Glm46VProcessor(Glm46VConfig 模型)
- glm4v — Glm4vProcessor(Glm4vConfig 模型)
- glm4v_moe — Glm4vProcessor(Glm4vMoeConfig 模型)
- glm5_next — Glm5NextProcessor(Glm5NextConfig 模型)
- glm_image — GlmImageProcessor(GlmImageConfig 模型)
- glmasr — GlmAsrProcessor(GlmAsrConfig 模型)
- got_ocr2 — GotOcr2Processor(GotOcr2Config 模型)
- gradium_phonon_tts — PocketTTSProcessor(GradiumPhononTTSConfig 模型)
- granite4_vision — Granite4VisionProcessor(Granite4VisionConfig 模型)
- granite_speech — GraniteSpeechProcessor(GraniteSpeechConfig 模型)
- granite_speech5_ctc — GraniteSpeech5Processor(GraniteSpeech5CTCConfig 模型)
- granite_speech_plus — GraniteSpeechProcessor(GraniteSpeechPlusConfig 模型)
- grounding-dino — GroundingDinoProcessor(GroundingDinoConfig 模型)
- groupvit — CLIPProcessor(GroupViTConfig 模型)
- higgs_audio_v2 — HiggsAudioV2Processor(HiggsAudioV2Config 模型)
- hubert — Wav2Vec2Processor(HubertConfig 模型)
- hunyuan_vl — HunYuanVLProcessor(HunYuanVLConfig 模型)
- hyperclovax_vision_v2 — HyperCLOVAXVisionV2Processor(HyperCLOVAXVisionV2Config 模型)
- idefics — IdeficsProcessor(IdeficsConfig 模型)
- idefics2 — Idefics2Processor(Idefics2Config 模型)
- idefics3 — Idefics3Processor(Idefics3Config 模型)
- inkling_mm_model — InklingProcessor(InklingConfig 模型)
- instructblip — InstructBlipProcessor(InstructBlipConfig 模型)
- instructblipvideo — InstructBlipVideoProcessor(InstructBlipVideoConfig 模型)
- internvl — InternVLProcessor(InternVLConfig 模型)
- janus — JanusProcessor(JanusConfig 模型)
- kimi_k25 — Kimi_K25Processor(Kimi_K25Config 模型)
- kyutai_speech_to_text — KyutaiSpeechToTextProcessor(KyutaiSpeechToTextConfig 模型)
- lasr_ctc — LasrProcessor(LasrCTCConfig 模型)
- lasr_encoder — LasrProcessor(LasrEncoderConfig 模型)
- layoutlmv2 — LayoutLMv2Processor(LayoutLMv2Config 模型)
- layoutlmv3 — LayoutLMv3Processor(LayoutLMv3Config 模型)
- layoutxlm — LayoutXLMProcessor(LayoutXLMConfig 模型)
- lfm2_vl — Lfm2VlProcessor(Lfm2VlConfig 模型)
- lighton_ocr — LightOnOcrProcessor(LightOnOcrConfig 模型)
- llama4 — Llama4Processor(Llama4Config 模型)
- llava — LlavaProcessor(LlavaConfig 模型)
- llava_next — LlavaNextProcessor(LlavaNextConfig 模型)
- llava_next_video — LlavaNextVideoProcessor(LlavaNextVideoConfig 模型)
- llava_onevision — LlavaOnevisionProcessor(LlavaOnevisionConfig 模型)
- markuplm — MarkupLMProcessor(MarkupLMConfig 模型)
- metaclip_2 — CLIPProcessor(MetaClip2Config 模型)
- mgp-str — MgpstrProcessor(MgpstrConfig 模型)
- minicpm_ocr — MiniCPMOcrProcessor(MiniCPMOcrConfig 模型)
- minicpmv4_6 — MiniCPMV4_6Processor(MiniCPMV4_6Config 模型)
- minicpmv4_7 — MiniCPMV4_7Processor(MiniCPMV4_7Config 模型)
- minimax_m3_vl — MiniMaxM3VLProcessor(MiniMaxM3VLConfig 模型)
- mistral3 — PixtralProcessor(Mistral3Config 模型)
- mistral_large4 — PixtralProcessor(MistralLarge4Config 模型)
- mllama — MllamaProcessor(MllamaConfig 模型)
- mm-grounding-dino — GroundingDinoProcessor(MMGroundingDinoConfig 模型)
- modernvbert — Idefics3Processor(ModernVBertConfig 模型)
- molmo2 — Molmo2Processor(Molmo2Config 模型)
- moonshine — Wav2Vec2Processor(MoonshineConfig 模型)
- moonshine_streaming — MoonshineStreamingProcessor(MoonshineStreamingConfig 模型)
- moss_transcribe_diarize — MossTranscribeDiarizeProcessor(MossTranscribeDiarizeConfig 模型)
- muse_glimmer — MuseGlimmerProcessor(MuseGlimmerConfig 模型)
- muse_spark — MuseSparkProcessor(MuseSparkConfig 模型)
- musicflamingo — MusicFlamingoProcessor(MusicFlamingoConfig 模型)
- musicgen — MusicgenProcessor(MusicgenConfig 模型)
- musicgen_melody — MusicgenMelodyProcessor(MusicgenMelodyConfig 模型)
- nemo_speechlm — Nemotron3_5TranscribeProcessor(Nemotron3_5TranscribeConfig 模型)
- nemotron3_5_asr — Nemotron3_5AsrProcessor(Nemotron3_5AsrConfig 模型)
- nemotron3_diarization — Nemotron3DiarizationProcessor(Nemotron3DiarizationConfig 模型)
- nemotron_asr_streaming — NemotronAsrStreamingProcessor(NemotronAsrStreamingConfig 模型)
- nemotron_h_omni — NemotronH_Omni_Reasoning_V3Processor(NemotronH_Omni_Reasoning_V3_Config 模型)
- neomme — NeoMMEProcessor(NeoMMEConfig 模型)
- nougat — NougatProcessor(NougatConfig 模型)
- omdet-turbo — OmDetTurboProcessor(OmDetTurboConfig 模型)
- oneformer — OneFormerProcessor(OneFormerConfig 模型)
- ovis2 — Ovis2Processor(Ovis2Config 模型)
- owlv2 — Owlv2Processor(Owlv2Config 模型)
- owlvit — OwlViTProcessor(OwlViTConfig 模型)
- paddleocr_vl — PaddleOCRVLProcessor(PaddleOCRVLConfig 模型)
- paligemma — PaliGemmaProcessor(PaliGemmaConfig 模型)
- parakeet_ctc — ParakeetProcessor(ParakeetCTCConfig 模型)
- parakeet_rnnt — ParakeetProcessor(ParakeetRNNTConfig 模型)
- parakeet_tdt — ParakeetProcessor(ParakeetTDTConfig 模型)
- pe_audio — PeAudioProcessor(PeAudioConfig 模型)
- pe_audio_video — PeAudioVideoProcessor(PeAudioVideoConfig 模型)
- pe_video — PeVideoProcessor(PeVideoConfig 模型)
- perception_lm — PerceptionLMProcessor(PerceptionLMConfig 模型)
- phi4_multimodal — Phi4MultimodalProcessor(Phi4MultimodalConfig 模型)
- pi0 — PI0Processor(PI0Config 模型)
- pix2struct — Pix2StructProcessor(Pix2StructConfig 模型)
- pixtral — PixtralProcessor(PixtralVisionConfig 模型)
- pocket_tts — PocketTTSProcessor(PocketTTSConfig 模型)
- pop2piano — Pop2PianoProcessor(Pop2PianoConfig 模型)
- pp_chart2table — PPChart2TableProcessor(PPChart2TableConfig 模型)
- pp_formulanet — PPFormulaNetProcessor(PPFormulaNetConfig 模型)
- qianfan_ocr — QianfanOCRProcessor(QianfanOCRConfig 模型)
- qwen2_5_omni — Qwen2_5OmniProcessor(Qwen2_5OmniConfig 模型)
- qwen2_5_vl — Qwen2_5_VLProcessor(Qwen2_5_VLConfig 模型)
- qwen2_audio — Qwen2AudioProcessor(Qwen2AudioConfig 模型)
- qwen2_vl — Qwen2VLProcessor(Qwen2VLConfig 模型)
- qwen3_5 — Qwen3VLProcessor(Qwen3_5Config 模型)
- qwen3_5_moe — Qwen3VLProcessor(Qwen3_5MoeConfig 模型)
- qwen3_asr — Qwen3ASRProcessor(Qwen3ASRConfig 模型)
- qwen3_omni_moe — Qwen3OmniMoeProcessor(Qwen3OmniMoeConfig 模型)
- qwen3_vl — Qwen3VLProcessor(Qwen3VLConfig 模型)
- qwen3_vl_moe — Qwen3VLProcessor(Qwen3VLMoeConfig 模型)
- qwen4_exp — Qwen3VLProcessor(Qwen4ExpConfig 模型)
- sam — SamProcessor(SamConfig 模型)
- sam2 — Sam2Processor(Sam2Config 模型)
- sam2_video — Sam2VideoProcessor(Sam2VideoConfig 模型)
- sam3 — Sam3Processor(Sam3Config 模型)
- sam3_lite_text — Sam3Processor(Sam3LiteTextConfig 模型)
- sam3_tracker — Sam3TrackerProcessor(Sam3TrackerConfig 模型)
- sam3_tracker_video — Sam3TrackerVideoProcessor(Sam3TrackerVideoConfig 模型)
- sam3_video — Sam3VideoProcessor(Sam3VideoConfig 模型)
- sam_hq — SamHQProcessor(SamHQConfig 模型)
- seamless_m4t — SeamlessM4TProcessor(SeamlessM4TConfig 模型)
- sew — Wav2Vec2Processor(SEWConfig 模型)
- sew-d — Wav2Vec2Processor(SEWDConfig 模型)
- siglip — SiglipProcessor(SiglipConfig 模型)
- siglip2 — Siglip2Processor(Siglip2Config 模型)
- smolvlm — SmolVLMProcessor(SmolVLMConfig 模型)
- speech_to_text — Speech2TextProcessor(Speech2TextConfig 模型)
- speecht5 — SpeechT5Processor(SpeechT5Config 模型)
- step3p7 — Step3p7Processor(Step3p7Config 模型)
- t5gemma2 — Gemma3Processor(T5Gemma2Config 模型)
- t5gemma2_encoder — Gemma3Processor(T5Gemma2EncoderConfig 模型)
- tipsv2 — Tipsv2Processor(Tipsv2Config 模型)
- trocr — TrOCRProcessor(TrOCRConfig 模型)
- tvp — TvpProcessor(TvpConfig 模型)
- udop — UdopProcessor(UdopConfig 模型)
- ultravbert — Idefics3Processor(UltraVBertConfig 模型)
- unispeech — Wav2Vec2Processor(UniSpeechConfig 模型)
- unispeech-sat — Wav2Vec2Processor(UniSpeechSatConfig 模型)
- unlimited_ocr — UnlimitedOcrProcessor(UnlimitedOcrConfig 模型)
- vibevoice — VibeVoiceProcessor(VibeVoiceConfig 模型)
- vibevoice_asr — VibeVoiceAsrProcessor(VibeVoiceAsrConfig 模型)
- video_llama_3 — VideoLlama3Processor(VideoLlama3Config 模型)
- video_llava — VideoLlavaProcessor(VideoLlavaConfig 模型)
- videoprism — VideoPrismProcessor(VideoPrismConfig 模型)
- vilt — ViltProcessor(ViltConfig 模型)
- vipllava — LlavaProcessor(VipLlavaConfig 模型)
- vision-text-dual-encoder — VisionTextDualEncoderProcessor(VisionTextDualEncoderConfig 模型)
- voxtral — VoxtralProcessor(VoxtralConfig 模型)
- voxtral_realtime — VoxtralRealtimeProcessor(VoxtralRealtimeConfig 模型)
- wav2vec2 — Wav2Vec2Processor(Wav2Vec2Config 模型)
- wav2vec2-bert — Wav2Vec2BertProcessor(Wav2Vec2BertConfig 模型)
- wav2vec2-conformer — Wav2Vec2Processor(Wav2Vec2ConformerConfig 模型)
- wavlm — Wav2Vec2Processor(WavLMConfig 模型)
- whisper — WhisperProcessor(WhisperConfig 模型)
若要使用私有模型,必须传入
token=True。
示例:
>>> from transformers import AutoProcessor
>>> # Download processor from huggingface.co and cache.
>>> processor = AutoProcessor.from_pretrained("facebook/wav2vec2-base-960h")
>>> # If processor files are in a directory (e.g. processor was saved using *save_pretrained('./test/saved_model/')*)
>>> # processor = AutoProcessor.from_pretrained("./test/saved_model/")注册
< source >( config_classprocessor_classexist_ok = False )
参数
- config_class (PreTrainedConfig) — 与要注册的模型对应的配置。
- processor_class (ProcessorMixin) — 要注册的处理器。
为此类注册一个新的处理器。
通用模型类
以下自动类可用于实例化不带特定头部的基模型类。
AutoModel
这是一个通用模型类,在通过 from_pretrained() 类方法或 from_config() 类方法创建时,会被实例化为该库的某个基础模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- ASTConfig 配置类:ASTModel(ASTConfig 模型)
- AXK1Config 配置类:AXK1Model(AXK1Config 模型)
- AXK2Config 配置类:AXK2Model(AXK2Config 模型)
- AfmoeConfig 配置类:AfmoeModel(AfmoeConfig 模型)
- Aimv2Config 配置类:Aimv2Model(Aimv2Config 模型)
- Aimv2VisionConfig 配置类:Aimv2VisionModel(Aimv2VisionConfig 模型)
- AlbertConfig 配置类:AlbertModel(AlbertConfig 模型)
- AlignConfig 配置类:AlignModel(AlignConfig 模型)
- AltCLIPConfig 配置类:AltCLIPModel(AltCLIPConfig 模型)
- ApertusConfig 配置类:ApertusModel(ApertusConfig 模型)
- ArceeConfig 配置类:ArceeModel(ArceeConfig 模型)
- AriaConfig 配置类:AriaModel(AriaConfig 模型)
- AriaTextConfig 配置类:AriaTextModel(AriaTextConfig 模型)
- AudioFlamingo3Config 配置类:AudioFlamingo3Model(AudioFlamingo3Config 模型)
- AudioFlamingo3EncoderConfig 配置类:AudioFlamingo3Encoder(AudioFlamingo3EncoderConfig 模型)
- AutoformerConfig 配置类:AutoformerModel(AutoformerConfig 模型)
- AyaVisionConfig 配置类:AyaVisionModel(AyaVisionConfig 模型)
- BailingHybridConfig 配置类:BailingHybridModel(BailingHybridConfig 模型)
- BambaConfig 配置类:BambaModel(BambaConfig 模型)
- BarkConfig 配置类:BarkModel(BarkConfig 模型)
- BartConfig 配置类:BartModel(BartConfig 模型)
- BeamConfig 配置类:BeamModel(BeamConfig 模型)
- BeitConfig 配置类:BeitModel(BeitConfig 模型)
- BertConfig 配置类:BertModel(BertConfig 模型)
- BertGenerationConfig 配置类:BertGenerationEncoder(BertGenerationConfig 模型)
- BigBirdConfig 配置类:BigBirdModel(BigBirdConfig 模型)
- BigBirdPegasusConfig 配置类:BigBirdPegasusModel(BigBirdPegasusConfig 模型)
- BioGptConfig 配置类:BioGptModel(BioGptConfig 模型)
- BitConfig 配置类:BitModel(BitConfig 模型)
- BitNetConfig 配置类:BitNetModel(BitNetConfig 模型)
- BlenderbotConfig 配置类:BlenderbotModel(BlenderbotConfig 模型)
- BlenderbotSmallConfig 配置类:BlenderbotSmallModel(BlenderbotSmallConfig 模型)
- Blip2Config 配置类:Blip2Model(Blip2Config 模型)
- Blip2QFormerConfig 配置类:Blip2QFormerModel(Blip2QFormerConfig 模型)
- BlipConfig 配置类:BlipModel(BlipConfig 模型)
- BloomConfig 配置类:BloomModel(BloomConfig 模型)
- BltConfig 配置类:BltModel(BltConfig 模型)
- BridgeTowerConfig 配置类:BridgeTowerModel(BridgeTowerConfig 模型)
- BrosConfig 配置类:BrosModel(BrosConfig 模型)
- CLIPConfig 配置类:CLIPModel(CLIPConfig 模型)
- CLIPSegConfig 配置类:CLIPSegModel(CLIPSegConfig 模型)
- CLIPTextConfig 配置类:CLIPTextModel(CLIPTextConfig 模型)
- CLIPVisionConfig 配置类:CLIPVisionModel(CLIPVisionConfig 模型)
- CTRLConfig 配置类:CTRLModel(CTRLConfig 模型)
- CamembertConfig 配置类:CamembertModel(CamembertConfig 模型)
- CanaryConfig 配置类:CanaryModel(CanaryConfig 模型)
- CanineConfig 配置类:CanineModel(CanineConfig 模型)
- ChameleonConfig 配置类:ChameleonModel(ChameleonConfig 模型)
- ChineseCLIPConfig 配置类:ChineseCLIPModel(ChineseCLIPConfig 模型)
- ChineseCLIPVisionConfig 配置类:ChineseCLIPVisionModel(ChineseCLIPVisionConfig 模型)
- ClapConfig 配置类:ClapModel(ClapConfig 模型)
- ClvpConfig 配置类:ClvpModelForConditionalGeneration(ClvpConfig 模型)
- CodeGenConfig 配置类:CodeGenModel(CodeGenConfig 模型)
- Cohere2Config 配置类:Cohere2Model(Cohere2Config 模型)
- Cohere2MoeConfig 配置类:Cohere2MoeModel(Cohere2MoeConfig 模型)
- Cohere2VisionConfig 配置类:Cohere2VisionModel(Cohere2VisionConfig 模型)
- CohereAsrConfig 配置类:CohereAsrModel(CohereAsrConfig 模型)
- CohereCompassConfig 配置类:CohereCompassModel(CohereCompassConfig 模型)
- CohereCompassTextConfig 配置类:CohereCompassTextModel(CohereCompassTextConfig 模型)
- CohereCompassVisionConfig 配置类:CohereCompassVisionModel(CohereCompassVisionConfig 模型)
- CohereConfig 配置类:CohereModel(CohereConfig 模型)
- ConditionalDetrConfig 配置类:ConditionalDetrModel(ConditionalDetrConfig 模型)
- ConvBertConfig 配置类:ConvBertModel(ConvBertConfig 模型)
- ConvNextConfig 配置类:ConvNextModel(ConvNextConfig 模型)
- ConvNextV2Config 配置类:ConvNextV2Model(ConvNextV2Config 模型)
- Cosmos3EdgeConfig 配置类:Cosmos3EdgeModel(Cosmos3EdgeConfig 模型)
- Cosmos3EdgeTextConfig 配置类:Cosmos3EdgeTextModel(Cosmos3EdgeTextConfig 模型)
- Cosmos3EdgeVisionConfig 配置类:Cosmos3EdgeVisionModel(Cosmos3EdgeVisionConfig 模型)
- Cosmos3OmniConfig 配置类:Cosmos3OmniModel(Cosmos3OmniConfig 模型)
- CpmAntConfig 配置类:CpmAntModel(CpmAntConfig 模型)
- CsmConfig 配置类:CsmForConditionalGeneration(CsmConfig 模型)
- CvtConfig 配置类:CvtModel(CvtConfig 模型)
- CwmConfig 配置类:CwmModel(CwmConfig 模型)
- DFineConfig 配置类:DFineModel(DFineConfig 模型)
- DINOv3ConvNextConfig 配置类:DINOv3ConvNextModel(DINOv3ConvNextConfig 模型)
- DINOv3ViTConfig 配置类:DINOv3ViTModel(DINOv3ViTConfig 模型)
- DPRConfig 配置类:DPRQuestionEncoder(DPRConfig 模型)
- DPTConfig 配置类:DPTModel(DPTConfig 模型)
- DabDetrConfig 配置类:DabDetrModel(DabDetrConfig 模型)
- DacConfig 配置类:DacModel(DacConfig 模型)
- Data2VecAudioConfig 配置类:Data2VecAudioModel(Data2VecAudioConfig 模型)
- Data2VecTextConfig 配置类:Data2VecTextModel(Data2VecTextConfig 模型)
- Data2VecVisionConfig 配置类:Data2VecVisionModel(Data2VecVisionConfig 模型)
- DbrxConfig 配置类:DbrxModel(DbrxConfig 模型)
- DebertaConfig 配置类:DebertaModel(DebertaConfig 模型)
- DebertaV2Config 配置类:DebertaV2Model(DebertaV2Config 模型)
- DecisionTransformerConfig 配置类:DecisionTransformerModel(DecisionTransformerConfig 模型)
- DeepseekOcr2Config 配置类:DeepseekOcr2Model(DeepseekOcr2Config 模型)
- DeepseekV2Config 配置类:DeepseekV2Model(DeepseekV2Config 模型)
- DeepseekV32Config 配置类:DeepseekV32Model(DeepseekV32Config 模型)
- DeepseekV3Config 配置类:DeepseekV3Model(DeepseekV3Config 模型)
- DeepseekV4Config 配置类:DeepseekV4Model(DeepseekV4Config 模型)
- DeepseekVLConfig 配置类:DeepseekVLModel(DeepseekVLConfig 模型)
- DeepseekVLHybridConfig 配置类:DeepseekVLHybridModel(DeepseekVLHybridConfig 模型)
- DeformableDetrConfig 配置类:DeformableDetrModel(DeformableDetrConfig 模型)
- DeiTConfig 配置类:DeiTModel(DeiTConfig 模型)
- Deimv2Config 配置类:Deimv2Model(Deimv2Config 模型)
- DepthProConfig 配置类:DepthProModel(DepthProConfig 模型)
- DetrConfig 配置类:DetrModel(DetrConfig 模型)
- DiaConfig 配置类:DiaModel(DiaConfig 模型)
- DiffLlamaConfig 配置类:DiffLlamaModel(DiffLlamaConfig 模型)
- DiffusionGemmaConfig 配置类:DiffusionGemmaModel(DiffusionGemmaConfig 模型)
- DinatConfig 配置类:DinatModel(DinatConfig 模型)
- Dinov2Config 配置类:Dinov2Model(Dinov2Config 模型)
- Dinov2WithRegistersConfig 配置类:Dinov2WithRegistersModel(Dinov2WithRegistersConfig 模型)
- DistilBertConfig 配置类:DistilBertModel(DistilBertConfig 模型)
- DogeConfig 配置类:DogeModel(DogeConfig 模型)
- DonutSwinConfig 配置类:DonutSwinModel(DonutSwinConfig 模型)
- Dots1Config 配置类:Dots1Model(Dots1Config 模型)
- EdgeTamConfig 配置类:EdgeTamModel(EdgeTamConfig 模型)
- EdgeTamVideoConfig 配置类:EdgeTamVideoModel(EdgeTamVideoConfig 模型)
- EdgeTamVisionConfig 配置类:EdgeTamVisionModel(EdgeTamVisionConfig 模型)
- EfficientLoFTRConfig 配置类:EfficientLoFTRModel(EfficientLoFTRConfig 模型)
- EfficientNetConfig 配置类:EfficientNetModel(EfficientNetConfig 模型)
- ElectraConfig 配置类:ElectraModel(ElectraConfig 模型)
- EmbeddingGemma2Config 配置类:EmbeddingGemma2Model(EmbeddingGemma2Config 模型)
- EmbeddingGemma2TextConfig 配置类:EmbeddingGemma2TextModel(EmbeddingGemma2TextConfig 模型)
- Emu3Config 配置类:Emu3Model(Emu3Config 模型)
- EncodecConfig 配置类:EncodecModel(EncodecConfig 模型)
- Ernie4_5Config 配置类:Ernie4_5Model(Ernie4_5Config 模型)
- Ernie4_5_MoeConfig 配置类:Ernie4_5_MoeModel(Ernie4_5_MoeConfig 模型)
- Ernie4_5_VLMoeConfig 配置类:Ernie4_5_VLMoeModel(Ernie4_5_VLMoeConfig 模型)
- ErnieConfig 配置类:ErnieModel(ErnieConfig 模型)
- EsmConfig 配置类:EsmModel(EsmConfig 模型)
- EsmcConfig 配置类:EsmcModel(EsmcConfig 模型)
- EuroBertConfig 配置类:EuroBertModel(EuroBertConfig 模型)
- EvollaConfig 配置类:EvollaModel(EvollaConfig 模型)
- Exaone4Config 配置类:Exaone4Model(Exaone4Config 模型)
- Exaone4_5_Config 配置类:Exaone4_5_Model(Exaone4_5_Config 模型)
- Exaone4_5_VisionConfig 配置类:Exaone4_5_VisionModel(Exaone4_5_VisionConfig 模型)
- ExaoneMoeConfig 配置类:ExaoneMoeModel(ExaoneMoeConfig 模型)
- FNetConfig 配置类:FNetModel(FNetConfig 模型)
- FSMTConfig 配置类:FSMTModel(FSMTConfig 模型)
- FalconConfig 配置类:FalconModel(FalconConfig 模型)
- FalconH1Config 配置类:FalconH1Model(FalconH1Config 模型)
- FalconMambaConfig 配置类:FalconMambaModel(FalconMambaConfig 模型)
- FastSpeech2ConformerConfig 配置类:FastSpeech2ConformerModel(FastSpeech2ConformerConfig 模型)
- FastSpeech2ConformerWithHifiGanConfig 配置类:FastSpeech2ConformerWithHifiGan(FastSpeech2ConformerWithHifiGanConfig 模型)
- FastVlmConfig 配置类:FastVlmModel(FastVlmConfig 模型)
- FlaubertConfig 配置类:FlaubertModel(FlaubertConfig 模型)
- FlavaConfig 配置类:FlavaModel(FlavaConfig 模型)
- FlexOlmoConfig 配置类:FlexOlmoModel(FlexOlmoConfig 模型)
- FlintConfig 配置类:FlintModel(FlintConfig 模型)
- Florence2Config 配置类:Florence2Model(Florence2Config 模型)
- FocalNetConfig 配置类:FocalNetModel(FocalNetConfig 模型)
- FunAsrNanoConfig 配置类:FunAsrNanoModel(FunAsrNanoConfig 模型)
- FunAsrNanoEncoderConfig 配置类:FunAsrNanoEncoder(FunAsrNanoEncoderConfig 模型)
- FunnelConfig 配置类:FunnelModel 或 FunnelBaseModel(FunnelConfig 模型)
- FuyuConfig 配置类:FuyuModel(FuyuConfig 模型)
- GLPNConfig 配置类:GLPNModel(GLPNConfig 模型)
- GPT2Config 配置类:GPT2Model(GPT2Config 模型)
- GPTBigCodeConfig 配置类:GPTBigCodeModel(GPTBigCodeConfig 模型)
- GPTJConfig 配置类:GPTJModel(GPTJConfig 模型)
- GPTNeoConfig 配置类:GPTNeoModel(GPTNeoConfig 模型)
- GPTNeoXConfig 配置类:GPTNeoXModel(GPTNeoXConfig 模型)
- GPTNeoXJapaneseConfig 配置类:GPTNeoXJapaneseModel(GPTNeoXJapaneseConfig 模型)
- Gemma2Config 配置类:Gemma2Model(Gemma2Config 模型)
- Gemma3Config 配置类:Gemma3Model(Gemma3Config 模型)
- Gemma3TextConfig 配置类:Gemma3TextModel(Gemma3TextConfig 模型)
- Gemma3nAudioConfig 配置类:
Gemma3nAudioEncoder(Gemma3nAudioConfig 模型) - Gemma3nConfig 配置类:Gemma3nModel(Gemma3nConfig 模型)
- Gemma3nTextConfig 配置类:Gemma3nTextModel(Gemma3nTextConfig 模型)
- Gemma3nVisionConfig 配置类:TimmWrapperModel(Gemma3nVisionConfig 模型)
- Gemma4AudioConfig 配置类:Gemma4AudioModel(Gemma4AudioConfig 模型)
- Gemma4Config 配置类:Gemma4Model(Gemma4Config 模型)
- Gemma4TextConfig 配置类:Gemma4TextModel(Gemma4TextConfig 模型)
- Gemma4UnifiedConfig 配置类:Gemma4UnifiedModel(Gemma4UnifiedConfig 模型)
- Gemma4UnifiedTextConfig 配置类:Gemma4UnifiedTextModel(Gemma4UnifiedTextConfig 模型)
- Gemma4VisionConfig 配置类:Gemma4VisionModel(Gemma4VisionConfig 模型)
- GemmaConfig 配置类:GemmaModel(GemmaConfig 模型)
- GitConfig 配置类:GitModel(GitConfig 模型)
- Glm46VConfig 配置类:Glm46VModel(Glm46VConfig 模型)
- Glm4Config 配置类:Glm4Model(Glm4Config 模型)
- Glm4MoeConfig 配置类:Glm4MoeModel(Glm4MoeConfig 模型)
- Glm4MoeLiteConfig 配置类:Glm4MoeLiteModel(Glm4MoeLiteConfig 模型)
- Glm4vConfig 配置类:Glm4vModel(Glm4vConfig 模型)
- Glm4vMoeConfig 配置类:Glm4vMoeModel(Glm4vMoeConfig 模型)
- Glm4vMoeTextConfig 配置类:Glm4vMoeTextModel(Glm4vMoeTextConfig 模型)
- Glm4vMoeVisionConfig 配置类:Glm4vMoeVisionModel(Glm4vMoeVisionConfig 模型)
- Glm4vTextConfig 配置类:Glm4vTextModel(Glm4vTextConfig 模型)
- Glm4vVisionConfig 配置类:Glm4vVisionModel(Glm4vVisionConfig 模型)
- Glm5NextConfig 配置类:Glm5NextModel(Glm5NextConfig 模型)
- Glm5NextTextConfig 配置类:Glm5NextTextModel(Glm5NextTextConfig 模型)
- Glm5NextVisionConfig 配置类:Glm5NextVisionModel(Glm5NextVisionConfig 模型)
- GlmAsrConfig 配置类:GlmAsrModel(GlmAsrConfig 模型)
- GlmAsrEncoderConfig 配置类:GlmAsrEncoder(GlmAsrEncoderConfig 模型)
- GlmConfig 配置类:GlmModel(GlmConfig 模型)
- GlmImageConfig 配置类:GlmImageModel(GlmImageConfig 模型)
- GlmImageTextConfig 配置类:GlmImageTextModel(GlmImageTextConfig 模型)
- GlmImageVQVAEConfig 配置类:GlmImageVQVAE(GlmImageVQVAEConfig 模型)
- GlmImageVisionConfig 配置类:GlmImageVisionModel(GlmImageVisionConfig 模型)
- GlmMoeDsaConfig 配置类:GlmMoeDsaModel(GlmMoeDsaConfig 模型)
- GlmOcrConfig 配置类:GlmOcrModel(GlmOcrConfig 模型)
- GlmOcrTextConfig 配置类:GlmOcrTextModel(GlmOcrTextConfig 模型)
- GlmOcrVisionConfig 配置类:GlmOcrVisionModel(GlmOcrVisionConfig 模型)
- GlmgaConfig 配置类:Glm46VModel(GlmgaConfig 模型)
- GotOcr2Config 配置类:GotOcr2Model(GotOcr2Config 模型)
- GptOssConfig 配置类:GptOssModel(GptOssConfig 模型)
- GradiumPhononTTSConfig 配置类:GradiumPhononTTSModel(GradiumPhononTTSConfig 模型)
- Granite4VisionConfig 配置类:Granite4VisionModel(Granite4VisionConfig 模型)
- GraniteConfig 配置类:GraniteModel(GraniteConfig 模型)
- GraniteMoeConfig 配置类:GraniteMoeModel(GraniteMoeConfig 模型)
- GraniteMoeHybridConfig 配置类:GraniteMoeHybridModel(GraniteMoeHybridConfig 模型)
- GraniteMoeSWAConfig 配置类:GraniteMoeSWAModel(GraniteMoeSWAConfig 模型)
- GraniteMoeSharedConfig 配置类:GraniteMoeSharedModel(GraniteMoeSharedConfig 模型)
- GraniteSWAConfig 配置类:GraniteSWAModel(GraniteSWAConfig 模型)
- GraniteSpeech5CTCConfig 配置类:GraniteSpeech5ForCTC(GraniteSpeech5CTCConfig 模型)
- GraniteSpeech5EncoderConfig 配置类:GraniteSpeech5Encoder(GraniteSpeech5EncoderConfig 模型)
- GraniteSpeechConfig 配置类:GraniteSpeechModel(GraniteSpeechConfig 模型)
- GraniteSpeechPlusConfig 配置类:GraniteSpeechPlusModel(GraniteSpeechPlusConfig 模型)
- GroundingDinoConfig 配置类:GroundingDinoModel(GroundingDinoConfig 模型)
- GroupViTConfig 配置类:GroupViTModel(GroupViTConfig 模型)
- GteConfig 配置类:GteModel(GteConfig 模型)
- HGNetV2Config 配置类:HGNetV2Backbone(HGNetV2Config 模型)
- HYV3Config 配置类:HYV3Model(HYV3Config 模型)
- HYV4Config 配置类:HYV4Model(HYV4Config 模型)
- HeliumConfig 配置类:HeliumModel(HeliumConfig 模型)
- HieraConfig 配置类:HieraModel(HieraConfig 模型)
- HiggsAudioV2Config 配置类:HiggsAudioV2ForConditionalGeneration(HiggsAudioV2Config 模型)
- HiggsAudioV2TokenizerConfig 配置类:HiggsAudioV2TokenizerModel(HiggsAudioV2TokenizerConfig 模型)
- HrmTextConfig 配置类:HrmTextModel(HrmTextConfig 模型)
- HubertConfig 配置类:HubertModel(HubertConfig 模型)
- HunYuanDenseV1Config 配置类:HunYuanDenseV1Model(HunYuanDenseV1Config 模型)
- HunYuanMoEV1Config 配置类:HunYuanMoEV1Model(HunYuanMoEV1Config 模型)
- HunYuanVLConfig 配置类:HunYuanVLModel(HunYuanVLConfig 模型)
- HunYuanVLTextConfig 配置类:HunYuanVLTextModel(HunYuanVLTextConfig 模型)
- HunYuanVLVisionConfig 配置类:HunYuanVLVisionTransformer(HunYuanVLVisionConfig 模型)
- HyperCLOVAXConfig 配置类:HyperCLOVAXModel(HyperCLOVAXConfig 模型)
- HyperCLOVAXVisionV2Config 配置类:HyperCLOVAXVisionV2Model(HyperCLOVAXVisionV2Config 模型)
- IBertConfig 配置类:IBertModel(IBertConfig 模型)
- IJepaConfig 配置类:IJepaModel(IJepaConfig 模型)
- Idefics2Config 配置类:Idefics2Model(Idefics2Config 模型)
- Idefics3Config 配置类:Idefics3Model(Idefics3Config 模型)
- Idefics3VisionConfig 配置类:Idefics3VisionTransformer(Idefics3VisionConfig 模型)
- IdeficsConfig 配置类:IdeficsModel(IdeficsConfig 模型)
- ImageGPTConfig 配置类:ImageGPTModel(ImageGPTConfig 模型)
- InformerConfig 配置类:InformerModel(InformerConfig 模型)
- InklingConfig 配置类:InklingModel(InklingConfig 模型)
- InklingTextConfig 配置类:InklingTextModel(InklingTextConfig 模型)
- InstructBlipConfig 配置类:InstructBlipModel(InstructBlipConfig 模型)
- InstructBlipVideoConfig 配置类:InstructBlipVideoModel(InstructBlipVideoConfig 模型)
- InternVLConfig 配置类:InternVLModel(InternVLConfig 模型)
- InternVLVisionConfig 配置类:InternVLVisionModel(InternVLVisionConfig 模型)
- Jais2Config 配置类:Jais2Model(Jais2Config 模型)
- JambaConfig 配置类:JambaModel(JambaConfig 模型)
- JanusConfig 配置类:JanusModel(JanusConfig 模型)
- JetMoeConfig 配置类:JetMoeModel(JetMoeConfig 模型)
- JinaEmbeddingsV3Config 配置类:JinaEmbeddingsV3Model(JinaEmbeddingsV3Config 模型)
- KimiLinearConfig 配置类:KimiLinearModel(KimiLinearConfig 模型)
- Kimi_K25Config 配置类:Kimi_K25Model(Kimi_K25Config 模型)
- Kimi_K25VisionConfig 配置类:Kimi_K25VisionModel(Kimi_K25VisionConfig 模型)
- Kolibri1Config 配置类:Kolibri1Model(Kolibri1Config 模型)
- Kosmos2Config 配置类:Kosmos2Model(Kosmos2Config 模型)
- Kosmos2_5Config 配置类:Kosmos2_5Model(Kosmos2_5Config 模型)
- KyutaiSpeechToTextConfig 配置类:KyutaiSpeechToTextModel(KyutaiSpeechToTextConfig 模型)
- LEDConfig 配置类:LEDModel(LEDConfig 模型)
- LagunaConfig 配置类:LagunaModel(LagunaConfig 模型)
- LasrCTCConfig 配置类:LasrForCTC(LasrCTCConfig 模型)
- LasrEncoderConfig 配置类:LasrEncoder(LasrEncoderConfig 模型)
- LayoutLMConfig 配置类:LayoutLMModel(LayoutLMConfig 模型)
- LayoutLMv2Config 配置类:LayoutLMv2Model(LayoutLMv2Config 模型)
- LayoutLMv3Config 配置类:LayoutLMv3Model(LayoutLMv3Config 模型)
- LevitConfig 配置类:LevitModel(LevitConfig 模型)
- Lfm2Config 配置类:Lfm2Model(Lfm2Config 模型)
- Lfm2MoeConfig 配置类:Lfm2MoeModel(Lfm2MoeConfig 模型)
- Lfm2VlConfig 配置类:Lfm2VlModel(Lfm2VlConfig 模型)
- Lfm3Config 配置类:Lfm3Model(Lfm3Config 模型)
- LightGlueConfig 配置类:LightGlueForKeypointMatching(LightGlueConfig 模型)
- LightOnOcrConfig 配置类:LightOnOcrModel(LightOnOcrConfig 模型)
- LiltConfig 配置类:LiltModel(LiltConfig 模型)
- Llama4Config 配置类:Llama4ForConditionalGeneration(Llama4Config 模型)
- Llama4TextConfig 配置类:Llama4TextModel(Llama4TextConfig 模型)
- LlamaConfig 配置类:LlamaModel(LlamaConfig 模型)
- LlavaConfig 配置类:LlavaModel(LlavaConfig 模型)
- LlavaNextConfig 配置类:LlavaNextModel(LlavaNextConfig 模型)
- LlavaNextVideoConfig 配置类:LlavaNextVideoModel(LlavaNextVideoConfig 模型)
- LlavaOnevisionConfig 配置类:LlavaOnevisionModel(LlavaOnevisionConfig 模型)
- LongT5Config 配置类:LongT5Model(LongT5Config 模型)
- LongcatFlashConfig 配置类:LongcatFlashModel(LongcatFlashConfig 模型)
- LongformerConfig 配置类:LongformerModel(LongformerConfig 模型)
- LukeConfig 配置类:LukeModel(LukeConfig 模型)
- LwDetrConfig 配置类:LwDetrModel(LwDetrConfig 模型)
- LxmertConfig 配置类:LxmertModel(LxmertConfig 模型)
- M2M100Config 配置类:M2M100Model(M2M100Config 模型)
- MBartConfig 配置类:MBartModel(MBartConfig 模型)
- MLCDVisionConfig 配置类:MLCDVisionModel(MLCDVisionConfig 模型)
- MMGroundingDinoConfig 配置类:MMGroundingDinoModel(MMGroundingDinoConfig 模型)
- MPNetConfig 配置类:MPNetModel(MPNetConfig 模型)
- MT5Config 配置类:MT5Model(MT5Config 模型)
- Mamba2Config 配置类:Mamba2Model(Mamba2Config 模型)
- MambaConfig 配置类:MambaModel(MambaConfig 模型)
- MarianConfig 配置类:MarianModel(MarianConfig 模型)
- MarkupLMConfig 配置类:MarkupLMModel(MarkupLMConfig 模型)
- Mask2FormerConfig 配置类:Mask2FormerModel(Mask2FormerConfig 模型)
- MaskFormerConfig 配置类:MaskFormerModel(MaskFormerConfig 模型)
MaskFormerSwinConfig配置类:MaskFormerSwinModel(MaskFormerSwinConfig 模型)- MegatronBertConfig 配置类:MegatronBertModel(MegatronBertConfig 模型)
- MellumConfig 配置类:MellumModel(MellumConfig 模型)
- MetaClip2Config 配置类:MetaClip2Model(MetaClip2Config 模型)
- MgpstrConfig 配置类:MgpstrForSceneTextRecognition(MgpstrConfig 模型)
- MiMoV2FlashConfig 配置类:MiMoV2FlashModel(MiMoV2FlashConfig 模型)
- MimiConfig 配置类:MimiModel(MimiConfig 模型)
- MimiDecoderConfig 配置类:MimiDecoderModel(MimiDecoderConfig 模型)
- MimiEncoderConfig 配置类:MimiEncoderModel(MimiEncoderConfig 模型)
- MiniCPM3Config 配置类:MiniCPM3Model(MiniCPM3Config 模型)
- MiniCPMOcrConfig 配置类:MiniCPMOcrModel(MiniCPMOcrConfig 模型)
- MiniCPMOcrVisionConfig 配置类:MiniCPMOcrVisionModel(MiniCPMOcrVisionConfig 模型)
- MiniCPMV4_6Config 配置类:MiniCPMV4_6Model(MiniCPMV4_6Config 模型)
- MiniCPMV4_7Config 配置类:MiniCPMV4_7Model(MiniCPMV4_7Config 模型)
- MiniCPMV4_7VisionConfig 配置类:MiniCPMV4_7VisionModel(MiniCPMV4_7VisionConfig 模型)
- MiniMaxConfig 配置类:MiniMaxModel(MiniMaxConfig 模型)
- MiniMaxM2Config 配置类:MiniMaxM2Model(MiniMaxM2Config 模型)
- MiniMaxM3VLConfig 配置类:MiniMaxM3VLModel(MiniMaxM3VLConfig 模型)
- MiniMaxM3VLTextConfig 配置类:MiniMaxM3VLTextModel(MiniMaxM3VLTextConfig 模型)
- Ministral3Config 配置类:Ministral3Model(Ministral3Config 模型)
- MinistralConfig 配置类:MinistralModel(MinistralConfig 模型)
- Mistral3Config 配置类:Mistral3Model(Mistral3Config 模型)
- Mistral4Config 配置类:Mistral4Model(Mistral4Config 模型)
- MistralConfig 配置类:MistralModel(MistralConfig 模型)
- MistralLarge4Config 配置类:MistralLarge4Model(MistralLarge4Config 模型)
- MistralLarge4TextConfig 配置类:MistralLarge4TextModel(MistralLarge4TextConfig 模型)
- MixtralConfig 配置类:MixtralModel(MixtralConfig 模型)
- MllamaConfig 配置类:MllamaModel(MllamaConfig 模型)
- MobileBertConfig 配置类:MobileBertModel(MobileBertConfig 模型)
- MobileNetV1Config 配置类:MobileNetV1Model(MobileNetV1Config 模型)
- MobileNetV2Config 配置类:MobileNetV2Model(MobileNetV2Config 模型)
- MobileViTConfig 配置类:MobileViTModel(MobileViTConfig 模型)
- MobileViTV2Config 配置类:MobileViTV2Model(MobileViTV2Config 模型)
- ModernBertConfig 配置类:ModernBertModel(ModernBertConfig 模型)
- ModernBertDecoderConfig 配置类:ModernBertDecoderModel(ModernBertDecoderConfig 模型)
- ModernVBertConfig 配置类:ModernVBertModel(ModernVBertConfig 模型)
- Molmo2Config 配置类:Molmo2Model(Molmo2Config 模型)
- Molmo2TextConfig 配置类:Molmo2TextModel(Molmo2TextConfig 模型)
- MoonshineConfig 配置类:MoonshineModel(MoonshineConfig 模型)
- MoonshineStreamingConfig 配置类:MoonshineStreamingModel(MoonshineStreamingConfig 模型)
- MoshiConfig 配置类:MoshiModel(MoshiConfig 模型)
- MossTranscribeDiarizeAudioConfig 配置类:MossTranscribeDiarizeAudioModel(MossTranscribeDiarizeAudioConfig 模型)
- MossTranscribeDiarizeConfig 配置类:MossTranscribeDiarizeModel(MossTranscribeDiarizeConfig 模型)
- MptConfig 配置类:MptModel(MptConfig 模型)
- MraConfig 配置类:MraModel(MraConfig 模型)
- MuseGlimmerAssistantConfig 配置类:MuseGlimmerAssistantModel(MuseGlimmerAssistantConfig 模型)
- MuseGlimmerConfig 配置类:MuseGlimmerModel(MuseGlimmerConfig 模型)
- MuseGlimmerTextConfig 配置类:MuseGlimmerTextModel(MuseGlimmerTextConfig 模型)
- MuseGlimmerVisionConfig 配置类:MuseGlimmerVisionModel(MuseGlimmerVisionConfig 模型)
- MuseSparkAudioConfig 配置类:MuseSparkAudioModel(MuseSparkAudioConfig 模型)
- MuseSparkConfig 配置类:MuseSparkModel(MuseSparkConfig 模型)
- MuseSparkTextConfig 配置类:MuseSparkTextModel(MuseSparkTextConfig 模型)
- MuseSparkVisionConfig 配置类:MuseSparkVisionModel(MuseSparkVisionConfig 模型)
- MusicFlamingoConfig 配置类:MusicFlamingoModel(MusicFlamingoConfig 模型)
- MusicgenConfig 配置类:MusicgenModel(MusicgenConfig 模型)
- MusicgenMelodyConfig 配置类:MusicgenMelodyModel(MusicgenMelodyConfig 模型)
- MvpConfig 配置类:MvpModel(MvpConfig 模型)
- NanoChatConfig 配置类:NanoChatModel(NanoChatConfig 模型)
- Nemotron3DiarizationAudioConfig 配置类:Nemotron3DiarizationAudioModel(Nemotron3DiarizationAudioConfig 模型)
- Nemotron3DiarizationConfig 配置类:Nemotron3DiarizationModel(Nemotron3DiarizationConfig 模型)
- Nemotron3_5AsrConfig 配置类:Nemotron3_5AsrForRNNT(Nemotron3_5AsrConfig 模型)
- Nemotron3_5TranscribeAsrAudioConfig 配置类:Nemotron3_5TranscribeAsrAudioModel(Nemotron3_5TranscribeAsrAudioConfig 模型)
- Nemotron3_5TranscribeAudioConfig 配置类:Nemotron3_5TranscribeAudioModel(Nemotron3_5TranscribeAudioConfig 模型)
- Nemotron3_5TranscribeConfig 配置类:Nemotron3_5TranscribeModel(Nemotron3_5TranscribeConfig 模型)
- Nemotron3_5TranscribeWordTimestampConfig 配置类:Nemotron3_5TranscribeWordTimestampModel(Nemotron3_5TranscribeWordTimestampConfig 模型)
- NemotronAsrStreamingConfig 配置类:NemotronAsrStreamingForRNNT(NemotronAsrStreamingConfig 模型)
- NemotronAsrStreamingEncoderConfig 配置类:NemotronAsrStreamingEncoder(NemotronAsrStreamingEncoderConfig 模型)
- NemotronConfig 配置类:NemotronModel(NemotronConfig 模型)
- NemotronHConfig 配置类:NemotronHModel(NemotronHConfig 模型)
- NeoMMEConfig 配置类:NeoMMEModel(NeoMMEConfig 模型)
- NeuCodecConfig 配置类:NeuCodecModel(NeuCodecConfig 模型)
- NllbMoeConfig 配置类:NllbMoeModel(NllbMoeConfig 模型)
- NomicBertConfig 配置类:NomicBertModel(NomicBertConfig 模型)
- NystromformerConfig 配置类:NystromformerModel(NystromformerConfig 模型)
- OPTConfig 配置类:OPTModel(OPTConfig 模型)
- Olmo2Config 配置类:Olmo2Model(Olmo2Config 模型)
- Olmo3Config 配置类:Olmo3Model(Olmo3Config 模型)
- OlmoConfig 配置类:OlmoModel(OlmoConfig 模型)
- OlmoHybridConfig 配置类:OlmoHybridModel(OlmoHybridConfig 模型)
- OlmoeConfig 配置类:OlmoeModel(OlmoeConfig 模型)
- OmDetTurboConfig 配置类:OmDetTurboForObjectDetection(OmDetTurboConfig 模型)
- OneFormerConfig 配置类:OneFormerModel(OneFormerConfig 模型)
- OpenAIGPTConfig 配置类:OpenAIGPTModel(OpenAIGPTConfig 模型)
- OpenAIPrivacyFilterConfig 配置类:OpenAIPrivacyFilterModel(OpenAIPrivacyFilterConfig 模型)
- Ovis2Config 配置类:Ovis2Model(Ovis2Config 模型)
- OwlViTConfig 配置类:OwlViTModel(OwlViTConfig 模型)
- Owlv2Config 配置类:Owlv2Model(Owlv2Config 模型)
- PI0Config 配置类:PI0Model(PI0Config 模型)
- PLBartConfig 配置类:PLBartModel(PLBartConfig 模型)
- PPDocLayoutV3Config 配置类:PPDocLayoutV3Model(PPDocLayoutV3Config 模型)
- PPDocLayoutV4Config 配置类:PPDocLayoutV4Model(PPDocLayoutV4Config 模型)
- PPOCRV5MobileRecConfig 配置类:PPOCRV5MobileRecModel(PPOCRV5MobileRecConfig 模型)
- PPOCRV5ServerRecConfig 配置类:PPOCRV5ServerRecModel(PPOCRV5ServerRecConfig 模型)
- PPOCRV6MediumDetConfig 配置类:PPOCRV6MediumDetModel(PPOCRV6MediumDetConfig 模型)
- PPOCRV6SmallDetConfig 配置类:PPOCRV6SmallDetModel(PPOCRV6SmallDetConfig 模型)
- PPOCRV6SmallRecConfig 配置类:PPOCRV6SmallRecModel(PPOCRV6SmallRecConfig 模型)
- PPOCRV6TinyRecConfig 配置类:PPOCRV6TinyRecModel(PPOCRV6TinyRecConfig 模型)
- PaddleOCRVLConfig 配置类:PaddleOCRVLModel(PaddleOCRVLConfig 模型)
- PaliGemmaConfig 配置类:PaliGemmaModel(PaliGemmaConfig 模型)
- ParakeetCTCConfig 配置类:ParakeetForCTC(ParakeetCTCConfig 模型)
- ParakeetEncoderConfig 配置类:ParakeetEncoder(ParakeetEncoderConfig 模型)
- ParakeetRNNTConfig 配置类:ParakeetForRNNT(ParakeetRNNTConfig 模型)
- ParakeetTDTConfig 配置类:ParakeetForTDT(ParakeetTDTConfig 模型)
- PatchTSMixerConfig 配置类:PatchTSMixerModel(PatchTSMixerConfig 模型)
- PatchTSTConfig 配置类:PatchTSTModel(PatchTSTConfig 模型)
- PeAudioConfig 配置类:PeAudioModel(PeAudioConfig 模型)
- PeAudioEncoderConfig 配置类:PeAudioEncoder(PeAudioEncoderConfig 模型)
- PeAudioVideoConfig 配置类:PeAudioVideoModel(PeAudioVideoConfig 模型)
- PeAudioVideoEncoderConfig 配置类:PeAudioVideoEncoder(PeAudioVideoEncoderConfig 模型)
- PeVideoConfig 配置类:PeVideoModel(PeVideoConfig 模型)
- PeVideoEncoderConfig 配置类:PeVideoEncoder(PeVideoEncoderConfig 模型)
- PegasusConfig 配置类:PegasusModel(PegasusConfig 模型)
- PegasusXConfig 配置类:PegasusXModel(PegasusXConfig 模型)
- PerceiverConfig 配置类:PerceiverModel(PerceiverConfig 模型)
- PerceptionLMConfig 配置类:PerceptionLMModel(PerceptionLMConfig 模型)
- PersimmonConfig 配置类:PersimmonModel(PersimmonConfig 模型)
- Phi3Config 配置类:Phi3Model(Phi3Config 模型)
- Phi4MultimodalConfig 配置类:Phi4MultimodalModel(Phi4MultimodalConfig 模型)
- PhiConfig 配置类:PhiModel(PhiConfig 模型)
- PhimoeConfig 配置类:PhimoeModel(PhimoeConfig 模型)
- PixioConfig 配置类:PixioModel(PixioConfig 模型)
- PixtralVisionConfig 配置类:PixtralVisionModel(PixtralVisionConfig 模型)
- PocketTTSAudioTokenizerConfig 配置类:PocketTTSAudioTokenizerModel(PocketTTSAudioTokenizerConfig 模型)
- PocketTTSAudioTokenizerDecoderConfig 配置类:PocketTTSAudioTokenizerDecoderModel(PocketTTSAudioTokenizerDecoderConfig 模型)
- PocketTTSAudioTokenizerEncoderConfig 配置类:PocketTTSAudioTokenizerEncoderModel(PocketTTSAudioTokenizerEncoderConfig 模型)
- PocketTTSConfig 配置类:PocketTTSModel(PocketTTSConfig 模型)
- PoolFormerConfig 配置类:PoolFormerModel(PoolFormerConfig 模型)
- ProphetNetConfig 配置类:ProphetNetModel(ProphetNetConfig 模型)
- PvtConfig 配置类:PvtModel(PvtConfig 模型)
- PvtV2Config 配置类:PvtV2Model(PvtV2Config 模型)
- QianfanOCRConfig 配置类:QianfanOCRModel(QianfanOCRConfig 模型)
- QianfanOCRVisionConfig 配置类:QianfanOCRVisionModel(QianfanOCRVisionConfig 模型)
- Qwen2AudioConfig 配置类:Qwen2AudioModel(Qwen2AudioConfig 模型)
- Qwen2AudioEncoderConfig 配置类:Qwen2AudioEncoder(Qwen2AudioEncoderConfig 模型)
- Qwen2Config 配置类:Qwen2Model(Qwen2Config 模型)
- Qwen2MoeConfig 配置类:Qwen2MoeModel(Qwen2MoeConfig 模型)
- Qwen2VLConfig 配置类:Qwen2VLModel(Qwen2VLConfig 模型)
- Qwen2VLTextConfig 配置类:Qwen2VLTextModel(Qwen2VLTextConfig 模型)
- Qwen2_5OmniThinkerConfig 配置类:Qwen2_5OmniThinkerModel(Qwen2_5OmniThinkerConfig 模型)
- Qwen2_5_VLConfig 配置类:Qwen2_5_VLModel(Qwen2_5_VLConfig 模型)
- Qwen2_5_VLTextConfig 配置类:Qwen2_5_VLTextModel(Qwen2_5_VLTextConfig 模型)
- Qwen2_5_VLVisionConfig 配置类:Qwen2_5_VisionTransformerPretrainedModel(Qwen2_5_VLVisionConfig 模型)
- Qwen3ASRConfig 配置类:Qwen3ASRModel(Qwen3ASRConfig 模型)
- Qwen3ASREncoderConfig 配置类:Qwen3ASREncoder(Qwen3ASREncoderConfig 模型)
- Qwen3Config 配置类:Qwen3Model(Qwen3Config 模型)
- Qwen3MoeConfig 配置类:Qwen3MoeModel(Qwen3MoeConfig 模型)
- Qwen3NextConfig 配置类:Qwen3NextModel(Qwen3NextConfig 模型)
- Qwen3OmniMoeThinkerConfig 配置类:Qwen3OmniMoeThinkerModel(Qwen3OmniMoeThinkerConfig 模型)
- Qwen3VLConfig 配置类:Qwen3VLModel(Qwen3VLConfig 模型)
- Qwen3VLMoeConfig 配置类:Qwen3VLMoeModel(Qwen3VLMoeConfig 模型)
- Qwen3VLMoeTextConfig 配置类:Qwen3VLMoeTextModel(Qwen3VLMoeTextConfig 模型)
- Qwen3VLMoeVisionConfig 配置类:Qwen3VLMoeVisionModel(Qwen3VLMoeVisionConfig 模型)
- Qwen3VLTextConfig 配置类:Qwen3VLTextModel(Qwen3VLTextConfig 模型)
- Qwen3VLVisionConfig 配置类:Qwen3VLVisionModel(Qwen3VLVisionConfig 模型)
- Qwen3_5Config 配置类:Qwen3_5Model(Qwen3_5Config 模型)
- Qwen3_5MoeConfig 配置类:Qwen3_5MoeModel(Qwen3_5MoeConfig 模型)
- Qwen3_5MoeTextConfig 配置类:Qwen3_5MoeTextModel(Qwen3_5MoeTextConfig 模型)
- Qwen3_5MoeVisionConfig 配置类:Qwen3_5MoeVisionModel(Qwen3_5MoeVisionConfig 模型)
- Qwen3_5TextConfig 配置类:Qwen3_5TextModel(Qwen3_5TextConfig 模型)
- Qwen3_5VisionConfig 配置类:Qwen3_5VisionModel(Qwen3_5VisionConfig 模型)
- Qwen4ExpConfig 配置类:Qwen4ExpModel(Qwen4ExpConfig 模型)
- Qwen4ExpTextConfig 配置类:Qwen4ExpTextModel(Qwen4ExpTextConfig 模型)
- Qwen4ExpVisionConfig 配置类:Qwen4ExpVisionModel(Qwen4ExpVisionConfig 模型)
- RTDetrConfig 配置类:RTDetrModel(RTDetrConfig 模型)
- RTDetrV2Config 配置类:RTDetrV2Model(RTDetrV2Config 模型)
- RadioConfig 配置类:RadioModel(RadioConfig 模型)
- RecurrentGemmaConfig 配置类:RecurrentGemmaModel(RecurrentGemmaConfig 模型)
- ReformerConfig 配置类:ReformerModel(ReformerConfig 模型)
- RegNetConfig 配置类:RegNetModel(RegNetConfig 模型)
- RemBertConfig 配置类:RemBertModel(RemBertConfig 模型)
- ResNetConfig 配置类:ResNetModel(ResNetConfig 模型)
- RfDetrConfig 配置类:RfDetrModel(RfDetrConfig 模型)
- RoCBertConfig 配置类:RoCBertModel(RoCBertConfig 模型)
- RoFormerConfig 配置类:RoFormerModel(RoFormerConfig 模型)
- RobertaConfig 配置类:RobertaModel(RobertaConfig 模型)
- RobertaPreLayerNormConfig 配置类:RobertaPreLayerNormModel(RobertaPreLayerNormConfig 模型)
- RwkvConfig 配置类:RwkvModel(RwkvConfig 模型)
- SEWConfig 配置类:SEWModel(SEWConfig 模型)
- SEWDConfig 配置类:SEWDModel(SEWDConfig 模型)
- Sam2Config 配置类:Sam2Model(Sam2Config 模型)
- Sam2HieraDetConfig 配置类:Sam2HieraDetModel(Sam2HieraDetConfig 模型)
- Sam2VideoConfig 配置类:Sam2VideoModel(Sam2VideoConfig 模型)
- Sam2VisionConfig 配置类:Sam2VisionModel(Sam2VisionConfig 模型)
- Sam3Config 配置类:Sam3Model(Sam3Config 模型)
- Sam3LiteTextConfig 配置类:Sam3LiteTextModel(Sam3LiteTextConfig 模型)
- Sam3LiteTextTextConfig 配置类:Sam3LiteTextTextModel(Sam3LiteTextTextConfig 模型)
- Sam3TrackerConfig 配置类:Sam3TrackerModel(Sam3TrackerConfig 模型)
- Sam3TrackerVideoConfig 配置类:Sam3TrackerVideoModel(Sam3TrackerVideoConfig 模型)
- Sam3ViTConfig 配置类:Sam3ViTModel(Sam3ViTConfig 模型)
- Sam3VideoConfig 配置类:Sam3VideoModel(Sam3VideoConfig 模型)
- Sam3VisionConfig 配置类:Sam3VisionModel(Sam3VisionConfig 模型)
- SamConfig 配置类:SamModel(SamConfig 模型)
- SamHQConfig 配置类:SamHQModel(SamHQConfig 模型)
- SamHQVisionConfig 配置类:SamHQVisionModel(SamHQVisionConfig 模型)
- SamVisionConfig 配置类:SamVisionModel(SamVisionConfig 模型)
- Sapiens2Config 配置类:Sapiens2Model(Sapiens2Config 模型)
- SeamlessM4TConfig 配置类:SeamlessM4TModel(SeamlessM4TConfig 模型)
- SeamlessM4Tv2Config 配置类:SeamlessM4Tv2Model(SeamlessM4Tv2Config 模型)
- SeedOssConfig 配置类:SeedOssModel(SeedOssConfig 模型)
- SegGptConfig 配置类:SegGptModel(SegGptConfig 模型)
- SegformerConfig 配置类:SegformerModel(SegformerConfig 模型)
- Siglip2Config 配置类:Siglip2Model(Siglip2Config 模型)
- Siglip2VisionConfig 配置类:Siglip2VisionModel(Siglip2VisionConfig 模型)
- SiglipConfig 配置类:SiglipModel(SiglipConfig 模型)
- SiglipVisionConfig 配置类:SiglipVisionModel(SiglipVisionConfig 模型)
- SmolLM3Config 配置类:SmolLM3Model(SmolLM3Config 模型)
- SmolVLMConfig 配置类:SmolVLMModel(SmolVLMConfig 模型)
- SmolVLMVisionConfig 配置类:SmolVLMVisionTransformer(SmolVLMVisionConfig 模型)
- SolarOpenConfig 配置类:SolarOpenModel(SolarOpenConfig 模型)
- Speech2TextConfig 配置类:Speech2TextModel(Speech2TextConfig 模型)
- SpeechT5Config 配置类:SpeechT5Model(SpeechT5Config 模型)
- SplinterConfig 配置类:SplinterModel(SplinterConfig 模型)
- SqueezeBertConfig 配置类:SqueezeBertModel(SqueezeBertConfig 模型)
- StableLmConfig 配置类:StableLmModel(StableLmConfig 模型)
- Starcoder2Config 配置类:Starcoder2Model(Starcoder2Config 模型)
- Step3p7Config 配置类:Step3p7Model(Step3p7Config 模型)
- SwiftFormerConfig 配置类:SwiftFormerModel(SwiftFormerConfig 模型)
- Swin2SRConfig 配置类:Swin2SRModel(Swin2SRConfig 模型)
- SwinConfig 配置类:SwinModel(SwinConfig 模型)
- Swinv2Config 配置类:Swinv2Model(Swinv2Config 模型)
- SwitchTransformersConfig 配置类:SwitchTransformersModel(SwitchTransformersConfig 模型)
- T5Config 配置类:T5Model(T5Config 模型)
- T5Gemma2Config 配置类:T5Gemma2Model(T5Gemma2Config 模型)
- T5Gemma2EncoderConfig 配置类:
T5Gemma2Encoder(T5Gemma2EncoderConfig 模型) - T5GemmaConfig 配置类:T5GemmaModel(T5GemmaConfig 模型)
- TableTransformerConfig 配置类:TableTransformerModel(TableTransformerConfig 模型)
- TapasConfig 配置类:TapasModel(TapasConfig 模型)
- TextNetConfig 配置类:TextNetModel(TextNetConfig 模型)
- TimeSeriesTransformerConfig 配置类:TimeSeriesTransformerModel(TimeSeriesTransformerConfig 模型)
- TimesFm2_5Config 配置类:TimesFm2_5Model(TimesFm2_5Config 模型)
- TimesFmConfig 配置类:TimesFmModel(TimesFmConfig 模型)
- TimesformerConfig 配置类:TimesformerModel(TimesformerConfig 模型)
- TimmBackboneConfig 配置类:TimmBackbone(TimmBackboneConfig 模型)
- TimmWrapperConfig 配置类:TimmWrapperModel(TimmWrapperConfig 模型)
- Tipsv2Config 配置类:Tipsv2Model(Tipsv2Config 模型)
- Tipsv2TextConfig 配置类:Tipsv2TextModel(Tipsv2TextConfig 模型)
- Tipsv2VisionConfig 配置类:Tipsv2VisionModel(Tipsv2VisionConfig 模型)
- TvpConfig 配置类:TvpModel(TvpConfig 模型)
- UMT5Config 配置类:UMT5Model(UMT5Config 模型)
- UVDocConfig 配置类:UVDocModel(UVDocConfig 模型)
- UdopConfig 配置类:UdopModel(UdopConfig 模型)
- UltraVBertConfig 配置类:UltraVBertModel(UltraVBertConfig 模型)
- UltrabertConfig 配置类:UltrabertModel(UltrabertConfig 模型)
- UniSpeechConfig 配置类:UniSpeechModel(UniSpeechConfig 模型)
- UniSpeechSatConfig 配置类:UniSpeechSatModel(UniSpeechSatConfig 模型)
- UnivNetConfig 配置类:UnivNetModel(UnivNetConfig 模型)
- UnlimitedOcrConfig 配置类:UnlimitedOcrModel(UnlimitedOcrConfig 模型)
- VJEPA2Config 配置类:VJEPA2Model(VJEPA2Config 模型)
- VaultGemmaConfig 配置类:VaultGemmaModel(VaultGemmaConfig 模型)
- ViTConfig 配置类:ViTModel(ViTConfig 模型)
- ViTMAEConfig 配置类:ViTMAEModel(ViTMAEConfig 模型)
- ViTMSNConfig 配置类:ViTMSNModel(ViTMSNConfig 模型)
- VibeVoiceAcousticTokenizerConfig 配置类:VibeVoiceAcousticTokenizerModel(VibeVoiceAcousticTokenizerConfig 模型)
- VibeVoiceAcousticTokenizerDecoderConfig 配置类:VibeVoiceAcousticTokenizerDecoderModel(VibeVoiceAcousticTokenizerDecoderConfig 模型)
- VibeVoiceAcousticTokenizerEncoderConfig 配置类:VibeVoiceAcousticTokenizerEncoderModel(VibeVoiceAcousticTokenizerEncoderConfig 模型)
- VibeVoiceAsrConfig 配置类:VibeVoiceAsrModel(VibeVoiceAsrConfig 模型)
- VibeVoiceConfig 配置类:VibeVoiceForConditionalGeneration(VibeVoiceConfig 模型)
- VideoLlama3Config 配置类:VideoLlama3Model(VideoLlama3Config 模型)
- VideoLlama3VisionConfig 配置类:VideoLlama3VisionModel(VideoLlama3VisionConfig 模型)
- VideoLlavaConfig 配置类:VideoLlavaModel(VideoLlavaConfig 模型)
- VideoMAEConfig 配置类:VideoMAEModel(VideoMAEConfig 模型)
- VideoPrismConfig 配置类:VideoPrismClipModel(VideoPrismConfig 模型)
- VideoPrismVisionConfig 配置类:VideoPrismVisionModel(VideoPrismVisionConfig 模型)
- ViltConfig 配置类:ViltModel(ViltConfig 模型)
- VipLlavaConfig 配置类:VipLlavaModel(VipLlavaConfig 模型)
- VisionTextDualEncoderConfig 配置类:VisionTextDualEncoderModel(VisionTextDualEncoderConfig 模型)
- VisualBertConfig 配置类:VisualBertModel(VisualBertConfig 模型)
- VitDetConfig 配置类:VitDetModel(VitDetConfig 模型)
- VitsConfig 配置类:VitsModel(VitsConfig 模型)
- VivitConfig 配置类:VivitModel(VivitConfig 模型)
- VoxtralConfig 配置类:VoxtralModel(VoxtralConfig 模型)
- VoxtralEncoderConfig 配置类:VoxtralEncoder(VoxtralEncoderConfig 模型)
- VoxtralRealtimeConfig 配置类:VoxtralRealtimeModel(VoxtralRealtimeConfig 模型)
- VoxtralRealtimeEncoderConfig 配置类:VoxtralRealtimeEncoder(VoxtralRealtimeEncoderConfig 模型)
- VoxtralRealtimeTextConfig 配置类:
VoxtralRealtimeTextModel(VoxtralRealtimeTextConfig 模型) - Wav2Vec2BertConfig 配置类:Wav2Vec2BertModel(Wav2Vec2BertConfig 模型)
- Wav2Vec2Config 配置类:Wav2Vec2Model(Wav2Vec2Config 模型)
- Wav2Vec2ConformerConfig 配置类:Wav2Vec2ConformerModel(Wav2Vec2ConformerConfig 模型)
- WavLMConfig 配置类:WavLMModel(WavLMConfig 模型)
- WhisperConfig 配置类:WhisperModel(WhisperConfig 模型)
- XCLIPConfig 配置类:XCLIPModel(XCLIPConfig 模型)
- XGLMConfig 配置类:XGLMModel(XGLMConfig 模型)
- XLMConfig 配置类:XLMModel(XLMConfig 模型)
- XLMRobertaConfig 配置类:XLMRobertaModel(XLMRobertaConfig 模型)
- XLMRobertaXLConfig 配置类:XLMRobertaXLModel(XLMRobertaXLConfig 模型)
- XLNetConfig 配置类:XLNetModel(XLNetConfig 模型)
- Xcodec2Config 配置类:Xcodec2Model(Xcodec2Config 模型)
- XcodecConfig 配置类:XcodecModel(XcodecConfig 模型)
- XmodConfig 配置类:XmodModel(XmodConfig 模型)
- YolosConfig 配置类:YolosModel(YolosConfig 模型)
- YosoConfig 配置类:YosoModel(YosoConfig 模型)
- YoutuConfig 配置类:YoutuModel(YoutuConfig 模型)
- Zamba2Config 配置类:Zamba2Model(Zamba2Config 模型)
- ZambaConfig 配置类:ZambaModel(ZambaConfig 模型)
- ZayaConfig 配置类:ZayaModel(ZayaConfig 模型)
- xLSTMConfig 配置类:xLSTMModel(xLSTMConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库的某个基础模型类。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库的某个基础模型类。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- afmoe — AfmoeModel(AfmoeConfig 模型)
- aimv2 — Aimv2Model(Aimv2Config 模型)
- aimv2_vision_model — Aimv2VisionModel(Aimv2VisionConfig 模型)
- albert — AlbertModel(AlbertConfig 模型)
- align — AlignModel(AlignConfig 模型)
- altclip — AltCLIPModel(AltCLIPConfig 模型)
- apertus — ApertusModel(ApertusConfig 模型)
- arcee — ArceeModel(ArceeConfig 模型)
- aria — AriaModel(AriaConfig 模型)
- aria_text — AriaTextModel(AriaTextConfig 模型)
- audio-spectrogram-transformer — ASTModel(ASTConfig 模型)
- audioflamingo3 — AudioFlamingo3Model(AudioFlamingo3Config 模型)
- audioflamingo3_encoder — AudioFlamingo3Encoder(AudioFlamingo3EncoderConfig 模型)
- autoformer — AutoformerModel(AutoformerConfig 模型)
- axk1 — AXK1Model(AXK1Config 模型)
- axk2 — AXK2Model(AXK2Config 模型)
- aya_vision — AyaVisionModel(AyaVisionConfig 模型)
- bailing_hybrid — BailingHybridModel(BailingHybridConfig 模型)
- bamba — BambaModel(BambaConfig 模型)
- bark — BarkModel(BarkConfig 模型)
- bart — BartModel(BartConfig 模型)
- beam — BeamModel(BeamConfig 模型)
- beit — BeitModel(BeitConfig 模型)
- bert — BertModel(BertConfig 模型)
- bert-generation — BertGenerationEncoder(BertGenerationConfig 模型)
- big_bird — BigBirdModel(BigBirdConfig 模型)
- bigbird_pegasus — BigBirdPegasusModel(BigBirdPegasusConfig 模型)
- biogpt — BioGptModel(BioGptConfig 模型)
- bit — BitModel(BitConfig 模型)
- bitnet — BitNetModel(BitNetConfig 模型)
- blenderbot — BlenderbotModel(BlenderbotConfig 模型)
- blenderbot-small — BlenderbotSmallModel(BlenderbotSmallConfig 模型)
- blip — BlipModel(BlipConfig 模型)
- blip-2 — Blip2Model(Blip2Config 模型)
- blip_2_qformer — Blip2QFormerModel(Blip2QFormerConfig 模型)
- bloom — BloomModel(BloomConfig 模型)
- blt — BltModel(BltConfig 模型)
- bridgetower — BridgeTowerModel(BridgeTowerConfig 模型)
- bros — BrosModel(BrosConfig 模型)
- camembert — CamembertModel(CamembertConfig 模型)
- canary — CanaryModel(CanaryConfig 模型)
- canine — CanineModel(CanineConfig 模型)
- chameleon — ChameleonModel(ChameleonConfig 模型)
- chinese_clip — ChineseCLIPModel(ChineseCLIPConfig 模型)
- chinese_clip_vision_model — ChineseCLIPVisionModel(ChineseCLIPVisionConfig 模型)
- clap — ClapModel(ClapConfig 模型)
- clip — CLIPModel(CLIPConfig 模型)
- clip_text_model — CLIPTextModel(CLIPTextConfig 模型)
- clip_vision_model — CLIPVisionModel(CLIPVisionConfig 模型)
- clipseg — CLIPSegModel(CLIPSegConfig 模型)
- clvp — ClvpModelForConditionalGeneration(ClvpConfig 模型)
- codegen — CodeGenModel(CodeGenConfig 模型)
- cohere — CohereModel(CohereConfig 模型)
- cohere2 — Cohere2Model(Cohere2Config 模型)
- cohere2_moe — Cohere2MoeModel(Cohere2MoeConfig 模型)
- cohere2_vision — Cohere2VisionModel(Cohere2VisionConfig 模型)
- cohere_asr — CohereAsrModel(CohereAsrConfig 模型)
- cohere_compass — CohereCompassModel(CohereCompassConfig 模型)
- cohere_compass_text — CohereCompassTextModel(CohereCompassTextConfig 模型)
- cohere_compass_vision — CohereCompassVisionModel(CohereCompassVisionConfig 模型)
- conditional_detr — ConditionalDetrModel(ConditionalDetrConfig 模型)
- convbert — ConvBertModel(ConvBertConfig 模型)
- convnext — ConvNextModel(ConvNextConfig 模型)
- convnextv2 — ConvNextV2Model(ConvNextV2Config 模型)
- cosmos3_edge — Cosmos3EdgeModel(Cosmos3EdgeConfig 模型)
- cosmos3_edge_text — Cosmos3EdgeTextModel(Cosmos3EdgeTextConfig 模型)
- cosmos3_edge_vision — Cosmos3EdgeVisionModel(Cosmos3EdgeVisionConfig 模型)
- cosmos3_omni — Cosmos3OmniModel(Cosmos3OmniConfig 模型)
- cpmant — CpmAntModel(CpmAntConfig 模型)
- csm — CsmForConditionalGeneration(CsmConfig 模型)
- ctrl — CTRLModel(CTRLConfig 模型)
- cvt — CvtModel(CvtConfig 模型)
- cwm — CwmModel(CwmConfig 模型)
- d_fine — DFineModel(DFineConfig 模型)
- dab-detr — DabDetrModel(DabDetrConfig 模型)
- dac — DacModel(DacConfig 模型)
- data2vec-audio — Data2VecAudioModel(Data2VecAudioConfig 模型)
- data2vec-text — Data2VecTextModel(Data2VecTextConfig 模型)
- data2vec-vision — Data2VecVisionModel(Data2VecVisionConfig 模型)
- dbrx — DbrxModel(DbrxConfig 模型)
- deberta — DebertaModel(DebertaConfig 模型)
- deberta-v2 — DebertaV2Model(DebertaV2Config 模型)
- decision_transformer — DecisionTransformerModel(DecisionTransformerConfig 模型)
- deepseek_ocr2 — DeepseekOcr2Model(DeepseekOcr2Config 模型)
- deepseek_v2 — DeepseekV2Model(DeepseekV2Config 模型)
- deepseek_v3 — DeepseekV3Model(DeepseekV3Config 模型)
- deepseek_v32 — DeepseekV32Model(DeepseekV32Config 模型)
- deepseek_v4 — DeepseekV4Model(DeepseekV4Config 模型)
- deepseek_vl — DeepseekVLModel(DeepseekVLConfig 模型)
- deepseek_vl_hybrid — DeepseekVLHybridModel(DeepseekVLHybridConfig 模型)
- deformable_detr — DeformableDetrModel(DeformableDetrConfig 模型)
- deimv2 — Deimv2Model(Deimv2Config 模型)
- deit — DeiTModel(DeiTConfig 模型)
- depth_pro — DepthProModel(DepthProConfig 模型)
- detr — DetrModel(DetrConfig 模型)
- dia — DiaModel(DiaConfig 模型)
- diffllama — DiffLlamaModel(DiffLlamaConfig 模型)
- diffusion_gemma — DiffusionGemmaModel(DiffusionGemmaConfig 模型)
- dinat — DinatModel(DinatConfig 模型)
- dinov2 — Dinov2Model(Dinov2Config 模型)
- dinov2_with_registers — Dinov2WithRegistersModel(Dinov2WithRegistersConfig 模型)
- dinov3_convnext — DINOv3ConvNextModel(DINOv3ConvNextConfig 模型)
- dinov3_vit — DINOv3ViTModel(DINOv3ViTConfig 模型)
- distilbert — DistilBertModel(DistilBertConfig 模型)
- doge — DogeModel(DogeConfig 模型)
- donut-swin — DonutSwinModel(DonutSwinConfig 模型)
- dots1 — Dots1Model(Dots1Config 模型)
- dpr — DPRQuestionEncoder(DPRConfig 模型)
- dpt — DPTModel(DPTConfig 模型)
- edgetam — EdgeTamModel(EdgeTamConfig 模型)
- edgetam_video — EdgeTamVideoModel(EdgeTamVideoConfig 模型)
- edgetam_vision_model — EdgeTamVisionModel(EdgeTamVisionConfig 模型)
- efficientloftr — EfficientLoFTRModel(EfficientLoFTRConfig 模型)
- efficientnet — EfficientNetModel(EfficientNetConfig 模型)
- electra — ElectraModel(ElectraConfig 模型)
- embedding_gemma2 — EmbeddingGemma2Model(EmbeddingGemma2Config 模型)
- embedding_gemma2_text — EmbeddingGemma2TextModel(EmbeddingGemma2TextConfig 模型)
- emu3 — Emu3Model(Emu3Config 模型)
- encodec — EncodecModel(EncodecConfig 模型)
- ernie — ErnieModel(ErnieConfig 模型)
- ernie4_5 — Ernie4_5Model(Ernie4_5Config 模型)
- ernie4_5_moe — Ernie4_5_MoeModel(Ernie4_5_MoeConfig 模型)
- ernie4_5_vl_moe — Ernie4_5_VLMoeModel(Ernie4_5_VLMoeConfig 模型)
- esm — EsmModel(EsmConfig 模型)
- esmc — EsmcModel(EsmcConfig 模型)
- eurobert — EuroBertModel(EuroBertConfig 模型)
- evolla — EvollaModel(EvollaConfig 模型)
- exaone4 — Exaone4Model(Exaone4Config 模型)
- exaone4_5 — Exaone4_5_Model(Exaone4_5_Config 模型)
- exaone4_5_vision — Exaone4_5_VisionModel(Exaone4_5_VisionConfig 模型)
- exaone_moe — ExaoneMoeModel(ExaoneMoeConfig 模型)
- falcon — FalconModel(FalconConfig 模型)
- falcon_h1 — FalconH1Model(FalconH1Config 模型)
- falcon_mamba — FalconMambaModel(FalconMambaConfig 模型)
- fast_vlm — FastVlmModel(FastVlmConfig 模型)
- fastspeech2_conformer — FastSpeech2ConformerModel(FastSpeech2ConformerConfig 模型)
- fastspeech2_conformer_with_hifigan — FastSpeech2ConformerWithHifiGan(FastSpeech2ConformerWithHifiGanConfig 模型)
- flaubert — FlaubertModel(FlaubertConfig 模型)
- flava — FlavaModel(FlavaConfig 模型)
- flex_olmo — FlexOlmoModel(FlexOlmoConfig 模型)
- flint — FlintModel(FlintConfig 模型)
- florence2 — Florence2Model(Florence2Config 模型)
- fnet — FNetModel(FNetConfig 模型)
- focalnet — FocalNetModel(FocalNetConfig 模型)
- fsmt — FSMTModel(FSMTConfig 模型)
- fun_asr_nano — FunAsrNanoModel(FunAsrNanoConfig 模型)
- fun_asr_nano_encoder — FunAsrNanoEncoder(FunAsrNanoEncoderConfig 模型)
- funnel — FunnelModel 或 FunnelBaseModel(FunnelConfig 模型)
- fuyu — FuyuModel(FuyuConfig 模型)
- gemma — GemmaModel(GemmaConfig 模型)
- gemma2 — Gemma2Model(Gemma2Config 模型)
- gemma3 — Gemma3Model(Gemma3Config 模型)
- gemma3_text — Gemma3TextModel(Gemma3TextConfig 模型)
- gemma3n — Gemma3nModel(Gemma3nConfig 模型)
- gemma3n_audio —
Gemma3nAudioEncoder(Gemma3nAudioConfig 模型) - gemma3n_text — Gemma3nTextModel(Gemma3nTextConfig 模型)
- gemma3n_vision — TimmWrapperModel(Gemma3nVisionConfig 模型)
- gemma4 — Gemma4Model(Gemma4Config 模型)
- gemma4_audio — Gemma4AudioModel(Gemma4AudioConfig 模型)
- gemma4_text — Gemma4TextModel(Gemma4TextConfig 模型)
- gemma4_unified — Gemma4UnifiedModel(Gemma4UnifiedConfig 模型)
- gemma4_unified_text — Gemma4UnifiedTextModel(Gemma4UnifiedTextConfig 模型)
- gemma4_vision — Gemma4VisionModel(Gemma4VisionConfig 模型)
- git — GitModel(GitConfig 模型)
- glm — GlmModel(GlmConfig 模型)
- glm4 — Glm4Model(Glm4Config 模型)
- glm46v — Glm46VModel(Glm46VConfig 模型)
- glm4_moe — Glm4MoeModel(Glm4MoeConfig 模型)
- glm4_moe_lite — Glm4MoeLiteModel(Glm4MoeLiteConfig 模型)
- glm4v — Glm4vModel(Glm4vConfig 模型)
- glm4v_moe — Glm4vMoeModel(Glm4vMoeConfig 模型)
- glm4v_moe_text — Glm4vMoeTextModel(Glm4vMoeTextConfig 模型)
- glm4v_moe_vision — Glm4vMoeVisionModel(Glm4vMoeVisionConfig 模型)
- glm4v_text — Glm4vTextModel(Glm4vTextConfig 模型)
- glm4v_vision — Glm4vVisionModel(Glm4vVisionConfig 模型)
- glm5_next — Glm5NextModel(Glm5NextConfig 模型)
- glm5_next_text — Glm5NextTextModel(Glm5NextTextConfig 模型)
- glm5_next_vision — Glm5NextVisionModel(Glm5NextVisionConfig 模型)
- glm_image — GlmImageModel(GlmImageConfig 模型)
- glm_image_text — GlmImageTextModel(GlmImageTextConfig 模型)
- glm_image_vision — GlmImageVisionModel(GlmImageVisionConfig 模型)
- glm_image_vqmodel — GlmImageVQVAE(GlmImageVQVAEConfig 模型)
- glm_moe_dsa — GlmMoeDsaModel(GlmMoeDsaConfig 模型)
- glm_ocr — GlmOcrModel(GlmOcrConfig 模型)
- glm_ocr_text — GlmOcrTextModel(GlmOcrTextConfig 模型)
- glm_ocr_vision — GlmOcrVisionModel(GlmOcrVisionConfig 模型)
- glmasr — GlmAsrModel(GlmAsrConfig 模型)
- glmasr_encoder — GlmAsrEncoder(GlmAsrEncoderConfig 模型)
- glmga — Glm46VModel(GlmgaConfig 模型)
- glpn — GLPNModel(GLPNConfig 模型)
- got_ocr2 — GotOcr2Model(GotOcr2Config 模型)
- gpt-sw3 — GPT2Model(GPT2Config 模型)
- gpt2 — GPT2Model(GPT2Config 模型)
- gpt_bigcode — GPTBigCodeModel(GPTBigCodeConfig 模型)
- gpt_neo — GPTNeoModel(GPTNeoConfig 模型)
- gpt_neox — GPTNeoXModel(GPTNeoXConfig 模型)
- gpt_neox_japanese — GPTNeoXJapaneseModel(GPTNeoXJapaneseConfig 模型)
- gpt_oss — GptOssModel(GptOssConfig 模型)
- gptj — GPTJModel(GPTJConfig 模型)
- gradium_phonon_tts — GradiumPhononTTSModel(GradiumPhononTTSConfig 模型)
- granite — GraniteModel(GraniteConfig 模型)
- granite4_vision — Granite4VisionModel(Granite4VisionConfig 模型)
- granite_speech — GraniteSpeechModel(GraniteSpeechConfig 模型)
- granite_speech5_ctc — GraniteSpeech5ForCTC(GraniteSpeech5CTCConfig 模型)
- granite_speech5_encoder — GraniteSpeech5Encoder(GraniteSpeech5EncoderConfig 模型)
- granite_speech_plus — GraniteSpeechPlusModel(GraniteSpeechPlusConfig 模型)
- granite_swa — GraniteSWAModel(GraniteSWAConfig 模型)
- granitemoe — GraniteMoeModel(GraniteMoeConfig 模型)
- granitemoe_swa — GraniteMoeSWAModel(GraniteMoeSWAConfig 模型)
- granitemoehybrid — GraniteMoeHybridModel(GraniteMoeHybridConfig 模型)
- granitemoeshared — GraniteMoeSharedModel(GraniteMoeSharedConfig 模型)
- grounding-dino — GroundingDinoModel(GroundingDinoConfig 模型)
- groupvit — GroupViTModel(GroupViTConfig 模型)
- gte — GteModel(GteConfig 模型)
- helium — HeliumModel(HeliumConfig 模型)
- hgnet_v2 — HGNetV2Backbone(HGNetV2Config 模型)
- hiera — HieraModel(HieraConfig 模型)
- higgs_audio_v2 — HiggsAudioV2ForConditionalGeneration(HiggsAudioV2Config 模型)
- higgs_audio_v2_tokenizer — HiggsAudioV2TokenizerModel(HiggsAudioV2TokenizerConfig 模型)
- hrm_text — HrmTextModel(HrmTextConfig 模型)
- hubert — HubertModel(HubertConfig 模型)
- hunyuan_v1_dense — HunYuanDenseV1Model(HunYuanDenseV1Config 模型)
- hunyuan_v1_moe — HunYuanMoEV1Model(HunYuanMoEV1Config 模型)
- hunyuan_vl — HunYuanVLModel(HunYuanVLConfig 模型)
- hunyuan_vl_text — HunYuanVLTextModel(HunYuanVLTextConfig 模型)
- hunyuan_vl_vision — HunYuanVLVisionTransformer(HunYuanVLVisionConfig 模型)
- hy_v3 — HYV3Model(HYV3Config 模型)
- hy_v4 — HYV4Model(HYV4Config 模型)
- hyperclovax — HyperCLOVAXModel(HyperCLOVAXConfig 模型)
- hyperclovax_vision_v2 — HyperCLOVAXVisionV2Model(HyperCLOVAXVisionV2Config 模型)
- ibert — IBertModel(IBertConfig 模型)
- idefics — IdeficsModel(IdeficsConfig 模型)
- idefics2 — Idefics2Model(Idefics2Config 模型)
- idefics3 — Idefics3Model(Idefics3Config 模型)
- idefics3_vision — Idefics3VisionTransformer(Idefics3VisionConfig 模型)
- ijepa — IJepaModel(IJepaConfig 模型)
- imagegpt — ImageGPTModel(ImageGPTConfig 模型)
- informer — InformerModel(InformerConfig 模型)
- inkling_mm_model — InklingModel(InklingConfig 模型)
- inkling_text — InklingTextModel(InklingTextConfig 模型)
- instructblip — InstructBlipModel(InstructBlipConfig 模型)
- instructblipvideo — InstructBlipVideoModel(InstructBlipVideoConfig 模型)
- internvl — InternVLModel(InternVLConfig 模型)
- internvl_vision — InternVLVisionModel(InternVLVisionConfig 模型)
- jais2 — Jais2Model(Jais2Config 模型)
- jamba — JambaModel(JambaConfig 模型)
- janus — JanusModel(JanusConfig 模型)
- jetmoe — JetMoeModel(JetMoeConfig 模型)
- jina_embeddings_v3 — JinaEmbeddingsV3Model(JinaEmbeddingsV3Config 模型)
- kimi_k25 — Kimi_K25Model(Kimi_K25Config 模型)
- kimi_k25_vision — Kimi_K25VisionModel(Kimi_K25VisionConfig 模型)
- kimi_linear — KimiLinearModel(KimiLinearConfig 模型)
- kolibri1 — Kolibri1Model(Kolibri1Config 模型)
- kosmos-2 — Kosmos2Model(Kosmos2Config 模型)
- kosmos-2.5 — Kosmos2_5Model(Kosmos2_5Config 模型)
- kyutai_speech_to_text — KyutaiSpeechToTextModel(KyutaiSpeechToTextConfig 模型)
- laguna — LagunaModel(LagunaConfig 模型)
- lasr_ctc — LasrForCTC(LasrCTCConfig 模型)
- lasr_encoder — LasrEncoder(LasrEncoderConfig 模型)
- layoutlm — LayoutLMModel(LayoutLMConfig 模型)
- layoutlmv2 — LayoutLMv2Model(LayoutLMv2Config 模型)
- layoutlmv3 — LayoutLMv3Model(LayoutLMv3Config 模型)
- led — LEDModel(LEDConfig 模型)
- levit — LevitModel(LevitConfig 模型)
- lfm2 — Lfm2Model(Lfm2Config 模型)
- lfm2_moe — Lfm2MoeModel(Lfm2MoeConfig 模型)
- lfm2_vl — Lfm2VlModel(Lfm2VlConfig 模型)
- lfm3 — Lfm3Model(Lfm3Config 模型)
- lightglue — LightGlueForKeypointMatching(LightGlueConfig 模型)
- lighton_ocr — LightOnOcrModel(LightOnOcrConfig 模型)
- lilt — LiltModel(LiltConfig 模型)
- llama — LlamaModel(LlamaConfig 模型)
- llama4 — Llama4ForConditionalGeneration(Llama4Config 模型)
- llama4_text — Llama4TextModel(Llama4TextConfig 模型)
- llava — LlavaModel(LlavaConfig 模型)
- llava_next — LlavaNextModel(LlavaNextConfig 模型)
- llava_next_video — LlavaNextVideoModel(LlavaNextVideoConfig 模型)
- llava_onevision — LlavaOnevisionModel(LlavaOnevisionConfig 模型)
- longcat_flash — LongcatFlashModel(LongcatFlashConfig 模型)
- longformer — LongformerModel(LongformerConfig 模型)
- longt5 — LongT5Model(LongT5Config 模型)
- luke — LukeModel(LukeConfig 模型)
- lw_detr — LwDetrModel(LwDetrConfig 模型)
- lxmert — LxmertModel(LxmertConfig 模型)
- m2m_100 — M2M100Model(M2M100Config 模型)
- mamba — MambaModel(MambaConfig 模型)
- mamba2 — Mamba2Model(Mamba2Config 模型)
- marian — MarianModel(MarianConfig 模型)
- markuplm — MarkupLMModel(MarkupLMConfig 模型)
- mask2former — Mask2FormerModel(Mask2FormerConfig 模型)
- maskformer — MaskFormerModel(MaskFormerConfig 模型)
- maskformer-swin —
MaskFormerSwinModel(MaskFormerSwinConfig 模型) - mbart — MBartModel(MBartConfig 模型)
- megatron-bert — MegatronBertModel(MegatronBertConfig 模型)
- mellum — MellumModel(MellumConfig 模型)
- metaclip_2 — MetaClip2Model(MetaClip2Config 模型)
- mgp-str — MgpstrForSceneTextRecognition(MgpstrConfig 模型)
- mimi — MimiModel(MimiConfig 模型)
- mimi_decoder — MimiDecoderModel(MimiDecoderConfig 模型)
- mimi_encoder — MimiEncoderModel(MimiEncoderConfig 模型)
- mimo_v2_flash — MiMoV2FlashModel(MiMoV2FlashConfig 模型)
- minicpm3 — MiniCPM3Model(MiniCPM3Config 模型)
- minicpm_ocr — MiniCPMOcrModel(MiniCPMOcrConfig 模型)
- minicpm_ocr_vision — MiniCPMOcrVisionModel(MiniCPMOcrVisionConfig 模型)
- minicpmv4_6 — MiniCPMV4_6Model(MiniCPMV4_6Config 模型)
- minicpmv4_7 — MiniCPMV4_7Model(MiniCPMV4_7Config 模型)
- minicpmv4_7_vision — MiniCPMV4_7VisionModel(MiniCPMV4_7VisionConfig 模型)
- minimax — MiniMaxModel(MiniMaxConfig 模型)
- minimax_m2 — MiniMaxM2Model(MiniMaxM2Config 模型)
- minimax_m3_vl — MiniMaxM3VLModel(MiniMaxM3VLConfig 模型)
- minimax_m3_vl_text — MiniMaxM3VLTextModel(MiniMaxM3VLTextConfig 模型)
- ministral — MinistralModel(MinistralConfig 模型)
- ministral3 — Ministral3Model(Ministral3Config 模型)
- mistral — MistralModel(MistralConfig 模型)
- mistral3 — Mistral3Model(Mistral3Config 模型)
- mistral4 — Mistral4Model(Mistral4Config 模型)
- mistral_large4 — MistralLarge4Model(MistralLarge4Config 模型)
- mistral_large4_text — MistralLarge4TextModel(MistralLarge4TextConfig 模型)
- mixtral — MixtralModel(MixtralConfig 模型)
- mlcd — MLCDVisionModel(MLCDVisionConfig 模型)
- mlcd_vision_model — MLCDVisionModel(MLCDVisionConfig 模型)
- mllama — MllamaModel(MllamaConfig 模型)
- mm-grounding-dino — MMGroundingDinoModel(MMGroundingDinoConfig 模型)
- mobilebert — MobileBertModel(MobileBertConfig 模型)
- mobilenet_v1 — MobileNetV1Model(MobileNetV1Config 模型)
- mobilenet_v2 — MobileNetV2Model(MobileNetV2Config 模型)
- mobilevit — MobileViTModel(MobileViTConfig 模型)
- mobilevitv2 — MobileViTV2Model(MobileViTV2Config 模型)
- modernbert — ModernBertModel(ModernBertConfig 模型)
- modernbert-decoder — ModernBertDecoderModel(ModernBertDecoderConfig 模型)
- modernvbert — ModernVBertModel(ModernVBertConfig 模型)
- molmo2 — Molmo2Model(Molmo2Config 模型)
- molmo2_text — Molmo2TextModel(Molmo2TextConfig 模型)
- moonshine — MoonshineModel(MoonshineConfig 模型)
- moonshine_streaming — MoonshineStreamingModel(MoonshineStreamingConfig 模型)
- moshi — MoshiModel(MoshiConfig 模型)
- moss_transcribe_diarize — MossTranscribeDiarizeModel(MossTranscribeDiarizeConfig 模型)
- moss_transcribe_diarize_audio — MossTranscribeDiarizeAudioModel(MossTranscribeDiarizeAudioConfig 模型)
- mpnet — MPNetModel(MPNetConfig 模型)
- mpt — MptModel(MptConfig 模型)
- mra — MraModel(MraConfig 模型)
- mt5 — MT5Model(MT5Config 模型)
- muse_glimmer — MuseGlimmerModel(MuseGlimmerConfig 模型)
- muse_glimmer_assistant — MuseGlimmerAssistantModel(MuseGlimmerAssistantConfig 模型)
- muse_glimmer_text — MuseGlimmerTextModel(MuseGlimmerTextConfig 模型)
- muse_glimmer_vision — MuseGlimmerVisionModel(MuseGlimmerVisionConfig 模型)
- muse_spark — MuseSparkModel(MuseSparkConfig 模型)
- muse_spark_audio — MuseSparkAudioModel(MuseSparkAudioConfig 模型)
- muse_spark_text — MuseSparkTextModel(MuseSparkTextConfig 模型)
- muse_spark_vision — MuseSparkVisionModel(MuseSparkVisionConfig 模型)
- musicflamingo — MusicFlamingoModel(MusicFlamingoConfig 模型)
- musicgen — MusicgenModel(MusicgenConfig 模型)
- musicgen_melody — MusicgenMelodyModel(MusicgenMelodyConfig 模型)
- mvp — MvpModel(MvpConfig 模型)
- nanochat — NanoChatModel(NanoChatConfig 模型)
- nemo_speechlm — Nemotron3_5TranscribeModel(Nemotron3_5TranscribeConfig 模型)
- nemotron — NemotronModel(NemotronConfig 模型)
- nemotron3_5_asr — Nemotron3_5AsrForRNNT(Nemotron3_5AsrConfig 模型)
- nemotron3_5_transcribe_asr_audio — Nemotron3_5TranscribeAsrAudioModel(Nemotron3_5TranscribeAsrAudioConfig 模型)
- nemotron3_5_transcribe_audio — Nemotron3_5TranscribeAudioModel(Nemotron3_5TranscribeAudioConfig 模型)
- nemotron3_5_transcribe_word_timestamp — Nemotron3_5TranscribeWordTimestampModel(Nemotron3_5TranscribeWordTimestampConfig 模型)
- nemotron3_diarization — Nemotron3DiarizationModel(Nemotron3DiarizationConfig 模型)
- nemotron3_diarization_audio — Nemotron3DiarizationAudioModel(Nemotron3DiarizationAudioConfig 模型)
- nemotron_asr_streaming — NemotronAsrStreamingForRNNT(NemotronAsrStreamingConfig 模型)
- nemotron_asr_streaming_encoder — NemotronAsrStreamingEncoder(NemotronAsrStreamingEncoderConfig 模型)
- nemotron_h — NemotronHModel(NemotronHConfig 模型)
- neomme — NeoMMEModel(NeoMMEConfig 模型)
- neucodec — NeuCodecModel(NeuCodecConfig 模型)
- nllb-moe — NllbMoeModel(NllbMoeConfig 模型)
- nomic_bert — NomicBertModel(NomicBertConfig 模型)
- nystromformer — NystromformerModel(NystromformerConfig 模型)
- olmo — OlmoModel(OlmoConfig 模型)
- olmo2 — Olmo2Model(Olmo2Config 模型)
- olmo3 — Olmo3Model(Olmo3Config 模型)
- olmo_hybrid — OlmoHybridModel(OlmoHybridConfig 模型)
- olmoe — OlmoeModel(OlmoeConfig 模型)
- omdet-turbo — OmDetTurboForObjectDetection(OmDetTurboConfig 模型)
- oneformer — OneFormerModel(OneFormerConfig 模型)
- openai-gpt — OpenAIGPTModel(OpenAIGPTConfig 模型)
- openai_privacy_filter — OpenAIPrivacyFilterModel(OpenAIPrivacyFilterConfig 模型)
- opt — OPTModel(OPTConfig 模型)
- ovis2 — Ovis2Model(Ovis2Config 模型)
- owlv2 — Owlv2Model(Owlv2Config 模型)
- owlvit — OwlViTModel(OwlViTConfig 模型)
- paddleocr_vl — PaddleOCRVLModel(PaddleOCRVLConfig 模型)
- paligemma — PaliGemmaModel(PaliGemmaConfig 模型)
- parakeet_ctc — ParakeetForCTC(ParakeetCTCConfig 模型)
- parakeet_encoder — ParakeetEncoder(ParakeetEncoderConfig 模型)
- parakeet_rnnt — ParakeetForRNNT(ParakeetRNNTConfig 模型)
- parakeet_tdt — ParakeetForTDT(ParakeetTDTConfig 模型)
- patchtsmixer — PatchTSMixerModel(PatchTSMixerConfig 模型)
- patchtst — PatchTSTModel(PatchTSTConfig 模型)
- pe_audio — PeAudioModel(PeAudioConfig 模型)
- pe_audio_encoder — PeAudioEncoder(PeAudioEncoderConfig 模型)
- pe_audio_video — PeAudioVideoModel(PeAudioVideoConfig 模型)
- pe_audio_video_encoder — PeAudioVideoEncoder(PeAudioVideoEncoderConfig 模型)
- pe_video — PeVideoModel(PeVideoConfig 模型)
- pe_video_encoder — PeVideoEncoder(PeVideoEncoderConfig 模型)
- pegasus — PegasusModel(PegasusConfig 模型)
- pegasus_x — PegasusXModel(PegasusXConfig 模型)
- perceiver — PerceiverModel(PerceiverConfig 模型)
- perception_lm — PerceptionLMModel(PerceptionLMConfig 模型)
- persimmon — PersimmonModel(PersimmonConfig 模型)
- phi — PhiModel(PhiConfig 模型)
- phi3 — Phi3Model(Phi3Config 模型)
- phi4_multimodal — Phi4MultimodalModel(Phi4MultimodalConfig 模型)
- phimoe — PhimoeModel(PhimoeConfig 模型)
- pi0 — PI0Model(PI0Config 模型)
- pixio — PixioModel(PixioConfig 模型)
- pixtral — PixtralVisionModel(PixtralVisionConfig 模型)
- plbart — PLBartModel(PLBartConfig 模型)
- pocket_tts — PocketTTSModel(PocketTTSConfig 模型)
- pocket_tts_audio_tokenizer — PocketTTSAudioTokenizerModel(PocketTTSAudioTokenizerConfig 模型)
- pocket_tts_audio_tokenizer_decoder — PocketTTSAudioTokenizerDecoderModel(PocketTTSAudioTokenizerDecoderConfig 模型)
- pocket_tts_audio_tokenizer_encoder — PocketTTSAudioTokenizerEncoderModel(PocketTTSAudioTokenizerEncoderConfig 模型)
- poolformer — PoolFormerModel(PoolFormerConfig 模型)
- pp_doclayout_v3 — PPDocLayoutV3Model(PPDocLayoutV3Config 模型)
- pp_doclayout_v4 — PPDocLayoutV4Model(PPDocLayoutV4Config 模型)
- pp_ocrv5_mobile_rec — PPOCRV5MobileRecModel(PPOCRV5MobileRecConfig 模型)
- pp_ocrv5_server_rec — PPOCRV5ServerRecModel(PPOCRV5ServerRecConfig 模型)
- pp_ocrv6_medium_det — PPOCRV6MediumDetModel(PPOCRV6MediumDetConfig 模型)
- pp_ocrv6_small_det — PPOCRV6SmallDetModel(PPOCRV6SmallDetConfig 模型)
- pp_ocrv6_small_rec — PPOCRV6SmallRecModel(PPOCRV6SmallRecConfig 模型)
- pp_ocrv6_tiny_rec — PPOCRV6TinyRecModel(PPOCRV6TinyRecConfig 模型)
- prophetnet — ProphetNetModel(ProphetNetConfig 模型)
- pvt — PvtModel(PvtConfig 模型)
- pvt_v2 — PvtV2Model(PvtV2Config 模型)
- qianfan_ocr — QianfanOCRModel(QianfanOCRConfig 模型)
- qianfan_ocr_vision — QianfanOCRVisionModel(QianfanOCRVisionConfig 模型)
- qwen2 — Qwen2Model(Qwen2Config 模型)
- qwen2_5_omni_thinker — Qwen2_5OmniThinkerModel(Qwen2_5OmniThinkerConfig 模型)
- qwen2_5_vl — Qwen2_5_VLModel(Qwen2_5_VLConfig 模型)
- qwen2_5_vl_text — Qwen2_5_VLTextModel(Qwen2_5_VLTextConfig 模型)
- qwen2_5_vl_vision — Qwen2_5_VisionTransformerPretrainedModel(Qwen2_5_VLVisionConfig 模型)
- qwen2_audio — Qwen2AudioModel(Qwen2AudioConfig 模型)
- qwen2_audio_encoder — Qwen2AudioEncoder(Qwen2AudioEncoderConfig 模型)
- qwen2_moe — Qwen2MoeModel(Qwen2MoeConfig 模型)
- qwen2_vl — Qwen2VLModel(Qwen2VLConfig 模型)
- qwen2_vl_text — Qwen2VLTextModel(Qwen2VLTextConfig 模型)
- qwen3 — Qwen3Model(Qwen3Config 模型)
- qwen3_5 — Qwen3_5Model(Qwen3_5Config 模型)
- qwen3_5_moe — Qwen3_5MoeModel(Qwen3_5MoeConfig 模型)
- qwen3_5_moe_text — Qwen3_5MoeTextModel(Qwen3_5MoeTextConfig 模型)
- qwen3_5_moe_vision — Qwen3_5MoeVisionModel(Qwen3_5MoeVisionConfig 模型)
- qwen3_5_text — Qwen3_5TextModel(Qwen3_5TextConfig 模型)
- qwen3_5_vision — Qwen3_5VisionModel(Qwen3_5VisionConfig 模型)
- qwen3_asr — Qwen3ASRModel(Qwen3ASRConfig 模型)
- qwen3_asr_encoder — Qwen3ASREncoder(Qwen3ASREncoderConfig 模型)
- qwen3_moe — Qwen3MoeModel(Qwen3MoeConfig 模型)
- qwen3_next — Qwen3NextModel(Qwen3NextConfig 模型)
- qwen3_omni_moe_thinker — Qwen3OmniMoeThinkerModel(Qwen3OmniMoeThinkerConfig 模型)
- qwen3_vl — Qwen3VLModel(Qwen3VLConfig 模型)
- qwen3_vl_moe — Qwen3VLMoeModel(Qwen3VLMoeConfig 模型)
- qwen3_vl_moe_text — Qwen3VLMoeTextModel(Qwen3VLMoeTextConfig 模型)
- qwen3_vl_moe_vision — Qwen3VLMoeVisionModel(Qwen3VLMoeVisionConfig 模型)
- qwen3_vl_text — Qwen3VLTextModel(Qwen3VLTextConfig 模型)
- qwen3_vl_vision — Qwen3VLVisionModel(Qwen3VLVisionConfig 模型)
- qwen4_exp — Qwen4ExpModel(Qwen4ExpConfig 模型)
- qwen4_exp_text — Qwen4ExpTextModel(Qwen4ExpTextConfig 模型)
- qwen4_exp_vision — Qwen4ExpVisionModel(Qwen4ExpVisionConfig 模型)
- radio — RadioModel(RadioConfig 模型)
- recurrent_gemma — RecurrentGemmaModel(RecurrentGemmaConfig 模型)
- reformer — ReformerModel(ReformerConfig 模型)
- regnet — RegNetModel(RegNetConfig 模型)
- rembert — RemBertModel(RemBertConfig 模型)
- resnet — ResNetModel(ResNetConfig 模型)
- rf_detr — RfDetrModel(RfDetrConfig 模型)
- roberta — RobertaModel(RobertaConfig 模型)
- roberta-prelayernorm — RobertaPreLayerNormModel(RobertaPreLayerNormConfig 模型)
- roc_bert — RoCBertModel(RoCBertConfig 模型)
- roformer — RoFormerModel(RoFormerConfig 模型)
- rt_detr — RTDetrModel(RTDetrConfig 模型)
- rt_detr_v2 — RTDetrV2Model(RTDetrV2Config 模型)
- rwkv — RwkvModel(RwkvConfig 模型)
- sam — SamModel(SamConfig 模型)
- sam2 — Sam2Model(Sam2Config 模型)
- sam2_hiera_det_model — Sam2HieraDetModel(Sam2HieraDetConfig 模型)
- sam2_video — Sam2VideoModel(Sam2VideoConfig 模型)
- sam2_vision_model — Sam2VisionModel(Sam2VisionConfig 模型)
- sam3 — Sam3Model(Sam3Config 模型)
- sam3_lite_text — Sam3LiteTextModel(Sam3LiteTextConfig 模型)
- sam3_lite_text_text_model — Sam3LiteTextTextModel(Sam3LiteTextTextConfig 模型)
- sam3_tracker — Sam3TrackerModel(Sam3TrackerConfig 模型)
- sam3_tracker_video — Sam3TrackerVideoModel(Sam3TrackerVideoConfig 模型)
- sam3_video — Sam3VideoModel(Sam3VideoConfig 模型)
- sam3_vision_model — Sam3VisionModel(Sam3VisionConfig 模型)
- sam3_vit_model — Sam3ViTModel(Sam3ViTConfig 模型)
- sam_hq — SamHQModel(SamHQConfig 模型)
- sam_hq_vision_model — SamHQVisionModel(SamHQVisionConfig 模型)
- sam_vision_model — SamVisionModel(SamVisionConfig 模型)
- sapiens2 — Sapiens2Model(Sapiens2Config 模型)
- seamless_m4t — SeamlessM4TModel(SeamlessM4TConfig 模型)
- seamless_m4t_v2 — SeamlessM4Tv2Model(SeamlessM4Tv2Config 模型)
- seed_oss — SeedOssModel(SeedOssConfig 模型)
- segformer — SegformerModel(SegformerConfig 模型)
- seggpt — SegGptModel(SegGptConfig 模型)
- sew — SEWModel(SEWConfig 模型)
- sew-d — SEWDModel(SEWDConfig 模型)
- siglip — SiglipModel(SiglipConfig 模型)
- siglip2 — Siglip2Model(Siglip2Config 模型)
- siglip2_vision_model — Siglip2VisionModel(Siglip2VisionConfig 模型)
- siglip_vision_model — SiglipVisionModel(SiglipVisionConfig 模型)
- smollm3 — SmolLM3Model(SmolLM3Config 模型)
- smolvlm — SmolVLMModel(SmolVLMConfig 模型)
- smolvlm_vision — SmolVLMVisionTransformer(SmolVLMVisionConfig 模型)
- solar_open — SolarOpenModel(SolarOpenConfig 模型)
- speech_to_text — Speech2TextModel(Speech2TextConfig 模型)
- speecht5 — SpeechT5Model(SpeechT5Config 模型)
- splinter — SplinterModel(SplinterConfig 模型)
- squeezebert — SqueezeBertModel(SqueezeBertConfig 模型)
- stablelm — StableLmModel(StableLmConfig 模型)
- starcoder2 — Starcoder2Model(Starcoder2Config 模型)
- step3p7 — Step3p7Model(Step3p7Config 模型)
- swiftformer — SwiftFormerModel(SwiftFormerConfig 模型)
- swin — SwinModel(SwinConfig 模型)
- swin2sr — Swin2SRModel(Swin2SRConfig 模型)
- swinv2 — Swinv2Model(Swinv2Config 模型)
- switch_transformers — SwitchTransformersModel(SwitchTransformersConfig 模型)
- t5 — T5Model(T5Config 模型)
- t5gemma — T5GemmaModel(T5GemmaConfig 模型)
- t5gemma2 — T5Gemma2Model(T5Gemma2Config 模型)
- t5gemma2_encoder —
T5Gemma2Encoder(T5Gemma2EncoderConfig 模型) - table-transformer — TableTransformerModel(TableTransformerConfig 模型)
- tapas — TapasModel(TapasConfig 模型)
- textnet — TextNetModel(TextNetConfig 模型)
- time_series_transformer — TimeSeriesTransformerModel(TimeSeriesTransformerConfig 模型)
- timesfm — TimesFmModel(TimesFmConfig 模型)
- timesfm2_5 — TimesFm2_5Model(TimesFm2_5Config 模型)
- timesformer — TimesformerModel(TimesformerConfig 模型)
- timm_backbone — TimmBackbone(TimmBackboneConfig 模型)
- timm_wrapper — TimmWrapperModel(TimmWrapperConfig 模型)
- tipsv2 — Tipsv2Model(Tipsv2Config 模型)
- tipsv2_text_model — Tipsv2TextModel(Tipsv2TextConfig 模型)
- tipsv2_vision_model — Tipsv2VisionModel(Tipsv2VisionConfig 模型)
- tvp — TvpModel(TvpConfig 模型)
- udop — UdopModel(UdopConfig 模型)
- ultrabert — UltrabertModel(UltrabertConfig 模型)
- ultravbert — UltraVBertModel(UltraVBertConfig 模型)
- umt5 — UMT5Model(UMT5Config 模型)
- unispeech — UniSpeechModel(UniSpeechConfig 模型)
- unispeech-sat — UniSpeechSatModel(UniSpeechSatConfig 模型)
- univnet — UnivNetModel(UnivNetConfig 模型)
- unlimited_ocr — UnlimitedOcrModel(UnlimitedOcrConfig 模型)
- uvdoc — UVDocModel(UVDocConfig 模型)
- vaultgemma — VaultGemmaModel(VaultGemmaConfig 模型)
- vibevoice — VibeVoiceForConditionalGeneration(VibeVoiceConfig 模型)
- vibevoice_acoustic_tokenizer — VibeVoiceAcousticTokenizerModel(VibeVoiceAcousticTokenizerConfig 模型)
- vibevoice_acoustic_tokenizer_decoder — VibeVoiceAcousticTokenizerDecoderModel(VibeVoiceAcousticTokenizerDecoderConfig 模型)
- vibevoice_acoustic_tokenizer_encoder — VibeVoiceAcousticTokenizerEncoderModel(VibeVoiceAcousticTokenizerEncoderConfig 模型)
- vibevoice_asr — VibeVoiceAsrModel(VibeVoiceAsrConfig 模型)
- video_llama_3 — VideoLlama3Model(VideoLlama3Config 模型)
- video_llama_3_vision — VideoLlama3VisionModel(VideoLlama3VisionConfig 模型)
- video_llava — VideoLlavaModel(VideoLlavaConfig 模型)
- videomae — VideoMAEModel(VideoMAEConfig 模型)
- videoprism — VideoPrismClipModel(VideoPrismConfig 模型)
- videoprism_vision_model — VideoPrismVisionModel(VideoPrismVisionConfig 模型)
- vilt — ViltModel(ViltConfig 模型)
- vipllava — VipLlavaModel(VipLlavaConfig 模型)
- vision-text-dual-encoder — VisionTextDualEncoderModel(VisionTextDualEncoderConfig 模型)
- visual_bert — VisualBertModel(VisualBertConfig 模型)
- vit — ViTModel(ViTConfig 模型)
- vit_mae — ViTMAEModel(ViTMAEConfig 模型)
- vit_msn — ViTMSNModel(ViTMSNConfig 模型)
- vitdet — VitDetModel(VitDetConfig 模型)
- vits — VitsModel(VitsConfig 模型)
- vivit — VivitModel(VivitConfig 模型)
- vjepa2 — VJEPA2Model(VJEPA2Config 模型)
- voxtral — VoxtralModel(VoxtralConfig 模型)
- voxtral_encoder — VoxtralEncoder(VoxtralEncoderConfig 模型)
- voxtral_realtime — VoxtralRealtimeModel(VoxtralRealtimeConfig 模型)
- voxtral_realtime_encoder — VoxtralRealtimeEncoder(VoxtralRealtimeEncoderConfig 模型)
- voxtral_realtime_text —
VoxtralRealtimeTextModel(VoxtralRealtimeTextConfig 模型) - wav2vec2 — Wav2Vec2Model(Wav2Vec2Config 模型)
- wav2vec2-bert — Wav2Vec2BertModel(Wav2Vec2BertConfig 模型)
- wav2vec2-conformer — Wav2Vec2ConformerModel(Wav2Vec2ConformerConfig 模型)
- wavlm — WavLMModel(WavLMConfig 模型)
- whisper — WhisperModel(WhisperConfig 模型)
- xclip — XCLIPModel(XCLIPConfig 模型)
- xcodec — XcodecModel(XcodecConfig 模型)
- xcodec2 — Xcodec2Model(Xcodec2Config 模型)
- xglm — XGLMModel(XGLMConfig 模型)
- xlm — XLMModel(XLMConfig 模型)
- xlm-roberta — XLMRobertaModel(XLMRobertaConfig 模型)
- xlm-roberta-xl — XLMRobertaXLModel(XLMRobertaXLConfig 模型)
- xlnet — XLNetModel(XLNetConfig 模型)
- xlstm — xLSTMModel(xLSTMConfig 模型)
- xmod — XmodModel(XmodConfig 模型)
- yolos — YolosModel(YolosConfig 模型)
- yoso — YosoModel(YosoConfig 模型)
- youtu — YoutuModel(YoutuConfig 模型)
- zamba — ZambaModel(ZambaConfig 模型)
- zamba2 — Zamba2Model(Zamba2Config 模型)
- zaya — ZayaModel(ZayaConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModel
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModel.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModel.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True通用预训练类
以下自动类可用于实例化带有预训练头的模型。
AutoModelForPreTraining
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中某个带有预训练头的模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- AlbertConfig 配置类:AlbertForPreTraining(AlbertConfig 模型)
- AudioFlamingo3Config 配置类:AudioFlamingo3ForConditionalGeneration(AudioFlamingo3Config 模型)
- BartConfig 配置类:BartForConditionalGeneration(BartConfig 模型)
- BertConfig 配置类:BertForPreTraining(BertConfig 模型)
- BigBirdConfig 配置类:BigBirdForPreTraining(BigBirdConfig 模型)
- BloomConfig 配置类:BloomForCausalLM(BloomConfig 模型)
- CTRLConfig 配置类:CTRLLMHeadModel(CTRLConfig 模型)
- CamembertConfig 配置类:CamembertForMaskedLM(CamembertConfig 模型)
- ColModernVBertConfig 配置类:ColModernVBertForRetrieval(ColModernVBertConfig 模型)
- ColPaliConfig 配置类:ColPaliForRetrieval(ColPaliConfig 模型)
- ColQwen2Config 配置类:ColQwen2ForRetrieval(ColQwen2Config 模型)
- Data2VecTextConfig 配置类:Data2VecTextForMaskedLM(Data2VecTextConfig 模型)
- DebertaConfig 配置类:DebertaForMaskedLM(DebertaConfig 模型)
- DebertaV2Config 配置类:DebertaV2ForMaskedLM(DebertaV2Config 模型)
- DistilBertConfig 配置类:DistilBertForMaskedLM(DistilBertConfig 模型)
- ElectraConfig 配置类:ElectraForPreTraining(ElectraConfig 模型)
- ErnieConfig 配置类:ErnieForPreTraining(ErnieConfig 模型)
- EvollaConfig 配置类:EvollaForProteinText2Text(EvollaConfig 模型)
- Exaone4Config 配置类:Exaone4ForCausalLM(Exaone4Config 模型)
- ExaoneMoeConfig 配置类:ExaoneMoeForCausalLM(ExaoneMoeConfig 模型)
- FNetConfig 配置类:FNetForPreTraining(FNetConfig 模型)
- FSMTConfig 配置类:FSMTForConditionalGeneration(FSMTConfig 模型)
- FalconMambaConfig 配置类:FalconMambaForCausalLM(FalconMambaConfig 模型)
- FlaubertConfig 配置类:FlaubertWithLMHeadModel(FlaubertConfig 模型)
- FlavaConfig 配置类:FlavaForPreTraining(FlavaConfig 模型)
- Florence2Config 配置类:Florence2ForConditionalGeneration(Florence2Config 模型)
- FunAsrNanoConfig 配置类:FunAsrNanoForConditionalGeneration(FunAsrNanoConfig 模型)
- FunnelConfig 配置类:FunnelForPreTraining(FunnelConfig 模型)
- GPT2Config 配置类:GPT2LMHeadModel(GPT2Config 模型)
- GPTBigCodeConfig 配置类:GPTBigCodeForCausalLM(GPTBigCodeConfig 模型)
- Gemma3Config 配置类:Gemma3ForConditionalGeneration(Gemma3Config 模型)
- Gemma4Config 配置类:Gemma4ForConditionalGeneration(Gemma4Config 模型)
- Gemma4UnifiedConfig 配置类:Gemma4UnifiedForConditionalGeneration(Gemma4UnifiedConfig 模型)
- GlmAsrConfig 配置类:GlmAsrForConditionalGeneration(GlmAsrConfig 模型)
- HieraConfig 配置类:HieraForPreTraining(HieraConfig 模型)
- IBertConfig 配置类:IBertForMaskedLM(IBertConfig 模型)
- Idefics2Config 配置类:Idefics2ForConditionalGeneration(Idefics2Config 模型)
- Idefics3Config 配置类:Idefics3ForConditionalGeneration(Idefics3Config 模型)
- IdeficsConfig 配置类:IdeficsForVisionText2Text(IdeficsConfig 模型)
- InklingConfig 配置类:InklingForConditionalGeneration(InklingConfig 模型)
- JanusConfig 配置类:JanusForConditionalGeneration(JanusConfig 模型)
- LayoutLMConfig 配置类:LayoutLMForMaskedLM(LayoutLMConfig 模型)
- LlavaConfig 配置类:LlavaForConditionalGeneration(LlavaConfig 模型)
- LlavaNextConfig 配置类:LlavaNextForConditionalGeneration(LlavaNextConfig 模型)
- LlavaNextVideoConfig 配置类:LlavaNextVideoForConditionalGeneration(LlavaNextVideoConfig 模型)
- LlavaOnevisionConfig 配置类:LlavaOnevisionForConditionalGeneration(LlavaOnevisionConfig 模型)
- LongformerConfig 配置类:LongformerForMaskedLM(LongformerConfig 模型)
- LukeConfig 配置类:LukeForMaskedLM(LukeConfig 模型)
- LxmertConfig 配置类:LxmertForPreTraining(LxmertConfig 模型)
- MPNetConfig 配置类:MPNetForMaskedLM(MPNetConfig 模型)
- Mamba2Config 配置类:Mamba2ForCausalLM(Mamba2Config 模型)
- MambaConfig 配置类:MambaForCausalLM(MambaConfig 模型)
- MegatronBertConfig 配置类:MegatronBertForPreTraining(MegatronBertConfig 模型)
- Mistral3Config 配置类:Mistral3ForConditionalGeneration(Mistral3Config 模型)
- Mistral4Config 配置类:Mistral4ForCausalLM(Mistral4Config 模型)
- MistralLarge4Config 配置类:MistralLarge4ForConditionalGeneration(MistralLarge4Config 模型)
- MllamaConfig 配置类:MllamaForConditionalGeneration(MllamaConfig 模型)
- MobileBertConfig 配置类:MobileBertForPreTraining(MobileBertConfig 模型)
- MossTranscribeDiarizeConfig 配置类:MossTranscribeDiarizeForConditionalGeneration(MossTranscribeDiarizeConfig 模型)
- MptConfig 配置类:MptForCausalLM(MptConfig 模型)
- MraConfig 配置类:MraForMaskedLM(MraConfig 模型)
- MusicFlamingoConfig 配置类:MusicFlamingoForConditionalGeneration(MusicFlamingoConfig 模型)
- MvpConfig 配置类:MvpForConditionalGeneration(MvpConfig 模型)
- NanoChatConfig 配置类:NanoChatForCausalLM(NanoChatConfig 模型)
- Nemotron3_5TranscribeConfig 配置类:Nemotron3_5TranscribeForConditionalGeneration(Nemotron3_5TranscribeConfig 模型)
- NllbMoeConfig 配置类:NllbMoeForConditionalGeneration(NllbMoeConfig 模型)
- OpenAIGPTConfig 配置类:OpenAIGPTLMHeadModel(OpenAIGPTConfig 模型)
- PaliGemmaConfig 配置类:PaliGemmaForConditionalGeneration(PaliGemmaConfig 模型)
- Qwen2AudioConfig 配置类:Qwen2AudioForConditionalGeneration(Qwen2AudioConfig 模型)
- Qwen3ASRConfig 配置类:Qwen3ASRForConditionalGeneration(Qwen3ASRConfig 模型)
- RoCBertConfig 配置类:RoCBertForPreTraining(RoCBertConfig 模型)
- RobertaConfig 配置类:RobertaForMaskedLM(RobertaConfig 模型)
- RobertaPreLayerNormConfig 配置类:RobertaPreLayerNormForMaskedLM(RobertaPreLayerNormConfig 模型)
- RwkvConfig 配置类:RwkvForCausalLM(RwkvConfig 模型)
- SplinterConfig 配置类:SplinterForPreTraining(SplinterConfig 模型)
- SqueezeBertConfig 配置类:SqueezeBertForMaskedLM(SqueezeBertConfig 模型)
- SwitchTransformersConfig 配置类:SwitchTransformersForConditionalGeneration(SwitchTransformersConfig 模型)
- T5Config 配置类:T5ForConditionalGeneration(T5Config 模型)
- T5Gemma2Config 配置类:T5Gemma2ForConditionalGeneration(T5Gemma2Config 模型)
- T5GemmaConfig 配置类:T5GemmaForConditionalGeneration(T5GemmaConfig 模型)
- TapasConfig 配置类:TapasForMaskedLM(TapasConfig 模型)
- UniSpeechConfig 配置类:UniSpeechForPreTraining(UniSpeechConfig 模型)
- UniSpeechSatConfig 配置类:UniSpeechSatForPreTraining(UniSpeechSatConfig 模型)
- ViTMAEConfig 配置类:ViTMAEForPreTraining(ViTMAEConfig 模型)
- VibeVoiceAsrConfig 配置类:VibeVoiceAsrForConditionalGeneration(VibeVoiceAsrConfig 模型)
- VideoLlavaConfig 配置类:VideoLlavaForConditionalGeneration(VideoLlavaConfig 模型)
- VideoMAEConfig 配置类:VideoMAEForPreTraining(VideoMAEConfig 模型)
- VipLlavaConfig 配置类:VipLlavaForConditionalGeneration(VipLlavaConfig 模型)
- VisualBertConfig 配置类:VisualBertForPreTraining(VisualBertConfig 模型)
- VoxtralConfig 配置类:VoxtralForConditionalGeneration(VoxtralConfig 模型)
- VoxtralRealtimeConfig 配置类:VoxtralRealtimeForConditionalGeneration(VoxtralRealtimeConfig 模型)
- Wav2Vec2Config 配置类:Wav2Vec2ForPreTraining(Wav2Vec2Config 模型)
- Wav2Vec2ConformerConfig 配置类:Wav2Vec2ConformerForPreTraining(Wav2Vec2ConformerConfig 模型)
- XLMConfig 配置类:XLMWithLMHeadModel(XLMConfig 模型)
- XLMRobertaConfig 配置类:XLMRobertaForMaskedLM(XLMRobertaConfig 模型)
- XLMRobertaXLConfig 配置类:XLMRobertaXLForMaskedLM(XLMRobertaXLConfig 模型)
- XLNetConfig 配置类:XLNetLMHeadModel(XLNetConfig 模型)
- XmodConfig 配置类:XmodForMaskedLM(XmodConfig 模型)
- xLSTMConfig 配置类:xLSTMForCausalLM(xLSTMConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库的某个模型类(带有预训练头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库的某个模型类(带有预训练头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- albert — AlbertForPreTraining(AlbertConfig 模型)
- audioflamingo3 — AudioFlamingo3ForConditionalGeneration(AudioFlamingo3Config 模型)
- bart — BartForConditionalGeneration(BartConfig 模型)
- bert — BertForPreTraining(BertConfig 模型)
- big_bird — BigBirdForPreTraining(BigBirdConfig 模型)
- bloom — BloomForCausalLM(BloomConfig 模型)
- camembert — CamembertForMaskedLM(CamembertConfig 模型)
- colmodernvbert — ColModernVBertForRetrieval(ColModernVBertConfig 模型)
- colpali — ColPaliForRetrieval(ColPaliConfig 模型)
- colqwen2 — ColQwen2ForRetrieval(ColQwen2Config 模型)
- ctrl — CTRLLMHeadModel(CTRLConfig 模型)
- data2vec-text — Data2VecTextForMaskedLM(Data2VecTextConfig 模型)
- deberta — DebertaForMaskedLM(DebertaConfig 模型)
- deberta-v2 — DebertaV2ForMaskedLM(DebertaV2Config 模型)
- distilbert — DistilBertForMaskedLM(DistilBertConfig 模型)
- electra — ElectraForPreTraining(ElectraConfig 模型)
- ernie — ErnieForPreTraining(ErnieConfig 模型)
- evolla — EvollaForProteinText2Text(EvollaConfig 模型)
- exaone4 — Exaone4ForCausalLM(Exaone4Config 模型)
- exaone_moe — ExaoneMoeForCausalLM(ExaoneMoeConfig 模型)
- falcon_mamba — FalconMambaForCausalLM(FalconMambaConfig 模型)
- flaubert — FlaubertWithLMHeadModel(FlaubertConfig 模型)
- flava — FlavaForPreTraining(FlavaConfig 模型)
- florence2 — Florence2ForConditionalGeneration(Florence2Config 模型)
- fnet — FNetForPreTraining(FNetConfig 模型)
- fsmt — FSMTForConditionalGeneration(FSMTConfig 模型)
- fun_asr_nano — FunAsrNanoForConditionalGeneration(FunAsrNanoConfig 模型)
- funnel — FunnelForPreTraining(FunnelConfig 模型)
- gemma3 — Gemma3ForConditionalGeneration(Gemma3Config 模型)
- gemma4 — Gemma4ForConditionalGeneration(Gemma4Config 模型)
- gemma4_unified — Gemma4UnifiedForConditionalGeneration(Gemma4UnifiedConfig 模型)
- glmasr — GlmAsrForConditionalGeneration(GlmAsrConfig 模型)
- gpt-sw3 — GPT2LMHeadModel(GPT2Config 模型)
- gpt2 — GPT2LMHeadModel(GPT2Config 模型)
- gpt_bigcode — GPTBigCodeForCausalLM(GPTBigCodeConfig 模型)
- hiera — HieraForPreTraining(HieraConfig 模型)
- ibert — IBertForMaskedLM(IBertConfig 模型)
- idefics — IdeficsForVisionText2Text(IdeficsConfig 模型)
- idefics2 — Idefics2ForConditionalGeneration(Idefics2Config 模型)
- idefics3 — Idefics3ForConditionalGeneration(Idefics3Config 模型)
- inkling_mm_model — InklingForConditionalGeneration(InklingConfig 模型)
- janus — JanusForConditionalGeneration(JanusConfig 模型)
- layoutlm — LayoutLMForMaskedLM(LayoutLMConfig 模型)
- llava — LlavaForConditionalGeneration(LlavaConfig 模型)
- llava_next — LlavaNextForConditionalGeneration(LlavaNextConfig 模型)
- llava_next_video — LlavaNextVideoForConditionalGeneration(LlavaNextVideoConfig 模型)
- llava_onevision — LlavaOnevisionForConditionalGeneration(LlavaOnevisionConfig 模型)
- longformer — LongformerForMaskedLM(LongformerConfig 模型)
- luke — LukeForMaskedLM(LukeConfig 模型)
- lxmert — LxmertForPreTraining(LxmertConfig 模型)
- mamba — MambaForCausalLM(MambaConfig 模型)
- mamba2 — Mamba2ForCausalLM(Mamba2Config 模型)
- megatron-bert — MegatronBertForPreTraining(MegatronBertConfig 模型)
- mistral3 — Mistral3ForConditionalGeneration(Mistral3Config 模型)
- mistral4 — Mistral4ForCausalLM(Mistral4Config 模型)
- mistral_large4 — MistralLarge4ForConditionalGeneration(MistralLarge4Config 模型)
- mllama — MllamaForConditionalGeneration(MllamaConfig 模型)
- mobilebert — MobileBertForPreTraining(MobileBertConfig 模型)
- moss_transcribe_diarize — MossTranscribeDiarizeForConditionalGeneration(MossTranscribeDiarizeConfig 模型)
- mpnet — MPNetForMaskedLM(MPNetConfig 模型)
- mpt — MptForCausalLM(MptConfig 模型)
- mra — MraForMaskedLM(MraConfig 模型)
- musicflamingo — MusicFlamingoForConditionalGeneration(MusicFlamingoConfig 模型)
- mvp — MvpForConditionalGeneration(MvpConfig 模型)
- nanochat — NanoChatForCausalLM(NanoChatConfig 模型)
- nemo_speechlm — Nemotron3_5TranscribeForConditionalGeneration(Nemotron3_5TranscribeConfig 模型)
- nllb-moe — NllbMoeForConditionalGeneration(NllbMoeConfig 模型)
- openai-gpt — OpenAIGPTLMHeadModel(OpenAIGPTConfig 模型)
- paligemma — PaliGemmaForConditionalGeneration(PaliGemmaConfig 模型)
- qwen2_audio — Qwen2AudioForConditionalGeneration(Qwen2AudioConfig 模型)
- qwen3_asr — Qwen3ASRForConditionalGeneration(Qwen3ASRConfig 模型)
- roberta — RobertaForMaskedLM(RobertaConfig 模型)
- roberta-prelayernorm — RobertaPreLayerNormForMaskedLM(RobertaPreLayerNormConfig 模型)
- roc_bert — RoCBertForPreTraining(RoCBertConfig 模型)
- rwkv — RwkvForCausalLM(RwkvConfig 模型)
- splinter — SplinterForPreTraining(SplinterConfig 模型)
- squeezebert — SqueezeBertForMaskedLM(SqueezeBertConfig 模型)
- switch_transformers — SwitchTransformersForConditionalGeneration(SwitchTransformersConfig 模型)
- t5 — T5ForConditionalGeneration(T5Config 模型)
- t5gemma — T5GemmaForConditionalGeneration(T5GemmaConfig 模型)
- t5gemma2 — T5Gemma2ForConditionalGeneration(T5Gemma2Config 模型)
- tapas — TapasForMaskedLM(TapasConfig 模型)
- unispeech — UniSpeechForPreTraining(UniSpeechConfig 模型)
- unispeech-sat — UniSpeechSatForPreTraining(UniSpeechSatConfig 模型)
- vibevoice_asr — VibeVoiceAsrForConditionalGeneration(VibeVoiceAsrConfig 模型)
- video_llava — VideoLlavaForConditionalGeneration(VideoLlavaConfig 模型)
- videomae — VideoMAEForPreTraining(VideoMAEConfig 模型)
- vipllava — VipLlavaForConditionalGeneration(VipLlavaConfig 模型)
- visual_bert — VisualBertForPreTraining(VisualBertConfig 模型)
- vit_mae — ViTMAEForPreTraining(ViTMAEConfig 模型)
- voxtral — VoxtralForConditionalGeneration(VoxtralConfig 模型)
- voxtral_realtime — VoxtralRealtimeForConditionalGeneration(VoxtralRealtimeConfig 模型)
- wav2vec2 — Wav2Vec2ForPreTraining(Wav2Vec2Config 模型)
- wav2vec2-conformer — Wav2Vec2ConformerForPreTraining(Wav2Vec2ConformerConfig 模型)
- xlm — XLMWithLMHeadModel(XLMConfig 模型)
- xlm-roberta — XLMRobertaForMaskedLM(XLMRobertaConfig 模型)
- xlm-roberta-xl — XLMRobertaXLForMaskedLM(XLMRobertaXLConfig 模型)
- xlnet — XLNetLMHeadModel(XLNetConfig 模型)
- xlstm — xLSTMForCausalLM(xLSTMConfig 模型)
- xmod — XmodForMaskedLM(XmodConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForPreTraining
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForPreTraining.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForPreTraining.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True自然语言处理
以下自动类可用于以下自然语言处理任务。
AutoModelForCausalLM
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有因果语言建模头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- AXK1Config 配置类:AXK1ForCausalLM(AXK1Config 模型)
- AXK2Config 配置类:AXK2ForCausalLM(AXK2Config 模型)
- AfmoeConfig 配置类:AfmoeForCausalLM(AfmoeConfig 模型)
- ApertusConfig 配置类:ApertusForCausalLM(ApertusConfig 模型)
- ArceeConfig 配置类:ArceeForCausalLM(ArceeConfig 模型)
- AriaTextConfig 配置类:AriaTextForCausalLM(AriaTextConfig 模型)
- BailingHybridConfig 配置类:BailingHybridForCausalLM(BailingHybridConfig 模型)
- BambaConfig 配置类:BambaForCausalLM(BambaConfig 模型)
- BartConfig 配置类:BartForCausalLM(BartConfig 模型)
- BeamConfig 配置类:BeamForCausalLM(BeamConfig 模型)
- BertConfig 配置类:BertLMHeadModel(BertConfig 模型)
- BertGenerationConfig 配置类:BertGenerationDecoder(BertGenerationConfig 模型)
- BigBirdConfig 配置类:BigBirdForCausalLM(BigBirdConfig 模型)
- BigBirdPegasusConfig 配置类:BigBirdPegasusForCausalLM(BigBirdPegasusConfig 模型)
- BioGptConfig 配置类:BioGptForCausalLM(BioGptConfig 模型)
- BitNetConfig 配置类:BitNetForCausalLM(BitNetConfig 模型)
- BlenderbotConfig 配置类:BlenderbotForCausalLM(BlenderbotConfig 模型)
- BlenderbotSmallConfig 配置类:BlenderbotSmallForCausalLM(BlenderbotSmallConfig 模型)
- BloomConfig 配置类:BloomForCausalLM(BloomConfig 模型)
- BltConfig 配置类:BltForCausalLM(BltConfig 模型)
- CTRLConfig 配置类:CTRLLMHeadModel(CTRLConfig 模型)
- CamembertConfig 配置类:CamembertForCausalLM(CamembertConfig 模型)
- CodeGenConfig 配置类:CodeGenForCausalLM(CodeGenConfig 模型)
- Cohere2Config 配置类:Cohere2ForCausalLM(Cohere2Config 模型)
- Cohere2MoeConfig 配置类:Cohere2MoeForCausalLM(Cohere2MoeConfig 模型)
- CohereCompassTextConfig 配置类:CohereCompassForCausalLM(CohereCompassTextConfig 模型)
- CohereConfig 配置类:CohereForCausalLM(CohereConfig 模型)
- CpmAntConfig 配置类:CpmAntForCausalLM(CpmAntConfig 模型)
- CwmConfig 配置类:CwmForCausalLM(CwmConfig 模型)
- Data2VecTextConfig 配置类:Data2VecTextForCausalLM(Data2VecTextConfig 模型)
- DbrxConfig 配置类:DbrxForCausalLM(DbrxConfig 模型)
- DeepseekV2Config 配置类:DeepseekV2ForCausalLM(DeepseekV2Config 模型)
- DeepseekV32Config 配置类:DeepseekV32ForCausalLM(DeepseekV32Config 模型)
- DeepseekV3Config 配置类:DeepseekV3ForCausalLM(DeepseekV3Config 模型)
- DeepseekV4Config 配置类:DeepseekV4ForCausalLM(DeepseekV4Config 模型)
- DiffLlamaConfig 配置类:DiffLlamaForCausalLM(DiffLlamaConfig 模型)
- DogeConfig 配置类:DogeForCausalLM(DogeConfig 模型)
- Dots1Config 配置类:Dots1ForCausalLM(Dots1Config 模型)
- ElectraConfig 配置类:ElectraForCausalLM(ElectraConfig 模型)
- Emu3Config 配置类:Emu3ForCausalLM(Emu3Config 模型)
- Ernie4_5Config 配置类:Ernie4_5ForCausalLM(Ernie4_5Config 模型)
- Ernie4_5_MoeConfig 配置类:Ernie4_5_MoeForCausalLM(Ernie4_5_MoeConfig 模型)
- ErnieConfig 配置类:ErnieForCausalLM(ErnieConfig 模型)
- Exaone4Config 配置类:Exaone4ForCausalLM(Exaone4Config 模型)
- ExaoneMoeConfig 配置类:ExaoneMoeForCausalLM(ExaoneMoeConfig 模型)
- FalconConfig 配置类:FalconForCausalLM(FalconConfig 模型)
- FalconH1Config 配置类:FalconH1ForCausalLM(FalconH1Config 模型)
- FalconMambaConfig 配置类:FalconMambaForCausalLM(FalconMambaConfig 模型)
- FlexOlmoConfig 配置类:FlexOlmoForCausalLM(FlexOlmoConfig 模型)
- FlintConfig 配置类:FlintForCausalLM(FlintConfig 模型)
- FuyuConfig 配置类:FuyuForCausalLM(FuyuConfig 模型)
- GPT2Config 配置类:GPT2LMHeadModel(GPT2Config 模型)
- GPTBigCodeConfig 配置类:GPTBigCodeForCausalLM(GPTBigCodeConfig 模型)
- GPTJConfig 配置类:GPTJForCausalLM(GPTJConfig 模型)
- GPTNeoConfig 配置类:GPTNeoForCausalLM(GPTNeoConfig 模型)
- GPTNeoXConfig 配置类:GPTNeoXForCausalLM(GPTNeoXConfig 模型)
- GPTNeoXJapaneseConfig 配置类:GPTNeoXJapaneseForCausalLM(GPTNeoXJapaneseConfig 模型)
- Gemma2Config 配置类:Gemma2ForCausalLM(Gemma2Config 模型)
- Gemma3Config 配置类:Gemma3ForConditionalGeneration(Gemma3Config 模型)
- Gemma3TextConfig 配置类:Gemma3ForCausalLM(Gemma3TextConfig 模型)
- Gemma3nConfig 配置类:Gemma3nForConditionalGeneration(Gemma3nConfig 模型)
- Gemma3nTextConfig 配置类:Gemma3nForCausalLM(Gemma3nTextConfig 模型)
- Gemma4AssistantConfig 配置类:Gemma4AssistantForCausalLM(Gemma4AssistantConfig 模型)
- Gemma4Config 配置类:Gemma4ForConditionalGeneration(Gemma4Config 模型)
- Gemma4TextConfig 配置类:Gemma4ForCausalLM(Gemma4TextConfig 模型)
- Gemma4UnifiedAssistantConfig 配置类:Gemma4UnifiedAssistantForCausalLM(Gemma4UnifiedAssistantConfig 模型)
- Gemma4UnifiedConfig 配置类:Gemma4UnifiedForConditionalGeneration(Gemma4UnifiedConfig 模型)
- Gemma4UnifiedTextConfig 配置类:Gemma4UnifiedForCausalLM(Gemma4UnifiedTextConfig 模型)
- GemmaConfig 配置类:GemmaForCausalLM(GemmaConfig 模型)
- GitConfig 配置类:GitForCausalLM(GitConfig 模型)
- Glm4Config 配置类:Glm4ForCausalLM(Glm4Config 模型)
- Glm4MoeConfig 配置类:Glm4MoeForCausalLM(Glm4MoeConfig 模型)
- Glm4MoeLiteConfig 配置类:Glm4MoeLiteForCausalLM(Glm4MoeLiteConfig 模型)
- GlmConfig 配置类:GlmForCausalLM(GlmConfig 模型)
- GlmMoeDsaConfig 配置类:GlmMoeDsaForCausalLM(GlmMoeDsaConfig 模型)
- GotOcr2Config 配置类:GotOcr2ForConditionalGeneration(GotOcr2Config 模型)
- GptOssConfig 配置类:GptOssForCausalLM(GptOssConfig 模型)
- GraniteConfig 配置类:GraniteForCausalLM(GraniteConfig 模型)
- GraniteMoeConfig 配置类:GraniteMoeForCausalLM(GraniteMoeConfig 模型)
- GraniteMoeHybridConfig 配置类:GraniteMoeHybridForCausalLM(GraniteMoeHybridConfig 模型)
- GraniteMoeSWAConfig 配置类:GraniteMoeSWAForCausalLM(GraniteMoeSWAConfig 模型)
- GraniteMoeSharedConfig 配置类:GraniteMoeSharedForCausalLM(GraniteMoeSharedConfig 模型)
- GraniteSWAConfig 配置类:GraniteSWAForCausalLM(GraniteSWAConfig 模型)
- HYV3Config 配置类:HYV3ForCausalLM(HYV3Config 模型)
- HYV4Config 配置类:HYV4ForCausalLM(HYV4Config 模型)
- HeliumConfig 配置类:HeliumForCausalLM(HeliumConfig 模型)
- HrmTextConfig 配置类:HrmTextForCausalLM(HrmTextConfig 模型)
- HunYuanDenseV1Config 配置类:HunYuanDenseV1ForCausalLM(HunYuanDenseV1Config 模型)
- HunYuanMoEV1Config 配置类:HunYuanMoEV1ForCausalLM(HunYuanMoEV1Config 模型)
- HyperCLOVAXConfig 配置类:HyperCLOVAXForCausalLM(HyperCLOVAXConfig 模型)
- InklingTextConfig 配置类:InklingForCausalLM(InklingTextConfig 模型)
- Jais2Config 配置类:Jais2ForCausalLM(Jais2Config 模型)
- JambaConfig 配置类:JambaForCausalLM(JambaConfig 模型)
- JetMoeConfig 配置类:JetMoeForCausalLM(JetMoeConfig 模型)
- KimiLinearConfig 配置类:KimiLinearForCausalLM(KimiLinearConfig 模型)
- Kolibri1Config 配置类:Kolibri1ForCausalLM(Kolibri1Config 模型)
- LagunaConfig 配置类:LagunaForCausalLM(LagunaConfig 模型)
- Lfm2Config 配置类:Lfm2ForCausalLM(Lfm2Config 模型)
- Lfm2MoeConfig 配置类:Lfm2MoeForCausalLM(Lfm2MoeConfig 模型)
- Lfm3Config 配置类:Lfm3ForCausalLM(Lfm3Config 模型)
- Llama4Config 配置类:Llama4ForCausalLM(Llama4Config 模型)
- Llama4TextConfig 配置类:Llama4ForCausalLM(Llama4TextConfig 模型)
- LlamaConfig 配置类:LlamaForCausalLM(LlamaConfig 模型)
- LongcatFlashConfig 配置类:LongcatFlashForCausalLM(LongcatFlashConfig 模型)
- MBartConfig 配置类:MBartForCausalLM(MBartConfig 模型)
- Mamba2Config 配置类:Mamba2ForCausalLM(Mamba2Config 模型)
- MambaConfig 配置类:MambaForCausalLM(MambaConfig 模型)
- MarianConfig 配置类:MarianForCausalLM(MarianConfig 模型)
- MegatronBertConfig 配置类:MegatronBertForCausalLM(MegatronBertConfig 模型)
- MellumConfig 配置类:MellumForCausalLM(MellumConfig 模型)
- MiMoV2FlashConfig 配置类:MiMoV2FlashForCausalLM(MiMoV2FlashConfig 模型)
- MiniCPM3Config 配置类:MiniCPM3ForCausalLM(MiniCPM3Config 模型)
- MiniMaxConfig 配置类:MiniMaxForCausalLM(MiniMaxConfig 模型)
- MiniMaxM2Config 配置类:MiniMaxM2ForCausalLM(MiniMaxM2Config 模型)
- MiniMaxM3VLTextConfig 配置类:MiniMaxM3VLForCausalLM(MiniMaxM3VLTextConfig 模型)
- Ministral3Config 配置类:Ministral3ForCausalLM(Ministral3Config 模型)
- MinistralConfig 配置类:MinistralForCausalLM(MinistralConfig 模型)
- MistralConfig 配置类:MistralForCausalLM(MistralConfig 模型)
- MixtralConfig 配置类:MixtralForCausalLM(MixtralConfig 模型)
- MllamaConfig 配置类:MllamaForCausalLM(MllamaConfig 模型)
- ModernBertDecoderConfig 配置类:ModernBertDecoderForCausalLM(ModernBertDecoderConfig 模型)
- MoshiConfig 配置类:MoshiForCausalLM(MoshiConfig 模型)
- MossTranscribeDiarizeConfig 配置类:MossTranscribeDiarizeForConditionalGeneration(MossTranscribeDiarizeConfig 模型)
- MptConfig 配置类:MptForCausalLM(MptConfig 模型)
- MusicgenConfig 配置类:MusicgenForCausalLM(MusicgenConfig 模型)
- MusicgenMelodyConfig 配置类:MusicgenMelodyForCausalLM(MusicgenMelodyConfig 模型)
- MvpConfig 配置类:MvpForCausalLM(MvpConfig 模型)
- NanoChatConfig 配置类:NanoChatForCausalLM(NanoChatConfig 模型)
- NemotronConfig 配置类:NemotronForCausalLM(NemotronConfig 模型)
- NemotronHConfig 配置类:NemotronHForCausalLM(NemotronHConfig 模型)
- OPTConfig 配置类:OPTForCausalLM(OPTConfig 模型)
- Olmo2Config 配置类:Olmo2ForCausalLM(Olmo2Config 模型)
- Olmo3Config 配置类:Olmo3ForCausalLM(Olmo3Config 模型)
- OlmoConfig 配置类:OlmoForCausalLM(OlmoConfig 模型)
- OlmoHybridConfig 配置类:OlmoHybridForCausalLM(OlmoHybridConfig 模型)
- OlmoeConfig 配置类:OlmoeForCausalLM(OlmoeConfig 模型)
- OpenAIGPTConfig 配置类:OpenAIGPTLMHeadModel(OpenAIGPTConfig 模型)
- PLBartConfig 配置类:PLBartForCausalLM(PLBartConfig 模型)
- PegasusConfig 配置类:PegasusForCausalLM(PegasusConfig 模型)
- PersimmonConfig 配置类:PersimmonForCausalLM(PersimmonConfig 模型)
- Phi3Config 配置类:Phi3ForCausalLM(Phi3Config 模型)
- Phi4MultimodalConfig 配置类:Phi4MultimodalForCausalLM(Phi4MultimodalConfig 模型)
- PhiConfig 配置类:PhiForCausalLM(PhiConfig 模型)
- PhimoeConfig 配置类:PhimoeForCausalLM(PhimoeConfig 模型)
- ProphetNetConfig 配置类:ProphetNetForCausalLM(ProphetNetConfig 模型)
- Qwen2Config 配置类:Qwen2ForCausalLM(Qwen2Config 模型)
- Qwen2MoeConfig 配置类:Qwen2MoeForCausalLM(Qwen2MoeConfig 模型)
- Qwen3Config 配置类:Qwen3ForCausalLM(Qwen3Config 模型)
- Qwen3MoeConfig 配置类:Qwen3MoeForCausalLM(Qwen3MoeConfig 模型)
- Qwen3NextConfig 配置类:Qwen3NextForCausalLM(Qwen3NextConfig 模型)
- Qwen3_5Config 配置类:Qwen3_5ForCausalLM(Qwen3_5Config 模型)
- Qwen3_5MoeConfig 配置类:Qwen3_5MoeForCausalLM(Qwen3_5MoeConfig 模型)
- Qwen3_5MoeTextConfig 配置类:Qwen3_5MoeForCausalLM(Qwen3_5MoeTextConfig 模型)
- Qwen3_5TextConfig 配置类:Qwen3_5ForCausalLM(Qwen3_5TextConfig 模型)
- Qwen4ExpConfig 配置类:Qwen4ExpForCausalLM(Qwen4ExpConfig 模型)
- Qwen4ExpTextConfig 配置类:Qwen4ExpForCausalLM(Qwen4ExpTextConfig 模型)
- RecurrentGemmaConfig 配置类:RecurrentGemmaForCausalLM(RecurrentGemmaConfig 模型)
- ReformerConfig 配置类:ReformerModelWithLMHead(ReformerConfig 模型)
- RemBertConfig 配置类:RemBertForCausalLM(RemBertConfig 模型)
- RoCBertConfig 配置类:RoCBertForCausalLM(RoCBertConfig 模型)
- RoFormerConfig 配置类:RoFormerForCausalLM(RoFormerConfig 模型)
- RobertaConfig 配置类:RobertaForCausalLM(RobertaConfig 模型)
- RobertaPreLayerNormConfig 配置类:RobertaPreLayerNormForCausalLM(RobertaPreLayerNormConfig 模型)
- RwkvConfig 配置类:RwkvForCausalLM(RwkvConfig 模型)
- SeedOssConfig 配置类:SeedOssForCausalLM(SeedOssConfig 模型)
- SmolLM3Config 配置类:SmolLM3ForCausalLM(SmolLM3Config 模型)
- SolarOpenConfig 配置类:SolarOpenForCausalLM(SolarOpenConfig 模型)
- StableLmConfig 配置类:StableLmForCausalLM(StableLmConfig 模型)
- Starcoder2Config 配置类:Starcoder2ForCausalLM(Starcoder2Config 模型)
- TrOCRConfig 配置类:TrOCRForCausalLM(TrOCRConfig 模型)
- VaultGemmaConfig 配置类:VaultGemmaForCausalLM(VaultGemmaConfig 模型)
- WhisperConfig 配置类:WhisperForCausalLM(WhisperConfig 模型)
- XGLMConfig 配置类:XGLMForCausalLM(XGLMConfig 模型)
- XLMConfig 配置类:XLMWithLMHeadModel(XLMConfig 模型)
- XLMRobertaConfig 配置类:XLMRobertaForCausalLM(XLMRobertaConfig 模型)
- XLMRobertaXLConfig 配置类:XLMRobertaXLForCausalLM(XLMRobertaXLConfig 模型)
- XLNetConfig 配置类:XLNetLMHeadModel(XLNetConfig 模型)
- XmodConfig 配置类:XmodForCausalLM(XmodConfig 模型)
- YoutuConfig 配置类:YoutuForCausalLM(YoutuConfig 模型)
- Zamba2Config 配置类:Zamba2ForCausalLM(Zamba2Config 模型)
- ZambaConfig 配置类:ZambaForCausalLM(ZambaConfig 模型)
- ZayaConfig 配置类:ZayaForCausalLM(ZayaConfig 模型)
- xLSTMConfig 配置类:xLSTMForCausalLM(xLSTMConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有因果语言建模头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有因果语言建模头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- afmoe — AfmoeForCausalLM(AfmoeConfig 模型)
- apertus — ApertusForCausalLM(ApertusConfig 模型)
- arcee — ArceeForCausalLM(ArceeConfig 模型)
- aria_text — AriaTextForCausalLM(AriaTextConfig 模型)
- axk1 — AXK1ForCausalLM(AXK1Config 模型)
- axk2 — AXK2ForCausalLM(AXK2Config 模型)
- bailing_hybrid — BailingHybridForCausalLM(BailingHybridConfig 模型)
- bamba — BambaForCausalLM(BambaConfig 模型)
- bart — BartForCausalLM(BartConfig 模型)
- beam — BeamForCausalLM(BeamConfig 模型)
- bert — BertLMHeadModel(BertConfig 模型)
- bert-generation — BertGenerationDecoder(BertGenerationConfig 模型)
- big_bird — BigBirdForCausalLM(BigBirdConfig 模型)
- bigbird_pegasus — BigBirdPegasusForCausalLM(BigBirdPegasusConfig 模型)
- biogpt — BioGptForCausalLM(BioGptConfig 模型)
- bitnet — BitNetForCausalLM(BitNetConfig 模型)
- blenderbot — BlenderbotForCausalLM(BlenderbotConfig 模型)
- blenderbot-small — BlenderbotSmallForCausalLM(BlenderbotSmallConfig 模型)
- bloom — BloomForCausalLM(BloomConfig 模型)
- blt — BltForCausalLM(BltConfig 模型)
- camembert — CamembertForCausalLM(CamembertConfig 模型)
- codegen — CodeGenForCausalLM(CodeGenConfig 模型)
- cohere — CohereForCausalLM(CohereConfig 模型)
- cohere2 — Cohere2ForCausalLM(Cohere2Config 模型)
- cohere2_moe — Cohere2MoeForCausalLM(Cohere2MoeConfig 模型)
- cohere_compass_text — CohereCompassForCausalLM(CohereCompassTextConfig 模型)
- cpmant — CpmAntForCausalLM(CpmAntConfig 模型)
- ctrl — CTRLLMHeadModel(CTRLConfig 模型)
- cwm — CwmForCausalLM(CwmConfig 模型)
- data2vec-text — Data2VecTextForCausalLM(Data2VecTextConfig 模型)
- dbrx — DbrxForCausalLM(DbrxConfig 模型)
- deepseek_v2 — DeepseekV2ForCausalLM(DeepseekV2Config 模型)
- deepseek_v3 — DeepseekV3ForCausalLM(DeepseekV3Config 模型)
- deepseek_v32 — DeepseekV32ForCausalLM(DeepseekV32Config 模型)
- deepseek_v4 — DeepseekV4ForCausalLM(DeepseekV4Config 模型)
- diffllama — DiffLlamaForCausalLM(DiffLlamaConfig 模型)
- doge — DogeForCausalLM(DogeConfig 模型)
- dots1 — Dots1ForCausalLM(Dots1Config 模型)
- electra — ElectraForCausalLM(ElectraConfig 模型)
- emu3 — Emu3ForCausalLM(Emu3Config 模型)
- ernie — ErnieForCausalLM(ErnieConfig 模型)
- ernie4_5 — Ernie4_5ForCausalLM(Ernie4_5Config 模型)
- ernie4_5_moe — Ernie4_5_MoeForCausalLM(Ernie4_5_MoeConfig 模型)
- exaone4 — Exaone4ForCausalLM(Exaone4Config 模型)
- exaone_moe — ExaoneMoeForCausalLM(ExaoneMoeConfig 模型)
- falcon — FalconForCausalLM(FalconConfig 模型)
- falcon_h1 — FalconH1ForCausalLM(FalconH1Config 模型)
- falcon_mamba — FalconMambaForCausalLM(FalconMambaConfig 模型)
- flex_olmo — FlexOlmoForCausalLM(FlexOlmoConfig 模型)
- flint — FlintForCausalLM(FlintConfig 模型)
- fuyu — FuyuForCausalLM(FuyuConfig 模型)
- gemma — GemmaForCausalLM(GemmaConfig 模型)
- gemma2 — Gemma2ForCausalLM(Gemma2Config 模型)
- gemma3 — Gemma3ForConditionalGeneration(Gemma3Config 模型)
- gemma3_text — Gemma3ForCausalLM(Gemma3TextConfig 模型)
- gemma3n — Gemma3nForConditionalGeneration(Gemma3nConfig 模型)
- gemma3n_text — Gemma3nForCausalLM(Gemma3nTextConfig 模型)
- gemma4 — Gemma4ForConditionalGeneration(Gemma4Config 模型)
- gemma4_assistant — Gemma4AssistantForCausalLM(Gemma4AssistantConfig 模型)
- gemma4_text — Gemma4ForCausalLM(Gemma4TextConfig 模型)
- gemma4_unified — Gemma4UnifiedForConditionalGeneration(Gemma4UnifiedConfig 模型)
- gemma4_unified_assistant — Gemma4UnifiedAssistantForCausalLM(Gemma4UnifiedAssistantConfig 模型)
- gemma4_unified_text — Gemma4UnifiedForCausalLM(Gemma4UnifiedTextConfig 模型)
- git — GitForCausalLM(GitConfig 模型)
- glm — GlmForCausalLM(GlmConfig 模型)
- glm4 — Glm4ForCausalLM(Glm4Config 模型)
- glm4_moe — Glm4MoeForCausalLM(Glm4MoeConfig 模型)
- glm4_moe_lite — Glm4MoeLiteForCausalLM(Glm4MoeLiteConfig 模型)
- glm_moe_dsa — GlmMoeDsaForCausalLM(GlmMoeDsaConfig 模型)
- got_ocr2 — GotOcr2ForConditionalGeneration(GotOcr2Config 模型)
- gpt-sw3 — GPT2LMHeadModel(GPT2Config 模型)
- gpt2 — GPT2LMHeadModel(GPT2Config 模型)
- gpt_bigcode — GPTBigCodeForCausalLM(GPTBigCodeConfig 模型)
- gpt_neo — GPTNeoForCausalLM(GPTNeoConfig 模型)
- gpt_neox — GPTNeoXForCausalLM(GPTNeoXConfig 模型)
- gpt_neox_japanese — GPTNeoXJapaneseForCausalLM(GPTNeoXJapaneseConfig 模型)
- gpt_oss — GptOssForCausalLM(GptOssConfig 模型)
- gptj — GPTJForCausalLM(GPTJConfig 模型)
- granite — GraniteForCausalLM(GraniteConfig 模型)
- granite_swa — GraniteSWAForCausalLM(GraniteSWAConfig 模型)
- granitemoe — GraniteMoeForCausalLM(GraniteMoeConfig 模型)
- granitemoe_swa — GraniteMoeSWAForCausalLM(GraniteMoeSWAConfig 模型)
- granitemoehybrid — GraniteMoeHybridForCausalLM(GraniteMoeHybridConfig 模型)
- granitemoeshared — GraniteMoeSharedForCausalLM(GraniteMoeSharedConfig 模型)
- helium — HeliumForCausalLM(HeliumConfig 模型)
- hrm_text — HrmTextForCausalLM(HrmTextConfig 模型)
- hunyuan_v1_dense — HunYuanDenseV1ForCausalLM(HunYuanDenseV1Config 模型)
- hunyuan_v1_moe — HunYuanMoEV1ForCausalLM(HunYuanMoEV1Config 模型)
- hy_v3 — HYV3ForCausalLM(HYV3Config 模型)
- hy_v4 — HYV4ForCausalLM(HYV4Config 模型)
- hyperclovax — HyperCLOVAXForCausalLM(HyperCLOVAXConfig 模型)
- inkling_text — InklingForCausalLM(InklingTextConfig 模型)
- jais2 — Jais2ForCausalLM(Jais2Config 模型)
- jamba — JambaForCausalLM(JambaConfig 模型)
- jetmoe — JetMoeForCausalLM(JetMoeConfig 模型)
- kimi_linear — KimiLinearForCausalLM(KimiLinearConfig 模型)
- kolibri1 — Kolibri1ForCausalLM(Kolibri1Config 模型)
- laguna — LagunaForCausalLM(LagunaConfig 模型)
- lfm2 — Lfm2ForCausalLM(Lfm2Config 模型)
- lfm2_moe — Lfm2MoeForCausalLM(Lfm2MoeConfig 模型)
- lfm3 — Lfm3ForCausalLM(Lfm3Config 模型)
- llama — LlamaForCausalLM(LlamaConfig 模型)
- llama4 — Llama4ForCausalLM(Llama4Config 模型)
- llama4_text — Llama4ForCausalLM(Llama4TextConfig 模型)
- longcat_flash — LongcatFlashForCausalLM(LongcatFlashConfig 模型)
- mamba — MambaForCausalLM(MambaConfig 模型)
- mamba2 — Mamba2ForCausalLM(Mamba2Config 模型)
- marian — MarianForCausalLM(MarianConfig 模型)
- mbart — MBartForCausalLM(MBartConfig 模型)
- megatron-bert — MegatronBertForCausalLM(MegatronBertConfig 模型)
- mellum — MellumForCausalLM(MellumConfig 模型)
- mimo_v2_flash — MiMoV2FlashForCausalLM(MiMoV2FlashConfig 模型)
- minicpm3 — MiniCPM3ForCausalLM(MiniCPM3Config 模型)
- minimax — MiniMaxForCausalLM(MiniMaxConfig 模型)
- minimax_m2 — MiniMaxM2ForCausalLM(MiniMaxM2Config 模型)
- minimax_m3_vl_text — MiniMaxM3VLForCausalLM(MiniMaxM3VLTextConfig 模型)
- ministral — MinistralForCausalLM(MinistralConfig 模型)
- ministral3 — Ministral3ForCausalLM(Ministral3Config 模型)
- mistral — MistralForCausalLM(MistralConfig 模型)
- mixtral — MixtralForCausalLM(MixtralConfig 模型)
- mllama — MllamaForCausalLM(MllamaConfig 模型)
- modernbert-decoder — ModernBertDecoderForCausalLM(ModernBertDecoderConfig 模型)
- moshi — MoshiForCausalLM(MoshiConfig 模型)
- moss_transcribe_diarize — MossTranscribeDiarizeForConditionalGeneration(MossTranscribeDiarizeConfig 模型)
- mpt — MptForCausalLM(MptConfig 模型)
- musicgen — MusicgenForCausalLM(MusicgenConfig 模型)
- musicgen_melody — MusicgenMelodyForCausalLM(MusicgenMelodyConfig 模型)
- mvp — MvpForCausalLM(MvpConfig 模型)
- nanochat — NanoChatForCausalLM(NanoChatConfig 模型)
- nemotron — NemotronForCausalLM(NemotronConfig 模型)
- nemotron_h — NemotronHForCausalLM(NemotronHConfig 模型)
- olmo — OlmoForCausalLM(OlmoConfig 模型)
- olmo2 — Olmo2ForCausalLM(Olmo2Config 模型)
- olmo3 — Olmo3ForCausalLM(Olmo3Config 模型)
- olmo_hybrid — OlmoHybridForCausalLM(OlmoHybridConfig 模型)
- olmoe — OlmoeForCausalLM(OlmoeConfig 模型)
- openai-gpt — OpenAIGPTLMHeadModel(OpenAIGPTConfig 模型)
- opt — OPTForCausalLM(OPTConfig 模型)
- pegasus — PegasusForCausalLM(PegasusConfig 模型)
- persimmon — PersimmonForCausalLM(PersimmonConfig 模型)
- phi — PhiForCausalLM(PhiConfig 模型)
- phi3 — Phi3ForCausalLM(Phi3Config 模型)
- phi4_multimodal — Phi4MultimodalForCausalLM(Phi4MultimodalConfig 模型)
- phimoe — PhimoeForCausalLM(PhimoeConfig 模型)
- plbart — PLBartForCausalLM(PLBartConfig 模型)
- prophetnet — ProphetNetForCausalLM(ProphetNetConfig 模型)
- qwen2 — Qwen2ForCausalLM(Qwen2Config 模型)
- qwen2_moe — Qwen2MoeForCausalLM(Qwen2MoeConfig 模型)
- qwen3 — Qwen3ForCausalLM(Qwen3Config 模型)
- qwen3_5 — Qwen3_5ForCausalLM(Qwen3_5Config 模型)
- qwen3_5_moe — Qwen3_5MoeForCausalLM(Qwen3_5MoeConfig 模型)
- qwen3_5_moe_text — Qwen3_5MoeForCausalLM(Qwen3_5MoeTextConfig 模型)
- qwen3_5_text — Qwen3_5ForCausalLM(Qwen3_5TextConfig 模型)
- qwen3_moe — Qwen3MoeForCausalLM(Qwen3MoeConfig 模型)
- qwen3_next — Qwen3NextForCausalLM(Qwen3NextConfig 模型)
- qwen4_exp — Qwen4ExpForCausalLM(Qwen4ExpConfig 模型)
- qwen4_exp_text — Qwen4ExpForCausalLM(Qwen4ExpTextConfig 模型)
- recurrent_gemma — RecurrentGemmaForCausalLM(RecurrentGemmaConfig 模型)
- reformer — ReformerModelWithLMHead(ReformerConfig 模型)
- rembert — RemBertForCausalLM(RemBertConfig 模型)
- roberta — RobertaForCausalLM(RobertaConfig 模型)
- roberta-prelayernorm — RobertaPreLayerNormForCausalLM(RobertaPreLayerNormConfig 模型)
- roc_bert — RoCBertForCausalLM(RoCBertConfig 模型)
- roformer — RoFormerForCausalLM(RoFormerConfig 模型)
- rwkv — RwkvForCausalLM(RwkvConfig 模型)
- seed_oss — SeedOssForCausalLM(SeedOssConfig 模型)
- smollm3 — SmolLM3ForCausalLM(SmolLM3Config 模型)
- solar_open — SolarOpenForCausalLM(SolarOpenConfig 模型)
- stablelm — StableLmForCausalLM(StableLmConfig 模型)
- starcoder2 — Starcoder2ForCausalLM(Starcoder2Config 模型)
- trocr — TrOCRForCausalLM(TrOCRConfig 模型)
- vaultgemma — VaultGemmaForCausalLM(VaultGemmaConfig 模型)
- whisper — WhisperForCausalLM(WhisperConfig 模型)
- xglm — XGLMForCausalLM(XGLMConfig 模型)
- xlm — XLMWithLMHeadModel(XLMConfig 模型)
- xlm-roberta — XLMRobertaForCausalLM(XLMRobertaConfig 模型)
- xlm-roberta-xl — XLMRobertaXLForCausalLM(XLMRobertaXLConfig 模型)
- xlnet — XLNetLMHeadModel(XLNetConfig 模型)
- xlstm — xLSTMForCausalLM(xLSTMConfig 模型)
- xmod — XmodForCausalLM(XmodConfig 模型)
- youtu — YoutuForCausalLM(YoutuConfig 模型)
- zamba — ZambaForCausalLM(ZambaConfig 模型)
- zamba2 — Zamba2ForCausalLM(Zamba2Config 模型)
- zaya — ZayaForCausalLM(ZayaConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForCausalLM
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForCausalLM.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForCausalLM.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForMaskedLM
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有掩码语言建模头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- AlbertConfig 配置类:AlbertForMaskedLM(AlbertConfig 模型)
- BartConfig 配置类:BartForConditionalGeneration(BartConfig 模型)
- BertConfig 配置类:BertForMaskedLM(BertConfig 模型)
- BigBirdConfig 配置类:BigBirdForMaskedLM(BigBirdConfig 模型)
- CamembertConfig 配置类:CamembertForMaskedLM(CamembertConfig 模型)
- ConvBertConfig 配置类:ConvBertForMaskedLM(ConvBertConfig 模型)
- Data2VecTextConfig 配置类:Data2VecTextForMaskedLM(Data2VecTextConfig 模型)
- DebertaConfig 配置类:DebertaForMaskedLM(DebertaConfig 模型)
- DebertaV2Config 配置类:DebertaV2ForMaskedLM(DebertaV2Config 模型)
- DistilBertConfig 配置类:DistilBertForMaskedLM(DistilBertConfig 模型)
- ElectraConfig 配置类:ElectraForMaskedLM(ElectraConfig 模型)
- ErnieConfig 配置类:ErnieForMaskedLM(ErnieConfig 模型)
- EsmConfig 配置类:EsmForMaskedLM(EsmConfig 模型)
- EsmcConfig 配置类:EsmcForMaskedLM(EsmcConfig 模型)
- EuroBertConfig 配置类:EuroBertForMaskedLM(EuroBertConfig 模型)
- FNetConfig 配置类:FNetForMaskedLM(FNetConfig 模型)
- FlaubertConfig 配置类:FlaubertWithLMHeadModel(FlaubertConfig 模型)
- FunnelConfig 配置类:FunnelForMaskedLM(FunnelConfig 模型)
- GteConfig 配置类:GteForMaskedLM(GteConfig 模型)
- IBertConfig 配置类:IBertForMaskedLM(IBertConfig 模型)
- JinaEmbeddingsV3Config 配置类:JinaEmbeddingsV3ForMaskedLM(JinaEmbeddingsV3Config 模型)
- LayoutLMConfig 配置类:LayoutLMForMaskedLM(LayoutLMConfig 模型)
- LongformerConfig 配置类:LongformerForMaskedLM(LongformerConfig 模型)
- LukeConfig 配置类:LukeForMaskedLM(LukeConfig 模型)
- MBartConfig 配置类:MBartForConditionalGeneration(MBartConfig 模型)
- MPNetConfig 配置类:MPNetForMaskedLM(MPNetConfig 模型)
- MegatronBertConfig 配置类:MegatronBertForMaskedLM(MegatronBertConfig 模型)
- MobileBertConfig 配置类:MobileBertForMaskedLM(MobileBertConfig 模型)
- ModernBertConfig 配置类:ModernBertForMaskedLM(ModernBertConfig 模型)
- ModernVBertConfig 配置类:ModernVBertForMaskedLM(ModernVBertConfig 模型)
- MraConfig 配置类:MraForMaskedLM(MraConfig 模型)
- MvpConfig 配置类:MvpForConditionalGeneration(MvpConfig 模型)
- NeoMMEConfig 配置类:NeoMMEForMaskedLM(NeoMMEConfig 模型)
- NomicBertConfig 配置类:NomicBertForMaskedLM(NomicBertConfig 模型)
- NystromformerConfig 配置类:NystromformerForMaskedLM(NystromformerConfig 模型)
- PerceiverConfig 配置类:PerceiverForMaskedLM(PerceiverConfig 模型)
- ReformerConfig 配置类:ReformerForMaskedLM(ReformerConfig 模型)
- RemBertConfig 配置类:RemBertForMaskedLM(RemBertConfig 模型)
- RoCBertConfig 配置类:RoCBertForMaskedLM(RoCBertConfig 模型)
- RoFormerConfig 配置类:RoFormerForMaskedLM(RoFormerConfig 模型)
- RobertaConfig 配置类:RobertaForMaskedLM(RobertaConfig 模型)
- RobertaPreLayerNormConfig 配置类:RobertaPreLayerNormForMaskedLM(RobertaPreLayerNormConfig 模型)
- SqueezeBertConfig 配置类:SqueezeBertForMaskedLM(SqueezeBertConfig 模型)
- TapasConfig 配置类:TapasForMaskedLM(TapasConfig 模型)
- UltraVBertConfig 配置类:UltraVBertForMaskedLM(UltraVBertConfig 模型)
- UltrabertConfig 配置类:UltrabertForMaskedLM(UltrabertConfig 模型)
- XLMConfig 配置类:XLMWithLMHeadModel(XLMConfig 模型)
- XLMRobertaConfig 配置类:XLMRobertaForMaskedLM(XLMRobertaConfig 模型)
- XLMRobertaXLConfig 配置类:XLMRobertaXLForMaskedLM(XLMRobertaXLConfig 模型)
- XmodConfig 配置类:XmodForMaskedLM(XmodConfig 模型)
- YosoConfig 配置类:YosoForMaskedLM(YosoConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
从配置实例化该库的某个模型类(带有掩码语言建模头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有掩码语言建模头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- albert — AlbertForMaskedLM(AlbertConfig 模型)
- bart — BartForConditionalGeneration(BartConfig 模型)
- bert — BertForMaskedLM(BertConfig 模型)
- big_bird — BigBirdForMaskedLM(BigBirdConfig 模型)
- camembert — CamembertForMaskedLM(CamembertConfig 模型)
- convbert — ConvBertForMaskedLM(ConvBertConfig 模型)
- data2vec-text — Data2VecTextForMaskedLM(Data2VecTextConfig 模型)
- deberta — DebertaForMaskedLM(DebertaConfig 模型)
- deberta-v2 — DebertaV2ForMaskedLM(DebertaV2Config 模型)
- distilbert — DistilBertForMaskedLM(DistilBertConfig 模型)
- electra — ElectraForMaskedLM(ElectraConfig 模型)
- ernie — ErnieForMaskedLM(ErnieConfig 模型)
- esm — EsmForMaskedLM(EsmConfig 模型)
- esmc — EsmcForMaskedLM(EsmcConfig 模型)
- eurobert — EuroBertForMaskedLM(EuroBertConfig 模型)
- flaubert — FlaubertWithLMHeadModel(FlaubertConfig 模型)
- fnet — FNetForMaskedLM(FNetConfig 模型)
- funnel — FunnelForMaskedLM(FunnelConfig 模型)
- gte — GteForMaskedLM(GteConfig 模型)
- ibert — IBertForMaskedLM(IBertConfig 模型)
- jina_embeddings_v3 — JinaEmbeddingsV3ForMaskedLM(JinaEmbeddingsV3Config 模型)
- layoutlm — LayoutLMForMaskedLM(LayoutLMConfig 模型)
- longformer — LongformerForMaskedLM(LongformerConfig 模型)
- luke — LukeForMaskedLM(LukeConfig 模型)
- mbart — MBartForConditionalGeneration(MBartConfig 模型)
- megatron-bert — MegatronBertForMaskedLM(MegatronBertConfig 模型)
- mobilebert — MobileBertForMaskedLM(MobileBertConfig 模型)
- modernbert — ModernBertForMaskedLM(ModernBertConfig 模型)
- modernvbert — ModernVBertForMaskedLM(ModernVBertConfig 模型)
- mpnet — MPNetForMaskedLM(MPNetConfig 模型)
- mra — MraForMaskedLM(MraConfig 模型)
- mvp — MvpForConditionalGeneration(MvpConfig 模型)
- neomme — NeoMMEForMaskedLM(NeoMMEConfig 模型)
- nomic_bert — NomicBertForMaskedLM(NomicBertConfig 模型)
- nystromformer — NystromformerForMaskedLM(NystromformerConfig 模型)
- perceiver — PerceiverForMaskedLM(PerceiverConfig 模型)
- reformer — ReformerForMaskedLM(ReformerConfig 模型)
- rembert — RemBertForMaskedLM(RemBertConfig 模型)
- roberta — RobertaForMaskedLM(RobertaConfig 模型)
- roberta-prelayernorm — RobertaPreLayerNormForMaskedLM(RobertaPreLayerNormConfig 模型)
- roc_bert — RoCBertForMaskedLM(RoCBertConfig 模型)
- roformer — RoFormerForMaskedLM(RoFormerConfig 模型)
- squeezebert — SqueezeBertForMaskedLM(SqueezeBertConfig 模型)
- tapas — TapasForMaskedLM(TapasConfig 模型)
- ultrabert — UltrabertForMaskedLM(UltrabertConfig 模型)
- ultravbert — UltraVBertForMaskedLM(UltraVBertConfig 模型)
- xlm — XLMWithLMHeadModel(XLMConfig 模型)
- xlm-roberta — XLMRobertaForMaskedLM(XLMRobertaConfig 模型)
- xlm-roberta-xl — XLMRobertaXLForMaskedLM(XLMRobertaXLConfig 模型)
- xmod — XmodForMaskedLM(XmodConfig 模型)
- yoso — YosoForMaskedLM(YosoConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForMaskedLM
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForMaskedLM.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForMaskedLM.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForMaskGeneration
AutoModelForSeq2SeqLM
这是一个通用模型类,当通过 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有序列到序列语言建模头)。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- AudioFlamingo3Config 配置类:AudioFlamingo3ForConditionalGeneration(AudioFlamingo3Config 模型)
- BartConfig 配置类:BartForConditionalGeneration(BartConfig 模型)
- BigBirdPegasusConfig 配置类:BigBirdPegasusForConditionalGeneration(BigBirdPegasusConfig 模型)
- BlenderbotConfig 配置类:BlenderbotForConditionalGeneration(BlenderbotConfig 模型)
- BlenderbotSmallConfig 配置类:BlenderbotSmallForConditionalGeneration(BlenderbotSmallConfig 模型)
- EncoderDecoderConfig 配置类:EncoderDecoderModel(EncoderDecoderConfig 模型)
- FSMTConfig 配置类:FSMTForConditionalGeneration(FSMTConfig 模型)
- GlmAsrConfig 配置类:GlmAsrForConditionalGeneration(GlmAsrConfig 模型)
- GraniteSpeechConfig 配置类:GraniteSpeechForConditionalGeneration(GraniteSpeechConfig 模型)
- GraniteSpeechPlusConfig 配置类:GraniteSpeechPlusForConditionalGeneration(GraniteSpeechPlusConfig 模型)
- LEDConfig 配置类:LEDForConditionalGeneration(LEDConfig 模型)
- LongT5Config 配置类:LongT5ForConditionalGeneration(LongT5Config 模型)
- M2M100Config 配置类:M2M100ForConditionalGeneration(M2M100Config 模型)
- MBartConfig 配置类:MBartForConditionalGeneration(MBartConfig 模型)
- MT5Config 配置类:MT5ForConditionalGeneration(MT5Config 模型)
- MarianConfig 配置类:MarianMTModel(MarianConfig 模型)
- MossTranscribeDiarizeConfig 配置类:MossTranscribeDiarizeForConditionalGeneration(MossTranscribeDiarizeConfig 模型)
- MusicFlamingoConfig 配置类:MusicFlamingoForConditionalGeneration(MusicFlamingoConfig 模型)
- MvpConfig 配置类:MvpForConditionalGeneration(MvpConfig 模型)
- Nemotron3_5TranscribeConfig 配置类:Nemotron3_5TranscribeForConditionalGeneration(Nemotron3_5TranscribeConfig 模型)
- NllbMoeConfig 配置类:NllbMoeForConditionalGeneration(NllbMoeConfig 模型)
- PLBartConfig 配置类:PLBartForConditionalGeneration(PLBartConfig 模型)
- PegasusConfig 配置类:PegasusForConditionalGeneration(PegasusConfig 模型)
- PegasusXConfig 配置类:PegasusXForConditionalGeneration(PegasusXConfig 模型)
- ProphetNetConfig 配置类:ProphetNetForConditionalGeneration(ProphetNetConfig 模型)
- Qwen2AudioConfig 配置类:Qwen2AudioForConditionalGeneration(Qwen2AudioConfig 模型)
- Qwen3ASRConfig 配置类:Qwen3ASRForConditionalGeneration(Qwen3ASRConfig 模型)
- SeamlessM4TConfig 配置类:SeamlessM4TForTextToText(SeamlessM4TConfig 模型)
- SeamlessM4Tv2Config 配置类:SeamlessM4Tv2ForTextToText(SeamlessM4Tv2Config 模型)
- SwitchTransformersConfig 配置类:SwitchTransformersForConditionalGeneration(SwitchTransformersConfig 模型)
- T5Config 配置类:T5ForConditionalGeneration(T5Config 模型)
- T5Gemma2Config 配置类:T5Gemma2ForConditionalGeneration(T5Gemma2Config 模型)
- T5GemmaConfig 配置类:T5GemmaForConditionalGeneration(T5GemmaConfig 模型)
- UMT5Config 配置类:UMT5ForConditionalGeneration(UMT5Config 模型)
- VibeVoiceAsrConfig 配置类:VibeVoiceAsrForConditionalGeneration(VibeVoiceAsrConfig 模型)
- VoxtralConfig 配置类:VoxtralForConditionalGeneration(VoxtralConfig 模型)
- VoxtralRealtimeConfig 配置类:VoxtralRealtimeForConditionalGeneration(VoxtralRealtimeConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
从配置实例化该库的某个模型类(带有序列到序列语言建模头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有序列到序列语言建模头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- audioflamingo3 — AudioFlamingo3ForConditionalGeneration(AudioFlamingo3Config 模型)
- bart — BartForConditionalGeneration(BartConfig 模型)
- bigbird_pegasus — BigBirdPegasusForConditionalGeneration(BigBirdPegasusConfig 模型)
- blenderbot — BlenderbotForConditionalGeneration(BlenderbotConfig 模型)
- blenderbot-small — BlenderbotSmallForConditionalGeneration(BlenderbotSmallConfig 模型)
- encoder-decoder — EncoderDecoderModel(EncoderDecoderConfig 模型)
- fsmt — FSMTForConditionalGeneration(FSMTConfig 模型)
- glmasr — GlmAsrForConditionalGeneration(GlmAsrConfig 模型)
- granite_speech — GraniteSpeechForConditionalGeneration(GraniteSpeechConfig 模型)
- granite_speech_plus — GraniteSpeechPlusForConditionalGeneration(GraniteSpeechPlusConfig 模型)
- led — LEDForConditionalGeneration(LEDConfig 模型)
- longt5 — LongT5ForConditionalGeneration(LongT5Config 模型)
- m2m_100 — M2M100ForConditionalGeneration(M2M100Config 模型)
- marian — MarianMTModel(MarianConfig 模型)
- mbart — MBartForConditionalGeneration(MBartConfig 模型)
- moss_transcribe_diarize — MossTranscribeDiarizeForConditionalGeneration(MossTranscribeDiarizeConfig 模型)
- mt5 — MT5ForConditionalGeneration(MT5Config 模型)
- musicflamingo — MusicFlamingoForConditionalGeneration(MusicFlamingoConfig 模型)
- mvp — MvpForConditionalGeneration(MvpConfig 模型)
- nemo_speechlm — Nemotron3_5TranscribeForConditionalGeneration(Nemotron3_5TranscribeConfig 模型)
- nllb-moe — NllbMoeForConditionalGeneration(NllbMoeConfig 模型)
- pegasus — PegasusForConditionalGeneration(PegasusConfig 模型)
- pegasus_x — PegasusXForConditionalGeneration(PegasusXConfig 模型)
- plbart — PLBartForConditionalGeneration(PLBartConfig 模型)
- prophetnet — ProphetNetForConditionalGeneration(ProphetNetConfig 模型)
- qwen2_audio — Qwen2AudioForConditionalGeneration(Qwen2AudioConfig 模型)
- qwen3_asr — Qwen3ASRForConditionalGeneration(Qwen3ASRConfig 模型)
- seamless_m4t — SeamlessM4TForTextToText(SeamlessM4TConfig 模型)
- seamless_m4t_v2 — SeamlessM4Tv2ForTextToText(SeamlessM4Tv2Config 模型)
- switch_transformers — SwitchTransformersForConditionalGeneration(SwitchTransformersConfig 模型)
- t5 — T5ForConditionalGeneration(T5Config 模型)
- t5gemma — T5GemmaForConditionalGeneration(T5GemmaConfig 模型)
- t5gemma2 — T5Gemma2ForConditionalGeneration(T5Gemma2Config 模型)
- umt5 — UMT5ForConditionalGeneration(UMT5Config 模型)
- vibevoice_asr — VibeVoiceAsrForConditionalGeneration(VibeVoiceAsrConfig 模型)
- voxtral — VoxtralForConditionalGeneration(VoxtralConfig 模型)
- voxtral_realtime — VoxtralRealtimeForConditionalGeneration(VoxtralRealtimeConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForSeq2SeqLM
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForSeq2SeqLM.from_pretrained("google-t5/t5-base")
>>> # Update configuration during loading
>>> model = AutoModelForSeq2SeqLM.from_pretrained("google-t5/t5-base", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForSequenceClassification
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有序列分类头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- AXK1Config 配置类:AXK1ForSequenceClassification(AXK1Config 模型)
- AXK2Config 配置类:AXK2ForSequenceClassification(AXK2Config 模型)
- AlbertConfig 配置类:AlbertForSequenceClassification(AlbertConfig 模型)
- ArceeConfig 配置类:ArceeForSequenceClassification(ArceeConfig 模型)
- BartConfig 配置类:BartForSequenceClassification(BartConfig 模型)
- BertConfig 配置类:BertForSequenceClassification(BertConfig 模型)
- BigBirdConfig 配置类:BigBirdForSequenceClassification(BigBirdConfig 模型)
- BigBirdPegasusConfig 配置类:BigBirdPegasusForSequenceClassification(BigBirdPegasusConfig 模型)
- BioGptConfig 配置类:BioGptForSequenceClassification(BioGptConfig 模型)
- BloomConfig 配置类:BloomForSequenceClassification(BloomConfig 模型)
- CTRLConfig 配置类:CTRLForSequenceClassification(CTRLConfig 模型)
- CamembertConfig 配置类:CamembertForSequenceClassification(CamembertConfig 模型)
- CanineConfig 配置类:CanineForSequenceClassification(CanineConfig 模型)
- CohereCompassTextConfig 配置类:CohereCompassTextForSequenceClassification(CohereCompassTextConfig 模型)
- ConvBertConfig 配置类:ConvBertForSequenceClassification(ConvBertConfig 模型)
- Data2VecTextConfig 配置类:Data2VecTextForSequenceClassification(Data2VecTextConfig 模型)
- DebertaConfig 配置类:DebertaForSequenceClassification(DebertaConfig 模型)
- DebertaV2Config 配置类:DebertaV2ForSequenceClassification(DebertaV2Config 模型)
- DeepseekV2Config 配置类:DeepseekV2ForSequenceClassification(DeepseekV2Config 模型)
- DeepseekV3Config 配置类:DeepseekV3ForSequenceClassification(DeepseekV3Config 模型)
- DiffLlamaConfig 配置类:DiffLlamaForSequenceClassification(DiffLlamaConfig 模型)
- DistilBertConfig 配置类:DistilBertForSequenceClassification(DistilBertConfig 模型)
- DogeConfig 配置类:DogeForSequenceClassification(DogeConfig 模型)
- ElectraConfig 配置类:ElectraForSequenceClassification(ElectraConfig 模型)
- ErnieConfig 配置类:ErnieForSequenceClassification(ErnieConfig 模型)
- EsmConfig 配置类:EsmForSequenceClassification(EsmConfig 模型)
- EsmcConfig 配置类:EsmcForSequenceClassification(EsmcConfig 模型)
- EuroBertConfig 配置类:EuroBertForSequenceClassification(EuroBertConfig 模型)
- Exaone4Config 配置类:Exaone4ForSequenceClassification(Exaone4Config 模型)
- FNetConfig 配置类:FNetForSequenceClassification(FNetConfig 模型)
- FalconConfig 配置类:FalconForSequenceClassification(FalconConfig 模型)
- FlaubertConfig 配置类:FlaubertForSequenceClassification(FlaubertConfig 模型)
- FunnelConfig 配置类:FunnelForSequenceClassification(FunnelConfig 模型)
- GPT2Config 配置类:GPT2ForSequenceClassification(GPT2Config 模型)
- GPTBigCodeConfig 配置类:GPTBigCodeForSequenceClassification(GPTBigCodeConfig 模型)
- GPTJConfig 配置类:GPTJForSequenceClassification(GPTJConfig 模型)
- GPTNeoConfig 配置类:GPTNeoForSequenceClassification(GPTNeoConfig 模型)
- GPTNeoXConfig 配置类:GPTNeoXForSequenceClassification(GPTNeoXConfig 模型)
- Gemma2Config 配置类:Gemma2ForSequenceClassification(Gemma2Config 模型)
- Gemma3Config 配置类:Gemma3ForSequenceClassification(Gemma3Config 模型)
- Gemma3TextConfig 配置类:Gemma3TextForSequenceClassification(Gemma3TextConfig 模型)
- GemmaConfig 配置类:GemmaForSequenceClassification(GemmaConfig 模型)
- Glm4Config 配置类:Glm4ForSequenceClassification(Glm4Config 模型)
- GlmConfig 配置类:GlmForSequenceClassification(GlmConfig 模型)
- GptOssConfig 配置类:GptOssForSequenceClassification(GptOssConfig 模型)
- GteConfig 配置类:GteForSequenceClassification(GteConfig 模型)
- HeliumConfig 配置类:HeliumForSequenceClassification(HeliumConfig 模型)
- HunYuanDenseV1Config 配置类:HunYuanDenseV1ForSequenceClassification(HunYuanDenseV1Config 模型)
- HunYuanMoEV1Config 配置类:HunYuanMoEV1ForSequenceClassification(HunYuanMoEV1Config 模型)
- IBertConfig 配置类:IBertForSequenceClassification(IBertConfig 模型)
- JambaConfig 配置类:JambaForSequenceClassification(JambaConfig 模型)
- JetMoeConfig 配置类:JetMoeForSequenceClassification(JetMoeConfig 模型)
- JinaEmbeddingsV3Config 配置类:JinaEmbeddingsV3ForSequenceClassification(JinaEmbeddingsV3Config 模型)
- LayoutLMConfig 配置类:LayoutLMForSequenceClassification(LayoutLMConfig 模型)
- LayoutLMv2Config 配置类:LayoutLMv2ForSequenceClassification(LayoutLMv2Config 模型)
- LayoutLMv3Config 配置类:LayoutLMv3ForSequenceClassification(LayoutLMv3Config 模型)
- LiltConfig 配置类:LiltForSequenceClassification(LiltConfig 模型)
- LlamaConfig 配置类:LlamaForSequenceClassification(LlamaConfig 模型)
- LongformerConfig 配置类:LongformerForSequenceClassification(LongformerConfig 模型)
- LukeConfig 配置类:LukeForSequenceClassification(LukeConfig 模型)
- MBartConfig 配置类:MBartForSequenceClassification(MBartConfig 模型)
- MPNetConfig 配置类:MPNetForSequenceClassification(MPNetConfig 模型)
- MT5Config 配置类:MT5ForSequenceClassification(MT5Config 模型)
- MarkupLMConfig 配置类:MarkupLMForSequenceClassification(MarkupLMConfig 模型)
- MegatronBertConfig 配置类:MegatronBertForSequenceClassification(MegatronBertConfig 模型)
- MiniCPM3Config 配置类:MiniCPM3ForSequenceClassification(MiniCPM3Config 模型)
- MiniMaxConfig 配置类:MiniMaxForSequenceClassification(MiniMaxConfig 模型)
- Ministral3Config 配置类:Ministral3ForSequenceClassification(Ministral3Config 模型)
- MinistralConfig 配置类:MinistralForSequenceClassification(MinistralConfig 模型)
- Mistral4Config 配置类:Mistral4ForSequenceClassification(Mistral4Config 模型)
- MistralConfig 配置类:MistralForSequenceClassification(MistralConfig 模型)
- MixtralConfig 配置类:MixtralForSequenceClassification(MixtralConfig 模型)
- MobileBertConfig 配置类:MobileBertForSequenceClassification(MobileBertConfig 模型)
- ModernBertConfig 配置类:ModernBertForSequenceClassification(ModernBertConfig 模型)
- ModernBertDecoderConfig 配置类:ModernBertDecoderForSequenceClassification(ModernBertDecoderConfig 模型)
- ModernVBertConfig 配置类:ModernVBertForSequenceClassification(ModernVBertConfig 模型)
- MptConfig 配置类:MptForSequenceClassification(MptConfig 模型)
- MraConfig 配置类:MraForSequenceClassification(MraConfig 模型)
- MvpConfig 配置类:MvpForSequenceClassification(MvpConfig 模型)
- NemotronConfig 配置类:NemotronForSequenceClassification(NemotronConfig 模型)
- NomicBertConfig 配置类:NomicBertForSequenceClassification(NomicBertConfig 模型)
- NystromformerConfig 配置类:NystromformerForSequenceClassification(NystromformerConfig 模型)
- OPTConfig 配置类:OPTForSequenceClassification(OPTConfig 模型)
- Olmo2Config 配置类:Olmo2ForSequenceClassification(Olmo2Config 模型)
- Olmo3Config 配置类:Olmo3ForSequenceClassification(Olmo3Config 模型)
- OlmoConfig 配置类:OlmoForSequenceClassification(OlmoConfig 模型)
- OpenAIGPTConfig 配置类:OpenAIGPTForSequenceClassification(OpenAIGPTConfig 模型)
- PLBartConfig 配置类:PLBartForSequenceClassification(PLBartConfig 模型)
- PerceiverConfig 配置类:PerceiverForSequenceClassification(PerceiverConfig 模型)
- PersimmonConfig 配置类:PersimmonForSequenceClassification(PersimmonConfig 模型)
- Phi3Config 配置类:Phi3ForSequenceClassification(Phi3Config 模型)
- PhiConfig 配置类:PhiForSequenceClassification(PhiConfig 模型)
- PhimoeConfig 配置类:PhimoeForSequenceClassification(PhimoeConfig 模型)
- Qwen2Config 配置类:Qwen2ForSequenceClassification(Qwen2Config 模型)
- Qwen2MoeConfig 配置类:Qwen2MoeForSequenceClassification(Qwen2MoeConfig 模型)
- Qwen3Config 配置类:Qwen3ForSequenceClassification(Qwen3Config 模型)
- Qwen3MoeConfig 配置类:Qwen3MoeForSequenceClassification(Qwen3MoeConfig 模型)
- Qwen3NextConfig 配置类:Qwen3NextForSequenceClassification(Qwen3NextConfig 模型)
- Qwen3_5Config 配置类:Qwen3_5ForSequenceClassification(Qwen3_5Config 模型)
- Qwen3_5TextConfig 配置类:Qwen3_5TextForSequenceClassification(Qwen3_5TextConfig 模型)
- ReformerConfig 配置类:ReformerForSequenceClassification(ReformerConfig 模型)
- RemBertConfig 配置类:RemBertForSequenceClassification(RemBertConfig 模型)
- RoCBertConfig 配置类:RoCBertForSequenceClassification(RoCBertConfig 模型)
- RoFormerConfig 配置类:RoFormerForSequenceClassification(RoFormerConfig 模型)
- RobertaConfig 配置类:RobertaForSequenceClassification(RobertaConfig 模型)
- RobertaPreLayerNormConfig 配置类:RobertaPreLayerNormForSequenceClassification(RobertaPreLayerNormConfig 模型)
- SeedOssConfig 配置类:SeedOssForSequenceClassification(SeedOssConfig 模型)
- SmolLM3Config 配置类:SmolLM3ForSequenceClassification(SmolLM3Config 模型)
- SqueezeBertConfig 配置类:SqueezeBertForSequenceClassification(SqueezeBertConfig 模型)
- StableLmConfig 配置类:StableLmForSequenceClassification(StableLmConfig 模型)
- Starcoder2Config 配置类:Starcoder2ForSequenceClassification(Starcoder2Config 模型)
- T5Config 配置类:T5ForSequenceClassification(T5Config 模型)
- T5Gemma2Config 配置类:T5Gemma2ForSequenceClassification(T5Gemma2Config 模型)
- T5GemmaConfig 配置类:T5GemmaForSequenceClassification(T5GemmaConfig 模型)
- TapasConfig 配置类:TapasForSequenceClassification(TapasConfig 模型)
- UMT5Config 配置类:UMT5ForSequenceClassification(UMT5Config 模型)
- UltraVBertConfig 配置类:UltraVBertForSequenceClassification(UltraVBertConfig 模型)
- UltrabertConfig 配置类:UltrabertForSequenceClassification(UltrabertConfig 模型)
- XLMConfig 配置类:XLMForSequenceClassification(XLMConfig 模型)
- XLMRobertaConfig 配置类:XLMRobertaForSequenceClassification(XLMRobertaConfig 模型)
- XLMRobertaXLConfig 配置类:XLMRobertaXLForSequenceClassification(XLMRobertaXLConfig 模型)
- XLNetConfig 配置类:XLNetForSequenceClassification(XLNetConfig 模型)
- XmodConfig 配置类:XmodForSequenceClassification(XmodConfig 模型)
- YosoConfig 配置类:YosoForSequenceClassification(YosoConfig 模型)
- Zamba2Config 配置类:Zamba2ForSequenceClassification(Zamba2Config 模型)
- ZambaConfig 配置类:ZambaForSequenceClassification(ZambaConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
从配置实例化该库的某个模型类(带有序列分类头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库的某个模型类(带有序列分类头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- albert — AlbertForSequenceClassification(AlbertConfig 模型)
- arcee — ArceeForSequenceClassification(ArceeConfig 模型)
- axk1 — AXK1ForSequenceClassification(AXK1Config 模型)
- axk2 — AXK2ForSequenceClassification(AXK2Config 模型)
- bart — BartForSequenceClassification(BartConfig 模型)
- bert — BertForSequenceClassification(BertConfig 模型)
- big_bird — BigBirdForSequenceClassification(BigBirdConfig 模型)
- bigbird_pegasus — BigBirdPegasusForSequenceClassification(BigBirdPegasusConfig 模型)
- biogpt — BioGptForSequenceClassification(BioGptConfig 模型)
- bloom — BloomForSequenceClassification(BloomConfig 模型)
- camembert — CamembertForSequenceClassification(CamembertConfig 模型)
- canine — CanineForSequenceClassification(CanineConfig 模型)
- cohere_compass_text — CohereCompassTextForSequenceClassification(CohereCompassTextConfig 模型)
- convbert — ConvBertForSequenceClassification(ConvBertConfig 模型)
- ctrl — CTRLForSequenceClassification(CTRLConfig 模型)
- data2vec-text — Data2VecTextForSequenceClassification(Data2VecTextConfig 模型)
- deberta — DebertaForSequenceClassification(DebertaConfig 模型)
- deberta-v2 — DebertaV2ForSequenceClassification(DebertaV2Config 模型)
- deepseek_v2 — DeepseekV2ForSequenceClassification(DeepseekV2Config 模型)
- deepseek_v3 — DeepseekV3ForSequenceClassification(DeepseekV3Config 模型)
- diffllama — DiffLlamaForSequenceClassification(DiffLlamaConfig 模型)
- distilbert — DistilBertForSequenceClassification(DistilBertConfig 模型)
- doge — DogeForSequenceClassification(DogeConfig 模型)
- electra — ElectraForSequenceClassification(ElectraConfig 模型)
- ernie — ErnieForSequenceClassification(ErnieConfig 模型)
- esm — EsmForSequenceClassification(EsmConfig 模型)
- esmc — EsmcForSequenceClassification(EsmcConfig 模型)
- eurobert — EuroBertForSequenceClassification(EuroBertConfig 模型)
- exaone4 — Exaone4ForSequenceClassification(Exaone4Config 模型)
- falcon — FalconForSequenceClassification(FalconConfig 模型)
- flaubert — FlaubertForSequenceClassification(FlaubertConfig 模型)
- fnet — FNetForSequenceClassification(FNetConfig 模型)
- funnel — FunnelForSequenceClassification(FunnelConfig 模型)
- gemma — GemmaForSequenceClassification(GemmaConfig 模型)
- gemma2 — Gemma2ForSequenceClassification(Gemma2Config 模型)
- gemma3 — Gemma3ForSequenceClassification(Gemma3Config 模型)
- gemma3_text — Gemma3TextForSequenceClassification(Gemma3TextConfig 模型)
- glm — GlmForSequenceClassification(GlmConfig 模型)
- glm4 — Glm4ForSequenceClassification(Glm4Config 模型)
- gpt-sw3 — GPT2ForSequenceClassification(GPT2Config 模型)
- gpt2 — GPT2ForSequenceClassification(GPT2Config 模型)
- gpt_bigcode — GPTBigCodeForSequenceClassification(GPTBigCodeConfig 模型)
- gpt_neo — GPTNeoForSequenceClassification(GPTNeoConfig 模型)
- gpt_neox — GPTNeoXForSequenceClassification(GPTNeoXConfig 模型)
- gpt_oss — GptOssForSequenceClassification(GptOssConfig 模型)
- gptj — GPTJForSequenceClassification(GPTJConfig 模型)
- gte — GteForSequenceClassification(GteConfig 模型)
- helium — HeliumForSequenceClassification(HeliumConfig 模型)
- hunyuan_v1_dense — HunYuanDenseV1ForSequenceClassification(HunYuanDenseV1Config 模型)
- hunyuan_v1_moe — HunYuanMoEV1ForSequenceClassification(HunYuanMoEV1Config 模型)
- ibert — IBertForSequenceClassification(IBertConfig 模型)
- jamba — JambaForSequenceClassification(JambaConfig 模型)
- jetmoe — JetMoeForSequenceClassification(JetMoeConfig 模型)
- jina_embeddings_v3 — JinaEmbeddingsV3ForSequenceClassification(JinaEmbeddingsV3Config 模型)
- layoutlm — LayoutLMForSequenceClassification(LayoutLMConfig 模型)
- layoutlmv2 — LayoutLMv2ForSequenceClassification(LayoutLMv2Config 模型)
- layoutlmv3 — LayoutLMv3ForSequenceClassification(LayoutLMv3Config 模型)
- lilt — LiltForSequenceClassification(LiltConfig 模型)
- llama — LlamaForSequenceClassification(LlamaConfig 模型)
- longformer — LongformerForSequenceClassification(LongformerConfig 模型)
- luke — LukeForSequenceClassification(LukeConfig 模型)
- markuplm — MarkupLMForSequenceClassification(MarkupLMConfig 模型)
- mbart — MBartForSequenceClassification(MBartConfig 模型)
- megatron-bert — MegatronBertForSequenceClassification(MegatronBertConfig 模型)
- minicpm3 — MiniCPM3ForSequenceClassification(MiniCPM3Config 模型)
- minimax — MiniMaxForSequenceClassification(MiniMaxConfig 模型)
- ministral — MinistralForSequenceClassification(MinistralConfig 模型)
- ministral3 — Ministral3ForSequenceClassification(Ministral3Config 模型)
- mistral — MistralForSequenceClassification(MistralConfig 模型)
- mistral4 — Mistral4ForSequenceClassification(Mistral4Config 模型)
- mixtral — MixtralForSequenceClassification(MixtralConfig 模型)
- mobilebert — MobileBertForSequenceClassification(MobileBertConfig 模型)
- modernbert — ModernBertForSequenceClassification(ModernBertConfig 模型)
- modernbert-decoder — ModernBertDecoderForSequenceClassification(ModernBertDecoderConfig 模型)
- modernvbert — ModernVBertForSequenceClassification(ModernVBertConfig 模型)
- mpnet — MPNetForSequenceClassification(MPNetConfig 模型)
- mpt — MptForSequenceClassification(MptConfig 模型)
- mra — MraForSequenceClassification(MraConfig 模型)
- mt5 — MT5ForSequenceClassification(MT5Config 模型)
- mvp — MvpForSequenceClassification(MvpConfig 模型)
- nemotron — NemotronForSequenceClassification(NemotronConfig 模型)
- nomic_bert — NomicBertForSequenceClassification(NomicBertConfig 模型)
- nystromformer — NystromformerForSequenceClassification(NystromformerConfig 模型)
- olmo — OlmoForSequenceClassification(OlmoConfig 模型)
- olmo2 — Olmo2ForSequenceClassification(Olmo2Config 模型)
- olmo3 — Olmo3ForSequenceClassification(Olmo3Config 模型)
- openai-gpt — OpenAIGPTForSequenceClassification(OpenAIGPTConfig 模型)
- opt — OPTForSequenceClassification(OPTConfig 模型)
- perceiver — PerceiverForSequenceClassification(PerceiverConfig 模型)
- persimmon — PersimmonForSequenceClassification(PersimmonConfig 模型)
- phi — PhiForSequenceClassification(PhiConfig 模型)
- phi3 — Phi3ForSequenceClassification(Phi3Config 模型)
- phimoe — PhimoeForSequenceClassification(PhimoeConfig 模型)
- plbart — PLBartForSequenceClassification(PLBartConfig 模型)
- qwen2 — Qwen2ForSequenceClassification(Qwen2Config 模型)
- qwen2_moe — Qwen2MoeForSequenceClassification(Qwen2MoeConfig 模型)
- qwen3 — Qwen3ForSequenceClassification(Qwen3Config 模型)
- qwen3_5 — Qwen3_5ForSequenceClassification(Qwen3_5Config 模型)
- qwen3_5_text — Qwen3_5TextForSequenceClassification(Qwen3_5TextConfig 模型)
- qwen3_moe — Qwen3MoeForSequenceClassification(Qwen3MoeConfig 模型)
- qwen3_next — Qwen3NextForSequenceClassification(Qwen3NextConfig 模型)
- reformer — ReformerForSequenceClassification(ReformerConfig 模型)
- rembert — RemBertForSequenceClassification(RemBertConfig 模型)
- roberta — RobertaForSequenceClassification(RobertaConfig 模型)
- roberta-prelayernorm — RobertaPreLayerNormForSequenceClassification(RobertaPreLayerNormConfig 模型)
- roc_bert — RoCBertForSequenceClassification(RoCBertConfig 模型)
- roformer — RoFormerForSequenceClassification(RoFormerConfig 模型)
- seed_oss — SeedOssForSequenceClassification(SeedOssConfig 模型)
- smollm3 — SmolLM3ForSequenceClassification(SmolLM3Config 模型)
- squeezebert — SqueezeBertForSequenceClassification(SqueezeBertConfig 模型)
- stablelm — StableLmForSequenceClassification(StableLmConfig 模型)
- starcoder2 — Starcoder2ForSequenceClassification(Starcoder2Config 模型)
- t5 — T5ForSequenceClassification(T5Config 模型)
- t5gemma — T5GemmaForSequenceClassification(T5GemmaConfig 模型)
- t5gemma2 — T5Gemma2ForSequenceClassification(T5Gemma2Config 模型)
- tapas — TapasForSequenceClassification(TapasConfig 模型)
- ultrabert — UltrabertForSequenceClassification(UltrabertConfig 模型)
- ultravbert — UltraVBertForSequenceClassification(UltraVBertConfig 模型)
- umt5 — UMT5ForSequenceClassification(UMT5Config 模型)
- xlm — XLMForSequenceClassification(XLMConfig 模型)
- xlm-roberta — XLMRobertaForSequenceClassification(XLMRobertaConfig 模型)
- xlm-roberta-xl — XLMRobertaXLForSequenceClassification(XLMRobertaXLConfig 模型)
- xlnet — XLNetForSequenceClassification(XLNetConfig 模型)
- xmod — XmodForSequenceClassification(XmodConfig 模型)
- yoso — YosoForSequenceClassification(YosoConfig 模型)
- zamba — ZambaForSequenceClassification(ZambaConfig 模型)
- zamba2 — Zamba2ForSequenceClassification(Zamba2Config 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForSequenceClassification
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForSequenceClassification.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForSequenceClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForMultipleChoice
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有多个选择头的模型类之一。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- AlbertConfig 配置类:AlbertForMultipleChoice(AlbertConfig 模型)
- BertConfig 配置类:BertForMultipleChoice(BertConfig 模型)
- BigBirdConfig 配置类:BigBirdForMultipleChoice(BigBirdConfig 模型)
- CamembertConfig 配置类:CamembertForMultipleChoice(CamembertConfig 模型)
- CanineConfig 配置类:CanineForMultipleChoice(CanineConfig 模型)
- ConvBertConfig 配置类:ConvBertForMultipleChoice(ConvBertConfig 模型)
- Data2VecTextConfig 配置类:Data2VecTextForMultipleChoice(Data2VecTextConfig 模型)
- DebertaV2Config 配置类:DebertaV2ForMultipleChoice(DebertaV2Config 模型)
- DistilBertConfig 配置类:DistilBertForMultipleChoice(DistilBertConfig 模型)
- ElectraConfig 配置类:ElectraForMultipleChoice(ElectraConfig 模型)
- ErnieConfig 配置类:ErnieForMultipleChoice(ErnieConfig 模型)
- FNetConfig 配置类:FNetForMultipleChoice(FNetConfig 模型)
- FlaubertConfig 配置类:FlaubertForMultipleChoice(FlaubertConfig 模型)
- FunnelConfig 配置类:FunnelForMultipleChoice(FunnelConfig 模型)
- IBertConfig 配置类:IBertForMultipleChoice(IBertConfig 模型)
- LongformerConfig 配置类:LongformerForMultipleChoice(LongformerConfig 模型)
- LukeConfig 配置类:LukeForMultipleChoice(LukeConfig 模型)
- MPNetConfig 配置类:MPNetForMultipleChoice(MPNetConfig 模型)
- MegatronBertConfig 配置类:MegatronBertForMultipleChoice(MegatronBertConfig 模型)
- MobileBertConfig 配置类:MobileBertForMultipleChoice(MobileBertConfig 模型)
- ModernBertConfig 配置类:ModernBertForMultipleChoice(ModernBertConfig 模型)
- MraConfig 配置类:MraForMultipleChoice(MraConfig 模型)
- NystromformerConfig 配置类:NystromformerForMultipleChoice(NystromformerConfig 模型)
- RemBertConfig 配置类:RemBertForMultipleChoice(RemBertConfig 模型)
- RoCBertConfig 配置类:RoCBertForMultipleChoice(RoCBertConfig 模型)
- RoFormerConfig 配置类:RoFormerForMultipleChoice(RoFormerConfig 模型)
- RobertaConfig 配置类:RobertaForMultipleChoice(RobertaConfig 模型)
- RobertaPreLayerNormConfig 配置类:RobertaPreLayerNormForMultipleChoice(RobertaPreLayerNormConfig 模型)
- SqueezeBertConfig 配置类:SqueezeBertForMultipleChoice(SqueezeBertConfig 模型)
- XLMConfig 配置类:XLMForMultipleChoice(XLMConfig 模型)
- XLMRobertaConfig 配置类:XLMRobertaForMultipleChoice(XLMRobertaConfig 模型)
- XLMRobertaXLConfig 配置类:XLMRobertaXLForMultipleChoice(XLMRobertaXLConfig 模型)
- XLNetConfig 配置类:XLNetForMultipleChoice(XLNetConfig 模型)
- XmodConfig 配置类:XmodForMultipleChoice(XmodConfig 模型)
- YosoConfig 配置类:YosoForMultipleChoice(YosoConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有多选头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有多选头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- albert — AlbertForMultipleChoice(AlbertConfig 模型)
- bert — BertForMultipleChoice(BertConfig 模型)
- big_bird — BigBirdForMultipleChoice(BigBirdConfig 模型)
- camembert — CamembertForMultipleChoice(CamembertConfig 模型)
- canine — CanineForMultipleChoice(CanineConfig 模型)
- convbert — ConvBertForMultipleChoice(ConvBertConfig 模型)
- data2vec-text — Data2VecTextForMultipleChoice(Data2VecTextConfig 模型)
- deberta-v2 — DebertaV2ForMultipleChoice(DebertaV2Config 模型)
- distilbert — DistilBertForMultipleChoice(DistilBertConfig 模型)
- electra — ElectraForMultipleChoice(ElectraConfig 模型)
- ernie — ErnieForMultipleChoice(ErnieConfig 模型)
- flaubert — FlaubertForMultipleChoice(FlaubertConfig 模型)
- fnet — FNetForMultipleChoice(FNetConfig 模型)
- funnel — FunnelForMultipleChoice(FunnelConfig 模型)
- ibert — IBertForMultipleChoice(IBertConfig 模型)
- longformer — LongformerForMultipleChoice(LongformerConfig 模型)
- luke — LukeForMultipleChoice(LukeConfig 模型)
- megatron-bert — MegatronBertForMultipleChoice(MegatronBertConfig 模型)
- mobilebert — MobileBertForMultipleChoice(MobileBertConfig 模型)
- modernbert — ModernBertForMultipleChoice(ModernBertConfig 模型)
- mpnet — MPNetForMultipleChoice(MPNetConfig 模型)
- mra — MraForMultipleChoice(MraConfig 模型)
- nystromformer — NystromformerForMultipleChoice(NystromformerConfig 模型)
- rembert — RemBertForMultipleChoice(RemBertConfig 模型)
- roberta — RobertaForMultipleChoice(RobertaConfig 模型)
- roberta-prelayernorm — RobertaPreLayerNormForMultipleChoice(RobertaPreLayerNormConfig 模型)
- roc_bert — RoCBertForMultipleChoice(RoCBertConfig 模型)
- roformer — RoFormerForMultipleChoice(RoFormerConfig 模型)
- squeezebert — SqueezeBertForMultipleChoice(SqueezeBertConfig 模型)
- xlm — XLMForMultipleChoice(XLMConfig 模型)
- xlm-roberta — XLMRobertaForMultipleChoice(XLMRobertaConfig 模型)
- xlm-roberta-xl — XLMRobertaXLForMultipleChoice(XLMRobertaXLConfig 模型)
- xlnet — XLNetForMultipleChoice(XLNetConfig 模型)
- xmod — XmodForMultipleChoice(XmodConfig 模型)
- yoso — YosoForMultipleChoice(YosoConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForMultipleChoice
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForMultipleChoice.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForMultipleChoice.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForNextSentencePrediction
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有下一句预测头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- BertConfig 配置类:BertForNextSentencePrediction(BertConfig 模型)
- ErnieConfig 配置类:ErnieForNextSentencePrediction(ErnieConfig 模型)
- FNetConfig 配置类:FNetForNextSentencePrediction(FNetConfig 模型)
- MegatronBertConfig 配置类:MegatronBertForNextSentencePrediction(MegatronBertConfig 模型)
- MobileBertConfig 配置类:MobileBertForNextSentencePrediction(MobileBertConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
从配置实例化该库的某个模型类(带有下一句预测头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有下一句预测头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- bert — BertForNextSentencePrediction(BertConfig 模型)
- ernie — ErnieForNextSentencePrediction(ErnieConfig 模型)
- fnet — FNetForNextSentencePrediction(FNetConfig 模型)
- megatron-bert — MegatronBertForNextSentencePrediction(MegatronBertConfig 模型)
- mobilebert — MobileBertForNextSentencePrediction(MobileBertConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForNextSentencePrediction
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForNextSentencePrediction.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForNextSentencePrediction.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForTokenClassification
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有 token 分类头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- AXK1Config 配置类:AXK1ForTokenClassification(AXK1Config 模型)
- AXK2Config 配置类:AXK2ForTokenClassification(AXK2Config 模型)
- AlbertConfig 配置类:AlbertForTokenClassification(AlbertConfig 模型)
- ApertusConfig 配置类:ApertusForTokenClassification(ApertusConfig 模型)
- ArceeConfig 配置类:ArceeForTokenClassification(ArceeConfig 模型)
- BertConfig 配置类:BertForTokenClassification(BertConfig 模型)
- BigBirdConfig 配置类:BigBirdForTokenClassification(BigBirdConfig 模型)
- BioGptConfig 配置类:BioGptForTokenClassification(BioGptConfig 模型)
- BloomConfig 配置类:BloomForTokenClassification(BloomConfig 模型)
- BrosConfig 配置类:BrosForTokenClassification(BrosConfig 模型)
- CamembertConfig 配置类:CamembertForTokenClassification(CamembertConfig 模型)
- CanineConfig 配置类:CanineForTokenClassification(CanineConfig 模型)
- ConvBertConfig 配置类:ConvBertForTokenClassification(ConvBertConfig 模型)
- Data2VecTextConfig 配置类:Data2VecTextForTokenClassification(Data2VecTextConfig 模型)
- DebertaConfig 配置类:DebertaForTokenClassification(DebertaConfig 模型)
- DebertaV2Config 配置类:DebertaV2ForTokenClassification(DebertaV2Config 模型)
- DeepseekV3Config 配置类:DeepseekV3ForTokenClassification(DeepseekV3Config 模型)
- DiffLlamaConfig 配置类:DiffLlamaForTokenClassification(DiffLlamaConfig 模型)
- DistilBertConfig 配置类:DistilBertForTokenClassification(DistilBertConfig 模型)
- ElectraConfig 配置类:ElectraForTokenClassification(ElectraConfig 模型)
- ErnieConfig 配置类:ErnieForTokenClassification(ErnieConfig 模型)
- EsmConfig 配置类:EsmForTokenClassification(EsmConfig 模型)
- EsmcConfig 配置类:EsmcForTokenClassification(EsmcConfig 模型)
- EuroBertConfig 配置类:EuroBertForTokenClassification(EuroBertConfig 模型)
- Exaone4Config 配置类:Exaone4ForTokenClassification(Exaone4Config 模型)
- FNetConfig 配置类:FNetForTokenClassification(FNetConfig 模型)
- FalconConfig 配置类:FalconForTokenClassification(FalconConfig 模型)
- FlaubertConfig 配置类:FlaubertForTokenClassification(FlaubertConfig 模型)
- FunnelConfig 配置类:FunnelForTokenClassification(FunnelConfig 模型)
- GPT2Config 配置类:GPT2ForTokenClassification(GPT2Config 模型)
- GPTBigCodeConfig 配置类:GPTBigCodeForTokenClassification(GPTBigCodeConfig 模型)
- GPTNeoConfig 配置类:GPTNeoForTokenClassification(GPTNeoConfig 模型)
- GPTNeoXConfig 配置类:GPTNeoXForTokenClassification(GPTNeoXConfig 模型)
- Gemma2Config 配置类:Gemma2ForTokenClassification(Gemma2Config 模型)
- GemmaConfig 配置类:GemmaForTokenClassification(GemmaConfig 模型)
- Glm4Config 配置类:Glm4ForTokenClassification(Glm4Config 模型)
- GlmConfig 配置类:GlmForTokenClassification(GlmConfig 模型)
- GptOssConfig 配置类:GptOssForTokenClassification(GptOssConfig 模型)
- GteConfig 配置类:GteForTokenClassification(GteConfig 模型)
- HeliumConfig 配置类:HeliumForTokenClassification(HeliumConfig 模型)
- IBertConfig 配置类:IBertForTokenClassification(IBertConfig 模型)
- JinaEmbeddingsV3Config 配置类:JinaEmbeddingsV3ForTokenClassification(JinaEmbeddingsV3Config 模型)
- LayoutLMConfig 配置类:LayoutLMForTokenClassification(LayoutLMConfig 模型)
- LayoutLMv2Config 配置类:LayoutLMv2ForTokenClassification(LayoutLMv2Config 模型)
- LayoutLMv3Config 配置类:LayoutLMv3ForTokenClassification(LayoutLMv3Config 模型)
- LiltConfig 配置类:LiltForTokenClassification(LiltConfig 模型)
- LlamaConfig 配置类:LlamaForTokenClassification(LlamaConfig 模型)
- LongformerConfig 配置类:LongformerForTokenClassification(LongformerConfig 模型)
- LukeConfig 配置类:LukeForTokenClassification(LukeConfig 模型)
- MPNetConfig 配置类:MPNetForTokenClassification(MPNetConfig 模型)
- MT5Config 配置类:MT5ForTokenClassification(MT5Config 模型)
- MarkupLMConfig 配置类:MarkupLMForTokenClassification(MarkupLMConfig 模型)
- MegatronBertConfig 配置类:MegatronBertForTokenClassification(MegatronBertConfig 模型)
- MiniMaxConfig 配置类:MiniMaxForTokenClassification(MiniMaxConfig 模型)
- Ministral3Config 配置类:Ministral3ForTokenClassification(Ministral3Config 模型)
- MinistralConfig 配置类:MinistralForTokenClassification(MinistralConfig 模型)
- Mistral4Config 配置类:Mistral4ForTokenClassification(Mistral4Config 模型)
- MistralConfig 配置类:MistralForTokenClassification(MistralConfig 模型)
- MixtralConfig 配置类:MixtralForTokenClassification(MixtralConfig 模型)
- MobileBertConfig 配置类:MobileBertForTokenClassification(MobileBertConfig 模型)
- ModernBertConfig 配置类:ModernBertForTokenClassification(ModernBertConfig 模型)
- ModernVBertConfig 配置类:ModernVBertForTokenClassification(ModernVBertConfig 模型)
- MptConfig 配置类:MptForTokenClassification(MptConfig 模型)
- MraConfig 配置类:MraForTokenClassification(MraConfig 模型)
- NemotronConfig 配置类:NemotronForTokenClassification(NemotronConfig 模型)
- NomicBertConfig 配置类:NomicBertForTokenClassification(NomicBertConfig 模型)
- NystromformerConfig 配置类:NystromformerForTokenClassification(NystromformerConfig 模型)
- OpenAIPrivacyFilterConfig 配置类:OpenAIPrivacyFilterForTokenClassification(OpenAIPrivacyFilterConfig 模型)
- PersimmonConfig 配置类:PersimmonForTokenClassification(PersimmonConfig 模型)
- Phi3Config 配置类:Phi3ForTokenClassification(Phi3Config 模型)
- PhiConfig 配置类:PhiForTokenClassification(PhiConfig 模型)
- Qwen2Config 配置类:Qwen2ForTokenClassification(Qwen2Config 模型)
- Qwen2MoeConfig 配置类:Qwen2MoeForTokenClassification(Qwen2MoeConfig 模型)
- Qwen3ASRConfig 配置类:Qwen3ASRForTokenClassification(Qwen3ASRConfig 模型)
- Qwen3Config 配置类:Qwen3ForTokenClassification(Qwen3Config 模型)
- Qwen3MoeConfig 配置类:Qwen3MoeForTokenClassification(Qwen3MoeConfig 模型)
- Qwen3NextConfig 配置类:Qwen3NextForTokenClassification(Qwen3NextConfig 模型)
- Qwen3_5Config 配置类:Qwen3_5ForTokenClassification(Qwen3_5Config 模型)
- RemBertConfig 配置类:RemBertForTokenClassification(RemBertConfig 模型)
- RoCBertConfig 配置类:RoCBertForTokenClassification(RoCBertConfig 模型)
- RoFormerConfig 配置类:RoFormerForTokenClassification(RoFormerConfig 模型)
- RobertaConfig 配置类:RobertaForTokenClassification(RobertaConfig 模型)
- RobertaPreLayerNormConfig 配置类:RobertaPreLayerNormForTokenClassification(RobertaPreLayerNormConfig 模型)
- SeedOssConfig 配置类:SeedOssForTokenClassification(SeedOssConfig 模型)
- SmolLM3Config 配置类:SmolLM3ForTokenClassification(SmolLM3Config 模型)
- SqueezeBertConfig 配置类:SqueezeBertForTokenClassification(SqueezeBertConfig 模型)
- StableLmConfig 配置类:StableLmForTokenClassification(StableLmConfig 模型)
- Starcoder2Config 配置类:Starcoder2ForTokenClassification(Starcoder2Config 模型)
- T5Config 配置类:T5ForTokenClassification(T5Config 模型)
- T5Gemma2Config 配置类:T5Gemma2ForTokenClassification(T5Gemma2Config 模型)
- T5GemmaConfig 配置类:T5GemmaForTokenClassification(T5GemmaConfig 模型)
- UMT5Config 配置类:UMT5ForTokenClassification(UMT5Config 模型)
- UltraVBertConfig 配置类:UltraVBertForTokenClassification(UltraVBertConfig 模型)
- UltrabertConfig 配置类:UltrabertForTokenClassification(UltrabertConfig 模型)
- XLMConfig 配置类:XLMForTokenClassification(XLMConfig 模型)
- XLMRobertaConfig 配置类:XLMRobertaForTokenClassification(XLMRobertaConfig 模型)
- XLMRobertaXLConfig 配置类:XLMRobertaXLForTokenClassification(XLMRobertaXLConfig 模型)
- XLNetConfig 配置类:XLNetForTokenClassification(XLNetConfig 模型)
- XmodConfig 配置类:XmodForTokenClassification(XmodConfig 模型)
- YosoConfig 配置类:YosoForTokenClassification(YosoConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化库中的一个模型类(带有 token 分类头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有 token 分类头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- albert — AlbertForTokenClassification(AlbertConfig 模型)
- apertus — ApertusForTokenClassification(ApertusConfig 模型)
- arcee — ArceeForTokenClassification(ArceeConfig 模型)
- axk1 — AXK1ForTokenClassification(AXK1Config 模型)
- axk2 — AXK2ForTokenClassification(AXK2Config 模型)
- bert — BertForTokenClassification(BertConfig 模型)
- big_bird — BigBirdForTokenClassification(BigBirdConfig 模型)
- biogpt — BioGptForTokenClassification(BioGptConfig 模型)
- bloom — BloomForTokenClassification(BloomConfig 模型)
- bros — BrosForTokenClassification(BrosConfig 模型)
- camembert — CamembertForTokenClassification(CamembertConfig 模型)
- canine — CanineForTokenClassification(CanineConfig 模型)
- convbert — ConvBertForTokenClassification(ConvBertConfig 模型)
- data2vec-text — Data2VecTextForTokenClassification(Data2VecTextConfig 模型)
- deberta — DebertaForTokenClassification(DebertaConfig 模型)
- deberta-v2 — DebertaV2ForTokenClassification(DebertaV2Config 模型)
- deepseek_v3 — DeepseekV3ForTokenClassification(DeepseekV3Config 模型)
- diffllama — DiffLlamaForTokenClassification(DiffLlamaConfig 模型)
- distilbert — DistilBertForTokenClassification(DistilBertConfig 模型)
- electra — ElectraForTokenClassification(ElectraConfig 模型)
- ernie — ErnieForTokenClassification(ErnieConfig 模型)
- esm — EsmForTokenClassification(EsmConfig 模型)
- esmc — EsmcForTokenClassification(EsmcConfig 模型)
- eurobert — EuroBertForTokenClassification(EuroBertConfig 模型)
- exaone4 — Exaone4ForTokenClassification(Exaone4Config 模型)
- falcon — FalconForTokenClassification(FalconConfig 模型)
- flaubert — FlaubertForTokenClassification(FlaubertConfig 模型)
- fnet — FNetForTokenClassification(FNetConfig 模型)
- funnel — FunnelForTokenClassification(FunnelConfig 模型)
- gemma — GemmaForTokenClassification(GemmaConfig 模型)
- gemma2 — Gemma2ForTokenClassification(Gemma2Config 模型)
- glm — GlmForTokenClassification(GlmConfig 模型)
- glm4 — Glm4ForTokenClassification(Glm4Config 模型)
- gpt-sw3 — GPT2ForTokenClassification(GPT2Config 模型)
- gpt2 — GPT2ForTokenClassification(GPT2Config 模型)
- gpt_bigcode — GPTBigCodeForTokenClassification(GPTBigCodeConfig 模型)
- gpt_neo — GPTNeoForTokenClassification(GPTNeoConfig 模型)
- gpt_neox — GPTNeoXForTokenClassification(GPTNeoXConfig 模型)
- gpt_oss — GptOssForTokenClassification(GptOssConfig 模型)
- gte — GteForTokenClassification(GteConfig 模型)
- helium — HeliumForTokenClassification(HeliumConfig 模型)
- ibert — IBertForTokenClassification(IBertConfig 模型)
- jina_embeddings_v3 — JinaEmbeddingsV3ForTokenClassification(JinaEmbeddingsV3Config 模型)
- layoutlm — LayoutLMForTokenClassification(LayoutLMConfig 模型)
- layoutlmv2 — LayoutLMv2ForTokenClassification(LayoutLMv2Config 模型)
- layoutlmv3 — LayoutLMv3ForTokenClassification(LayoutLMv3Config 模型)
- lilt — LiltForTokenClassification(LiltConfig 模型)
- llama — LlamaForTokenClassification(LlamaConfig 模型)
- longformer — LongformerForTokenClassification(LongformerConfig 模型)
- luke — LukeForTokenClassification(LukeConfig 模型)
- markuplm — MarkupLMForTokenClassification(MarkupLMConfig 模型)
- megatron-bert — MegatronBertForTokenClassification(MegatronBertConfig 模型)
- minimax — MiniMaxForTokenClassification(MiniMaxConfig 模型)
- ministral — MinistralForTokenClassification(MinistralConfig 模型)
- ministral3 — Ministral3ForTokenClassification(Ministral3Config 模型)
- mistral — MistralForTokenClassification(MistralConfig 模型)
- mistral4 — Mistral4ForTokenClassification(Mistral4Config 模型)
- mixtral — MixtralForTokenClassification(MixtralConfig 模型)
- mobilebert — MobileBertForTokenClassification(MobileBertConfig 模型)
- modernbert — ModernBertForTokenClassification(ModernBertConfig 模型)
- modernvbert — ModernVBertForTokenClassification(ModernVBertConfig 模型)
- mpnet — MPNetForTokenClassification(MPNetConfig 模型)
- mpt — MptForTokenClassification(MptConfig 模型)
- mra — MraForTokenClassification(MraConfig 模型)
- mt5 — MT5ForTokenClassification(MT5Config 模型)
- nemotron — NemotronForTokenClassification(NemotronConfig 模型)
- nomic_bert — NomicBertForTokenClassification(NomicBertConfig 模型)
- nystromformer — NystromformerForTokenClassification(NystromformerConfig 模型)
- openai_privacy_filter — OpenAIPrivacyFilterForTokenClassification(OpenAIPrivacyFilterConfig 模型)
- persimmon — PersimmonForTokenClassification(PersimmonConfig 模型)
- phi — PhiForTokenClassification(PhiConfig 模型)
- phi3 — Phi3ForTokenClassification(Phi3Config 模型)
- qwen2 — Qwen2ForTokenClassification(Qwen2Config 模型)
- qwen2_moe — Qwen2MoeForTokenClassification(Qwen2MoeConfig 模型)
- qwen3 — Qwen3ForTokenClassification(Qwen3Config 模型)
- qwen3_5 — Qwen3_5ForTokenClassification(Qwen3_5Config 模型)
- qwen3_asr — Qwen3ASRForTokenClassification(Qwen3ASRConfig 模型)
- qwen3_moe — Qwen3MoeForTokenClassification(Qwen3MoeConfig 模型)
- qwen3_next — Qwen3NextForTokenClassification(Qwen3NextConfig 模型)
- rembert — RemBertForTokenClassification(RemBertConfig 模型)
- roberta — RobertaForTokenClassification(RobertaConfig 模型)
- roberta-prelayernorm — RobertaPreLayerNormForTokenClassification(RobertaPreLayerNormConfig 模型)
- roc_bert — RoCBertForTokenClassification(RoCBertConfig 模型)
- roformer — RoFormerForTokenClassification(RoFormerConfig 模型)
- seed_oss — SeedOssForTokenClassification(SeedOssConfig 模型)
- smollm3 — SmolLM3ForTokenClassification(SmolLM3Config 模型)
- squeezebert — SqueezeBertForTokenClassification(SqueezeBertConfig 模型)
- stablelm — StableLmForTokenClassification(StableLmConfig 模型)
- starcoder2 — Starcoder2ForTokenClassification(Starcoder2Config 模型)
- t5 — T5ForTokenClassification(T5Config 模型)
- t5gemma — T5GemmaForTokenClassification(T5GemmaConfig 模型)
- t5gemma2 — T5Gemma2ForTokenClassification(T5Gemma2Config 模型)
- ultrabert — UltrabertForTokenClassification(UltrabertConfig 模型)
- ultravbert — UltraVBertForTokenClassification(UltraVBertConfig 模型)
- umt5 — UMT5ForTokenClassification(UMT5Config 模型)
- xlm — XLMForTokenClassification(XLMConfig 模型)
- xlm-roberta — XLMRobertaForTokenClassification(XLMRobertaConfig 模型)
- xlm-roberta-xl — XLMRobertaXLForTokenClassification(XLMRobertaXLConfig 模型)
- xlnet — XLNetForTokenClassification(XLNetConfig 模型)
- xmod — XmodForTokenClassification(XmodConfig 模型)
- yoso — YosoForTokenClassification(YosoConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForTokenClassification
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForTokenClassification.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForTokenClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForQuestionAnswering
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有问答头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- AlbertConfig 配置类:AlbertForQuestionAnswering(AlbertConfig 模型)
- ArceeConfig 配置类:ArceeForQuestionAnswering(ArceeConfig 模型)
- BartConfig 配置类:BartForQuestionAnswering(BartConfig 模型)
- BertConfig 配置类:BertForQuestionAnswering(BertConfig 模型)
- BigBirdConfig 配置类:BigBirdForQuestionAnswering(BigBirdConfig 模型)
- BigBirdPegasusConfig 配置类:BigBirdPegasusForQuestionAnswering(BigBirdPegasusConfig 模型)
- BloomConfig 配置类:BloomForQuestionAnswering(BloomConfig 模型)
- CamembertConfig 配置类:CamembertForQuestionAnswering(CamembertConfig 模型)
- CanineConfig 配置类:CanineForQuestionAnswering(CanineConfig 模型)
- ConvBertConfig 配置类:ConvBertForQuestionAnswering(ConvBertConfig 模型)
- Data2VecTextConfig 配置类:Data2VecTextForQuestionAnswering(Data2VecTextConfig 模型)
- DebertaConfig 配置类:DebertaForQuestionAnswering(DebertaConfig 模型)
- DebertaV2Config 配置类:DebertaV2ForQuestionAnswering(DebertaV2Config 模型)
- DiffLlamaConfig 配置类:DiffLlamaForQuestionAnswering(DiffLlamaConfig 模型)
- DistilBertConfig 配置类:DistilBertForQuestionAnswering(DistilBertConfig 模型)
- ElectraConfig 配置类:ElectraForQuestionAnswering(ElectraConfig 模型)
- ErnieConfig 配置类:ErnieForQuestionAnswering(ErnieConfig 模型)
- Exaone4Config 配置类:Exaone4ForQuestionAnswering(Exaone4Config 模型)
- FNetConfig 配置类:FNetForQuestionAnswering(FNetConfig 模型)
- FalconConfig 配置类:FalconForQuestionAnswering(FalconConfig 模型)
- FlaubertConfig 配置类:FlaubertForQuestionAnsweringSimple(FlaubertConfig 模型)
- FunnelConfig 配置类:FunnelForQuestionAnswering(FunnelConfig 模型)
- GPT2Config 配置类:GPT2ForQuestionAnswering(GPT2Config 模型)
- GPTJConfig 配置类:GPTJForQuestionAnswering(GPTJConfig 模型)
- GPTNeoConfig 配置类:GPTNeoForQuestionAnswering(GPTNeoConfig 模型)
- GPTNeoXConfig 配置类:GPTNeoXForQuestionAnswering(GPTNeoXConfig 模型)
- IBertConfig 配置类:IBertForQuestionAnswering(IBertConfig 模型)
- JinaEmbeddingsV3Config 配置类:JinaEmbeddingsV3ForQuestionAnswering(JinaEmbeddingsV3Config 模型)
- LEDConfig 配置类:LEDForQuestionAnswering(LEDConfig 模型)
- LayoutLMv2Config 配置类:LayoutLMv2ForQuestionAnswering(LayoutLMv2Config 模型)
- LayoutLMv3Config 配置类:LayoutLMv3ForQuestionAnswering(LayoutLMv3Config 模型)
- LiltConfig 配置类:LiltForQuestionAnswering(LiltConfig 模型)
- LlamaConfig 配置类:LlamaForQuestionAnswering(LlamaConfig 模型)
- LongformerConfig 配置类:LongformerForQuestionAnswering(LongformerConfig 模型)
- LukeConfig 配置类:LukeForQuestionAnswering(LukeConfig 模型)
- LxmertConfig 配置类:LxmertForQuestionAnswering(LxmertConfig 模型)
- MBartConfig 配置类:MBartForQuestionAnswering(MBartConfig 模型)
- MPNetConfig 配置类:MPNetForQuestionAnswering(MPNetConfig 模型)
- MT5Config 配置类:MT5ForQuestionAnswering(MT5Config 模型)
- MarkupLMConfig 配置类:MarkupLMForQuestionAnswering(MarkupLMConfig 模型)
- MegatronBertConfig 配置类:MegatronBertForQuestionAnswering(MegatronBertConfig 模型)
- MiniMaxConfig 配置类:MiniMaxForQuestionAnswering(MiniMaxConfig 模型)
- Ministral3Config 配置类:Ministral3ForQuestionAnswering(Ministral3Config 模型)
- MinistralConfig 配置类:MinistralForQuestionAnswering(MinistralConfig 模型)
- MistralConfig 配置类:MistralForQuestionAnswering(MistralConfig 模型)
- MixtralConfig 配置类:MixtralForQuestionAnswering(MixtralConfig 模型)
- MobileBertConfig 配置类:MobileBertForQuestionAnswering(MobileBertConfig 模型)
- ModernBertConfig 配置类:ModernBertForQuestionAnswering(ModernBertConfig 模型)
- MptConfig 配置类:MptForQuestionAnswering(MptConfig 模型)
- MraConfig 配置类:MraForQuestionAnswering(MraConfig 模型)
- MvpConfig 配置类:MvpForQuestionAnswering(MvpConfig 模型)
- NemotronConfig 配置类:NemotronForQuestionAnswering(NemotronConfig 模型)
- NystromformerConfig 配置类:NystromformerForQuestionAnswering(NystromformerConfig 模型)
- OPTConfig 配置类:OPTForQuestionAnswering(OPTConfig 模型)
- Qwen2Config 配置类:Qwen2ForQuestionAnswering(Qwen2Config 模型)
- Qwen2MoeConfig 配置类:Qwen2MoeForQuestionAnswering(Qwen2MoeConfig 模型)
- Qwen3Config 配置类:Qwen3ForQuestionAnswering(Qwen3Config 模型)
- Qwen3MoeConfig 配置类:Qwen3MoeForQuestionAnswering(Qwen3MoeConfig 模型)
- Qwen3NextConfig 配置类:Qwen3NextForQuestionAnswering(Qwen3NextConfig 模型)
- ReformerConfig 配置类:ReformerForQuestionAnswering(ReformerConfig 模型)
- RemBertConfig 配置类:RemBertForQuestionAnswering(RemBertConfig 模型)
- RoCBertConfig 配置类:RoCBertForQuestionAnswering(RoCBertConfig 模型)
- RoFormerConfig 配置类:RoFormerForQuestionAnswering(RoFormerConfig 模型)
- RobertaConfig 配置类:RobertaForQuestionAnswering(RobertaConfig 模型)
- RobertaPreLayerNormConfig 配置类:RobertaPreLayerNormForQuestionAnswering(RobertaPreLayerNormConfig 模型)
- SeedOssConfig 配置类:SeedOssForQuestionAnswering(SeedOssConfig 模型)
- SmolLM3Config 配置类:SmolLM3ForQuestionAnswering(SmolLM3Config 模型)
- SplinterConfig 配置类:SplinterForQuestionAnswering(SplinterConfig 模型)
- SqueezeBertConfig 配置类:SqueezeBertForQuestionAnswering(SqueezeBertConfig 模型)
- T5Config 配置类:T5ForQuestionAnswering(T5Config 模型)
- UMT5Config 配置类:UMT5ForQuestionAnswering(UMT5Config 模型)
- UltrabertConfig 配置类:UltrabertForQuestionAnswering(UltrabertConfig 模型)
- XLMConfig 配置类:XLMForQuestionAnsweringSimple(XLMConfig 模型)
- XLMRobertaConfig 配置类:XLMRobertaForQuestionAnswering(XLMRobertaConfig 模型)
- XLMRobertaXLConfig 配置类:XLMRobertaXLForQuestionAnswering(XLMRobertaXLConfig 模型)
- XLNetConfig 配置类:XLNetForQuestionAnsweringSimple(XLNetConfig 模型)
- XmodConfig 配置类:XmodForQuestionAnswering(XmodConfig 模型)
- YosoConfig 配置类:YosoForQuestionAnswering(YosoConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有问答头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有问答头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- albert — AlbertForQuestionAnswering(AlbertConfig 模型)
- arcee — ArceeForQuestionAnswering(ArceeConfig 模型)
- bart — BartForQuestionAnswering(BartConfig 模型)
- bert — BertForQuestionAnswering(BertConfig 模型)
- big_bird — BigBirdForQuestionAnswering(BigBirdConfig 模型)
- bigbird_pegasus — BigBirdPegasusForQuestionAnswering(BigBirdPegasusConfig 模型)
- bloom — BloomForQuestionAnswering(BloomConfig 模型)
- camembert — CamembertForQuestionAnswering(CamembertConfig 模型)
- canine — CanineForQuestionAnswering(CanineConfig 模型)
- convbert — ConvBertForQuestionAnswering(ConvBertConfig 模型)
- data2vec-text — Data2VecTextForQuestionAnswering(Data2VecTextConfig 模型)
- deberta — DebertaForQuestionAnswering(DebertaConfig 模型)
- deberta-v2 — DebertaV2ForQuestionAnswering(DebertaV2Config 模型)
- diffllama — DiffLlamaForQuestionAnswering(DiffLlamaConfig 模型)
- distilbert — DistilBertForQuestionAnswering(DistilBertConfig 模型)
- electra — ElectraForQuestionAnswering(ElectraConfig 模型)
- ernie — ErnieForQuestionAnswering(ErnieConfig 模型)
- exaone4 — Exaone4ForQuestionAnswering(Exaone4Config 模型)
- falcon — FalconForQuestionAnswering(FalconConfig 模型)
- flaubert — FlaubertForQuestionAnsweringSimple(FlaubertConfig 模型)
- fnet — FNetForQuestionAnswering(FNetConfig 模型)
- funnel — FunnelForQuestionAnswering(FunnelConfig 模型)
- gpt2 — GPT2ForQuestionAnswering(GPT2Config 模型)
- gpt_neo — GPTNeoForQuestionAnswering(GPTNeoConfig 模型)
- gpt_neox — GPTNeoXForQuestionAnswering(GPTNeoXConfig 模型)
- gptj — GPTJForQuestionAnswering(GPTJConfig 模型)
- ibert — IBertForQuestionAnswering(IBertConfig 模型)
- jina_embeddings_v3 — JinaEmbeddingsV3ForQuestionAnswering(JinaEmbeddingsV3Config 模型)
- layoutlmv2 — LayoutLMv2ForQuestionAnswering(LayoutLMv2Config 模型)
- layoutlmv3 — LayoutLMv3ForQuestionAnswering(LayoutLMv3Config 模型)
- led — LEDForQuestionAnswering(LEDConfig 模型)
- lilt — LiltForQuestionAnswering(LiltConfig 模型)
- llama — LlamaForQuestionAnswering(LlamaConfig 模型)
- longformer — LongformerForQuestionAnswering(LongformerConfig 模型)
- luke — LukeForQuestionAnswering(LukeConfig 模型)
- lxmert — LxmertForQuestionAnswering(LxmertConfig 模型)
- markuplm — MarkupLMForQuestionAnswering(MarkupLMConfig 模型)
- mbart — MBartForQuestionAnswering(MBartConfig 模型)
- megatron-bert — MegatronBertForQuestionAnswering(MegatronBertConfig 模型)
- minimax — MiniMaxForQuestionAnswering(MiniMaxConfig 模型)
- ministral — MinistralForQuestionAnswering(MinistralConfig 模型)
- ministral3 — Ministral3ForQuestionAnswering(Ministral3Config 模型)
- mistral — MistralForQuestionAnswering(MistralConfig 模型)
- mixtral — MixtralForQuestionAnswering(MixtralConfig 模型)
- mobilebert — MobileBertForQuestionAnswering(MobileBertConfig 模型)
- modernbert — ModernBertForQuestionAnswering(ModernBertConfig 模型)
- mpnet — MPNetForQuestionAnswering(MPNetConfig 模型)
- mpt — MptForQuestionAnswering(MptConfig 模型)
- mra — MraForQuestionAnswering(MraConfig 模型)
- mt5 — MT5ForQuestionAnswering(MT5Config 模型)
- mvp — MvpForQuestionAnswering(MvpConfig 模型)
- nemotron — NemotronForQuestionAnswering(NemotronConfig 模型)
- nystromformer — NystromformerForQuestionAnswering(NystromformerConfig 模型)
- opt — OPTForQuestionAnswering(OPTConfig 模型)
- qwen2 — Qwen2ForQuestionAnswering(Qwen2Config 模型)
- qwen2_moe — Qwen2MoeForQuestionAnswering(Qwen2MoeConfig 模型)
- qwen3 — Qwen3ForQuestionAnswering(Qwen3Config 模型)
- qwen3_moe — Qwen3MoeForQuestionAnswering(Qwen3MoeConfig 模型)
- qwen3_next — Qwen3NextForQuestionAnswering(Qwen3NextConfig 模型)
- reformer — ReformerForQuestionAnswering(ReformerConfig 模型)
- rembert — RemBertForQuestionAnswering(RemBertConfig 模型)
- roberta — RobertaForQuestionAnswering(RobertaConfig 模型)
- roberta-prelayernorm — RobertaPreLayerNormForQuestionAnswering(RobertaPreLayerNormConfig 模型)
- roc_bert — RoCBertForQuestionAnswering(RoCBertConfig 模型)
- roformer — RoFormerForQuestionAnswering(RoFormerConfig 模型)
- seed_oss — SeedOssForQuestionAnswering(SeedOssConfig 模型)
- smollm3 — SmolLM3ForQuestionAnswering(SmolLM3Config 模型)
- splinter — SplinterForQuestionAnswering(SplinterConfig 模型)
- squeezebert — SqueezeBertForQuestionAnswering(SqueezeBertConfig 模型)
- t5 — T5ForQuestionAnswering(T5Config 模型)
- ultrabert — UltrabertForQuestionAnswering(UltrabertConfig 模型)
- umt5 — UMT5ForQuestionAnswering(UMT5Config 模型)
- xlm — XLMForQuestionAnsweringSimple(XLMConfig 模型)
- xlm-roberta — XLMRobertaForQuestionAnswering(XLMRobertaConfig 模型)
- xlm-roberta-xl — XLMRobertaXLForQuestionAnswering(XLMRobertaXLConfig 模型)
- xlnet — XLNetForQuestionAnsweringSimple(XLNetConfig 模型)
- xmod — XmodForQuestionAnswering(XmodConfig 模型)
- yoso — YosoForQuestionAnswering(YosoConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForQuestionAnswering
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForQuestionAnswering.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForQuestionAnswering.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForTextEncoding
计算机视觉
以下自动类可用于以下计算机视觉任务。
AutoModelForDepthEstimation
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有深度估计头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- CHMv2Config 配置类:CHMv2ForDepthEstimation(CHMv2Config 模型)
- DPTConfig 配置类:DPTForDepthEstimation(DPTConfig 模型)
- DepthAnythingConfig 配置类:DepthAnythingForDepthEstimation(DepthAnythingConfig 模型)
- DepthProConfig 配置类:DepthProForDepthEstimation(DepthProConfig 模型)
- GLPNConfig 配置类:GLPNForDepthEstimation(GLPNConfig 模型)
- PromptDepthAnythingConfig 配置类:PromptDepthAnythingForDepthEstimation(PromptDepthAnythingConfig 模型)
- Tipsv2DptConfig 配置类:Tipsv2DptForDepthEstimation(Tipsv2DptConfig 模型)
- ZoeDepthConfig 配置类:ZoeDepthForDepthEstimation(ZoeDepthConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化库中的一个模型类(带有深度估计头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有深度估计头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- chmv2 — CHMv2ForDepthEstimation(CHMv2Config 模型)
- depth_anything — DepthAnythingForDepthEstimation(DepthAnythingConfig 模型)
- depth_pro — DepthProForDepthEstimation(DepthProConfig 模型)
- dpt — DPTForDepthEstimation(DPTConfig 模型)
- glpn — GLPNForDepthEstimation(GLPNConfig 模型)
- prompt_depth_anything — PromptDepthAnythingForDepthEstimation(PromptDepthAnythingConfig 模型)
- tipsv2_dpt — Tipsv2DptForDepthEstimation(Tipsv2DptConfig 模型)
- zoedepth — ZoeDepthForDepthEstimation(ZoeDepthConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForDepthEstimation
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForDepthEstimation.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForDepthEstimation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForNormalEstimation
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有常规估计头)。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- Sapiens2Config 配置类:Sapiens2ForNormalEstimation(Sapiens2Config 模型)
- Tipsv2DptConfig 配置类:Tipsv2DptForNormalEstimation(Tipsv2DptConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
从配置实例化该库的某个模型类(带有常规估计头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库的某个模型类(带有常规估计头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- sapiens2 — Sapiens2ForNormalEstimation(Sapiens2Config 模型)
- tipsv2_dpt — Tipsv2DptForNormalEstimation(Tipsv2DptConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForNormalEstimation
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForNormalEstimation.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForNormalEstimation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForPointmapEstimation
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有 pointmap 估计头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- Sapiens2Config 配置类:Sapiens2ForPointmapEstimation(Sapiens2Config 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
从配置实例化库中的一个模型类(带有 pointmap 估计头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有 pointmap 估计头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- sapiens2 — Sapiens2ForPointmapEstimation(Sapiens2Config 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForPointmapEstimation
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForPointmapEstimation.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForPointmapEstimation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForImageMatting
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有图像抠图头的模型类之一。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- Sapiens2Config 配置类:Sapiens2ForImageMatting(Sapiens2Config 模型)
- VitMatteConfig 配置类:VitMatteForImageMatting(VitMatteConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
从配置实例化该库的某个模型类(带有图像抠图头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库的某个模型类(带有图像抠图头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- sapiens2 — Sapiens2ForImageMatting(Sapiens2Config 模型)
- vitmatte — VitMatteForImageMatting(VitMatteConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForImageMatting
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForImageMatting.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForImageMatting.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForTextRecognition
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有文本识别头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- PPOCRV5MobileRecConfig 配置类:PPOCRV5MobileRecForTextRecognition(PPOCRV5MobileRecConfig 模型)
- PPOCRV5ServerRecConfig 配置类:PPOCRV5ServerRecForTextRecognition(PPOCRV5ServerRecConfig 模型)
- PPOCRV6SmallRecConfig 配置类:PPOCRV6SmallRecForTextRecognition(PPOCRV6SmallRecConfig 模型)
- PPOCRV6TinyRecConfig 配置类:PPOCRV6TinyRecForTextRecognition(PPOCRV6TinyRecConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
从配置实例化该库的某个模型类(带有文本识别头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库的某个模型类(带有文本识别头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- pp_ocrv5_mobile_rec — PPOCRV5MobileRecForTextRecognition(PPOCRV5MobileRecConfig 模型)
- pp_ocrv5_server_rec — PPOCRV5ServerRecForTextRecognition(PPOCRV5ServerRecConfig 模型)
- pp_ocrv6_small_rec — PPOCRV6SmallRecForTextRecognition(PPOCRV6SmallRecConfig 模型)
- pp_ocrv6_tiny_rec — PPOCRV6TinyRecForTextRecognition(PPOCRV6TinyRecConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForTextRecognition
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForTextRecognition.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForTextRecognition.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForTableRecognition
这是一个通用模型类,在通过 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有表格识别头)。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- SLANeXtConfig 配置类:SLANeXtForTableRecognition(SLANeXtConfig 模型)
- SLANetConfig 配置类:SLANetForTableRecognition(SLANetConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
从配置实例化该库的某个模型类(带有表格识别头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有表格识别头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- slanet — SLANetForTableRecognition(SLANetConfig 模型)
- slanext — SLANeXtForTableRecognition(SLANeXtConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForTableRecognition
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForTableRecognition.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForTableRecognition.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForImageClassification
这是一个通用模型类,在使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有图像分类头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- BeitConfig 配置类:BeitForImageClassification(BeitConfig 模型)
- BitConfig 配置类:BitForImageClassification(BitConfig 模型)
- CLIPConfig 配置类:CLIPForImageClassification(CLIPConfig 模型)
- ConvNextConfig 配置类:ConvNextForImageClassification(ConvNextConfig 模型)
- ConvNextV2Config 配置类:ConvNextV2ForImageClassification(ConvNextV2Config 模型)
- CvtConfig 配置类:CvtForImageClassification(CvtConfig 模型)
- Data2VecVisionConfig 配置类:Data2VecVisionForImageClassification(Data2VecVisionConfig 模型)
- DeiTConfig 配置类:DeiTForImageClassification 或 DeiTForImageClassificationWithTeacher(DeiTConfig 模型)
- DinatConfig 配置类:DinatForImageClassification(DinatConfig 模型)
- Dinov2Config 配置类:Dinov2ForImageClassification(Dinov2Config 模型)
- Dinov2WithRegistersConfig 配置类:Dinov2WithRegistersForImageClassification(Dinov2WithRegistersConfig 模型)
- DonutSwinConfig 配置类:DonutSwinForImageClassification(DonutSwinConfig 模型)
- EfficientNetConfig 配置类:EfficientNetForImageClassification(EfficientNetConfig 模型)
- FocalNetConfig 配置类:FocalNetForImageClassification(FocalNetConfig 模型)
- HGNetV2Config 配置类:HGNetV2ForImageClassification(HGNetV2Config 模型)
- HieraConfig 配置类:HieraForImageClassification(HieraConfig 模型)
- IJepaConfig 配置类:IJepaForImageClassification(IJepaConfig 模型)
- ImageGPTConfig 配置类:ImageGPTForImageClassification(ImageGPTConfig 模型)
- LevitConfig 配置类:LevitForImageClassification 或 LevitForImageClassificationWithTeacher(LevitConfig 模型)
- MetaClip2Config 配置类:MetaClip2ForImageClassification(MetaClip2Config 模型)
- MobileNetV1Config 配置类:MobileNetV1ForImageClassification(MobileNetV1Config 模型)
- MobileNetV2Config 配置类:MobileNetV2ForImageClassification(MobileNetV2Config 模型)
- MobileViTConfig 配置类:MobileViTForImageClassification(MobileViTConfig 模型)
- MobileViTV2Config 配置类:MobileViTV2ForImageClassification(MobileViTV2Config 模型)
- PPLCNetConfig 配置类:PPLCNetForImageClassification(PPLCNetConfig 模型)
- PerceiverConfig 配置类:PerceiverForImageClassificationLearned 或 PerceiverForImageClassificationFourier 或 PerceiverForImageClassificationConvProcessing(PerceiverConfig 模型)
- PoolFormerConfig 配置类:PoolFormerForImageClassification(PoolFormerConfig 模型)
- PvtConfig 配置类:PvtForImageClassification(PvtConfig 模型)
- PvtV2Config 配置类:PvtV2ForImageClassification(PvtV2Config 模型)
- RegNetConfig 配置类:RegNetForImageClassification(RegNetConfig 模型)
- ResNetConfig 配置类:ResNetForImageClassification(ResNetConfig 模型)
- SegformerConfig 配置类:SegformerForImageClassification(SegformerConfig 模型)
- ShieldGemma2Config 配置类:ShieldGemma2ForImageClassification(ShieldGemma2Config 模型)
- Siglip2Config 配置类:Siglip2ForImageClassification(Siglip2Config 模型)
- SiglipConfig 配置类:SiglipForImageClassification(SiglipConfig 模型)
- SwiftFormerConfig 配置类:SwiftFormerForImageClassification(SwiftFormerConfig 模型)
- SwinConfig 配置类:SwinForImageClassification(SwinConfig 模型)
- Swinv2Config 配置类:Swinv2ForImageClassification(Swinv2Config 模型)
- TextNetConfig 配置类:TextNetForImageClassification(TextNetConfig 模型)
- TimmWrapperConfig 配置类:TimmWrapperForImageClassification(TimmWrapperConfig 模型)
- ViTConfig 配置类:ViTForImageClassification(ViTConfig 模型)
- ViTMSNConfig 配置类:ViTMSNForImageClassification(ViTMSNConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库的某个模型类(带有图像分类头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库的某个模型类(带有图像分类头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- beit — BeitForImageClassification(BeitConfig 模型)
- bit — BitForImageClassification(BitConfig 模型)
- clip — CLIPForImageClassification(CLIPConfig 模型)
- convnext — ConvNextForImageClassification(ConvNextConfig 模型)
- convnextv2 — ConvNextV2ForImageClassification(ConvNextV2Config 模型)
- cvt — CvtForImageClassification(CvtConfig 模型)
- data2vec-vision — Data2VecVisionForImageClassification(Data2VecVisionConfig 模型)
- deit — DeiTForImageClassification 或 DeiTForImageClassificationWithTeacher(DeiTConfig 模型)
- dinat — DinatForImageClassification(DinatConfig 模型)
- dinov2 — Dinov2ForImageClassification(Dinov2Config 模型)
- dinov2_with_registers — Dinov2WithRegistersForImageClassification(Dinov2WithRegistersConfig 模型)
- donut-swin — DonutSwinForImageClassification(DonutSwinConfig 模型)
- efficientnet — EfficientNetForImageClassification(EfficientNetConfig 模型)
- focalnet — FocalNetForImageClassification(FocalNetConfig 模型)
- hgnet_v2 — HGNetV2ForImageClassification(HGNetV2Config 模型)
- hiera — HieraForImageClassification(HieraConfig 模型)
- ijepa — IJepaForImageClassification(IJepaConfig 模型)
- imagegpt — ImageGPTForImageClassification(ImageGPTConfig 模型)
- levit — LevitForImageClassification 或 LevitForImageClassificationWithTeacher(LevitConfig 模型)
- metaclip_2 — MetaClip2ForImageClassification(MetaClip2Config 模型)
- mobilenet_v1 — MobileNetV1ForImageClassification(MobileNetV1Config 模型)
- mobilenet_v2 — MobileNetV2ForImageClassification(MobileNetV2Config 模型)
- mobilevit — MobileViTForImageClassification(MobileViTConfig 模型)
- mobilevitv2 — MobileViTV2ForImageClassification(MobileViTV2Config 模型)
- perceiver — PerceiverForImageClassificationLearned 或 PerceiverForImageClassificationFourier 或 PerceiverForImageClassificationConvProcessing(PerceiverConfig 模型)
- poolformer — PoolFormerForImageClassification(PoolFormerConfig 模型)
- pp_lcnet — PPLCNetForImageClassification(PPLCNetConfig 模型)
- pvt — PvtForImageClassification(PvtConfig 模型)
- pvt_v2 — PvtV2ForImageClassification(PvtV2Config 模型)
- regnet — RegNetForImageClassification(RegNetConfig 模型)
- resnet — ResNetForImageClassification(ResNetConfig 模型)
- segformer — SegformerForImageClassification(SegformerConfig 模型)
- shieldgemma2 — ShieldGemma2ForImageClassification(ShieldGemma2Config 模型)
- siglip — SiglipForImageClassification(SiglipConfig 模型)
- siglip2 — Siglip2ForImageClassification(Siglip2Config 模型)
- swiftformer — SwiftFormerForImageClassification(SwiftFormerConfig 模型)
- swin — SwinForImageClassification(SwinConfig 模型)
- swinv2 — Swinv2ForImageClassification(Swinv2Config 模型)
- textnet — TextNetForImageClassification(TextNetConfig 模型)
- timm_wrapper — TimmWrapperForImageClassification(TimmWrapperConfig 模型)
- vit — ViTForImageClassification(ViTConfig 模型)
- vit_msn — ViTMSNForImageClassification(ViTMSNConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForImageClassification
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForImageClassification.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForImageClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForVideoClassification
这是一个通用模型类,当通过 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有视频分类头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- TimesformerConfig 配置类:TimesformerForVideoClassification(TimesformerConfig 模型)
- VJEPA2Config 配置类:VJEPA2ForVideoClassification(VJEPA2Config 模型)
- VideoMAEConfig 配置类:VideoMAEForVideoClassification(VideoMAEConfig 模型)
- VideoPrismVisionConfig 配置类:VideoPrismForVideoClassification(VideoPrismVisionConfig 模型)
- VivitConfig 配置类:VivitForVideoClassification(VivitConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有视频分类头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有视频分类头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- timesformer — TimesformerForVideoClassification(TimesformerConfig 模型)
- videomae — VideoMAEForVideoClassification(VideoMAEConfig 模型)
- videoprism_vision_model — VideoPrismForVideoClassification(VideoPrismVisionConfig 模型)
- vivit — VivitForVideoClassification(VivitConfig 模型)
- vjepa2 — VJEPA2ForVideoClassification(VJEPA2Config 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForVideoClassification
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForVideoClassification.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForVideoClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForPoseEstimation
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有姿态估计头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- Sapiens2Config 配置类:Sapiens2ForPoseEstimation(Sapiens2Config 模型)
- VitPoseConfig 配置类:VitPoseForPoseEstimation(VitPoseConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
从配置实例化该库的某个模型类(带有姿态估计头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有姿态估计头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- sapiens2 — Sapiens2ForPoseEstimation(Sapiens2Config 模型)
- vitpose — VitPoseForPoseEstimation(VitPoseConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForPoseEstimation
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForPoseEstimation.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForPoseEstimation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForKeypointDetection
AutoModelForKeypointMatching
AutoModelForMaskedImageModeling
这是一个通用模型类,在使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有掩码图像建模头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- DeiTConfig 配置类:DeiTForMaskedImageModeling(DeiTConfig 模型)
- FocalNetConfig 配置类:FocalNetForMaskedImageModeling(FocalNetConfig 模型)
- SwinConfig 配置类:SwinForMaskedImageModeling(SwinConfig 模型)
- Swinv2Config 配置类:Swinv2ForMaskedImageModeling(Swinv2Config 模型)
- ViTConfig 配置类:ViTForMaskedImageModeling(ViTConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有掩码图像建模头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有掩码图像建模头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- deit — DeiTForMaskedImageModeling(DeiTConfig 模型)
- focalnet — FocalNetForMaskedImageModeling(FocalNetConfig 模型)
- swin — SwinForMaskedImageModeling(SwinConfig 模型)
- swinv2 — Swinv2ForMaskedImageModeling(Swinv2Config 模型)
- vit — ViTForMaskedImageModeling(ViTConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForMaskedImageModeling
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForMaskedImageModeling.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForMaskedImageModeling.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForObjectDetection
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有目标检测头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- ConditionalDetrConfig 配置类:ConditionalDetrForObjectDetection(ConditionalDetrConfig 模型)
- DFineConfig 配置类:DFineForObjectDetection(DFineConfig 模型)
- DabDetrConfig 配置类:DabDetrForObjectDetection(DabDetrConfig 模型)
- DeformableDetrConfig 配置类:DeformableDetrForObjectDetection(DeformableDetrConfig 模型)
- Deimv2Config 配置类:Deimv2ForObjectDetection(Deimv2Config 模型)
- DetrConfig 配置类:DetrForObjectDetection(DetrConfig 模型)
- LwDetrConfig 配置类:LwDetrForObjectDetection(LwDetrConfig 模型)
- PPDocLayoutV2Config 配置类:PPDocLayoutV2ForObjectDetection(PPDocLayoutV2Config 模型)
- PPDocLayoutV3Config 配置类:PPDocLayoutV3ForObjectDetection(PPDocLayoutV3Config 模型)
- PPDocLayoutV4Config 配置类:PPDocLayoutV4ForObjectDetection(PPDocLayoutV4Config 模型)
- PPOCRV5MobileDetConfig 配置类:PPOCRV5MobileDetForObjectDetection(PPOCRV5MobileDetConfig 模型)
- PPOCRV5ServerDetConfig 配置类:PPOCRV5ServerDetForObjectDetection(PPOCRV5ServerDetConfig 模型)
- PPOCRV6MediumDetConfig 配置类:PPOCRV6MediumDetForObjectDetection(PPOCRV6MediumDetConfig 模型)
- PPOCRV6SmallDetConfig 配置类:PPOCRV6SmallDetForObjectDetection(PPOCRV6SmallDetConfig 模型)
- RTDetrConfig 配置类:RTDetrForObjectDetection(RTDetrConfig 模型)
- RTDetrV2Config 配置类:RTDetrV2ForObjectDetection(RTDetrV2Config 模型)
- RfDetrConfig 配置类:RfDetrForObjectDetection(RfDetrConfig 模型)
- TableTransformerConfig 配置类:TableTransformerForObjectDetection(TableTransformerConfig 模型)
- YolosConfig 配置类:YolosForObjectDetection(YolosConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化库中的一个模型类(带有目标检测头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有目标检测头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- conditional_detr — ConditionalDetrForObjectDetection(ConditionalDetrConfig 模型)
- d_fine — DFineForObjectDetection(DFineConfig 模型)
- dab-detr — DabDetrForObjectDetection(DabDetrConfig 模型)
- deformable_detr — DeformableDetrForObjectDetection(DeformableDetrConfig 模型)
- deimv2 — Deimv2ForObjectDetection(Deimv2Config 模型)
- detr — DetrForObjectDetection(DetrConfig 模型)
- lw_detr — LwDetrForObjectDetection(LwDetrConfig 模型)
- pp_doclayout_v2 — PPDocLayoutV2ForObjectDetection(PPDocLayoutV2Config 模型)
- pp_doclayout_v3 — PPDocLayoutV3ForObjectDetection(PPDocLayoutV3Config 模型)
- pp_doclayout_v4 — PPDocLayoutV4ForObjectDetection(PPDocLayoutV4Config 模型)
- pp_ocrv5_mobile_det — PPOCRV5MobileDetForObjectDetection(PPOCRV5MobileDetConfig 模型)
- pp_ocrv5_server_det — PPOCRV5ServerDetForObjectDetection(PPOCRV5ServerDetConfig 模型)
- pp_ocrv6_medium_det — PPOCRV6MediumDetForObjectDetection(PPOCRV6MediumDetConfig 模型)
- pp_ocrv6_small_det — PPOCRV6SmallDetForObjectDetection(PPOCRV6SmallDetConfig 模型)
- rf_detr — RfDetrForObjectDetection(RfDetrConfig 模型)
- rt_detr — RTDetrForObjectDetection(RTDetrConfig 模型)
- rt_detr_v2 — RTDetrV2ForObjectDetection(RTDetrV2Config 模型)
- table-transformer — TableTransformerForObjectDetection(TableTransformerConfig 模型)
- yolos — YolosForObjectDetection(YolosConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForObjectDetection
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForObjectDetection.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForObjectDetection.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForImageSegmentation
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有图像分割头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- DetrConfig 配置类:DetrForSegmentation(DetrConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有图像分割头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有图像分割头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- detr — DetrForSegmentation(DetrConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForImageSegmentation
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForImageSegmentation.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForImageSegmentation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForImageToImage
AutoModelForSemanticSegmentation
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有语义分割头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- BeitConfig 配置类:BeitForSemanticSegmentation(BeitConfig 模型)
- DPTConfig 配置类:DPTForSemanticSegmentation(DPTConfig 模型)
- Data2VecVisionConfig 配置类:Data2VecVisionForSemanticSegmentation(Data2VecVisionConfig 模型)
- MobileNetV2Config 配置类:MobileNetV2ForSemanticSegmentation(MobileNetV2Config 模型)
- MobileViTConfig 配置类:MobileViTForSemanticSegmentation(MobileViTConfig 模型)
- MobileViTV2Config 配置类:MobileViTV2ForSemanticSegmentation(MobileViTV2Config 模型)
- Sapiens2Config 配置类:Sapiens2ForSemanticSegmentation(Sapiens2Config 模型)
- SegformerConfig 配置类:SegformerForSemanticSegmentation(SegformerConfig 模型)
- Tipsv2DptConfig 配置类:Tipsv2DptForSemanticSegmentation(Tipsv2DptConfig 模型)
- UperNetConfig 配置类:UperNetForSemanticSegmentation(UperNetConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有语义分割头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库的某个模型类(带有语义分割头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- beit — BeitForSemanticSegmentation(BeitConfig 模型)
- data2vec-vision — Data2VecVisionForSemanticSegmentation(Data2VecVisionConfig 模型)
- dpt — DPTForSemanticSegmentation(DPTConfig 模型)
- mobilenet_v2 — MobileNetV2ForSemanticSegmentation(MobileNetV2Config 模型)
- mobilevit — MobileViTForSemanticSegmentation(MobileViTConfig 模型)
- mobilevitv2 — MobileViTV2ForSemanticSegmentation(MobileViTV2Config 模型)
- sapiens2 — Sapiens2ForSemanticSegmentation(Sapiens2Config 模型)
- segformer — SegformerForSemanticSegmentation(SegformerConfig 模型)
- tipsv2_dpt — Tipsv2DptForSemanticSegmentation(Tipsv2DptConfig 模型)
- upernet — UperNetForSemanticSegmentation(UperNetConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForSemanticSegmentation
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForSemanticSegmentation.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForSemanticSegmentation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForInstanceSegmentation
这是一个通用模型类,在通过 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有实例分割头)。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- MaskFormerConfig 配置类:MaskFormerForInstanceSegmentation(MaskFormerConfig 模型)
- RfDetrConfig 配置类:RfDetrForInstanceSegmentation(RfDetrConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有实例分割头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有实例分割头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- maskformer — MaskFormerForInstanceSegmentation(MaskFormerConfig 模型)
- rf_detr — RfDetrForInstanceSegmentation(RfDetrConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForInstanceSegmentation
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForInstanceSegmentation.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForInstanceSegmentation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForUniversalSegmentation
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有通用图像分割头)。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- DetrConfig 配置类:DetrForSegmentation(DetrConfig 模型)
- EomtConfig 配置类:EomtForUniversalSegmentation(EomtConfig 模型)
- EomtDinov3Config 配置类:EomtDinov3ForUniversalSegmentation(EomtDinov3Config 模型)
- Mask2FormerConfig 配置类:Mask2FormerForUniversalSegmentation(Mask2FormerConfig 模型)
- MaskFormerConfig 配置类:MaskFormerForInstanceSegmentation(MaskFormerConfig 模型)
- OneFormerConfig 配置类:OneFormerForUniversalSegmentation(OneFormerConfig 模型)
- VideomtConfig 配置类:VideomtForUniversalSegmentation(VideomtConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有通用图像分割头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有通用图像分割头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- detr — DetrForSegmentation(DetrConfig 模型)
- eomt — EomtForUniversalSegmentation(EomtConfig 模型)
- eomt_dinov3 — EomtDinov3ForUniversalSegmentation(EomtDinov3Config 模型)
- mask2former — Mask2FormerForUniversalSegmentation(Mask2FormerConfig 模型)
- maskformer — MaskFormerForInstanceSegmentation(MaskFormerConfig 模型)
- oneformer — OneFormerForUniversalSegmentation(OneFormerConfig 模型)
- videomt — VideomtForUniversalSegmentation(VideomtConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForUniversalSegmentation
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForUniversalSegmentation.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForUniversalSegmentation.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForZeroShotImageClassification
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有零样本图像分类头)。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- AlignConfig 配置类:AlignModel(AlignConfig 模型)
- AltCLIPConfig 配置类:AltCLIPModel(AltCLIPConfig 模型)
- Blip2Config 配置类:Blip2ForImageTextRetrieval(Blip2Config 模型)
- BlipConfig 配置类:BlipModel(BlipConfig 模型)
- CLIPConfig 配置类:CLIPModel(CLIPConfig 模型)
- CLIPSegConfig 配置类:CLIPSegModel(CLIPSegConfig 模型)
- ChineseCLIPConfig 配置类:ChineseCLIPModel(ChineseCLIPConfig 模型)
- MetaClip2Config 配置类:MetaClip2Model(MetaClip2Config 模型)
- Siglip2Config 配置类:Siglip2Model(Siglip2Config 模型)
- SiglipConfig 配置类:SiglipModel(SiglipConfig 模型)
- Tipsv2Config 配置类:Tipsv2Model(Tipsv2Config 模型)
- VideoPrismConfig 配置类:VideoPrismClipModel(VideoPrismConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
从配置实例化该库的某个模型类(带有零样本图像分类头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有零样本图像分类头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- align — AlignModel(AlignConfig 模型)
- altclip — AltCLIPModel(AltCLIPConfig 模型)
- blip — BlipModel(BlipConfig 模型)
- blip-2 — Blip2ForImageTextRetrieval(Blip2Config 模型)
- chinese_clip — ChineseCLIPModel(ChineseCLIPConfig 模型)
- clip — CLIPModel(CLIPConfig 模型)
- clipseg — CLIPSegModel(CLIPSegConfig 模型)
- metaclip_2 — MetaClip2Model(MetaClip2Config 模型)
- siglip — SiglipModel(SiglipConfig 模型)
- siglip2 — Siglip2Model(Siglip2Config 模型)
- tipsv2 — Tipsv2Model(Tipsv2Config 模型)
- videoprism — VideoPrismClipModel(VideoPrismConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForZeroShotImageClassification
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForZeroShotImageClassification.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForZeroShotImageClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForZeroShotObjectDetection
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中某个带有零样本目标检测头的模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- GroundingDinoConfig 配置类:GroundingDinoForObjectDetection(GroundingDinoConfig 模型)
- MMGroundingDinoConfig 配置类:MMGroundingDinoForObjectDetection(MMGroundingDinoConfig 模型)
- OmDetTurboConfig 配置类:OmDetTurboForObjectDetection(OmDetTurboConfig 模型)
- OwlViTConfig 配置类:OwlViTForObjectDetection(OwlViTConfig 模型)
- Owlv2Config 配置类:Owlv2ForObjectDetection(Owlv2Config 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有零样本目标检测头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有零样本目标检测头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- grounding-dino — GroundingDinoForObjectDetection(GroundingDinoConfig 模型)
- mm-grounding-dino — MMGroundingDinoForObjectDetection(MMGroundingDinoConfig 模型)
- omdet-turbo — OmDetTurboForObjectDetection(OmDetTurboConfig 模型)
- owlv2 — Owlv2ForObjectDetection(Owlv2Config 模型)
- owlvit — OwlViTForObjectDetection(OwlViTConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForZeroShotObjectDetection
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForZeroShotObjectDetection.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForZeroShotObjectDetection.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True音频
以下自动类可用于以下音频任务。
AutoModelForAudioClassification
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有音频分类头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- ASTConfig 配置类:ASTForAudioClassification(ASTConfig 模型)
- Data2VecAudioConfig 配置类:Data2VecAudioForSequenceClassification(Data2VecAudioConfig 模型)
- HubertConfig 配置类:HubertForSequenceClassification(HubertConfig 模型)
- SEWConfig 配置类:SEWForSequenceClassification(SEWConfig 模型)
- SEWDConfig 配置类:SEWDForSequenceClassification(SEWDConfig 模型)
- UniSpeechConfig 配置类:UniSpeechForSequenceClassification(UniSpeechConfig 模型)
- UniSpeechSatConfig 配置类:UniSpeechSatForSequenceClassification(UniSpeechSatConfig 模型)
- Wav2Vec2BertConfig 配置类:Wav2Vec2BertForSequenceClassification(Wav2Vec2BertConfig 模型)
- Wav2Vec2Config 配置类:Wav2Vec2ForSequenceClassification(Wav2Vec2Config 模型)
- Wav2Vec2ConformerConfig 配置类:Wav2Vec2ConformerForSequenceClassification(Wav2Vec2ConformerConfig 模型)
- WavLMConfig 配置类:WavLMForSequenceClassification(WavLMConfig 模型)
- WhisperConfig 配置类:WhisperForAudioClassification(WhisperConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
从配置实例化该库的某个模型类(带有音频分类头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库的某个模型类(带有音频分类头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- audio-spectrogram-transformer — ASTForAudioClassification(ASTConfig 模型)
- data2vec-audio — Data2VecAudioForSequenceClassification(Data2VecAudioConfig 模型)
- hubert — HubertForSequenceClassification(HubertConfig 模型)
- sew — SEWForSequenceClassification(SEWConfig 模型)
- sew-d — SEWDForSequenceClassification(SEWDConfig 模型)
- unispeech — UniSpeechForSequenceClassification(UniSpeechConfig 模型)
- unispeech-sat — UniSpeechSatForSequenceClassification(UniSpeechSatConfig 模型)
- wav2vec2 — Wav2Vec2ForSequenceClassification(Wav2Vec2Config 模型)
- wav2vec2-bert — Wav2Vec2BertForSequenceClassification(Wav2Vec2BertConfig 模型)
- wav2vec2-conformer — Wav2Vec2ConformerForSequenceClassification(Wav2Vec2ConformerConfig 模型)
- wavlm — WavLMForSequenceClassification(WavLMConfig 模型)
- whisper — WhisperForAudioClassification(WhisperConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForAudioClassification
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForAudioClassification.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForAudioClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForAudioFrameClassification
这是一个通用模型类,在通过 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有音频帧(token)分类头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- Data2VecAudioConfig 配置类:Data2VecAudioForAudioFrameClassification(Data2VecAudioConfig 模型)
- Nemotron3DiarizationConfig 配置类:Nemotron3DiarizationForAudioFrameClassification(Nemotron3DiarizationConfig 模型)
- UniSpeechSatConfig 配置类:UniSpeechSatForAudioFrameClassification(UniSpeechSatConfig 模型)
- Wav2Vec2BertConfig 配置类:Wav2Vec2BertForAudioFrameClassification(Wav2Vec2BertConfig 模型)
- Wav2Vec2Config 配置类:Wav2Vec2ForAudioFrameClassification(Wav2Vec2Config 模型)
- Wav2Vec2ConformerConfig 配置类:Wav2Vec2ConformerForAudioFrameClassification(Wav2Vec2ConformerConfig 模型)
- WavLMConfig 配置类:WavLMForAudioFrameClassification(WavLMConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有音频帧(token)分类头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有音频帧(token)分类头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- data2vec-audio — Data2VecAudioForAudioFrameClassification(Data2VecAudioConfig 模型)
- nemotron3_diarization — Nemotron3DiarizationForAudioFrameClassification(Nemotron3DiarizationConfig 模型)
- unispeech-sat — UniSpeechSatForAudioFrameClassification(UniSpeechSatConfig 模型)
- wav2vec2 — Wav2Vec2ForAudioFrameClassification(Wav2Vec2Config 模型)
- wav2vec2-bert — Wav2Vec2BertForAudioFrameClassification(Wav2Vec2BertConfig 模型)
- wav2vec2-conformer — Wav2Vec2ConformerForAudioFrameClassification(Wav2Vec2ConformerConfig 模型)
- wavlm — WavLMForAudioFrameClassification(WavLMConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForAudioFrameClassification
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForAudioFrameClassification.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForAudioFrameClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForCTC
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有连接时序分类头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- Data2VecAudioConfig 配置类:Data2VecAudioForCTC(Data2VecAudioConfig 模型)
- GraniteSpeech5CTCConfig 配置类:GraniteSpeech5ForCTC(GraniteSpeech5CTCConfig 模型)
- HubertConfig 配置类:HubertForCTC(HubertConfig 模型)
- LasrCTCConfig 配置类:LasrForCTC(LasrCTCConfig 模型)
- ParakeetCTCConfig 配置类:ParakeetForCTC(ParakeetCTCConfig 模型)
- SEWConfig 配置类:SEWForCTC(SEWConfig 模型)
- SEWDConfig 配置类:SEWDForCTC(SEWDConfig 模型)
- UniSpeechConfig 配置类:UniSpeechForCTC(UniSpeechConfig 模型)
- UniSpeechSatConfig 配置类:UniSpeechSatForCTC(UniSpeechSatConfig 模型)
- Wav2Vec2BertConfig 配置类:Wav2Vec2BertForCTC(Wav2Vec2BertConfig 模型)
- Wav2Vec2Config 配置类:Wav2Vec2ForCTC(Wav2Vec2Config 模型)
- Wav2Vec2ConformerConfig 配置类:Wav2Vec2ConformerForCTC(Wav2Vec2ConformerConfig 模型)
- WavLMConfig 配置类:WavLMForCTC(WavLMConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
从配置实例化该库的某个模型类(带有连接时序分类头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库的某个模型类(带有连接时序分类头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- data2vec-audio — Data2VecAudioForCTC(Data2VecAudioConfig 模型)
- granite_speech5_ctc — GraniteSpeech5ForCTC(GraniteSpeech5CTCConfig 模型)
- hubert — HubertForCTC(HubertConfig 模型)
- lasr_ctc — LasrForCTC(LasrCTCConfig 模型)
- parakeet_ctc — ParakeetForCTC(ParakeetCTCConfig 模型)
- sew — SEWForCTC(SEWConfig 模型)
- sew-d — SEWDForCTC(SEWDConfig 模型)
- unispeech — UniSpeechForCTC(UniSpeechConfig 模型)
- unispeech-sat — UniSpeechSatForCTC(UniSpeechSatConfig 模型)
- wav2vec2 — Wav2Vec2ForCTC(Wav2Vec2Config 模型)
- wav2vec2-bert — Wav2Vec2BertForCTC(Wav2Vec2BertConfig 模型)
- wav2vec2-conformer — Wav2Vec2ConformerForCTC(Wav2Vec2ConformerConfig 模型)
- wavlm — WavLMForCTC(WavLMConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForCTC
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForCTC.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForCTC.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForTDT
This is a generic model class that will be instantiated as one of the model classes of the library (with a token-and-duration transducer head) when created with the from_pretrained() class method or the from_config() class method.
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- ParakeetTDTConfig 配置类:ParakeetForTDT(ParakeetTDTConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有 token-and-duration 转导器头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有 token-and-duration 转导器头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- parakeet_tdt — ParakeetForTDT(ParakeetTDTConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForTDT
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForTDT.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForTDT.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForRNNT
This is a generic model class that will be instantiated as one of the model classes of the library (with a RNN transducer head) when created with the from_pretrained() class method or the from_config() class method.
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- Nemotron3_5AsrConfig 配置类:Nemotron3_5AsrForRNNT(Nemotron3_5AsrConfig 模型)
- NemotronAsrStreamingConfig 配置类:NemotronAsrStreamingForRNNT(NemotronAsrStreamingConfig 模型)
- ParakeetRNNTConfig 配置类:ParakeetForRNNT(ParakeetRNNTConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化库中的一个模型类(带有 RNN 转导器头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有 RNN transducer 头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- nemotron3_5_asr — Nemotron3_5AsrForRNNT(Nemotron3_5AsrConfig 模型)
- nemotron_asr_streaming — NemotronAsrStreamingForRNNT(NemotronAsrStreamingConfig 模型)
- parakeet_rnnt — ParakeetForRNNT(ParakeetRNNTConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForRNNT
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForRNNT.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForRNNT.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForSpeechSeq2Seq
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有序列到序列的语音到文本建模头)。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- CanaryConfig 配置类:CanaryForConditionalGeneration(CanaryConfig 模型)
- CohereAsrConfig 配置类:CohereAsrForConditionalGeneration(CohereAsrConfig 模型)
- DiaConfig 配置类:DiaForConditionalGeneration(DiaConfig 模型)
- FunAsrNanoConfig 配置类:FunAsrNanoForConditionalGeneration(FunAsrNanoConfig 模型)
- GraniteSpeechConfig 配置类:GraniteSpeechForConditionalGeneration(GraniteSpeechConfig 模型)
- GraniteSpeechPlusConfig 配置类:GraniteSpeechPlusForConditionalGeneration(GraniteSpeechPlusConfig 模型)
- KyutaiSpeechToTextConfig 配置类:KyutaiSpeechToTextForConditionalGeneration(KyutaiSpeechToTextConfig 模型)
- MoonshineConfig 配置类:MoonshineForConditionalGeneration(MoonshineConfig 模型)
- MoonshineStreamingConfig 配置类:MoonshineStreamingForConditionalGeneration(MoonshineStreamingConfig 模型)
- Pop2PianoConfig 配置类:Pop2PianoForConditionalGeneration(Pop2PianoConfig 模型)
- Qwen3ASRConfig 配置类:Qwen3ASRForConditionalGeneration(Qwen3ASRConfig 模型)
- SeamlessM4TConfig 配置类:SeamlessM4TForSpeechToText(SeamlessM4TConfig 模型)
- SeamlessM4Tv2Config 配置类:SeamlessM4Tv2ForSpeechToText(SeamlessM4Tv2Config 模型)
- Speech2TextConfig 配置类:Speech2TextForConditionalGeneration(Speech2TextConfig 模型)
- SpeechEncoderDecoderConfig 配置类:SpeechEncoderDecoderModel(SpeechEncoderDecoderConfig 模型)
- SpeechT5Config 配置类:SpeechT5ForSpeechToText(SpeechT5Config 模型)
- VibeVoiceAsrConfig 配置类:VibeVoiceAsrForConditionalGeneration(VibeVoiceAsrConfig 模型)
- VibeVoiceConfig 配置类:VibeVoiceForConditionalGeneration(VibeVoiceConfig 模型)
- VoxtralConfig 配置类:VoxtralForConditionalGeneration(VoxtralConfig 模型)
- VoxtralRealtimeConfig 配置类:VoxtralRealtimeForConditionalGeneration(VoxtralRealtimeConfig 模型)
- WhisperConfig 配置类:WhisperForConditionalGeneration(WhisperConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有序列到序列的语音到文本建模头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有序列到序列的语音到文本建模头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- canary — CanaryForConditionalGeneration(CanaryConfig 模型)
- cohere_asr — CohereAsrForConditionalGeneration(CohereAsrConfig 模型)
- dia — DiaForConditionalGeneration(DiaConfig 模型)
- fun_asr_nano — FunAsrNanoForConditionalGeneration(FunAsrNanoConfig 模型)
- granite_speech — GraniteSpeechForConditionalGeneration(GraniteSpeechConfig 模型)
- granite_speech_plus — GraniteSpeechPlusForConditionalGeneration(GraniteSpeechPlusConfig 模型)
- kyutai_speech_to_text — KyutaiSpeechToTextForConditionalGeneration(KyutaiSpeechToTextConfig 模型)
- moonshine — MoonshineForConditionalGeneration(MoonshineConfig 模型)
- moonshine_streaming — MoonshineStreamingForConditionalGeneration(MoonshineStreamingConfig 模型)
- pop2piano — Pop2PianoForConditionalGeneration(Pop2PianoConfig 模型)
- qwen3_asr — Qwen3ASRForConditionalGeneration(Qwen3ASRConfig 模型)
- seamless_m4t — SeamlessM4TForSpeechToText(SeamlessM4TConfig 模型)
- seamless_m4t_v2 — SeamlessM4Tv2ForSpeechToText(SeamlessM4Tv2Config 模型)
- speech-encoder-decoder — SpeechEncoderDecoderModel(SpeechEncoderDecoderConfig 模型)
- speech_to_text — Speech2TextForConditionalGeneration(Speech2TextConfig 模型)
- speecht5 — SpeechT5ForSpeechToText(SpeechT5Config 模型)
- vibevoice — VibeVoiceForConditionalGeneration(VibeVoiceConfig 模型)
- vibevoice_asr — VibeVoiceAsrForConditionalGeneration(VibeVoiceAsrConfig 模型)
- voxtral — VoxtralForConditionalGeneration(VoxtralConfig 模型)
- voxtral_realtime — VoxtralRealtimeForConditionalGeneration(VoxtralRealtimeConfig 模型)
- whisper — WhisperForConditionalGeneration(WhisperConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForSpeechSeq2Seq
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForSpeechSeq2Seq.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForSpeechSeq2Seq.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForAudioXVector
This is a generic model class that will be instantiated as one of the model classes of the library (with a audio retrieval via x-vector head) when created with the from_pretrained() class method or the from_config() class method.
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- Data2VecAudioConfig 配置类:Data2VecAudioForXVector(Data2VecAudioConfig 模型)
- UniSpeechSatConfig 配置类:UniSpeechSatForXVector(UniSpeechSatConfig 模型)
- Wav2Vec2BertConfig 配置类:Wav2Vec2BertForXVector(Wav2Vec2BertConfig 模型)
- Wav2Vec2Config 配置类:Wav2Vec2ForXVector(Wav2Vec2Config 模型)
- Wav2Vec2ConformerConfig 配置类:Wav2Vec2ConformerForXVector(Wav2Vec2ConformerConfig 模型)
- WavLMConfig 配置类:WavLMForXVector(WavLMConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有通过 x-vector 头进行音频检索的功能)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有通过 x-vector 头进行音频检索的功能)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- data2vec-audio — Data2VecAudioForXVector(Data2VecAudioConfig 模型)
- unispeech-sat — UniSpeechSatForXVector(UniSpeechSatConfig 模型)
- wav2vec2 — Wav2Vec2ForXVector(Wav2Vec2Config 模型)
- wav2vec2-bert — Wav2Vec2BertForXVector(Wav2Vec2BertConfig 模型)
- wav2vec2-conformer — Wav2Vec2ConformerForXVector(Wav2Vec2ConformerConfig 模型)
- wavlm — WavLMForXVector(WavLMConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForAudioXVector
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForAudioXVector.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForAudioXVector.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForTextToSpectrogram
AutoModelForTextToWaveform
AutoModelForAudioTokenization
这是一个通用模型类,当通过 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中的某个模型类(带有通过码本头进行音频分词的功能)。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- DacConfig 配置类:DacModel(DacConfig 模型)
- HiggsAudioV2TokenizerConfig 配置类:HiggsAudioV2TokenizerModel(HiggsAudioV2TokenizerConfig 模型)
- NeuCodecConfig 配置类:NeuCodecModel(NeuCodecConfig 模型)
- PocketTTSAudioTokenizerConfig 配置类:PocketTTSAudioTokenizerModel(PocketTTSAudioTokenizerConfig 模型)
- VibeVoiceAcousticTokenizerConfig 配置类:VibeVoiceAcousticTokenizerModel(VibeVoiceAcousticTokenizerConfig 模型)
- Xcodec2Config 配置类:Xcodec2Model(Xcodec2Config 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(通过码本头进行音频分词)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库的某个模型类(通过码本头进行音频分词)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- dac — DacModel(DacConfig 模型)
- higgs_audio_v2_tokenizer — HiggsAudioV2TokenizerModel(HiggsAudioV2TokenizerConfig 模型)
- neucodec — NeuCodecModel(NeuCodecConfig 模型)
- pocket_tts_audio_tokenizer — PocketTTSAudioTokenizerModel(PocketTTSAudioTokenizerConfig 模型)
- vibevoice_acoustic_tokenizer — VibeVoiceAcousticTokenizerModel(VibeVoiceAcousticTokenizerConfig 模型)
- xcodec2 — Xcodec2Model(Xcodec2Config 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForAudioTokenization
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForAudioTokenization.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForAudioTokenization.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True多模态
以下自动类可用于以下多模态任务。
AutoModelForMultimodalLM
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中某个带有多模态生成头的模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- AriaConfig 配置类:AriaForConditionalGeneration(AriaConfig 模型)
- AyaVisionConfig 配置类:AyaVisionForConditionalGeneration(AyaVisionConfig 模型)
- Blip2Config 配置类:Blip2ForConditionalGeneration(Blip2Config 模型)
- BlipConfig 配置类:BlipForConditionalGeneration(BlipConfig 模型)
- ChameleonConfig 配置类:ChameleonForConditionalGeneration(ChameleonConfig 模型)
- Cohere2VisionConfig 配置类:Cohere2VisionForConditionalGeneration(Cohere2VisionConfig 模型)
- CohereCompassConfig 配置类:CohereCompassForConditionalGeneration(CohereCompassConfig 模型)
- Cosmos3EdgeConfig 配置类:Cosmos3EdgeForConditionalGeneration(Cosmos3EdgeConfig 模型)
- Cosmos3OmniConfig 配置类:Cosmos3OmniForConditionalGeneration(Cosmos3OmniConfig 模型)
- DeepseekOcr2Config 配置类:DeepseekOcr2ForConditionalGeneration(DeepseekOcr2Config 模型)
- DeepseekVLConfig 配置类:DeepseekVLForConditionalGeneration(DeepseekVLConfig 模型)
- DeepseekVLHybridConfig 配置类:DeepseekVLHybridForConditionalGeneration(DeepseekVLHybridConfig 模型)
- DiffusionGemmaConfig 配置类:DiffusionGemmaForBlockDiffusion(DiffusionGemmaConfig 模型)
- Emu3Config 配置类:Emu3ForConditionalGeneration(Emu3Config 模型)
- Ernie4_5_VLMoeConfig 配置类:Ernie4_5_VLMoeForConditionalGeneration(Ernie4_5_VLMoeConfig 模型)
- EvollaConfig 配置类:EvollaForProteinText2Text(EvollaConfig 模型)
- Exaone4_5_Config 配置类:Exaone4_5_ForConditionalGeneration(Exaone4_5_Config 模型)
- FastVlmConfig 配置类:FastVlmForConditionalGeneration(FastVlmConfig 模型)
- Florence2Config 配置类:Florence2ForConditionalGeneration(Florence2Config 模型)
- FunAsrNanoConfig 配置类:FunAsrNanoForConditionalGeneration(FunAsrNanoConfig 模型)
- FuyuConfig 配置类:FuyuForCausalLM(FuyuConfig 模型)
- Gemma3Config 配置类:Gemma3ForConditionalGeneration(Gemma3Config 模型)
- Gemma3nConfig 配置类:Gemma3nForConditionalGeneration(Gemma3nConfig 模型)
- Gemma4Config 配置类:Gemma4ForConditionalGeneration(Gemma4Config 模型)
- Gemma4UnifiedConfig 配置类:Gemma4UnifiedForConditionalGeneration(Gemma4UnifiedConfig 模型)
- GitConfig 配置类:GitForCausalLM(GitConfig 模型)
- Glm46VConfig 配置类:Glm46VForConditionalGeneration(Glm46VConfig 模型)
- Glm4vConfig 配置类:Glm4vForConditionalGeneration(Glm4vConfig 模型)
- Glm4vMoeConfig 配置类:Glm4vMoeForConditionalGeneration(Glm4vMoeConfig 模型)
- Glm5NextConfig 配置类:Glm5NextForConditionalGeneration(Glm5NextConfig 模型)
- GlmAsrConfig 配置类:GlmAsrForConditionalGeneration(GlmAsrConfig 模型)
- GlmOcrConfig 配置类:GlmOcrForConditionalGeneration(GlmOcrConfig 模型)
- GlmgaConfig 配置类:Glm46VForConditionalGeneration(GlmgaConfig 模型)
- GotOcr2Config 配置类:GotOcr2ForConditionalGeneration(GotOcr2Config 模型)
- Granite4VisionConfig 配置类:Granite4VisionForConditionalGeneration(Granite4VisionConfig 模型)
- GraniteSpeechConfig 配置类:GraniteSpeechForConditionalGeneration(GraniteSpeechConfig 模型)
- GraniteSpeechPlusConfig 配置类:GraniteSpeechPlusForConditionalGeneration(GraniteSpeechPlusConfig 模型)
- HunYuanVLConfig 配置类:HunYuanVLForConditionalGeneration(HunYuanVLConfig 模型)
- HyperCLOVAXVisionV2Config 配置类:HyperCLOVAXVisionV2ForConditionalGeneration(HyperCLOVAXVisionV2Config 模型)
- Idefics2Config 配置类:Idefics2ForConditionalGeneration(Idefics2Config 模型)
- Idefics3Config 配置类:Idefics3ForConditionalGeneration(Idefics3Config 模型)
- IdeficsConfig 配置类:IdeficsForVisionText2Text(IdeficsConfig 模型)
- InklingConfig 配置类:InklingForConditionalGeneration(InklingConfig 模型)
- InstructBlipConfig 配置类:InstructBlipForConditionalGeneration(InstructBlipConfig 模型)
- InstructBlipVideoConfig 配置类:InstructBlipVideoForConditionalGeneration(InstructBlipVideoConfig 模型)
- InternVLConfig 配置类:InternVLForConditionalGeneration(InternVLConfig 模型)
- JanusConfig 配置类:JanusForConditionalGeneration(JanusConfig 模型)
- Kimi_K25Config 配置类:Kimi_K25ForConditionalGeneration(Kimi_K25Config 模型)
- Kosmos2Config 配置类:Kosmos2ForConditionalGeneration(Kosmos2Config 模型)
- Kosmos2_5Config 配置类:Kosmos2_5ForConditionalGeneration(Kosmos2_5Config 模型)
- KyutaiSpeechToTextConfig 配置类:KyutaiSpeechToTextForConditionalGeneration(KyutaiSpeechToTextConfig 模型)
- Lfm2VlConfig 配置类:Lfm2VlForConditionalGeneration(Lfm2VlConfig 模型)
- LightOnOcrConfig 配置类:LightOnOcrForConditionalGeneration(LightOnOcrConfig 模型)
- Llama4Config 配置类:Llama4ForConditionalGeneration(Llama4Config 模型)
- LlavaConfig 配置类:LlavaForConditionalGeneration(LlavaConfig 模型)
- LlavaNextConfig 配置类:LlavaNextForConditionalGeneration(LlavaNextConfig 模型)
- LlavaNextVideoConfig 配置类:LlavaNextVideoForConditionalGeneration(LlavaNextVideoConfig 模型)
- LlavaOnevisionConfig 配置类:LlavaOnevisionForConditionalGeneration(LlavaOnevisionConfig 模型)
- MiniCPMOcrConfig 配置类:MiniCPMOcrForConditionalGeneration(MiniCPMOcrConfig 模型)
- MiniCPMV4_6Config 配置类:MiniCPMV4_6ForConditionalGeneration(MiniCPMV4_6Config 模型)
- MiniCPMV4_7Config 配置类:MiniCPMV4_7ForConditionalGeneration(MiniCPMV4_7Config 模型)
- MiniMaxM3VLConfig 配置类:MiniMaxM3SparseForConditionalGeneration(MiniMaxM3VLConfig 模型)
- Mistral3Config 配置类:Mistral3ForConditionalGeneration(Mistral3Config 模型)
- Mistral4Config 配置类:Mistral4ForCausalLM(Mistral4Config 模型)
- MistralLarge4Config 配置类:MistralLarge4ForConditionalGeneration(MistralLarge4Config 模型)
- MllamaConfig 配置类:MllamaForConditionalGeneration(MllamaConfig 模型)
- Molmo2Config 配置类:Molmo2ForConditionalGeneration(Molmo2Config 模型)
- MossTranscribeDiarizeConfig 配置类:MossTranscribeDiarizeForConditionalGeneration(MossTranscribeDiarizeConfig 模型)
- MuseGlimmerConfig 配置类:MuseGlimmerForConditionalGeneration(MuseGlimmerConfig 模型)
- MuseSparkConfig 配置类:MuseSparkForConditionalGeneration(MuseSparkConfig 模型)
- Nemotron3_5TranscribeConfig 配置类:Nemotron3_5TranscribeForConditionalGeneration(Nemotron3_5TranscribeConfig 模型)
- NemotronH_Omni_Reasoning_V3_Config 配置类:NemotronH_Omni_Reasoning_V3(NemotronH_Omni_Reasoning_V3_Config 模型)
- Ovis2Config 配置类:Ovis2ForConditionalGeneration(Ovis2Config 模型)
- PI0Config 配置类:PI0ForConditionalGeneration(PI0Config 模型)
- PPChart2TableConfig 配置类:GotOcr2ForConditionalGeneration(PPChart2TableConfig 模型)
- PPFormulaNetConfig 配置类:PPFormulaNetForConditionalGeneration(PPFormulaNetConfig 模型)
- PaddleOCRVLConfig 配置类:PaddleOCRVLForConditionalGeneration(PaddleOCRVLConfig 模型)
- PaliGemmaConfig 配置类:PaliGemmaForConditionalGeneration(PaliGemmaConfig 模型)
- PerceptionLMConfig 配置类:PerceptionLMForConditionalGeneration(PerceptionLMConfig 模型)
- Phi4MultimodalConfig 配置类:Phi4MultimodalForCausalLM(Phi4MultimodalConfig 模型)
- Pix2StructConfig 配置类:Pix2StructForConditionalGeneration(Pix2StructConfig 模型)
- QianfanOCRConfig 配置类:QianfanOCRForConditionalGeneration(QianfanOCRConfig 模型)
- Qwen2AudioConfig 配置类:Qwen2AudioForConditionalGeneration(Qwen2AudioConfig 模型)
- Qwen2VLConfig 配置类:Qwen2VLForConditionalGeneration(Qwen2VLConfig 模型)
- Qwen2_5OmniConfig 配置类:Qwen2_5OmniForConditionalGeneration(Qwen2_5OmniConfig 模型)
- Qwen2_5OmniThinkerConfig 配置类:Qwen2_5OmniThinkerForConditionalGeneration(Qwen2_5OmniThinkerConfig 模型)
- Qwen2_5_VLConfig 配置类:Qwen2_5_VLForConditionalGeneration(Qwen2_5_VLConfig 模型)
- Qwen3ASRConfig 配置类:Qwen3ASRForConditionalGeneration(Qwen3ASRConfig 模型)
- Qwen3OmniMoeConfig 配置类:Qwen3OmniMoeForConditionalGeneration(Qwen3OmniMoeConfig 模型)
- Qwen3OmniMoeThinkerConfig 配置类:Qwen3OmniMoeThinkerForConditionalGeneration(Qwen3OmniMoeThinkerConfig 模型)
- Qwen3VLConfig 配置类:Qwen3VLForConditionalGeneration(Qwen3VLConfig 模型)
- Qwen3VLMoeConfig 配置类:Qwen3VLMoeForConditionalGeneration(Qwen3VLMoeConfig 模型)
- Qwen3_5Config 配置类:Qwen3_5ForConditionalGeneration(Qwen3_5Config 模型)
- Qwen3_5MoeConfig 配置类:Qwen3_5MoeForConditionalGeneration(Qwen3_5MoeConfig 模型)
- Qwen4ExpConfig 配置类:Qwen4ExpForConditionalGeneration(Qwen4ExpConfig 模型)
- ShieldGemma2Config 配置类:Gemma3ForConditionalGeneration(ShieldGemma2Config 模型)
- SmolVLMConfig 配置类:SmolVLMForConditionalGeneration(SmolVLMConfig 模型)
- Step3p7Config 配置类:Step3p7ForConditionalGeneration(Step3p7Config 模型)
- T5Gemma2Config 配置类:T5Gemma2ForConditionalGeneration(T5Gemma2Config 模型)
- UdopConfig 配置类:UdopForConditionalGeneration(UdopConfig 模型)
- UnlimitedOcrConfig 配置类:UnlimitedOcrForConditionalGeneration(UnlimitedOcrConfig 模型)
- VibeVoiceAsrConfig 配置类:VibeVoiceAsrForConditionalGeneration(VibeVoiceAsrConfig 模型)
- VideoLlama3Config 配置类:VideoLlama3ForConditionalGeneration(VideoLlama3Config 模型)
- VideoLlavaConfig 配置类:VideoLlavaForConditionalGeneration(VideoLlavaConfig 模型)
- VipLlavaConfig 配置类:VipLlavaForConditionalGeneration(VipLlavaConfig 模型)
- VisionEncoderDecoderConfig 配置类:VisionEncoderDecoderModel(VisionEncoderDecoderConfig 模型)
- VoxtralConfig 配置类:VoxtralForConditionalGeneration(VoxtralConfig 模型)
- VoxtralRealtimeConfig 配置类:VoxtralRealtimeForConditionalGeneration(VoxtralRealtimeConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有多模态生成头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有多模态生成头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- aria — AriaForConditionalGeneration(AriaConfig 模型)
- aya_vision — AyaVisionForConditionalGeneration(AyaVisionConfig 模型)
- blip — BlipForConditionalGeneration(BlipConfig 模型)
- blip-2 — Blip2ForConditionalGeneration(Blip2Config 模型)
- chameleon — ChameleonForConditionalGeneration(ChameleonConfig 模型)
- cohere2_vision — Cohere2VisionForConditionalGeneration(Cohere2VisionConfig 模型)
- cohere_compass — CohereCompassForConditionalGeneration(CohereCompassConfig 模型)
- cosmos3_edge — Cosmos3EdgeForConditionalGeneration(Cosmos3EdgeConfig 模型)
- cosmos3_omni — Cosmos3OmniForConditionalGeneration(Cosmos3OmniConfig 模型)
- deepseek_ocr2 — DeepseekOcr2ForConditionalGeneration(DeepseekOcr2Config 模型)
- deepseek_vl — DeepseekVLForConditionalGeneration(DeepseekVLConfig 模型)
- deepseek_vl_hybrid — DeepseekVLHybridForConditionalGeneration(DeepseekVLHybridConfig 模型)
- diffusion_gemma — DiffusionGemmaForBlockDiffusion(DiffusionGemmaConfig 模型)
- emu3 — Emu3ForConditionalGeneration(Emu3Config 模型)
- ernie4_5_vl_moe — Ernie4_5_VLMoeForConditionalGeneration(Ernie4_5_VLMoeConfig 模型)
- evolla — EvollaForProteinText2Text(EvollaConfig 模型)
- exaone4_5 — Exaone4_5_ForConditionalGeneration(Exaone4_5_Config 模型)
- fast_vlm — FastVlmForConditionalGeneration(FastVlmConfig 模型)
- florence2 — Florence2ForConditionalGeneration(Florence2Config 模型)
- fun_asr_nano — FunAsrNanoForConditionalGeneration(FunAsrNanoConfig 模型)
- fuyu — FuyuForCausalLM(FuyuConfig 模型)
- gemma3 — Gemma3ForConditionalGeneration(Gemma3Config 模型)
- gemma3n — Gemma3nForConditionalGeneration(Gemma3nConfig 模型)
- gemma4 — Gemma4ForConditionalGeneration(Gemma4Config 模型)
- gemma4_unified — Gemma4UnifiedForConditionalGeneration(Gemma4UnifiedConfig 模型)
- git — GitForCausalLM(GitConfig 模型)
- glm46v — Glm46VForConditionalGeneration(Glm46VConfig 模型)
- glm4v — Glm4vForConditionalGeneration(Glm4vConfig 模型)
- glm4v_moe — Glm4vMoeForConditionalGeneration(Glm4vMoeConfig 模型)
- glm5_next — Glm5NextForConditionalGeneration(Glm5NextConfig 模型)
- glm_ocr — GlmOcrForConditionalGeneration(GlmOcrConfig 模型)
- glmasr — GlmAsrForConditionalGeneration(GlmAsrConfig 模型)
- glmga — Glm46VForConditionalGeneration(GlmgaConfig 模型)
- got_ocr2 — GotOcr2ForConditionalGeneration(GotOcr2Config 模型)
- granite4_vision — Granite4VisionForConditionalGeneration(Granite4VisionConfig 模型)
- granite_speech — GraniteSpeechForConditionalGeneration(GraniteSpeechConfig 模型)
- granite_speech_plus — GraniteSpeechPlusForConditionalGeneration(GraniteSpeechPlusConfig 模型)
- hunyuan_vl — HunYuanVLForConditionalGeneration(HunYuanVLConfig 模型)
- hyperclovax_vision_v2 — HyperCLOVAXVisionV2ForConditionalGeneration(HyperCLOVAXVisionV2Config 模型)
- idefics — IdeficsForVisionText2Text(IdeficsConfig 模型)
- idefics2 — Idefics2ForConditionalGeneration(Idefics2Config 模型)
- idefics3 — Idefics3ForConditionalGeneration(Idefics3Config 模型)
- inkling_mm_model — InklingForConditionalGeneration(InklingConfig 模型)
- instructblip — InstructBlipForConditionalGeneration(InstructBlipConfig 模型)
- instructblipvideo — InstructBlipVideoForConditionalGeneration(InstructBlipVideoConfig 模型)
- internvl — InternVLForConditionalGeneration(InternVLConfig 模型)
- janus — JanusForConditionalGeneration(JanusConfig 模型)
- kimi_k25 — Kimi_K25ForConditionalGeneration(Kimi_K25Config 模型)
- kosmos-2 — Kosmos2ForConditionalGeneration(Kosmos2Config 模型)
- kosmos-2.5 — Kosmos2_5ForConditionalGeneration(Kosmos2_5Config 模型)
- kyutai_speech_to_text — KyutaiSpeechToTextForConditionalGeneration(KyutaiSpeechToTextConfig 模型)
- lfm2_vl — Lfm2VlForConditionalGeneration(Lfm2VlConfig 模型)
- lighton_ocr — LightOnOcrForConditionalGeneration(LightOnOcrConfig 模型)
- llama4 — Llama4ForConditionalGeneration(Llama4Config 模型)
- llava — LlavaForConditionalGeneration(LlavaConfig 模型)
- llava_next — LlavaNextForConditionalGeneration(LlavaNextConfig 模型)
- llava_next_video — LlavaNextVideoForConditionalGeneration(LlavaNextVideoConfig 模型)
- llava_onevision — LlavaOnevisionForConditionalGeneration(LlavaOnevisionConfig 模型)
- minicpm_ocr — MiniCPMOcrForConditionalGeneration(MiniCPMOcrConfig 模型)
- minicpmv4_6 — MiniCPMV4_6ForConditionalGeneration(MiniCPMV4_6Config 模型)
- minicpmv4_7 — MiniCPMV4_7ForConditionalGeneration(MiniCPMV4_7Config 模型)
- minimax_m3_vl — MiniMaxM3SparseForConditionalGeneration(MiniMaxM3VLConfig 模型)
- mistral3 — Mistral3ForConditionalGeneration(Mistral3Config 模型)
- mistral4 — Mistral4ForCausalLM(Mistral4Config 模型)
- mistral_large4 — MistralLarge4ForConditionalGeneration(MistralLarge4Config 模型)
- mllama — MllamaForConditionalGeneration(MllamaConfig 模型)
- molmo2 — Molmo2ForConditionalGeneration(Molmo2Config 模型)
- moss_transcribe_diarize — MossTranscribeDiarizeForConditionalGeneration(MossTranscribeDiarizeConfig 模型)
- muse_glimmer — MuseGlimmerForConditionalGeneration(MuseGlimmerConfig 模型)
- muse_spark — MuseSparkForConditionalGeneration(MuseSparkConfig 模型)
- nemo_speechlm — Nemotron3_5TranscribeForConditionalGeneration(Nemotron3_5TranscribeConfig 模型)
- nemotron_h_omni — NemotronH_Omni_Reasoning_V3(NemotronH_Omni_Reasoning_V3_Config 模型)
- ovis2 — Ovis2ForConditionalGeneration(Ovis2Config 模型)
- paddleocr_vl — PaddleOCRVLForConditionalGeneration(PaddleOCRVLConfig 模型)
- paligemma — PaliGemmaForConditionalGeneration(PaliGemmaConfig 模型)
- perception_lm — PerceptionLMForConditionalGeneration(PerceptionLMConfig 模型)
- phi4_multimodal — Phi4MultimodalForCausalLM(Phi4MultimodalConfig 模型)
- pi0 — PI0ForConditionalGeneration(PI0Config 模型)
- pix2struct — Pix2StructForConditionalGeneration(Pix2StructConfig 模型)
- pp_chart2table — GotOcr2ForConditionalGeneration(PPChart2TableConfig 模型)
- pp_formulanet — PPFormulaNetForConditionalGeneration(PPFormulaNetConfig 模型)
- qianfan_ocr — QianfanOCRForConditionalGeneration(QianfanOCRConfig 模型)
- qwen2_5_omni — Qwen2_5OmniForConditionalGeneration(Qwen2_5OmniConfig 模型)
- qwen2_5_omni_thinker — Qwen2_5OmniThinkerForConditionalGeneration(Qwen2_5OmniThinkerConfig 模型)
- qwen2_5_vl — Qwen2_5_VLForConditionalGeneration(Qwen2_5_VLConfig 模型)
- qwen2_audio — Qwen2AudioForConditionalGeneration(Qwen2AudioConfig 模型)
- qwen2_vl — Qwen2VLForConditionalGeneration(Qwen2VLConfig 模型)
- qwen3_5 — Qwen3_5ForConditionalGeneration(Qwen3_5Config 模型)
- qwen3_5_moe — Qwen3_5MoeForConditionalGeneration(Qwen3_5MoeConfig 模型)
- qwen3_asr — Qwen3ASRForConditionalGeneration(Qwen3ASRConfig 模型)
- qwen3_omni_moe — Qwen3OmniMoeForConditionalGeneration(Qwen3OmniMoeConfig 模型)
- qwen3_omni_moe_thinker — Qwen3OmniMoeThinkerForConditionalGeneration(Qwen3OmniMoeThinkerConfig 模型)
- qwen3_vl — Qwen3VLForConditionalGeneration(Qwen3VLConfig 模型)
- qwen3_vl_moe — Qwen3VLMoeForConditionalGeneration(Qwen3VLMoeConfig 模型)
- qwen4_exp — Qwen4ExpForConditionalGeneration(Qwen4ExpConfig 模型)
- shieldgemma2 — Gemma3ForConditionalGeneration(ShieldGemma2Config 模型)
- smolvlm — SmolVLMForConditionalGeneration(SmolVLMConfig 模型)
- step3p7 — Step3p7ForConditionalGeneration(Step3p7Config 模型)
- t5gemma2 — T5Gemma2ForConditionalGeneration(T5Gemma2Config 模型)
- udop — UdopForConditionalGeneration(UdopConfig 模型)
- unlimited_ocr — UnlimitedOcrForConditionalGeneration(UnlimitedOcrConfig 模型)
- vibevoice_asr — VibeVoiceAsrForConditionalGeneration(VibeVoiceAsrConfig 模型)
- video_llama_3 — VideoLlama3ForConditionalGeneration(VideoLlama3Config 模型)
- video_llava — VideoLlavaForConditionalGeneration(VideoLlavaConfig 模型)
- vipllava — VipLlavaForConditionalGeneration(VipLlavaConfig 模型)
- vision-encoder-decoder — VisionEncoderDecoderModel(VisionEncoderDecoderConfig 模型)
- voxtral — VoxtralForConditionalGeneration(VoxtralConfig 模型)
- voxtral_realtime — VoxtralRealtimeForConditionalGeneration(VoxtralRealtimeConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForMultimodalLM
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForMultimodalLM.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForMultimodalLM.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForTableQuestionAnswering
这是一个通用模型类,在使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有表格问答头的模型类之一。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- TapasConfig 配置类:TapasForQuestionAnswering(TapasConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
从配置实例化该库的某个模型类(带有表格问答头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有表格问答头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- tapas — TapasForQuestionAnswering(TapasConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForTableQuestionAnswering
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForTableQuestionAnswering.from_pretrained("google/tapas-base-finetuned-wtq")
>>> # Update configuration during loading
>>> model = AutoModelForTableQuestionAnswering.from_pretrained("google/tapas-base-finetuned-wtq", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForDocumentQuestionAnswering
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有文档问答头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- LayoutLMConfig 配置类:LayoutLMForQuestionAnswering(LayoutLMConfig 模型)
- LayoutLMv2Config 配置类:LayoutLMv2ForQuestionAnswering(LayoutLMv2Config 模型)
- LayoutLMv3Config 配置类:LayoutLMv3ForQuestionAnswering(LayoutLMv3Config 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有文档问答头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
示例:
>>> from transformers import AutoConfig, AutoModelForDocumentQuestionAnswering
>>> # Download configuration from huggingface.co and cache.
>>> config = AutoConfig.from_pretrained("impira/layoutlm-document-qa", revision="52e01b3")
>>> model = AutoModelForDocumentQuestionAnswering.from_config(config)from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有文档问答头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- layoutlm — LayoutLMForQuestionAnswering(LayoutLMConfig 模型)
- layoutlmv2 — LayoutLMv2ForQuestionAnswering(LayoutLMv2Config 模型)
- layoutlmv3 — LayoutLMv3ForQuestionAnswering(LayoutLMv3Config 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForDocumentQuestionAnswering
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForDocumentQuestionAnswering.from_pretrained("impira/layoutlm-document-qa", revision="52e01b3")
>>> # Update configuration during loading
>>> model = AutoModelForDocumentQuestionAnswering.from_pretrained("impira/layoutlm-document-qa", revision="52e01b3", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForVisualQuestionAnswering
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有视觉问答头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- Blip2Config 配置类:Blip2ForConditionalGeneration(Blip2Config 模型)
- BlipConfig 配置类:BlipForQuestionAnswering(BlipConfig 模型)
- ViltConfig 配置类:ViltForQuestionAnswering(ViltConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有视觉问答头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有视觉问答头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- blip — BlipForQuestionAnswering(BlipConfig 模型)
- blip-2 — Blip2ForConditionalGeneration(Blip2Config 模型)
- vilt — ViltForQuestionAnswering(ViltConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForVisualQuestionAnswering
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForVisualQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetuned-vqa")
>>> # Update configuration during loading
>>> model = AutoModelForVisualQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetuned-vqa", output_attentions=True)
>>> model.config.output_attentions
TrueAutoModelForImageTextToText
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中某个带有图像-文本到文本建模头的模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- AriaConfig 配置类:AriaForConditionalGeneration(AriaConfig 模型)
- AyaVisionConfig 配置类:AyaVisionForConditionalGeneration(AyaVisionConfig 模型)
- Blip2Config 配置类:Blip2ForConditionalGeneration(Blip2Config 模型)
- BlipConfig 配置类:BlipForConditionalGeneration(BlipConfig 模型)
- ChameleonConfig 配置类:ChameleonForConditionalGeneration(ChameleonConfig 模型)
- Cohere2VisionConfig 配置类:Cohere2VisionForConditionalGeneration(Cohere2VisionConfig 模型)
- CohereCompassConfig 配置类:CohereCompassForConditionalGeneration(CohereCompassConfig 模型)
- Cosmos3EdgeConfig 配置类:Cosmos3EdgeForConditionalGeneration(Cosmos3EdgeConfig 模型)
- Cosmos3OmniConfig 配置类:Cosmos3OmniForConditionalGeneration(Cosmos3OmniConfig 模型)
- DeepseekOcr2Config 配置类:DeepseekOcr2ForConditionalGeneration(DeepseekOcr2Config 模型)
- DeepseekVLConfig 配置类:DeepseekVLForConditionalGeneration(DeepseekVLConfig 模型)
- DeepseekVLHybridConfig 配置类:DeepseekVLHybridForConditionalGeneration(DeepseekVLHybridConfig 模型)
- DiffusionGemmaConfig 配置类:DiffusionGemmaForBlockDiffusion(DiffusionGemmaConfig 模型)
- Emu3Config 配置类:Emu3ForConditionalGeneration(Emu3Config 模型)
- Ernie4_5_VLMoeConfig 配置类:Ernie4_5_VLMoeForConditionalGeneration(Ernie4_5_VLMoeConfig 模型)
- EvollaConfig 配置类:EvollaForProteinText2Text(EvollaConfig 模型)
- Exaone4_5_Config 配置类:Exaone4_5_ForConditionalGeneration(Exaone4_5_Config 模型)
- FastVlmConfig 配置类:FastVlmForConditionalGeneration(FastVlmConfig 模型)
- Florence2Config 配置类:Florence2ForConditionalGeneration(Florence2Config 模型)
- FuyuConfig 配置类:FuyuForCausalLM(FuyuConfig 模型)
- Gemma3Config 配置类:Gemma3ForConditionalGeneration(Gemma3Config 模型)
- Gemma3nConfig 配置类:Gemma3nForConditionalGeneration(Gemma3nConfig 模型)
- Gemma4Config 配置类:Gemma4ForConditionalGeneration(Gemma4Config 模型)
- Gemma4UnifiedConfig 配置类:Gemma4UnifiedForConditionalGeneration(Gemma4UnifiedConfig 模型)
- GitConfig 配置类:GitForCausalLM(GitConfig 模型)
- Glm46VConfig 配置类:Glm46VForConditionalGeneration(Glm46VConfig 模型)
- Glm4vConfig 配置类:Glm4vForConditionalGeneration(Glm4vConfig 模型)
- Glm4vMoeConfig 配置类:Glm4vMoeForConditionalGeneration(Glm4vMoeConfig 模型)
- Glm5NextConfig 配置类:Glm5NextForConditionalGeneration(Glm5NextConfig 模型)
- GlmOcrConfig 配置类:GlmOcrForConditionalGeneration(GlmOcrConfig 模型)
- GlmgaConfig 配置类:Glm46VForConditionalGeneration(GlmgaConfig 模型)
- GotOcr2Config 配置类:GotOcr2ForConditionalGeneration(GotOcr2Config 模型)
- Granite4VisionConfig 配置类:Granite4VisionForConditionalGeneration(Granite4VisionConfig 模型)
- HunYuanVLConfig 配置类:HunYuanVLForConditionalGeneration(HunYuanVLConfig 模型)
- HyperCLOVAXVisionV2Config 配置类:HyperCLOVAXVisionV2ForConditionalGeneration(HyperCLOVAXVisionV2Config 模型)
- Idefics2Config 配置类:Idefics2ForConditionalGeneration(Idefics2Config 模型)
- Idefics3Config 配置类:Idefics3ForConditionalGeneration(Idefics3Config 模型)
- IdeficsConfig 配置类:IdeficsForVisionText2Text(IdeficsConfig 模型)
- InklingConfig 配置类:InklingForConditionalGeneration(InklingConfig 模型)
- InstructBlipConfig 配置类:InstructBlipForConditionalGeneration(InstructBlipConfig 模型)
- InstructBlipVideoConfig 配置类:InstructBlipVideoForConditionalGeneration(InstructBlipVideoConfig 模型)
- InternVLConfig 配置类:InternVLForConditionalGeneration(InternVLConfig 模型)
- JanusConfig 配置类:JanusForConditionalGeneration(JanusConfig 模型)
- Kimi_K25Config 配置类:Kimi_K25ForConditionalGeneration(Kimi_K25Config 模型)
- Kosmos2Config 配置类:Kosmos2ForConditionalGeneration(Kosmos2Config 模型)
- Kosmos2_5Config 配置类:Kosmos2_5ForConditionalGeneration(Kosmos2_5Config 模型)
- Lfm2VlConfig 配置类:Lfm2VlForConditionalGeneration(Lfm2VlConfig 模型)
- LightOnOcrConfig 配置类:LightOnOcrForConditionalGeneration(LightOnOcrConfig 模型)
- Llama4Config 配置类:Llama4ForConditionalGeneration(Llama4Config 模型)
- LlavaConfig 配置类:LlavaForConditionalGeneration(LlavaConfig 模型)
- LlavaNextConfig 配置类:LlavaNextForConditionalGeneration(LlavaNextConfig 模型)
- LlavaNextVideoConfig 配置类:LlavaNextVideoForConditionalGeneration(LlavaNextVideoConfig 模型)
- LlavaOnevisionConfig 配置类:LlavaOnevisionForConditionalGeneration(LlavaOnevisionConfig 模型)
- MiniCPMOcrConfig 配置类:MiniCPMOcrForConditionalGeneration(MiniCPMOcrConfig 模型)
- MiniCPMV4_6Config 配置类:MiniCPMV4_6ForConditionalGeneration(MiniCPMV4_6Config 模型)
- MiniCPMV4_7Config 配置类:MiniCPMV4_7ForConditionalGeneration(MiniCPMV4_7Config 模型)
- MiniMaxM3VLConfig 配置类:MiniMaxM3SparseForConditionalGeneration(MiniMaxM3VLConfig 模型)
- Mistral3Config 配置类:Mistral3ForConditionalGeneration(Mistral3Config 模型)
- Mistral4Config 配置类:Mistral4ForCausalLM(Mistral4Config 模型)
- MistralLarge4Config 配置类:MistralLarge4ForConditionalGeneration(MistralLarge4Config 模型)
- MllamaConfig 配置类:MllamaForConditionalGeneration(MllamaConfig 模型)
- Molmo2Config 配置类:Molmo2ForConditionalGeneration(Molmo2Config 模型)
- MuseGlimmerConfig 配置类:MuseGlimmerForConditionalGeneration(MuseGlimmerConfig 模型)
- MuseSparkConfig 配置类:MuseSparkForConditionalGeneration(MuseSparkConfig 模型)
- NemotronH_Omni_Reasoning_V3_Config 配置类:NemotronH_Omni_Reasoning_V3(NemotronH_Omni_Reasoning_V3_Config 模型)
- Ovis2Config 配置类:Ovis2ForConditionalGeneration(Ovis2Config 模型)
- PI0Config 配置类:PI0ForConditionalGeneration(PI0Config 模型)
- PPChart2TableConfig 配置类:GotOcr2ForConditionalGeneration(PPChart2TableConfig 模型)
- PPFormulaNetConfig 配置类:PPFormulaNetForConditionalGeneration(PPFormulaNetConfig 模型)
- PaddleOCRVLConfig 配置类:PaddleOCRVLForConditionalGeneration(PaddleOCRVLConfig 模型)
- PaliGemmaConfig 配置类:PaliGemmaForConditionalGeneration(PaliGemmaConfig 模型)
- PerceptionLMConfig 配置类:PerceptionLMForConditionalGeneration(PerceptionLMConfig 模型)
- Pix2StructConfig 配置类:Pix2StructForConditionalGeneration(Pix2StructConfig 模型)
- QianfanOCRConfig 配置类:QianfanOCRForConditionalGeneration(QianfanOCRConfig 模型)
- Qwen2VLConfig 配置类:Qwen2VLForConditionalGeneration(Qwen2VLConfig 模型)
- Qwen2_5OmniThinkerConfig 配置类:Qwen2_5OmniThinkerForConditionalGeneration(Qwen2_5OmniThinkerConfig 模型)
- Qwen2_5_VLConfig 配置类:Qwen2_5_VLForConditionalGeneration(Qwen2_5_VLConfig 模型)
- Qwen3OmniMoeThinkerConfig 配置类:Qwen3OmniMoeThinkerForConditionalGeneration(Qwen3OmniMoeThinkerConfig 模型)
- Qwen3VLConfig 配置类:Qwen3VLForConditionalGeneration(Qwen3VLConfig 模型)
- Qwen3VLMoeConfig 配置类:Qwen3VLMoeForConditionalGeneration(Qwen3VLMoeConfig 模型)
- Qwen3_5Config 配置类:Qwen3_5ForConditionalGeneration(Qwen3_5Config 模型)
- Qwen3_5MoeConfig 配置类:Qwen3_5MoeForConditionalGeneration(Qwen3_5MoeConfig 模型)
- Qwen4ExpConfig 配置类:Qwen4ExpForConditionalGeneration(Qwen4ExpConfig 模型)
- ShieldGemma2Config 配置类:Gemma3ForConditionalGeneration(ShieldGemma2Config 模型)
- SmolVLMConfig 配置类:SmolVLMForConditionalGeneration(SmolVLMConfig 模型)
- Step3p7Config 配置类:Step3p7ForConditionalGeneration(Step3p7Config 模型)
- T5Gemma2Config 配置类:T5Gemma2ForConditionalGeneration(T5Gemma2Config 模型)
- UdopConfig 配置类:UdopForConditionalGeneration(UdopConfig 模型)
- UnlimitedOcrConfig 配置类:UnlimitedOcrForConditionalGeneration(UnlimitedOcrConfig 模型)
- VideoLlama3Config 配置类:VideoLlama3ForConditionalGeneration(VideoLlama3Config 模型)
- VideoLlavaConfig 配置类:VideoLlavaForConditionalGeneration(VideoLlavaConfig 模型)
- VipLlavaConfig 配置类:VipLlavaForConditionalGeneration(VipLlavaConfig 模型)
- VisionEncoderDecoderConfig 配置类:VisionEncoderDecoderModel(VisionEncoderDecoderConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有图像-文本到文本建模头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库中的一个模型类(带有图像-文本到文本建模头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- aria — AriaForConditionalGeneration(AriaConfig 模型)
- aya_vision — AyaVisionForConditionalGeneration(AyaVisionConfig 模型)
- blip — BlipForConditionalGeneration(BlipConfig 模型)
- blip-2 — Blip2ForConditionalGeneration(Blip2Config 模型)
- chameleon — ChameleonForConditionalGeneration(ChameleonConfig 模型)
- cohere2_vision — Cohere2VisionForConditionalGeneration(Cohere2VisionConfig 模型)
- cohere_compass — CohereCompassForConditionalGeneration(CohereCompassConfig 模型)
- cosmos3_edge — Cosmos3EdgeForConditionalGeneration(Cosmos3EdgeConfig 模型)
- cosmos3_omni — Cosmos3OmniForConditionalGeneration(Cosmos3OmniConfig 模型)
- deepseek_ocr2 — DeepseekOcr2ForConditionalGeneration(DeepseekOcr2Config 模型)
- deepseek_vl — DeepseekVLForConditionalGeneration(DeepseekVLConfig 模型)
- deepseek_vl_hybrid — DeepseekVLHybridForConditionalGeneration(DeepseekVLHybridConfig 模型)
- diffusion_gemma — DiffusionGemmaForBlockDiffusion(DiffusionGemmaConfig 模型)
- emu3 — Emu3ForConditionalGeneration(Emu3Config 模型)
- ernie4_5_vl_moe — Ernie4_5_VLMoeForConditionalGeneration(Ernie4_5_VLMoeConfig 模型)
- evolla — EvollaForProteinText2Text(EvollaConfig 模型)
- exaone4_5 — Exaone4_5_ForConditionalGeneration(Exaone4_5_Config 模型)
- fast_vlm — FastVlmForConditionalGeneration(FastVlmConfig 模型)
- florence2 — Florence2ForConditionalGeneration(Florence2Config 模型)
- fuyu — FuyuForCausalLM(FuyuConfig 模型)
- gemma3 — Gemma3ForConditionalGeneration(Gemma3Config 模型)
- gemma3n — Gemma3nForConditionalGeneration(Gemma3nConfig 模型)
- gemma4 — Gemma4ForConditionalGeneration(Gemma4Config 模型)
- gemma4_unified — Gemma4UnifiedForConditionalGeneration(Gemma4UnifiedConfig 模型)
- git — GitForCausalLM(GitConfig 模型)
- glm46v — Glm46VForConditionalGeneration(Glm46VConfig 模型)
- glm4v — Glm4vForConditionalGeneration(Glm4vConfig 模型)
- glm4v_moe — Glm4vMoeForConditionalGeneration(Glm4vMoeConfig 模型)
- glm5_next — Glm5NextForConditionalGeneration(Glm5NextConfig 模型)
- glm_ocr — GlmOcrForConditionalGeneration(GlmOcrConfig 模型)
- glmga — Glm46VForConditionalGeneration(GlmgaConfig 模型)
- got_ocr2 — GotOcr2ForConditionalGeneration(GotOcr2Config 模型)
- granite4_vision — Granite4VisionForConditionalGeneration(Granite4VisionConfig 模型)
- hunyuan_vl — HunYuanVLForConditionalGeneration(HunYuanVLConfig 模型)
- hyperclovax_vision_v2 — HyperCLOVAXVisionV2ForConditionalGeneration(HyperCLOVAXVisionV2Config 模型)
- idefics — IdeficsForVisionText2Text(IdeficsConfig 模型)
- idefics2 — Idefics2ForConditionalGeneration(Idefics2Config 模型)
- idefics3 — Idefics3ForConditionalGeneration(Idefics3Config 模型)
- inkling_mm_model — InklingForConditionalGeneration(InklingConfig 模型)
- instructblip — InstructBlipForConditionalGeneration(InstructBlipConfig 模型)
- instructblipvideo — InstructBlipVideoForConditionalGeneration(InstructBlipVideoConfig 模型)
- internvl — InternVLForConditionalGeneration(InternVLConfig 模型)
- janus — JanusForConditionalGeneration(JanusConfig 模型)
- kimi_k25 — Kimi_K25ForConditionalGeneration(Kimi_K25Config 模型)
- kosmos-2 — Kosmos2ForConditionalGeneration(Kosmos2Config 模型)
- kosmos-2.5 — Kosmos2_5ForConditionalGeneration(Kosmos2_5Config 模型)
- lfm2_vl — Lfm2VlForConditionalGeneration(Lfm2VlConfig 模型)
- lighton_ocr — LightOnOcrForConditionalGeneration(LightOnOcrConfig 模型)
- llama4 — Llama4ForConditionalGeneration(Llama4Config 模型)
- llava — LlavaForConditionalGeneration(LlavaConfig 模型)
- llava_next — LlavaNextForConditionalGeneration(LlavaNextConfig 模型)
- llava_next_video — LlavaNextVideoForConditionalGeneration(LlavaNextVideoConfig 模型)
- llava_onevision — LlavaOnevisionForConditionalGeneration(LlavaOnevisionConfig 模型)
- minicpm_ocr — MiniCPMOcrForConditionalGeneration(MiniCPMOcrConfig 模型)
- minicpmv4_6 — MiniCPMV4_6ForConditionalGeneration(MiniCPMV4_6Config 模型)
- minicpmv4_7 — MiniCPMV4_7ForConditionalGeneration(MiniCPMV4_7Config 模型)
- minimax_m3_vl — MiniMaxM3SparseForConditionalGeneration(MiniMaxM3VLConfig 模型)
- mistral3 — Mistral3ForConditionalGeneration(Mistral3Config 模型)
- mistral4 — Mistral4ForCausalLM(Mistral4Config 模型)
- mistral_large4 — MistralLarge4ForConditionalGeneration(MistralLarge4Config 模型)
- mllama — MllamaForConditionalGeneration(MllamaConfig 模型)
- molmo2 — Molmo2ForConditionalGeneration(Molmo2Config 模型)
- muse_glimmer — MuseGlimmerForConditionalGeneration(MuseGlimmerConfig 模型)
- muse_spark — MuseSparkForConditionalGeneration(MuseSparkConfig 模型)
- nemotron_h_omni — NemotronH_Omni_Reasoning_V3(NemotronH_Omni_Reasoning_V3_Config 模型)
- ovis2 — Ovis2ForConditionalGeneration(Ovis2Config 模型)
- paddleocr_vl — PaddleOCRVLForConditionalGeneration(PaddleOCRVLConfig 模型)
- paligemma — PaliGemmaForConditionalGeneration(PaliGemmaConfig 模型)
- perception_lm — PerceptionLMForConditionalGeneration(PerceptionLMConfig 模型)
- pi0 — PI0ForConditionalGeneration(PI0Config 模型)
- pix2struct — Pix2StructForConditionalGeneration(Pix2StructConfig 模型)
- pp_chart2table — GotOcr2ForConditionalGeneration(PPChart2TableConfig 模型)
- pp_formulanet — PPFormulaNetForConditionalGeneration(PPFormulaNetConfig 模型)
- qianfan_ocr — QianfanOCRForConditionalGeneration(QianfanOCRConfig 模型)
- qwen2_5_omni_thinker — Qwen2_5OmniThinkerForConditionalGeneration(Qwen2_5OmniThinkerConfig 模型)
- qwen2_5_vl — Qwen2_5_VLForConditionalGeneration(Qwen2_5_VLConfig 模型)
- qwen2_vl — Qwen2VLForConditionalGeneration(Qwen2VLConfig 模型)
- qwen3_5 — Qwen3_5ForConditionalGeneration(Qwen3_5Config 模型)
- qwen3_5_moe — Qwen3_5MoeForConditionalGeneration(Qwen3_5MoeConfig 模型)
- qwen3_omni_moe_thinker — Qwen3OmniMoeThinkerForConditionalGeneration(Qwen3OmniMoeThinkerConfig 模型)
- qwen3_vl — Qwen3VLForConditionalGeneration(Qwen3VLConfig 模型)
- qwen3_vl_moe — Qwen3VLMoeForConditionalGeneration(Qwen3VLMoeConfig 模型)
- qwen4_exp — Qwen4ExpForConditionalGeneration(Qwen4ExpConfig 模型)
- shieldgemma2 — Gemma3ForConditionalGeneration(ShieldGemma2Config 模型)
- smolvlm — SmolVLMForConditionalGeneration(SmolVLMConfig 模型)
- step3p7 — Step3p7ForConditionalGeneration(Step3p7Config 模型)
- t5gemma2 — T5Gemma2ForConditionalGeneration(T5Gemma2Config 模型)
- udop — UdopForConditionalGeneration(UdopConfig 模型)
- unlimited_ocr — UnlimitedOcrForConditionalGeneration(UnlimitedOcrConfig 模型)
- video_llama_3 — VideoLlama3ForConditionalGeneration(VideoLlama3Config 模型)
- video_llava — VideoLlavaForConditionalGeneration(VideoLlavaConfig 模型)
- vipllava — VipLlavaForConditionalGeneration(VipLlavaConfig 模型)
- vision-encoder-decoder — VisionEncoderDecoderModel(VisionEncoderDecoderConfig 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForImageTextToText
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForImageTextToText.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForImageTextToText.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True时间序列
AutoModelForTimeSeriesPrediction
这是一个通用模型类,当使用 from_pretrained() 类方法或 from_config() 类方法创建时,它将被实例化为该库中带有时间序列预测头的某个模型类。
此类无法通过 __init__() 直接实例化(会抛出错误)。
from_config
< source >( **kwargs )
参数
- config (PreTrainedConfig) —
根据配置类选择要实例化的模型类:
- TimesFm2_5Config 配置类:TimesFm2_5ModelForPrediction(TimesFm2_5Config 模型)
- TimesFmConfig 配置类:TimesFmModelForPrediction(TimesFmConfig 模型)
- attn_implementation (
str, 可选) — 模型中使用的注意力实现方式(如适用)。可以是以下任意值:"eager"(手动实现的注意力机制)"sdpa"(使用F.scaled_dot_product_attention)"flash_attention_2"(使用 Dao-AILab/flash-attention)"flash_attention_3"(使用 Dao-AILab/flash-attention/hopper)"flash_attention_4"(使用 Dao-AILab/flash-attention/flash_attn/cute)。 默认情况下,如果可用,对于 torch>=2.1.1 将使用 SDPA。否则,默认使用手动"eager"实现。
根据配置实例化该库中的一个模型类(带有时间序列预测头)。
注意: 从配置文件加载模型不会加载模型权重。它仅影响模型的配置。请使用 from_pretrained() 来加载模型权重。
from_pretrained
< source >( *model_args**kwargs )
参数
- pretrained_model_name_or_path (
str或os.PathLike) — 可以是以下之一:- 一个字符串,表示托管在 huggingface.co 模型仓库中的预训练模型的 model id。
- 指向一个目录的路径,该目录包含使用 save_pretrained() 保存的模型权重,例如
./my_model_directory/。
- model_args(额外的位置参数,可选)—
将传递给底层模型的
__init__()方法。 - config (PreTrainedConfig, 可选) —
用于替代自动加载配置的模型配置。在以下情况下,配置可以自动加载:
- 该模型是由库提供的模型(通过预训练模型的 model id 字符串加载)。
- 该模型使用 save_pretrained() 保存,并通过提供保存目录来重新加载。
- 通过提供本地目录作为
pretrained_model_name_or_path来加载模型,并且在该目录中找到了名为 config.json 的配置文件。
- state_dict (dict[str, torch.Tensor], 可选) —
用于替代从保存的权重文件中加载的状态字典的状态字典。如果您想基于预训练配置创建模型但加载自己的权重,可以使用此选项。不过在这种情况下,您应该检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
如果你希望基于预训练配置创建模型,但加载自己的权重,可以使用此选项。不过在这种情况下,你应该先检查使用 save_pretrained() 和 from_pretrained() 是否是更简单的选择。
- cache_dir (
str或os.PathLike,可选) — 如果不应使用标准缓存,则用于缓存已下载的预训练模型配置的目录路径。 - force_download (
bool,可选,默认为False) — 是否强制(重新)下载模型权重和配置文件,如果存在缓存版本则覆盖它们。 - proxies (
dict[str, str],可选) — 按协议或端点使用的代理服务器字典,例如{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}。每次请求都会使用这些代理。 - output_loading_info(
bool, optional,默认为False) — 是否同时返回一个包含缺失键、意外键和错误消息的字典。 - local_files_only(
bool, 可选,默认为False) — 是否仅查看本地文件(例如,不尝试下载模型)。 - revision (
str,可选,默认为"main") — 要使用的特定模型版本。由于我们在 huggingface.co 上使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - trust_remote_code (
bool,可选,默认为False) — 是否允许使用在 Hub 上以自定义建模文件定义的模型。此选项仅应为您信任且已阅读过其代码的仓库设置为True,因为它会在您的本地机器上执行 Hub 上存在的代码。 - code_revision (
str, 可选,默认为"main") — 如果代码位于与模型其余部分不同的仓库中,则指定在 Hub 上用于该代码的具体版本。由于 huggingface.co 使用基于 git 的系统来存储模型和其他工件,因此它可以是分支名称、标签名称或提交 id,revision可以是 git 允许的任何标识符。 - kwargs (额外的关键字参数, 可选) —
可用于更新配置对象(在加载之后)并初始化模型(例如,
output_attentions=True). 其行为取决于是否提供了config或自动加载:- 如果通过
config提供了配置,**kwargs将直接传递给底层模型的__init__方法(我们假设对配置的所有相关更新均已完成) - 如果未提供配置,
kwargs会首先传递给配置类的初始化函数(from_pretrained())。kwargs中每个对应配置属性的键,都会使用所提供的kwargs值来覆盖该属性。其余未对应任何配置属性的键,将传递给底层模型的__init__函数。
- 如果通过
从预训练模型实例化该库的某个模型类(带有时间序列预测头)。
要实例化的模型类是根据配置对象的 model_type 属性(作为参数传入,或在可能的情况下从 pretrained_model_name_or_path 加载)来选择的;如果该属性缺失,则回退到对 pretrained_model_name_or_path 进行模式匹配:
- timesfm — TimesFmModelForPrediction(TimesFmConfig 模型)
- timesfm2_5 — TimesFm2_5ModelForPrediction(TimesFm2_5Config 模型)
模型默认使用 model.eval() 设置为评估模式(例如,dropout 模块会被禁用)。若要训练模型,应首先使用 model.train() 将其切换回训练模式。
示例:
>>> from transformers import AutoConfig, AutoModelForTimeSeriesPrediction
>>> # Download model and configuration from huggingface.co and cache.
>>> model = AutoModelForTimeSeriesPrediction.from_pretrained("google-bert/bert-base-cased")
>>> # Update configuration during loading
>>> model = AutoModelForTimeSeriesPrediction.from_pretrained("google-bert/bert-base-cased", output_attentions=True)
>>> model.config.output_attentions
True