-
Notifications
You must be signed in to change notification settings - Fork 6.4k
[docs] Add xDiT in section optimization #9365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| # xDiT | ||
|
|
||
| xDiT is an inference engine designed for the parallel deployment of DiTs on large scale. xDiT provides a suite of efficient parallel approaches for Diffusion Models, as well as GPU kernel accelerations. | ||
|
|
||
| <div class="flex justify-center"> | ||
| <img src="https://github.com/xdit-project/xDiT/raw/main/assets/methods/xdit_overview.png"> | ||
| </div> | ||
| You can install xDiT using the following command: | ||
|
|
||
|
|
||
| ```bash | ||
| pip install xfuser | ||
| ``` | ||
|
|
||
| Here's an example of using xDiT to accelerate the inference of a diffusers model: | ||
stevhliu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```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, | ||
| torch_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), | ||
| ) | ||
|
|
||
| + if input_config.output_type == "pil": | ||
| + pipe.save("results", "stable_diffusion_3") | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
|
|
||
| ``` | ||
|
|
||
| As you can see, we only need to use xFuserArgs from xDiT to get configuration parameters, and pass these parameters along with the pipeline object from the diffusers library into xDiTParallel to complete the parallelization of a specific pipeline in diffusers. | ||
stevhliu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| xDiT runtime parameters can be viewed in the command line using -h, and detailed introductions can also be found on the [xDiT Github page](https://github.com/xdit-project/xDiT?tab=readme-ov-file#2-usage). | ||
stevhliu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| xDiT needs to be launched using torchrun to support its multi-node, multi-GPU parallel capabilities. For example, the following command can be used for 8-GPU parallel inference: | ||
|
|
||
| ```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 | ||
| ``` | ||
|
|
||
| # Supported Models | ||
stevhliu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| We have supported a subset of diffusers models in xDiT, including the most popular models such as Flux.1, Stable Diffusion 3, etc. The latest supported models can be found on https://github.com/xdit-project/xDiT?tab=readme-ov-file#-supported-dits | ||
stevhliu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Benchmark | ||
|
|
||
| We tested different models on various machines. Here is some of the data: | ||
stevhliu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| ## Flux.1-schnell | ||
stevhliu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * Flux.1-schnell with 4 steps on 8 * L40 | ||
stevhliu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <div class="flex justify-center"> | ||
| <img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/flux/Flux-2k-L40.png"> | ||
| </div> | ||
|
|
||
|
|
||
| * Flux.1-schnell with 4 steps on 8 * A100 | ||
| <div class="flex justify-center"> | ||
| <img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/flux/Flux-2K-A100.png"> | ||
| </div> | ||
|
|
||
| ## Stable Diffusion 3 | ||
| * Stable Diffusion 3 with 20 steps on 8 * L40 | ||
| <div class="flex justify-center"> | ||
| <img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/sd3/L40-SD3.png"> | ||
| </div> | ||
|
|
||
| * Stable Diffusion 3 with 20 steps on 8 * A100 | ||
| <div class="flex justify-center"> | ||
| <img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/sd3/A100-SD3.png"> | ||
| </div> | ||
|
|
||
| ## HunyuanDiT | ||
| * HunyuanDiT with 20 steps on 8 * L40 | ||
| <div class="flex justify-center"> | ||
| <img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/hunuyuandit/L40-HunyuanDiT.png"> | ||
| </div> | ||
|
|
||
| * HunyuanDiT with 50 steps on 8 * A100 | ||
| <div class="flex justify-center"> | ||
| <img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/hunuyuandit/A100-HunyuanDiT.png"> | ||
| </div> | ||
|
|
||
| * HunyuanDiT with 50 steps on 4 * T4 | ||
| <div class="flex justify-center"> | ||
| <img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/hunuyuandit/T4-HunyuanDiT.png"> | ||
| </div> | ||
|
|
||
| More detailed performance metric can be found on our [github page](https://github.com/xdit-project/xDiT?tab=readme-ov-file#perf). | ||
|
|
||
| # Reference | ||
Eigensystem marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| [xDiT-project](https://github.com/xdit-project/xDiT) | ||
|
|
||
| [USP: A Unified Sequence Parallelism Approach for Long Context Generative AI](https://arxiv.org/abs/2405.07719) | ||
|
|
||
| [PipeFusion: Displaced Patch Pipeline Parallelism for Inference of Diffusion Transformer Models](https://arxiv.org/abs/2405.14430) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.