Skip to content
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

fix export and inference bug for stable diffusion #296

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ppdiffusers/deploy/export_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def convert_ppdiffusers_pipeline_to_fastdeploy_pipeline(
pipeline = StableDiffusionPipeline.from_pretrained(
model_path, unet=unet_model, safety_checker=None, feature_extractor=None
)
# make sure we disable xformers
pipeline.disable_xformers_memory_efficient_attention()
pipeline.unet.set_default_attn_processor()
pipeline.vae.set_default_attn_processor()
output_path = Path(output_path)
# calculate latent's H and W
latent_height = height // 8 if height is not None else None
Expand Down
23 changes: 15 additions & 8 deletions ppdiffusers/deploy/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,13 @@ def create_paddle_inference_runtime(
disable_paddle_pass=[],
paddle_stream=None,
workspace=None,
show_log=False
):
assert not use_fp16 or not use_bf16, "use_fp16 and use_bf16 are mutually exclusive"
option = fd.RuntimeOption()
option.use_paddle_backend()
if show_log:
option.enable_paddle_log_info()
if device_id == -1:
option.use_cpu()
else:
Expand Down Expand Up @@ -378,6 +381,15 @@ def main(args):
elif args.backend == "paddle" or args.backend == "paddle_tensorrt":
args.use_trt = args.backend == "paddle_tensorrt"
runtime_options = dict(
unet=create_paddle_inference_runtime(
use_trt=args.use_trt,
dynamic_shape=unet_dynamic_shape,
use_fp16=args.use_fp16,
use_bf16=args.use_bf16,
device_id=args.device_id,
paddle_stream=paddle_stream,
workspace=10*1024*1024*1024
),
text_encoder=create_paddle_inference_runtime(
use_trt=args.use_trt,
dynamic_shape=text_encoder_dynamic_shape,
Expand All @@ -386,6 +398,7 @@ def main(args):
device_id=args.device_id,
disable_paddle_trt_ops=["arg_max", "range", "lookup_table_v2"],
paddle_stream=paddle_stream,
workspace=10*1024*1024*1024
),
vae_encoder=create_paddle_inference_runtime(
use_trt=args.use_trt,
Expand All @@ -394,6 +407,7 @@ def main(args):
use_bf16=args.use_bf16,
device_id=args.device_id,
paddle_stream=paddle_stream,
workspace=10*1024*1024*1024
),
vae_decoder=create_paddle_inference_runtime(
use_trt=args.use_trt,
Expand All @@ -402,14 +416,7 @@ def main(args):
use_bf16=args.use_bf16,
device_id=args.device_id,
paddle_stream=paddle_stream,
),
unet=create_paddle_inference_runtime(
use_trt=args.use_trt,
dynamic_shape=unet_dynamic_shape,
use_fp16=args.use_fp16,
use_bf16=args.use_bf16,
device_id=args.device_id,
paddle_stream=paddle_stream,
workspace=10*1024*1024*1024
),
)
pipe = FastDeployStableDiffusionMegaPipeline.from_pretrained(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def __call__(

unet_inputs = dict(
sample=latent_model_input,
timestep=t,
timestep=paddle.to_tensor(t).reshape([1,]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个应该没有改全,后续需要把这些0d tensor啥的都改成1d

encoder_hidden_states=prompt_embeds,
infer_op=infer_op_dict.get("unet", None),
output_shape=latent_model_input.shape,
Expand Down