Diffusers documentation

파이프라인 및 모델 공유

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.43.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

파이프라인 및 모델 공유

PushToHubMixin를 사용하여 Hub에 파이프라인, 모델, 스케줄러를 공유할 수 있습니다. 이 믹신은 다음과 같은 기능을 제공합니다:

  1. Hub에 저장소를 생성합니다
  2. 모델, 스케줄러 또는 파이프라인 파일을 저장하여 나중에 다시 로드할 수 있도록 합니다
  3. 이 파일들이 포함된 폴더를 Hub에 업로드합니다

액세스 token으로 Hugging Face 계정에 로그인하세요.

노트북
hf CLI
from huggingface_hub import notebook_login

notebook_login()

짧은 id("my-controlnet-model")를 사용하여 사용자 네임스페이스에 push하거나 "your-org/my-controlnet-model" 형식으로 org에 push할 수 있습니다.

모델

모델을 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를 엽니다.

모델과 파이프라인도 fp16과 같은 이름이 지정된 가중치 파일을 원할 경우 push 시 variant=를 지원합니다. 스케줄러는 variant를 사용하지 않습니다.

Private repositories는 사용자 본인에게만 표시됩니다. 다른 사용자는 해당 저장소를 clone할 수 없으며 검색 결과에도 표시되지 않습니다. 사용자가 private repository의 URL을 가지고 있더라도 404 - Sorry, we can't find the page you are looking for를 받게 됩니다. private repository에서 모델을 로드하려면 로그인 상태여야 합니다.

Update on GitHub