|
1 |
| -# FastDeploy Diffusion模型高性能部署 |
| 1 | +English | [简体中文](README_CN.md) |
| 2 | +# FastDeploy Diffusion Model High-Performance Deployment |
2 | 3 |
|
3 |
| -本部署示例使用⚡️`FastDeploy`在Huggingface团队[Diffusers](https://github.com/huggingface/diffusers)项目设计的`DiffusionPipeline`基础上,完成Diffusion模型的高性能部署。 |
| 4 | +This document completes the high-performance deployment of the Diffusion model with ⚡️`FastDeploy`, based on `DiffusionPipeline` in project [Diffusers](https://github.com/huggingface/diffusers) designed by Huggingface. |
4 | 5 |
|
5 |
| -### 部署模型准备 |
| 6 | +### Preperation for Deployment |
6 | 7 |
|
7 |
| -本示例需要使用训练模型导出后的部署模型。有两种部署模型的获取方式: |
| 8 | +This example needs the deployment model after exporting the training model. Here are two ways to obtain the deployment model: |
8 | 9 |
|
9 |
| -- 模型导出方式,可参考[模型导出文档](./export.md)导出部署模型。 |
10 |
| -- 下载部署模型。为了方便开发者快速测试本示例,我们已经将部分`Diffusion`模型预先导出,开发者只要下载模型就可以快速测试: |
| 10 | +- Methods for model export. Please refer to [Model Export](./export_EN.md) to export deployment model. |
| 11 | +- Download the deployment model. To facilitate developers to test the example, we have pre-exported some of the `Diffusion` models, so you can just download models and test them quickly: |
11 | 12 |
|
12 |
| -| 模型 | Scheduler | |
| 13 | +| Model | Scheduler | |
13 | 14 | |----------|--------------|
|
14 | 15 | | [CompVis/stable-diffusion-v1-4](https://bj.bcebos.com/fastdeploy/models/stable-diffusion/CompVis/stable-diffusion-v1-4.tgz) | PNDM |
|
15 | 16 | | [runwayml/stable-diffusion-v1-5](https://bj.bcebos.com/fastdeploy/models/stable-diffusion/runwayml/stable-diffusion-v1-5.tgz) | EulerAncestral |
|
16 | 17 |
|
17 |
| -## 环境依赖 |
| 18 | +## Environment Dependency |
18 | 19 |
|
19 |
| -在示例中使用了PaddleNLP的CLIP模型的分词器,所以需要执行以下命令安装依赖。 |
| 20 | +In the example, the word splitter in CLIP model of PaddleNLP is required, so you need to run the following line to install the dependency. |
20 | 21 |
|
21 | 22 | ```shell
|
22 | 23 | pip install paddlenlp paddlepaddle-gpu
|
23 | 24 | ```
|
24 | 25 |
|
25 |
| -### 快速体验 |
| 26 | +### Quick Experience |
26 | 27 |
|
27 |
| -我们经过部署模型准备,可以开始进行测试。下面将指定模型目录以及推理引擎后端,运行`infer.py`脚本,完成推理。 |
| 28 | +We are ready to start testing after model deployment. Here we will specify the model directory as well as the inference engine backend, and run the `infer.py` script to complete the inference. |
28 | 29 |
|
29 | 30 | ```
|
30 | 31 | python infer.py --model_dir stable-diffusion-v1-4/ --scheduler "pndm" --backend paddle
|
31 | 32 | ```
|
32 | 33 |
|
33 |
| -得到的图像文件为fd_astronaut_rides_horse.png。生成的图片示例如下(每次生成的图片都不相同,示例仅作参考): |
| 34 | +The image file is fd_astronaut_rides_horse.png. An example of the generated image is as follows (the generated image is different each time, the example is for reference only): |
34 | 35 |
|
35 | 36 | 
|
36 | 37 |
|
37 |
| -如果使用stable-diffusion-v1-5模型,则可执行以下命令完成推理: |
| 38 | +If the stable-diffusion-v1-5 model is used, you can run these to complete the inference. |
38 | 39 |
|
39 | 40 | ```
|
40 |
| -# GPU上推理 |
| 41 | +# Inference on GPU |
41 | 42 | python infer.py --model_dir stable-diffusion-v1-5/ --scheduler "euler_ancestral" --backend paddle
|
42 | 43 |
|
43 |
| -# 在昆仑芯XPU上推理 |
| 44 | +# Inference on KunlunXin XPU |
44 | 45 | python infer.py --model_dir stable-diffusion-v1-5/ --scheduler "euler_ancestral" --backend paddle-kunlunxin
|
45 | 46 | ```
|
46 | 47 |
|
47 |
| -#### 参数说明 |
| 48 | +#### Parameters |
48 | 49 |
|
49 |
| -`infer.py` 除了以上示例的命令行参数,还支持更多命令行参数的设置。以下为各命令行参数的说明。 |
| 50 | +`infer.py` supports more command line parameters than the above example. The following is a description of each command line parameter. |
50 | 51 |
|
51 |
| -| 参数 |参数说明 | |
| 52 | +| Parameter |Description | |
52 | 53 | |----------|--------------|
|
53 |
| -| --model_dir | 导出后模型的目录。 | |
54 |
| -| --model_format | 模型格式。默认为`'paddle'`,可选列表:`['paddle', 'onnx']`。 | |
55 |
| -| --backend | 推理引擎后端。默认为`paddle`,可选列表:`['onnx_runtime', 'paddle', 'paddle-kunlunxin']`,当模型格式为`onnx`时,可选列表为`['onnx_runtime']`。 | |
56 |
| -| --scheduler | StableDiffusion 模型的scheduler。默认为`'pndm'`。可选列表:`['pndm', 'euler_ancestral']`,StableDiffusio模型对应的scheduler可参考[ppdiffuser模型列表](https://github.com/PaddlePaddle/PaddleNLP/tree/develop/ppdiffusers/examples/textual_inversion)。| |
57 |
| -| --unet_model_prefix | UNet模型前缀。默认为`unet`。 | |
58 |
| -| --vae_model_prefix | VAE模型前缀。默认为`vae_decoder`。 | |
59 |
| -| --text_encoder_model_prefix | TextEncoder模型前缀。默认为`text_encoder`。 | |
60 |
| -| --inference_steps | UNet模型运行的次数,默认为100。 | |
61 |
| -| --image_path | 生成图片的路径。默认为`fd_astronaut_rides_horse.png`。 | |
62 |
| -| --device_id | gpu设备的id。若`device_id`为-1,视为使用cpu推理。 | |
63 |
| -| --use_fp16 | 是否使用fp16精度。默认为`False`。使用tensorrt或者paddle-tensorrt后端时可以设为`True`开启。 | |
| 54 | +| --model_dir | Directory of the exported model. | |
| 55 | +| --model_format | Model format. Default is `'paddle'`, optional list: `['paddle', 'onnx']`. | |
| 56 | +| --backend | Inference engine backend. Default is`paddle`, optional list: `['onnx_runtime', 'paddle', 'paddle-kunlunxin']`, when the model format is `onnx`, optional list is`['onnx_runtime']`. | |
| 57 | +| --scheduler | Scheduler in StableDiffusion model. Default is`'pndm'`, optional list `['pndm', 'euler_ancestral']`. The scheduler corresponding to the StableDiffusio model can be found in [ppdiffuser model list](https://github.com/PaddlePaddle/PaddleNLP/tree/develop/ppdiffusers/examples/textual_inversion).| |
| 58 | +| --unet_model_prefix | UNet model prefix, default is `unet`. | |
| 59 | +| --vae_model_prefix | VAE model prefix, defalut is `vae_decoder`. | |
| 60 | +| --text_encoder_model_prefix | TextEncoder model prefix, default is `text_encoder`. | |
| 61 | +| --inference_steps | Running times of UNet model, default is 100. | |
| 62 | +| --image_path | Path to the generated images, defalut is `fd_astronaut_rides_horse.png`. | |
| 63 | +| --device_id | gpu id. If `device_id` is -1, cpu is used for inference. | |
| 64 | +| --use_fp16 | Indicates if fp16 is used, default is `False`. Can be set to `True` when using tensorrt or paddle-tensorrt backend. | |
0 commit comments