You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

解决HfApi.create_repo()意外参数'organization' TypeError问题

问题描述

按照Hugging Face的Sentence Transformers训练教程操作,执行以下代码保存模型时触发类型错误:

model.save_to_hub(
    "distilroberta-base-sentence-transformer", 
    organization="donhuvy",
    train_datasets=["embedding-data/QQP_triplets"],
    exist_ok=True, 
)

错误信息:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-16-4e42bc771dab> in <cell line: 1>()
----> 1 model.save_to_hub(
      2     "distilroberta-base-sentence-transformer",
      3     organization="donhuvy",
      4     train_datasets=["embedding-data/QQP_triplets"],
      5     exist_ok=True,

1 frames
/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_validators.py in _inner_fn(*args, **kwargs)
    118             kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=has_token, kwargs=kwargs)
    119 
--> 120         return fn(*args, **kwargs)
    121 
    122     return _inner_fn  # type: ignore

TypeError: HfApi.create_repo() got an unexpected keyword argument 'organization'
修复方案

错误原因是新版huggingface_hub库已废弃organization参数,需改用repo_id参数直接指定完整仓库ID(格式为{组织/用户名}/{模型名})。

修改后的代码:

model.save_to_hub(
    repo_id="donhuvy/distilroberta-base-sentence-transformer",
    train_datasets=["embedding-data/QQP_triplets"],
    exist_ok=True, 
)

说明:

  • 将原有的模型名称与组织名合并为repo_id参数值,无需再单独传入organization
  • 保留其他参数即可正常保存模型到指定仓库

内容的提问来源于stack exchange,提问作者Ferma Twist

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 03:07:46