Buckets:

mishig's picture
|
download
raw
5.07 kB
# Chia sẻ pipeline và mô hình
Chia sẻ các pipeline, model và scheduler của bạn lên Hub bằng [PushToHubMixin](/docs/diffusers/v0.43.0/vi/api/schedulers/overview#diffusers.utils.PushToHubMixin). Mixin này:
1. tạo một kho trên Hub
2. lưu tệp mô hình, trình lập lịch hoặc pipeline của bạn để có thể tải lại sau
3. tải lên Hub thư mục chứa các tệp này
Đăng nhập vào tài khoản Hugging Face của bạn bằng [token](https://huggingface.co/settings/tokens) truy cập của bạn.
```py
from huggingface_hub import notebook_login
notebook_login()
```
```bash
hf auth login
```
Đẩy lên namespace người dùng của bạn với một id ngắn (`"my-controlnet-model"`) hoặc lên một tổ chức với `"your-org/my-controlnet-model"`.
## Mô hình
Để đẩy một mô hình lên Hub, hãy gọi [push_to_hub()](/docs/diffusers/v0.43.0/vi/api/schedulers/overview#diffusers.utils.PushToHubMixin.push_to_hub) và chỉ định id kho chứa của mô hình.
```py
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")
```
Phương thức [push_to_hub()](/docs/diffusers/v0.43.0/vi/api/schedulers/overview#diffusers.utils.PushToHubMixin.push_to_hub) lưu tệp `config.json` của mô hình và trọng số được tự động lưu dưới dạng [file safetensors](./other-formats#safetensors).
Tải lại mô hình bằng [ControlNetModel.from_pretrained()](/docs/diffusers/v0.43.0/vi/api/models/overview#diffusers.ModelMixin.from_pretrained).
```py
model = ControlNetModel.from_pretrained("your-namespace/my-controlnet-model")
```
## Trình lập lịch
Để đẩy một scheduler lên Hub, hãy gọi [push_to_hub()](/docs/diffusers/v0.43.0/vi/api/schedulers/overview#diffusers.utils.PushToHubMixin.push_to_hub) và chỉ định repository id của scheduler.
```py
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")
```
Phương thức [push_to_hub()](/docs/diffusers/v0.43.0/vi/api/schedulers/overview#diffusers.utils.PushToHubMixin.push_to_hub) lưu tệp `scheduler_config.json` của trình lập lịch vào kho lưu trữ được chỉ định.
Tải lại trình lập lịch bằng [from_pretrained()](/docs/diffusers/v0.43.0/vi/api/schedulers/overview#diffusers.SchedulerMixin.from_pretrained).
```py
scheduler = DDIMScheduler.from_pretrained("your-namespace/my-ddim-scheduler")
```
## Pipeline
Để đẩy một pipeline lên Hub, hãy tải nó bằng [from_pretrained()](/docs/diffusers/v0.43.0/vi/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained), sau đó gọi [push_to_hub()](/docs/diffusers/v0.43.0/vi/api/schedulers/overview#diffusers.utils.PushToHubMixin.push_to_hub) với một repository id.
```py
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")
```
Phương thức [push_to_hub()](/docs/diffusers/v0.43.0/vi/api/schedulers/overview#diffusers.utils.PushToHubMixin.push_to_hub) lưu mỗi thành phần vào một thư mục con trong kho. Tải lại pipeline bằng [DiffusionPipeline.from_pretrained()](/docs/diffusers/v0.43.0/vi/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained).
```py
pipeline = DiffusionPipeline.from_pretrained("your-namespace/my-qwen-image")
```
## Quyền riêng tư
Đặt `private=True` trong [push_to_hub()](/docs/diffusers/v0.43.0/vi/api/schedulers/overview#diffusers.utils.PushToHubMixin.push_to_hub) để giữ các tệp của mô hình, trình lập lịch hoặc pipeline ở chế độ riêng tư.
```py
controlnet.push_to_hub("my-controlnet-model-private", private=True)
```
Truyền `create_pr=True` để mở một pull request trên một kho Hub hiện có thay vì đẩy trực tiếp lên nhánh mặc định.
Các mô hình và pipeline cũng chấp nhận `variant=` khi push nếu bạn muốn một tệp trọng số có tên cụ thể như `fp16`. Schedulers không sử dụng `variant`.
Kho lưu trữ riêng chỉ hiển thị cho bạn. Người dùng khác sẽ không thể clone kho lưu trữ và nó sẽ không xuất hiện trong kết quả tìm kiếm. Ngay cả khi một người dùng có URL của kho lưu trữ riêng của bạn, họ sẽ nhận được `404 - Sorry, we can't find the page you are looking for`. Bạn phải [đăng nhập](https://huggingface.co/docs/huggingface_hub/quick-start#login) để tải một model từ kho lưu trữ riêng.

Xet Storage Details

Size:
5.07 kB
·
Xet hash:
ffa5e73871bc544f3ba7e9c34e074c1f763c13005f5f2f0a4a6b1a9b10790309

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.