
* Add stable diffusion model base on fastdeploy * Add sd infer * pipelines->multimodal * add create_ort_runtime * use fp16 input * fix pil * Add optimize unet model * add hf license * Add workspace args * Add profile func * Add schedulers * usrelace torch.Tenosr byp.ndarray * Add readme * Add trt shape setting * add dynamic shape * Add dynamic shape for stable diffusion * fix max shape setting * rename tensorrt file suffix * update dynamic shape setting * Add scheduler output * Add inference_steps and benchmark steps * add diffuser benchmark * Add paddle infer script * Rename 1 * Rename infer.py to torch_onnx_infer.py * Add export torch to onnx model * renmove export model * Add paddle export model for diffusion * Fix export model * mv torch onnx infer to infer * Fix export model * Fix infer * modif create_trt_runtime create_ort_runtime * update export torch * update requirements * add paddle inference backend * Fix unet pp run * remove print * Add paddle model export and infer * Add device id * remove profile to utils * Add -1 device id * Add safety checker args * remove safety checker temporarily * Add export model description * Add predict description * Fix readme * Fix device_id description * add timestep shape * add use fp16 precision * move use gpu * Add EulerAncestralDiscreteScheduler * Use EulerAncestralDiscreteScheduler with v1-5 model * Add export model readme * Add link of exported model * Update scheduler on README * Addd stable-diffusion-v1-5
5.1 KiB
Diffusion模型导出教程
本项目支持两种模型导出方式:PPDiffusers模型导出以及Diffusers模型导出。下面分别介绍这两种模型导出方式。
PPDiffusers 模型导出
PPDiffusers是一款支持跨模态(如图像与语音)训练和推理的扩散模型(Diffusion Model)工具箱,其借鉴了🤗 Huggingface团队的Diffusers的优秀设计,并且依托PaddlePaddle框架和PaddleNLP自然语言处理库。下面介绍如何使用FastDeploy将PPDiffusers提供的Diffusion模型进行高性能部署。
依赖安装
模型导出需要依赖paddlepaddle
, paddlenlp
以及ppdiffusers
,可使用pip
执行下面的命令进行快速安装。
pip install -r requirements_paddle.txt
模型导出
注意:模型导出过程中,需要下载StableDiffusion模型。为了使用该模型与权重,你必须接受该模型所要求的License,请访问HuggingFace的model card, 仔细阅读里面的License,然后签署该协议。
Tips: Stable Diffusion是基于以下的License: The CreativeML OpenRAIL M license is an Open RAIL M license, adapted from the work that BigScience and the RAIL Initiative are jointly carrying in the area of responsible AI licensing. See also the article about the BLOOM Open RAIL license on which this license is based.
可执行以下命令行完成模型导出。
python export_model.py --pretrained_model_name_or_path CompVis/stable-diffusion-v1-4 --output_path stable-diffusion-v1-4
输出的模型目录结构如下:
stable-diffusion-v1-4/
├── text_encoder
│ ├── inference.pdiparams
│ ├── inference.pdiparams.info
│ └── inference.pdmodel
├── unet
│ ├── inference.pdiparams
│ ├── inference.pdiparams.info
│ └── inference.pdmodel
└── vae_decoder
├── inference.pdiparams
├── inference.pdiparams.info
└── inference.pdmodel
参数说明
export_model.py
各命令行参数的说明。
参数 | 参数说明 |
---|---|
--pretrained_model_name_or_path |
ppdiffuers提供的diffusion预训练模型。默认为:"CompVis/stable-diffusion-v1-4 "。更多diffusion预训练模型可参考ppdiffuser模型列表。 |
--output_path | 导出的模型目录。 |
Diffusers 模型导出
Diffusers是一款由HuggingFace打造的支持跨模态(如图像与语音)训练和推理的扩散模型(Diffusion Model)工具箱。其底层的模型代码提供PyTorch实现的版本以及Flax实现的版本两种版本。本示例将介绍如何使用FastDeploy将PyTorch实现的Diffusion模型进行高性能部署。
依赖安装
模型导出需要依赖onnx
, torch
, diffusers
以及transformers
,可使用pip
执行下面的命令进行快速安装。
pip install -r requirements_torch.txt
模型导出
注意:模型导出过程中,需要下载StableDiffusion模型。为了使用该模型与权重,你必须接受该模型所要求的License,并且获取HF Hub授予的Token。请访问HuggingFace的model card, 仔细阅读里面的License,然后签署该协议。
Tips: Stable Diffusion是基于以下的License: The CreativeML OpenRAIL M license is an Open RAIL M license, adapted from the work that BigScience and the RAIL Initiative are jointly carrying in the area of responsible AI licensing. See also the article about the BLOOM Open RAIL license on which this license is based.
若第一次导出模型,需要先登录HuggingFace客户端。执行以下命令进行登录:
huggingface-cli login
完成登录后,执行以下命令行完成模型导出。
python export_torch_to_onnx_model.py --pretrained_model_name_or_path CompVis/stable-diffusion-v1-4 --output_path torch_diffusion_model
输出的模型目录结构如下:
torch_diffusion_model/
├── text_encoder
│ └── inference.onnx
├── unet
│ └── inference.onnx
└── vae_decoder
└── inference.onnx
参数说明
export_torch_to_onnx_model.py
各命令行参数的说明。
参数 | 参数说明 |
---|---|
--pretrained_model_name_or_path |
ppdiffuers提供的diffusion预训练模型。默认为:"CompVis/stable-diffusion-v1-4 "。更多diffusion预训练模型可参考HuggingFace模型列表说明。 |
--output_path | 导出的模型目录。 |