Files
FastDeploy/examples/multimodal/stable_diffusion/README_CN.md
charl-u 1135d33dd7 [Doc]Add English version of documents in examples/ (#1042)
* 第一次提交

* 补充一处漏翻译

* deleted:    docs/en/quantize.md

* Update one translation

* Update en version

* Update one translation in code

* Standardize one writing

* Standardize one writing

* Update some en version

* Fix a grammer problem

* Update en version for api/vision result

* Merge branch 'develop' of https://github.com/charl-u/FastDeploy into develop

* Checkout the link in README in vision_results/ to the en documents

* Modify a title

* Add link to serving/docs/

* Finish translation of demo.md

* Update english version of serving/docs/

* Update title of readme

* Update some links

* Modify a title

* Update some links

* Update en version of java android README

* Modify some titles

* Modify some titles

* Modify some titles

* modify article to document

* update some english version of documents in examples

* Add english version of documents in examples/visions

* Sync to current branch

* Add english version of documents in examples
2023-01-06 09:35:12 +08:00

3.4 KiB
Raw Blame History

简体中文 English

FastDeploy Diffusion模型高性能部署

本部署示例使用FastDeploy在Huggingface团队Diffusers项目设计的DiffusionPipeline基础上完成Diffusion模型的高性能部署。

部署模型准备

本示例需要使用训练模型导出后的部署模型。有两种部署模型的获取方式:

  • 模型导出方式,可参考模型导出文档导出部署模型。
  • 下载部署模型。为了方便开发者快速测试本示例,我们已经将部分Diffusion模型预先导出,开发者只要下载模型就可以快速测试:
模型 Scheduler
CompVis/stable-diffusion-v1-4 PNDM
runwayml/stable-diffusion-v1-5 EulerAncestral

环境依赖

在示例中使用了PaddleNLP的CLIP模型的分词器所以需要执行以下命令安装依赖。

pip install paddlenlp paddlepaddle-gpu

快速体验

我们经过部署模型准备,可以开始进行测试。下面将指定模型目录以及推理引擎后端,运行infer.py脚本,完成推理。

python infer.py --model_dir stable-diffusion-v1-4/ --scheduler "pndm" --backend paddle

得到的图像文件为fd_astronaut_rides_horse.png。生成的图片示例如下每次生成的图片都不相同示例仅作参考

fd_astronaut_rides_horse.png

如果使用stable-diffusion-v1-5模型则可执行以下命令完成推理

# GPU上推理
python infer.py --model_dir stable-diffusion-v1-5/ --scheduler "euler_ancestral" --backend paddle

# 在昆仑芯XPU上推理
python infer.py --model_dir stable-diffusion-v1-5/ --scheduler "euler_ancestral" --backend paddle-kunlunxin

参数说明

infer.py 除了以上示例的命令行参数,还支持更多命令行参数的设置。以下为各命令行参数的说明。

参数 参数说明
--model_dir 导出后模型的目录。
--model_format 模型格式。默认为'paddle',可选列表:['paddle', 'onnx']
--backend 推理引擎后端。默认为paddle,可选列表:['onnx_runtime', 'paddle', 'paddle-kunlunxin'],当模型格式为onnx时,可选列表为['onnx_runtime']
--scheduler StableDiffusion 模型的scheduler。默认为'pndm'。可选列表:['pndm', 'euler_ancestral']StableDiffusio模型对应的scheduler可参考ppdiffuser模型列表
--unet_model_prefix UNet模型前缀。默认为unet
--vae_model_prefix VAE模型前缀。默认为vae_decoder
--text_encoder_model_prefix TextEncoder模型前缀。默认为text_encoder
--inference_steps UNet模型运行的次数默认为100。
--image_path 生成图片的路径。默认为fd_astronaut_rides_horse.png
--device_id gpu设备的id。若device_id为-1视为使用cpu推理。
--use_fp16 是否使用fp16精度。默认为False。使用tensorrt或者paddle-tensorrt后端时可以设为True开启。