Buckets:

mishig's picture
|
download
raw
4.8 kB
# xDiT
[xDiT](https://github.com/xdit-project/xDiT) là một engine suy luận được thiết kế cho việc triển khai song song quy mô lớn của Diffusion Transformers (DiTs). xDiT cung cấp một bộ các phương pháp song song hiệu quả cho Diffusion Models, cũng như các tăng tốc kernel GPU.
Có bốn phương pháp song song được hỗ trợ trong xDiT, bao gồm [Unified Sequence Parallelism](https://huggingface.co/papers/2405.07719), [PipeFusion](https://huggingface.co/papers/2405.14430), song song CFG và song song dữ liệu. Bốn phương pháp song song trong xDiT có thể được cấu hình theo cách lai, tối ưu hóa các mẫu giao tiếp để phù hợp nhất với phần cứng mạng nền tảng.
Tối ưu hóa độc lập với song song hóa tập trung vào việc tăng tốc hiệu năng của một GPU đơn. Ngoài việc sử dụng các thư viện tối ưu hóa Attention phổ biến, chúng tôi tận dụng các công nghệ tăng tốc biên dịch như torch.compile và onediff.
Tổng quan về xDiT được trình bày như sau.
Bạn có thể cài đặt xDiT bằng lệnh sau:
```bash
pip install xfuser
```
Dưới đây là một ví dụ về việc sử dụng xDiT để tăng tốc suy luận của một mô hình Diffusers.
```diff
import torch
from diffusers import StableDiffusion3Pipeline
from xfuser import xFuserArgs, xDiTParallel
from xfuser.config import FlexibleArgumentParser
from xfuser.core.distributed import get_world_group
def main():
+ parser = FlexibleArgumentParser(description="xFuser Arguments")
+ args = xFuserArgs.add_cli_args(parser).parse_args()
+ engine_args = xFuserArgs.from_cli_args(args)
+ engine_config, input_config = engine_args.create_config()
local_rank = get_world_group().local_rank
pipe = StableDiffusion3Pipeline.from_pretrained(
pretrained_model_name_or_path=engine_config.model_config.model,
dtype=torch.float16,
).to(f"cuda:{local_rank}")
# do anything you want with pipeline here
+ pipe = xDiTParallel(pipe, engine_config, input_config)
pipe(
height=input_config.height,
width=input_config.height,
prompt=input_config.prompt,
num_inference_steps=input_config.num_inference_steps,
output_type=input_config.output_type,
generator=torch.Generator(device="cuda").manual_seed(input_config.seed), # or "mps", "xpu", "cpu"
)
+ if input_config.output_type == "pil":
+ pipe.save("results", "stable_diffusion_3")
if __name__ == "__main__":
main()
```
Như bạn có thể thấy, chúng ta chỉ cần sử dụng xFuserArgs từ xDiT để lấy các tham số cấu hình, sau đó truyền các tham số này cùng với đối tượng pipeline từ thư viện Diffusers vào xDiTParallel để hoàn tất việc song song hóa một pipeline cụ thể trong Diffusers.
Các tham số runtime của xDiT có thể được xem trên dòng lệnh bằng cách sử dụng `-h`, và bạn có thể tham khảo ví dụ [sử dụng](https://github.com/xdit-project/xDiT?tab=readme-ov-file#2-usage) này để biết thêm chi tiết.
xDiT cần được khởi chạy bằng torchrun để hỗ trợ khả năng song song đa nút, đa GPU. Ví dụ, lệnh sau có thể được sử dụng cho suy luận song song 8-GPU:
```bash
torchrun --nproc_per_node=8 ./inference.py --model models/FLUX.1-dev --data_parallel_degree 2 --ulysses_degree 2 --ring_degree 2 --prompt "A snowy mountain" "A small dog" --num_inference_steps 50
```
## Các mô hình được hỗ trợ
Một tập con các mô hình Diffusers được hỗ trợ trong xDiT, chẳng hạn như Flux.1, Stable Diffusion 3, v.v. Các mô hình được hỗ trợ mới nhất có thể được tìm thấy [tại đây](https://github.com/xdit-project/xDiT?tab=readme-ov-file#-supported-dits).
## Đánh giá hiệu năng
Chúng tôi đã kiểm tra các mô hình khác nhau trên nhiều máy khác nhau, và đây là một số dữ liệu benchmark.
### Flux.1-schnell
### Stable Diffusion 3
### HunyuanDiT
Các chỉ số hiệu suất chi tiết hơn có thể được tìm thấy trên [trang github](https://github.com/xdit-project/xDiT?tab=readme-ov-file#perf) của chúng tôi.
## Tham khảo
[xDiT-project](https://github.com/xdit-project/xDiT)
[USP: Một phương pháp song song hóa chuỗi thống nhất cho AI tạo sinh ngữ cảnh dài](https://huggingface.co/papers/2405.07719)
[PipeFusion: Song song hóa pipeline theo từng khối bị dịch chuyển cho suy luận các mô hình Diffusion Transformer](https://huggingface.co/papers/2405.14430)

Xet Storage Details

Size:
4.8 kB
·
Xet hash:
8ed09d75d9155909b162bd85570a56919b8af51e98d5bf64b98cc741269077d4

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