-
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 3 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,122 @@ | ||
| # xDiT | ||
|
|
||
| [xDiT](https://github.com/xdit-project/xDiT) is an inference engine designed for the large scale parallel deployment of Diffusion Transformers (DiTs). xDiT provides a suite of efficient parallel approaches for Diffusion Models, as well as GPU kernel accelerations. | ||
|
|
||
| There are four parallel methods supported in xDiT, including [Unified Sequence Parallelism](https://arxiv.org/abs/2405.07719), [PipeFusion](https://arxiv.org/abs/2405.14430), CFG parallelism and data parallelism. The four parallel methods in xDiT can be configured in a hybrid manner, optimizing communication patterns to best suit the underlying network hardware. | ||
|
|
||
| Optimization orthogonal to parallelization focuses on accelerating single GPU performance. In addition to utilizing well-known Attention optimization libraries, we leverage compilation acceleration technologies such as torch.compile and onediff. | ||
|
|
||
| The overview of xDiT is shown as follows. | ||
|
|
||
| <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 inference of a Diffusers model. | ||
|
|
||
| ```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. | ||
|
|
||
| xDiT runtime parameters can be viewed in the command line using `-h`, and you can refer to this [usage](https://github.com/xdit-project/xDiT?tab=readme-ov-file#2-usage) example for more details. | ||
|
|
||
| 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 | ||
|
|
||
| A subset of Diffusers models are supported in xDiT, such as Flux.1, Stable Diffusion 3, etc. The latest supported models can be found [here](https://github.com/xdit-project/xDiT?tab=readme-ov-file#-supported-dits). | ||
|
|
||
| ## Benchmark | ||
| We tested different models on various machines, and here is some of the benchmark data. | ||
|
|
||
|
|
||
| ### Flux.1-schnell | ||
| <div class="flex justify-center"> | ||
| <img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/flux/Flux-2k-L40.png"> | ||
| </div> | ||
|
|
||
|
|
||
| <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 | ||
| <div class="flex justify-center"> | ||
| <img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/sd3/L40-SD3.png"> | ||
| </div> | ||
|
|
||
| <div class="flex justify-center"> | ||
| <img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/sd3/A100-SD3.png"> | ||
| </div> | ||
|
|
||
| ### HunyuanDiT | ||
| <div class="flex justify-center"> | ||
| <img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/hunuyuandit/L40-HunyuanDiT.png"> | ||
| </div> | ||
|
|
||
| <div class="flex justify-center"> | ||
| <img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/hunuyuandit/A100-HunyuanDiT.png"> | ||
| </div> | ||
|
|
||
| <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.