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

如何将Colab中Dreambooth微调的Stable Diffusion模型推送到HuggingFace Hub?

解决方案

方法1:推送Diffusers格式权重(文件夹内模型文件)

如果/content/my_model/facial-sketch/800是Diffusers标准格式(包含model_index.json等文件),按以下步骤操作:

  1. 安装依赖并登录Hugging Face Hub
!pip install --upgrade diffusers transformers huggingface_hub
!huggingface-cli login

登录时输入你的Hugging Face Token,确保拥有目标仓库的写入权限。

  1. 加载模型并推送
from diffusers import StableDiffusionPipeline

# 加载本地Diffusers格式模型
pipe = StableDiffusionPipeline.from_pretrained("/content/my_model/facial-sketch/800")
# 替换为你的仓库ID,格式为「用户名/仓库名」
pipe.push_to_hub("your-username/facial-sketch-model")

若不想加载模型,可直接用Repository类推送整个文件夹:

from huggingface_hub import Repository

# 克隆远程仓库到本地(仓库不存在会自动创建)
repo = Repository(local_dir="/tmp/hub-repo", repo_id="your-username/facial-sketch-model")
# 复制本地模型文件到克隆目录
!cp -r /content/my_model/facial-sketch/800/* /tmp/hub-repo/
# 提交并推送
repo.push_to_hub()

方法2:推送.ckpt权重文件

如果要单独推送.ckpt文件,直接使用huggingface_hub的上传工具:

  1. 安装依赖并登录(同方法1)
!pip install --upgrade huggingface_hub
!huggingface-cli login
  1. 上传单个.ckpt文件
from huggingface_hub import upload_file

# 替换为你的ckpt文件路径和目标仓库ID
upload_file(
    path_or_fileobj="/path/to/your/model.ckpt",
    path_in_repo="model.ckpt",
    repo_id="your-username/facial-sketch-model"
)

若要同时推送Diffusers格式文件和.ckpt,可结合upload_folder使用:

from huggingface_hub import upload_folder, upload_file

# 推送Diffusers格式文件夹
upload_folder(
    folder_path="/content/my_model/facial-sketch/800",
    path_in_repo="diffusers-model",
    repo_id="your-username/facial-sketch-model"
)

# 推送ckpt文件
upload_file(
    path_or_fileobj="/path/to/your/model.ckpt",
    path_in_repo="model.ckpt",
    repo_id="your-username/facial-sketch-model"
)

注意事项

  • 确保你的Hugging Face账号有权创建目标仓库,或已存在的仓库你拥有写入权限。
  • 若遇权限错误,检查Token是否开启write权限(在Hugging Face账号的「Access Tokens」中生成)。
  • Colab环境长时间闲置会断开,推送时建议保持页面活跃或启用后台运行模式。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 16:52:41