svanlin-tencent commited on
Commit
49597d5
·
verified ·
1 Parent(s): 046c4fd

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +119 -0
README.md ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: tencent-hunyuan-community
4
+ license_link: https://huggingface.co/Tencent-Hunyuan/HunyuanDiT/blob/main/LICENSE.txt
5
+ language:
6
+ - en
7
+ ---
8
+
9
+ # HunyuanDiT TensorRT Acceleration
10
+
11
+ Language: **English** | [**中文**](https://huggingface.co/Tencent-Hunyuan/TensorRT-libs/blob/main/README_zh.md)
12
+
13
+ We provide a TensorRT version of [HunyuanDiT](https://github.com/Tencent/HunyuanDiT) for inference acceleration
14
+ (faster than flash attention). One can convert the torch model to TensorRT model using the following steps based on
15
+ **TensorRT-10.1.0.27** and **cuda (11.7 or 11.8)**.
16
+
17
+ > ⚠️ Important Reminder (Suggestion for testing the TensorRT acceleration version):
18
+ > We recommend users to test the TensorRT version on NVIDIA GPUs with Compute Capability >= 8.0,(For example, RTX4090,
19
+ > RTX3090, H800, A10/A100/A800, etc.) you can query the Compute Capability corresponding to your GPU from
20
+ > [here](https://developer.nvidia.com/cuda-gpus#compute). For NVIDIA GPUs with Compute Capability < 8.0, if you want to
21
+ > try the TensorRT version, you may encounter errors that the TensorRT Engine file cannot be generated or the inference
22
+ > performance is poor, the main reason is that TensorRT does not support fused mha kernel on this architecture.
23
+
24
+ ## 🛠 Instructions
25
+
26
+ ### 1. Download dependencies from huggingface.
27
+
28
+ ```shell
29
+ cd HunyuanDiT
30
+ # Use the huggingface-cli tool to download the model.
31
+ huggingface-cli download Tencent-Hunyuan/TensorRT-libs --local-dir ./ckpts/t2i/model_trt
32
+ ```
33
+
34
+ ### 2. Install the TensorRT dependencies.
35
+
36
+ ```shell
37
+ # Extract and install the TensorRT dependencies.
38
+ sh trt/install.sh
39
+
40
+ # Set the TensorRT build environment variables. We provide a script to set up the environment.
41
+ source trt/activate.sh
42
+ ```
43
+
44
+ ### 3. Build the TensorRT engine.
45
+
46
+
47
+ #### Method 1: Use the prebuilt engine
48
+
49
+ We provide some prebuilt [TensorRT Engines](https://huggingface.co/Tencent-Hunyuan/TensorRT-engine), which need to be downloaded from Huggingface.
50
+
51
+ | Supported GPU | Remote Path |
52
+ |:----------------:|:---------------------------------:|
53
+ | GeForce RTX 3090 | `engines/RTX3090/model_onnx.plan` |
54
+ | GeForce RTX 4090 | `engines/RTX4090/model_onnx.plan` |
55
+ | A100 | `engines/A100/model_onnx.plan` |
56
+
57
+ Use the following command to download and place the engine in the specified location.
58
+
59
+ *Note: Please replace `<Remote Path>` with the corresponding remote path in the table above.*
60
+
61
+ ```shell
62
+ export REMOTE_PATH=<Remote Path>
63
+ huggingface-cli download Tencent-Hunyuan/TensorRT-engine ${REMOTE_PATH} ./ckpts/t2i/model_trt/engine/
64
+ ln -s ${REMOTE_PATH} ./ckpts/t2i/model_trt/engine/model_onnx.plan
65
+ ```
66
+
67
+ #### Method 2: Build your own engine
68
+
69
+ If you are using a different GPU, you can build the engine using the following command.
70
+
71
+ ##### Hunyuan-DiT v1.2
72
+
73
+ ```shell
74
+ # Build the TensorRT engine. By default, it will read the `ckpts` folder in the current directory.
75
+ sh trt/build_engine.sh
76
+ ```
77
+
78
+ ##### Using Previous versions, Hunyuan-DiT <= v1.1
79
+ ```shell
80
+ # v1.1
81
+ sh trt/build_engine.sh 1.1
82
+ # v1.0
83
+ sh trt/build_engine.sh 1.0
84
+ ```
85
+
86
+ Finally, if you see the output like `&&&& PASSED TensorRT.trtexec [TensorRT v10100]`, the engine is built successfully.
87
+
88
+ ### 4. Run the inference using the TensorRT model.
89
+
90
+ ```shell
91
+ # Important: If you have not activated the environment, please run the following command.
92
+ source trt/activate.sh
93
+
94
+ # Run the inference using the prompt-enhanced model + HunyuanDiT TensorRT model.
95
+ python sample_t2i.py --prompt "渔舟唱晚" --infer-mode trt
96
+
97
+ # Close prompt enhancement. (save GPU memory)
98
+ python sample_t2i.py --prompt "渔舟唱晚" --infer-mode trt --no-enhance
99
+ ```
100
+
101
+ ### 5. Notice
102
+
103
+ The TensorRT engine is designed to support following shapes of input for performance reasons.
104
+ In the future, we will verify and try to support arbitrary shapes.
105
+
106
+ ```python
107
+ STANDARD_SHAPE = [
108
+ [(1024, 1024), (1280, 1280)], # 1:1
109
+ [(1280, 960)], # 4:3
110
+ [(960, 1280)], # 3:4
111
+ [(1280, 768)], # 16:9
112
+ [(768, 1280)], # 9:16
113
+ ]
114
+ ```
115
+
116
+ ## ❓ Q&A
117
+
118
+ Please refer to the [Q&A](./QA.md) for more questions and answers about building the TensorRT Engine.
119
+