Buckets:
共享管道和模型
使用 PushToHubMixin 在 Hub 上分享您的 pipelines、models 和 schedulers。此 mixin:
- 在 Hub 上创建一个仓库
- 保存您的模型、调度器或流水线文件,以便稍后重新加载
- 将包含这些文件的文件夹上传到 Hub
使用您的访问 token 登录您的 Hugging Face 账户。
from huggingface_hub import notebook_login
notebook_login()
hf auth login
使用简短的 id("my-controlnet-model")推送到您的用户命名空间,或使用 "your-org/my-controlnet-model" 推送到组织。
模型
要将模型推送到 Hub,请调用 push_to_hub() 并指定模型的仓库 id。
from diffusers import ControlNetModel
controlnet = ControlNetModel(
block_out_channels=(32, 64),
layers_per_block=2,
in_channels=4,
down_block_types=("DownBlock2D", "CrossAttnDownBlock2D"),
cross_attention_dim=32,
conditioning_embedding_out_channels=(16, 32),
)
controlnet.push_to_hub("my-controlnet-model")
push_to_hub() 方法会保存模型的 config.json 文件,权重会自动保存为 safetensors 文件。
再次使用 ControlNetModel.from_pretrained() 加载模型。
model = ControlNetModel.from_pretrained("your-namespace/my-controlnet-model")
调度器
要将调度器推送到 Hub,请调用 push_to_hub() 并指定调度器的仓库 id。
from diffusers import DDIMScheduler
scheduler = DDIMScheduler(
beta_start=0.00085,
beta_end=0.012,
beta_schedule="scaled_linear",
clip_sample=False,
set_alpha_to_one=False,
)
scheduler.push_to_hub("my-ddim-scheduler")
push_to_hub() 方法会将调度器的 scheduler_config.json 文件保存到指定的仓库中。
再次使用 from_pretrained() 加载调度器。
scheduler = DDIMScheduler.from_pretrained("your-namespace/my-ddim-scheduler")
Pipeline
To push a pipeline to the Hub, load it with from_pretrained(), then call push_to_hub() with a repository id.
import torch
from diffusers import DiffusionPipeline
pipeline = DiffusionPipeline.from_pretrained(
"Qwen/Qwen-Image", dtype=torch.bfloat16, device_map="cuda" # or "mps", "xpu", "cpu"
)
pipeline.push_to_hub("your-namespace/my-qwen-image")
The push_to_hub() method saves each component to a subfolder in the repository. Load the pipeline again with DiffusionPipeline.from_pretrained().
pipeline = DiffusionPipeline.from_pretrained("your-namespace/my-qwen-image")
隐私
在 push_to_hub() 中设置 private=True,可将模型、调度器或流水线文件设为私有。
controlnet.push_to_hub("my-controlnet-model-private", private=True)
传入 create_pr=True 可在现有的 Hub 仓库上创建一个 pull request,而不是直接推送到默认分支。
模型和流水线在推送时同样接受 variant= 参数,以便指定诸如 fp16 这样的命名权重文件。调度器不使用 variant。
私有仓库仅对您可见。其他用户无法克隆该仓库,且该仓库不会出现在搜索结果中。即使用户拥有您私有仓库的 URL,他们也会收到 404 - Sorry, we can't find the page you are looking for。您必须 登录 才能从私有仓库加载模型。
Xet Storage Details
- Size:
- 4.54 kB
- Xet hash:
- 2266c1e03de34c999dc02ad0786d7a4771feb69fbbf715348716f51ba637dff8
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.